[cfe-dev] clang/library collusion

Bernard Ogden via cfe-dev cfe-dev at lists.llvm.org
Tue May 17 02:15:40 PDT 2016


Hello,

I'm pretty much a clang newbie, looking for some advice.

I'm considering looking at a small size optimization that goes like this:
* Compiler discovers that main's argv argument is unused
* Compiler emits object with information that can be used by library and/or linker to avoid inclusion of argv-handling code

One of my colleagues suggest emitting a dummy function that just returns. The library can then put its argv-handling code in an identically-named weak function and the linker won't include it if the dummy function exists. I like this solution as it works for any library without needing any extra special technology.

As the optimization is language-specific it seems it should happen in clang rather than LLVM, perhaps by adding a function to the AST. This implies manipulating the AST after it has been constructed which, IIUC, is not an especially supported way to do things.

Is such an approach possible/sane, and would it be acceptable to upstream?

Does clang have any recognised approaches to this kind of compiler/library collusion?

Thanks in advance,

Bernie




More information about the cfe-dev mailing list