llvm.org GIT mirror llvm / 753f326
Fix LLVM target initialization to deal with sociopathic outside projects that like to randomly define things like "X86", regenerate autoconf bits and update cmake. Fixes PR7852. Patch by Xerxes Rånby! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112499 91177308-0d34-0410-b5e6-96231b3b80d8 Eric Christopher 8 years ago
9 changed file(s) with 77 addition(s) and 48 deletion(s). Raw diff Collapse all Expand all
595595 # If so, define LLVM_NATIVE_ARCH to that LLVM target.
596596 for a_target in $TARGETS_TO_BUILD; do
597597 if test "$a_target" = "$LLVM_NATIVE_ARCH"; then
598 LLVM_NATIVE_ARCHTARGET="${LLVM_NATIVE_ARCH}Target"
599 AC_DEFINE_UNQUOTED(LLVM_NATIVE_ARCHNAME,$LLVM_NATIVE_ARCH,
600 [Short LLVM architecture name for the native architecture, if available])
601 AC_DEFINE_UNQUOTED(LLVM_NATIVE_ARCH,$LLVM_NATIVE_ARCHTARGET,
598 AC_DEFINE_UNQUOTED(LLVM_NATIVE_ARCH, $LLVM_NATIVE_ARCH,
602599 [LLVM architecture name for the native architecture, if available])
600 LLVM_NATIVE_TARGET="LLVMInitialize${LLVM_NATIVE_ARCH}Target"
601 LLVM_NATIVE_TARGETINFO="LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo"
602 LLVM_NATIVE_ASMPRINTER="LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter"
603 AC_DEFINE_UNQUOTED(LLVM_NATIVE_TARGET, $LLVM_NATIVE_TARGET,
604 [LLVM name for the native Target init function, if available])
605 AC_DEFINE_UNQUOTED(LLVM_NATIVE_TARGETINFO, $LLVM_NATIVE_TARGETINFO,
606 [LLVM name for the native TargetInfo init function, if available])
607 AC_DEFINE_UNQUOTED(LLVM_NATIVE_ASMPRINTER, $LLVM_NATIVE_ASMPRINTER,
608 [LLVM name for the native AsmPrinter init function, if available])
603609 fi
604610 done
605611
206206 endif ()
207207
208208 if (LLVM_NATIVE_ARCH)
209 set(LLVM_NATIVE_ARCHNAME ${LLVM_NATIVE_ARCH})
209 set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target)
210 set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo)
211 set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter)
210212 list(FIND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH} NATIVE_ARCH_IDX)
211213 if (NATIVE_ARCH_IDX EQUAL -1)
212214 message(STATUS
14131413 --enable-targets Build specific host targets: all or
14141414 target1,target2,... Valid targets are: host, x86,
14151415 x86_64, sparc, powerpc, alpha, arm, mips, spu,
1416 pic16, xcore, msp430, systemz, blackfin, cbe,
1417 and cpp (default=all)
1416 pic16, xcore, msp430, systemz, blackfin, cbe, and
1417 cpp (default=all)
14181418 --enable-cbe-printf-a Enable C Backend output with hex floating point via
14191419 %a (default is YES)
14201420 --enable-bindings Build specific language bindings:
50065006 # If so, define LLVM_NATIVE_ARCH to that LLVM target.
50075007 for a_target in $TARGETS_TO_BUILD; do
50085008 if test "$a_target" = "$LLVM_NATIVE_ARCH"; then
5009 LLVM_NATIVE_ARCHTARGET="${LLVM_NATIVE_ARCH}Target"
50105009
50115010 cat >>confdefs.h <<_ACEOF
5012 #define LLVM_NATIVE_ARCHNAME $LLVM_NATIVE_ARCH
5013 _ACEOF
5014
5011 #define LLVM_NATIVE_ARCH $LLVM_NATIVE_ARCH
5012 _ACEOF
5013
5014 LLVM_NATIVE_TARGET="LLVMInitialize${LLVM_NATIVE_ARCH}Target"
5015 LLVM_NATIVE_TARGETINFO="LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo"
5016 LLVM_NATIVE_ASMPRINTER="LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter"
50155017
50165018 cat >>confdefs.h <<_ACEOF
5017 #define LLVM_NATIVE_ARCH $LLVM_NATIVE_ARCHTARGET
5019 #define LLVM_NATIVE_TARGET $LLVM_NATIVE_TARGET
5020 _ACEOF
5021
5022
5023 cat >>confdefs.h <<_ACEOF
5024 #define LLVM_NATIVE_TARGETINFO $LLVM_NATIVE_TARGETINFO
5025 _ACEOF
5026
5027
5028 cat >>confdefs.h <<_ACEOF
5029 #define LLVM_NATIVE_ASMPRINTER $LLVM_NATIVE_ASMPRINTER
50185030 _ACEOF
50195031
50205032 fi
1137611388 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
1137711389 lt_status=$lt_dlunknown
1137811390 cat > conftest.$ac_ext <
11379 #line 11381 "configure"
11391 #line 11392 "configure"
1138011392 #include "confdefs.h"
1138111393
1138211394 #if HAVE_DLFCN_H
625625 /* Define to a function implementing strdup */
626626 #cmakedefine strdup ${strdup}
627627
628 /* Native LLVM architecture */
629 #cmakedefine LLVM_NATIVE_ARCH ${LLVM_NATIVE_ARCH}Target
630
631 /* Native LLVM architecture, short name */
632 #cmakedefine LLVM_NATIVE_ARCHNAME ${LLVM_NATIVE_ARCH}
628 /* LLVM architecture name for the native architecture, if available */
629 #cmakedefine LLVM_NATIVE_ARCH ${LLVM_NATIVE_ARCH}
630
631 /* LLVM name for the native Target init function, if available */
632 #cmakedefine LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target
633
634 /* LLVM name for the native TargetInfo init function, if available */
635 #cmakedefine LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo
636
637 /* LLVM name for the native AsmPrinter init function, if available */
638 #cmakedefine LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter
633639
634640 #endif
499499 /* LLVM architecture name for the native architecture, if available */
500500 #undef LLVM_NATIVE_ARCH
501501
502 /* Short LLVM architecture name for the native architecture, if available */
503 #undef LLVM_NATIVE_ARCHNAME
502 /* LLVM name for the native AsmPrinter init function, if available */
503 #undef LLVM_NATIVE_ASMPRINTER
504
505 /* LLVM name for the native Target init function, if available */
506 #undef LLVM_NATIVE_TARGET
507
508 /* LLVM name for the native TargetInfo init function, if available */
509 #undef LLVM_NATIVE_TARGETINFO
504510
505511 /* Define if this is Unixish platform */
506512 #undef LLVM_ON_UNIX
4949 #cmakedefine LLVM_MULTITHREADED
5050
5151 /* LLVM architecture name for the native architecture, if available */
52 #cmakedefine LLVM_NATIVE_ARCH ${LLVM_NATIVE_ARCH}Target
52 #cmakedefine LLVM_NATIVE_ARCH ${LLVM_NATIVE_ARCH}
5353
54 /* Short LLVM architecture name for the native architecture, if available */
55 #cmakedefine LLVM_NATIVE_ARCHNAME ${LLVM_NATIVE_ARCH}
54 /* LLVM name for the native Target init function, if available */
55 #cmakedefine LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target
56
57 /* LLVM name for the native TargetInfo init function, if available */
58 #cmakedefine LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo
59
60 /* LLVM name for the native AsmPrinter init function, if available */
61 #cmakedefine LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter
5662
5763 /* Define if this is Unixish platform */
5864 #cmakedefine LLVM_ON_UNIX
5151 /* LLVM architecture name for the native architecture, if available */
5252 #undef LLVM_NATIVE_ARCH
5353
54 /* Short LLVM architecture name for the native architecture, if available */
55 #undef LLVM_NATIVE_ARCHNAME
54 /* LLVM name for the native Target init function, if available */
55 #undef LLVM_NATIVE_TARGET
56
57 /* LLVM name for the native TargetInfo init function, if available */
58 #undef LLVM_NATIVE_TARGETINFO
59
60 /* LLVM name for the native AsmPrinter init function, if available */
61 #undef LLVM_NATIVE_ASMPRINTER
5662
5763 /* Define if this is Unixish platform */
5864 #undef LLVM_ON_UNIX
9999 /// It is legal for a client to make multiple calls to this function.
100100 inline bool InitializeNativeTarget() {
101101 // If we have a native target, initialize it to ensure it is linked in.
102 #ifdef LLVM_NATIVE_ARCHNAME
103 #define DoInit2(TARG) \
104 LLVMInitialize ## TARG ## Info (); \
105 LLVMInitialize ## TARG ()
106 #define DoInit(T) DoInit2(T)
107 DoInit(LLVM_NATIVE_ARCH);
102 #ifdef LLVM_NATIVE_TARGET
103 LLVM_NATIVE_TARGETINFO();
104 LLVM_NATIVE_TARGET();
108105 return false;
109 #undef DoInit
110 #undef DoInit2
111106 #else
112107 return true;
113108 #endif
117112 /// this function to initialize the native target asm printer.
118113 inline bool InitializeNativeTargetAsmPrinter() {
119114 // If we have a native target, initialize the corresponding asm printer.
120 #ifdef LLVM_NATIVE_ARCH
121 #define DoInit2(TARG) \
122 LLVMInitialize ## TARG ## AsmPrinter ();
123 #define DoInit(T) DoInit2(T)
124 DoInit(LLVM_NATIVE_ARCHNAME);
115 #ifdef LLVM_NATIVE_ASMPRINTER
116 LLVM_NATIVE_ASMPRINTER();
125117 return false;
126 #undef DoInit
127 #undef DoInit2
128118 #else
129119 return true;
130120 #endif
6363 for JIT applications to ensure that the target gets linked in correctly. */
6464 static inline LLVMBool LLVMInitializeNativeTarget(void) {
6565 /* If we have a native target, initialize it to ensure it is linked in. */
66 #ifdef LLVM_NATIVE_ARCH
67 #define DoInit2(TARG) \
68 LLVMInitialize ## TARG ## Info (); \
69 LLVMInitialize ## TARG ()
70 #define DoInit(T) DoInit2(T)
71 DoInit(LLVM_NATIVE_ARCH);
66 #ifdef LLVM_NATIVE_TARGET
67 LLVM_NATIVE_TARGETINFO();
68 LLVM_NATIVE_TARGET();
7269 return 0;
73 #undef DoInit
74 #undef DoInit2
7570 #else
7671 return 1;
7772 #endif