[llvm-dev] Best approach to add function code used by several modules?
serge guelton via llvm-dev
llvm-dev at lists.llvm.org
Thu Jan 21 06:37:43 PST 2016
Hi llvm-dev,
While developing a compiler pass, I met the following situation: I need
to insert calls to an extern custom function that would be bundled with the
application. A possible implementation, quite similar to how OpenMP
directives are handled, would be to put the custom function into a
library (say libmydep.so) and add it at link step, as in:
mycomp a0.c
mycomp a1.c
mycomp a0.o a1.o -lmydep
*But* We're in a cross compiling context, so this means we would need to
generate several version of `libmydep.so` and ship all of them.
libmydep contains a single function, implemented in a few dozens of
SLOC, so I'd like to explore alternatives! Here is what I'm thinking of:
- generate a bytecode version, libmydep.ll and bundle it with the
application, read it during the compilation process and inject the
function bytecode into each compilation unit, as a weak symbol, taking
advantage of the absence of conflict between two weak symbols (On my
laptop, the first symbol, based on the order of the object code on the
link command line, seems to be used).
I don't quite like this option because the .ll is not
architecture-independent (parametric llvm bytecode, anyone?)
- build the function at compile time, probably based on the output of
`llc -march=cpp`, using the DataLayout to abstract the (few in my case)
portability issues. Looks like a working solution, but not the most
maintainable one
Instead of using weak symbols, I could also duplicate the
implementations in static versions of the symbols...
Any other idea?
More information about the llvm-dev
mailing list