This is an archive of the discontinued LLVM Phabricator instance.

[ELF][test] Add test for --gc-sections + many sections
ClosedPublic

Authored by jhenderson on Mar 11 2020, 9:17 AM.

Details

Summary

This test covers the case where --gc-sections is used when there are many sections. In particular, it ensures that there is no adverse interaction with common and absolute symbols.

Diff Detail

Event Timeline

jhenderson created this revision.Mar 11 2020, 9:17 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: emaste. · View Herald Transcript
MaskRay added a comment.EditedMar 11 2020, 4:55 PM

An -O0 llvm-mc can take ~3 seconds to produce %t.o, we shall be careful adding such a test.

many-sections.s tests how e_shnum/sh_size of SHN_UNDEF is represented when there are more than SHN_LOPRESERVE sections. Did you find something interesting with lld's --gc-sections? Does it improve coverage? If it is still needed, we can add --gc-sections into many-sections.s, but I want to understand we need it at first.

jhenderson added a comment.EditedMar 13 2020, 6:42 AM

An -O0 llvm-mc can take ~3 seconds to produce %t.o, we shall be careful adding such a test.

many-sections.s tests how e_shnum/sh_size of SHN_UNDEF is represented when there are more than SHN_LOPRESERVE sections. Did you find something interesting with lld's --gc-sections? Does it improve coverage? If it is still needed, we can add --gc-sections into many-sections.s, but I want to understand we need it at first.

I'm not aware of any specific issue with lld's --gc-sections, but there is a conceptual area of coverage that this fills, namely that common and absolute symbols don't get accidentally misattributed to a real section (because their indexes conflict with such sections). We have an old testsuite that picked up a bug in another linker in relation to this issue, which we're trying to migrate to lit, hence why I'm adding this test (this same coverage was the thing that picked up the large file handling issue in the archive library that I fixed recently). I'm happy to try modifying many-sections.s (or more likely many-alloc-sections.s) instead of introducing a new test.

To expand on the conceptual coverage aspect, this is essentially a black-box test. It prevents the naive approach of implementing --gc-sections, whereby something like the following pseudo code exists:

for (Symbol S : Symbols) {
  if (!Sections[S->st_shndx]->Referenced)
    removeSymbol(S);
}

and ensures that there is a check first of all for st_shndx == SHN_COMMON etc. Of course, we may not have this code right now, but there's nothing stopping a future refactoring effort changing to something more like this.

jhenderson updated this revision to Diff 250199.EditedMar 13 2020, 7:31 AM

Merged new test into many-alloc-sections. This increased the duration of that test by about 50-60% in a debug build. Given the testsuite parallelism, I'm not convinced it wouldn't be better overall to put it in a separate test, but I'm okay doing it this way.

grimar accepted this revision.Mar 20 2020, 3:26 AM

This LGTM, please wait for @MaskRay since he had concerns before.

This revision is now accepted and ready to land.Mar 20 2020, 3:26 AM
MaskRay accepted this revision.Mar 30 2020, 3:36 PM

Looks great!

This revision was automatically updated to reflect the committed changes.