This is an archive of the discontinued LLVM Phabricator instance.

Force SHF_MERGE optimizations with -r
ClosedPublic

Authored by espindola on Mar 26 2018, 8:24 PM.

Details

Reviewers
ruiu
gbreynoo
Summary

This is an alternative to D43942 that handles sh_entsize.

Diff Detail

Event Timeline

espindola created this revision.Mar 26 2018, 8:24 PM

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.

ruiu added a comment.Mar 27 2018, 8:15 AM

Instead of changing the global configuration of -O, how about returning true from ObjFile::shouldMerge if Config->Relocatable is true?

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.

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.

Address review comments.

ruiu accepted this revision.Mar 27 2018, 8:31 AM

LGTM

This revision is now accepted and ready to land.Mar 27 2018, 8:31 AM

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.
ruiu added a comment.Mar 27 2018, 8:45 AM

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.