This is an alternative to D43942 that handles sh_entsize.
Diff Detail
Event Timeline
I disagree with forcing -O1 on a user when using -r. -O0 can be useful for debugging and we have tool features that rely on no optimisations. From the user perspective it seems arbitrary that these two flags don't work together, there should be a warning at least. This appears like a gap in implementation regarding combining SHF_MERGE sections by name and sh_entsize. I'm currently looking into implementing this.
Instead of changing the global configuration of -O, how about returning true from ObjFile::shouldMerge if Config->Relocatable is true?
Those tools are broken according to the ELF spec. Please fix them. Also, they are lld only as we are the first to offer a -O0 mode.
Our proprietary linker has always offered an equivalent of -O0, at this point we cannot reasonably fix these tools.
Other arguments:
- The inclusion of -O0 in LLD suggests there is a use case, why should this not work with -r?
- -O0 is very useful when linking broken input, often you don't have the source for object files and can't easily make a fix.
I don't intend to break things that work with your proprietary linker, but the similarity of lld's -O0 and your proprietary linker's feature is a coincidence. I think we reserve the right to do anything that we think make the linker faster for -O0, and it may or may not merge sections. If merging section is faster than not doing that (and that could happen if merging section reduces data to be written significantly), we may turn section merging on for -O0. So it is perhaps a bit too dangerous to depend on the current precise behavior of lld.