Advice for fixing some misguided code

I long while back, I added a static function to my ‘Subtarget’ implementation that allows me to pass all of the ‘-cc1’ arguments from CLang to the LLVM backend.

The reason I added this was because I would routinely get examples of “bugs” from developers that consisted of only assembly code, and no information about how the compiler was invoked, nor the C or C++ source.

So I partially addressed this by placing all the ‘-cc1’ options into a large comment section at the end of each generated assembly file to help with my diagnostics, and this information is passed from CLang to LLVM using this call.

But this breaks the natural decoupling of the CLang front-end and the LLVM backend, so that other clients of ‘libclang’ implicitly have this weak extern reference.

Using the GCC or CLang compilers, the use of weak-externs is not a problem so my additional function does not need to be linked into the image, but with VC++ it is a problem as there is no real equivalent that I know of for weak-extern; and this means that I cannot build many of the additional CLang utilities unless I also link them against the back-end, which is not the right thing to do.

I think that the right solution would be to decouple how I pass this information from CLang to LLVM, and I would like to seek advice from the community on how I might better implement this requirement. Or if there is an existing mechanism I could use to do this.

Thanks in advance,


The best mechanism would be module-level metadata. There’s already a creator node used for emitting DWARF debug info, so extending that to include the complete clang invocation seems like the best bet.


Thanks David, I will see if I can rework this using your suggestion. I just "know" there has to be a better way than what I am doing now :slight_smile:

All the best,


+Steven who embeds CC1 options on the bitcode to reproduce the compilation.