travitch / build-bom

Dynamically discover the commands used to create a piece of software
Apache License 2.0
45 stars 8 forks source link

Enable debug and suppress optimization if allowed for bitcode generation #28

Closed kquick closed 2 years ago

kquick commented 2 years ago

When generating bitcode, the -g flag is always supplied to add debug information to the output bitcode file. The -O0 flag will be specified as well to suppress optimization, unless the new --flags-unchanged/-f argument is specified, in which case the optimization setting (if any) of the original compilation command will be passed to the bitcode generation as well.

travitch commented 2 years ago

I've been thinking about how to make build-bom more general while supporting things like this. I worry that this could be a bit restrictive for related use cases where one might want debug information, but want to see what clang did to their code at -O1 or -O2.

What do you think about a general mechanism like --drop-argument=REGEX and --add-argument=STRING? I can build that out today if that would work.

travitch commented 2 years ago

To expand on my thoughts on what those flags can do:

kquick commented 2 years ago

The approach I took was with the intent that the default usage provided the most useful information in the bitcode output (although "useful" is clearly subjective, so here I'll define it as "closest to the original source"). If the user wanted their bitcode to have more fidelity with the compiled result, the --flags-unchanged argument could be added. I agree this is a bit simplistic, but part of my justification was to make the default, out-of-the-box configuration highly useful and needing to tweak things once you get to more advanced usage cases.

Your approach has more discrete control, but is also more complex. I'm a little worried that the price of this additional control is (a) not having good defaults for the simple starter case, and (b) might allow the user to specify problematic (or conflicting) flags like -E or -S or something already blacklisted. [As a small implementation note, this approach would probably need to pass some sort of structure or array through instead of the simple boolean currently threaded... which might actually end up being a good code optimization since it felt awkward to make so many function signature changes just to make a single config option available down where it was needed.]

Specifics:

All the above is just more background on the approach I took and a bit of pro/con analysis of the two approaches. I think either approach is reasonable, whichever you think is the most useful.

travitch commented 2 years ago

I agree that build-bom should definitely be able to add -g. Part of my concern around changing optimization levels by default is that -O0 is not universally good for analysis either, though I suppose one can always apply opt to that bitcode to turn it into anything else.