[PATCH] request for approval to commit: llvm-c: Make target initializer functions external functions in lib.
Filip Pizlo
fpizlo at apple.com
Mon Sep 30 12:02:11 PDT 2013
I can think of a reason why this patch would be a bad idea: right now, it's possible for LLVM to be used in the following build workflow:
1) Build LLVM with all or most targets and install the static libs wherever (/usr/local, say).
2) Compile and link a program that uses LLVM, but have it pull in only the static libs for the targets that the program wishes to use.
With this proposed patch, (2) won't work anymore. You'll get a link error since Target.cpp now requires all of the targets with which LLVM was configured to also be linked by the client.
-Filip
On Sep 30, 2013, at 11:51 AM, Rafael EspĂndola <rafael.espindola at gmail.com> wrote:
> I think this is the correct thing to do. Without this a program
> compiled to use LLVM version X will fail to dynamic link with version
> X+1 if we drop a target in X+1.
>
> Bob Wilson, it looks like you added the first of these static inline
> functions in r74026. Do you remember why you made them inline?
>
> On 18 September 2013 15:36, Anders Waldenborg <anders at 0x63.nu> wrote:
>> wanders added you to the CC list for the revision "request for approval to commit: llvm-c: Make target initializer functions external functions in lib.".
>>
>> Hi baldrick,
>>
>> Making them proper functions defined in the (shared)lib instead of
>> static inlines defined in the header files makes it possible to
>> actually distribute a binary compiled against the shared library
>> without having to worry about getting undefined symbol errors when
>> calling e.g LLVMInitializeAllTargetInfos because the shared library on
>> the other system was compiled with different targets.
>>
>> http://llvm-reviews.chandlerc.com/D1714
>>
>> Files:
>> include/llvm-c/Target.h
>> lib/Target/Target.cpp
>>
>> Index: include/llvm-c/Target.h
>> ===================================================================
>> --- include/llvm-c/Target.h
>> +++ include/llvm-c/Target.h
>> @@ -71,76 +71,41 @@
>> void LLVMInitialize##TargetName##Disassembler(void);
>> #include "llvm/Config/Disassemblers.def"
>> #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
>> -
>> +
>> /** LLVMInitializeAllTargetInfos - The main program should call this function if
>> it wants access to all available targets that LLVM is configured to
>> support. */
>> -static inline void LLVMInitializeAllTargetInfos(void) {
>> -#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
>> -#include "llvm/Config/Targets.def"
>> -#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
>> -}
>> +void LLVMInitializeAllTargetInfos(void);
>>
>> /** LLVMInitializeAllTargets - The main program should call this function if it
>> wants to link in all available targets that LLVM is configured to
>> support. */
>> -static inline void LLVMInitializeAllTargets(void) {
>> -#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
>> -#include "llvm/Config/Targets.def"
>> -#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
>> -}
>> +void LLVMInitializeAllTargets(void);
>>
>> /** LLVMInitializeAllTargetMCs - The main program should call this function if
>> it wants access to all available target MC that LLVM is configured to
>> support. */
>> -static inline void LLVMInitializeAllTargetMCs(void) {
>> -#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
>> -#include "llvm/Config/Targets.def"
>> -#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
>> -}
>> -
>> +void LLVMInitializeAllTargetMCs(void);
>> +
>> /** LLVMInitializeAllAsmPrinters - The main program should call this function if
>> it wants all asm printers that LLVM is configured to support, to make them
>> available via the TargetRegistry. */
>> -static inline void LLVMInitializeAllAsmPrinters(void) {
>> -#define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
>> -#include "llvm/Config/AsmPrinters.def"
>> -#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
>> -}
>> -
>> +void LLVMInitializeAllAsmPrinters(void);
>> +
>> /** LLVMInitializeAllAsmParsers - The main program should call this function if
>> it wants all asm parsers that LLVM is configured to support, to make them
>> available via the TargetRegistry. */
>> -static inline void LLVMInitializeAllAsmParsers(void) {
>> -#define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
>> -#include "llvm/Config/AsmParsers.def"
>> -#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
>> -}
>> -
>> +void LLVMInitializeAllAsmParsers(void);
>> +
>> /** LLVMInitializeAllDisassemblers - The main program should call this function
>> if it wants all disassemblers that LLVM is configured to support, to make
>> them available via the TargetRegistry. */
>> -static inline void LLVMInitializeAllDisassemblers(void) {
>> -#define LLVM_DISASSEMBLER(TargetName) \
>> - LLVMInitialize##TargetName##Disassembler();
>> -#include "llvm/Config/Disassemblers.def"
>> -#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
>> -}
>> -
>> +void LLVMInitializeAllDisassemblers(void);
>> +
>> /** LLVMInitializeNativeTarget - The main program should call this function to
>> - initialize the native target corresponding to the host. This is useful
>> + initialize the native target corresponding to the host. This is useful
>> for JIT applications to ensure that the target gets linked in correctly. */
>> -static inline LLVMBool LLVMInitializeNativeTarget(void) {
>> - /* If we have a native target, initialize it to ensure it is linked in. */
>> -#ifdef LLVM_NATIVE_TARGET
>> - LLVM_NATIVE_TARGETINFO();
>> - LLVM_NATIVE_TARGET();
>> - LLVM_NATIVE_TARGETMC();
>> - return 0;
>> -#else
>> - return 1;
>> -#endif
>> -}
>> +LLVMBool LLVMInitializeNativeTarget(void);
>>
>> /*===-- Target Data -------------------------------------------------------===*/
>>
>> Index: lib/Target/Target.cpp
>> ===================================================================
>> --- lib/Target/Target.cpp
>> +++ lib/Target/Target.cpp
>> @@ -50,6 +50,49 @@
>> initializeTarget(*unwrap(R));
>> }
>>
>> +void LLVMInitializeAllTargetInfos(void) {
>> +#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
>> +#include "llvm/Config/Targets.def"
>> +}
>> +
>> +void LLVMInitializeAllTargets(void) {
>> +#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
>> +#include "llvm/Config/Targets.def"
>> +}
>> +
>> +void LLVMInitializeAllTargetMCs(void) {
>> +#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
>> +#include "llvm/Config/Targets.def"
>> +}
>> +
>> +void LLVMInitializeAllAsmPrinters(void) {
>> +#define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
>> +#include "llvm/Config/AsmPrinters.def"
>> +}
>> +
>> +void LLVMInitializeAllAsmParsers(void) {
>> +#define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
>> +#include "llvm/Config/AsmParsers.def"
>> +}
>> +
>> +void LLVMInitializeAllDisassemblers(void) {
>> +#define LLVM_DISASSEMBLER(TargetName) \
>> + LLVMInitialize##TargetName##Disassembler();
>> +#include "llvm/Config/Disassemblers.def"
>> +}
>> +
>> +LLVMBool LLVMInitializeNativeTarget(void) {
>> +#ifdef LLVM_NATIVE_TARGET
>> + LLVM_NATIVE_TARGETINFO();
>> + LLVM_NATIVE_TARGET();
>> + LLVM_NATIVE_TARGETMC();
>> + return 0;
>> +#else
>> + return 1;
>> +#endif
>> +}
>> +
>> +
>> LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) {
>> return wrap(new DataLayout(StringRep));
>> }
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130930/003bb9d0/attachment.html>
More information about the llvm-commits
mailing list