[PATCH] D18095: Add __attribute__((linkonce_odr_linkage))
Tom Stellard via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 22 13:56:06 PDT 2016
tstellarAMD added a comment.
Hi John,
The problem we are trying to solve here is linking a LLVM bitcode program (OpenCL kernel in this specific case) with an LLVM bitcode library (OpenCL builtin library) and having the resulting LLVM bitcode module contain only the program code and the library functions that it uses.
The solution for this problem that we are using for libclc is to compile the OpenCL library to bitcode and then run a post-processing pass: https://github.com/llvm-mirror/libclc/blob/master/utils/prepare-builtins.cpp on the bitcode to set the linkage of the library functions to linkonce_odr. Doing this gives us what we are looking for, because the LLVM IR linker will drop all the linkonce_odr definitions that aren't used when it links the bitcode library in with the program.
The rationale for this specific patch was that if we could apply the linkonce_odr attribute to the functions at the source level, then we could avoid having to use the LLVM IR post-processing pass, which seems like a much cleaner and more portable solution.
Based on this comment:
> You could also get this effect by somehow making the definitions linkonce_odr when they're linked in from the library.
It seems like you are suggesting that a post-processing pass like we have would be better, but I'm not sure if you had the complete picture of what we were trying to do. GIven the problem I've described above is a post-processing pass the way to go or do you have some other suggestion?
Thanks,
Tom
http://reviews.llvm.org/D18095
More information about the cfe-commits
mailing list