These options need to be passed to the plugin in order to have
an effect on LTO/ThinLTO compiles.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Perhaps it would be better to enable -ffunction-sections/-fdata-sections unconditionally at the linker level if the linker supports it? See also PR22999.
My understanding is that these are not typically the default because it makes the resulting object files larger and the link slower. OTOH, for ThinLTO we definitely benefit more from these optimizations (and from PR22999 looks like there is a compelling reason to want this for LTO as well).
However, when you say enable them "unconditionally at the linker level" what do you mean - these need to go LLVM via plugin options. Are you suggesting having them enabled unconditionally in both gold-plugin and gold? That will require changes to both llvm and binutils, and the latter will have effects for other compilers. What about -Wl,-gc-sections, isn't that also needed to make effective use of these options?
Are you suggesting having them enabled unconditionally in both gold-plugin and gold? That will require changes to both llvm and binutils, and the latter will have effects for other compilers.
I mean in the gold plugin only. There would not need to be any changes to gold because it does not take these parameters directly.
What about -Wl,-gc-sections, isn't that also needed to make effective use of these options?
Not necessarily, PR22999 would happen with or without gc-sections.
There are two things pushing and pulling here:
a) You want to be able to pass compiler code generation options at the time we're actually doing the code generation,
b) "Traditionally" we don't pass CFLAGS to the linker.
I think I'd like to see us passing more options down at code generation time and handling it explicitly. In particular for this we don't have the knowledge at link time of what was intended. Even if we only turn it on when we see -gc-sections we won't know if the programmer wants function and data sections or just the former. Or maybe they want function sections for some reason other than gc-sections.
In short, I'm more on the a) side here in what I want :)
To go to PR22999: I think it might be reasonable for the linker during code generation to turn on function/data-sections where it isn't reasonable for us to do so in the compiler. I can come up with weird cases to break it, but those are largely module level inline assembly.
What about function attributes? Hey that's the trend :)
You could have a subset of the functions in their own sections but not all. With LTO it means that you can disable this for a single input file.
True, but we'd need data attributes too for -fdata-sections. That's the main reason I haven't migrated the options out of TargetOptions and into the IR here. Rough sketch on module merge time: We'd probably want to error on functions/data that had separate section set in one module but not in another - there are a few ways to make that not error at link time, but at that point you're really relying on weird linker side effects and it's probably not what you intended anyhow.
-eric
Ping. It seems like using attributes is not feasible at this time due to the lack of data attributes.
I'd like to fix PR22999 and was wondering if you think adding a function-section attribute to the IR would be a viable solution?
When doing LTO, we could add the same function-section to each function in a module in the IRLinker. @mehdi_amini did you think something like that when suggesting using attributes?
ps: Maybe it would be better to discuss this at the bug report, but this review seemed the easiest way to address the right people.
Not sure how this would work? How do you codegen half of the functions with function-section but not all? How is the backend supposed to behave if it starts with a function that isn't decorated with this attribute, then move to one that is, and finally proceed with one that isn't?
hm yes I guess we would have to group the functions by their function-section attribute, which isn't such a good idea probably.
@echristo you mentioned that the compiler maybe could determine if we should use function-sections during codegen, but it does not seem possible to determine the size of the code section before emitting all functions, at which point it is already too late. Maybe I am missing something?