This is an archive of the discontinued LLVM Phabricator instance.

ELF: Move code to where it is used, and related cleanups. NFC.
ClosedPublic

Authored by pcc on Apr 25 2016, 12:29 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc updated this revision to Diff 54885.Apr 25 2016, 12:29 PM
pcc retitled this revision from to ELF: Teach section GC to also GC shared symbols..
pcc updated this object.
pcc added reviewers: ruiu, rafael, davide, grimar.
pcc added a subscriber: llvm-commits.
ruiu added inline comments.Apr 25 2016, 1:41 PM
ELF/MarkLive.cpp
42 ↗(On Diff #54885)

So this code movement is just to move code to the file where it is used (plus a small cleanup), right?

165–168 ↗(On Diff #54885)

Is this order safe? If getSymbols happens to return non-shared symbols and shared symbols in this order, then you would clear IsUsedInRegularObj bit for all shared symbols, wouldn't you?

pcc added inline comments.Apr 25 2016, 1:56 PM
ELF/MarkLive.cpp
42 ↗(On Diff #54885)

Yes.

165–168 ↗(On Diff #54885)

We only ever process a shared symbol when we remove an section from the work list and call forEachSuccessor. MarkSymbol only calls Enqueue with a section+offset, never a symbol.

rafael edited edge metadata.Apr 25 2016, 1:58 PM
rafael added a subscriber: rafael.

Taking a look.

rafael added inline comments.Apr 25 2016, 2:06 PM
test/ELF/gc-sections-shared.s
9 ↗(On Diff #54885)

This matches the gold and bfd behaviour?

I would actually expect the .so to keep bar2 alive. After all, if a symbol in a .so can force us to export a symbol from an executable, why shouldn't it for us to keep it alive?

That is similar to us not gcing section that contribute to the dynamic table of a .so.

pcc added a comment.Apr 25 2016, 2:18 PM

This matches the gold and bfd behaviour?

bfd exports foo and bar. gold exports foo, bar and bar2.

I would actually expect the .so to keep bar2 alive. After all, if a symbol in a .so can force us to export a symbol from an executable, why shouldn't it for us to keep it alive?

That is what I am testing with the definition of bar. In this case, we are testing that we are removing bar2 from dynsym because it ends up being an unused reference.

pcc updated this revision to Diff 55029.Apr 26 2016, 10:11 AM
pcc edited edge metadata.

ELF: Move code to where it is used, and related cleanups. NFC.

pcc retitled this revision from ELF: Teach section GC to also GC shared symbols. to ELF: Move code to where it is used, and related cleanups. NFC..Apr 26 2016, 10:11 AM
pcc updated this object.
rafael added inline comments.Apr 26 2016, 11:48 AM
ELF/MarkLive.cpp
28 ↗(On Diff #55029)

Can you remove the include from InputSection.cpp?

ELF/OutputSections.cpp
1155 ↗(On Diff #55029)

This code is pretty much exactly what getRelocTargetSym was. Maybe keep just that as an utility function and move the rest to MarkLive?

pcc updated this revision to Diff 55111.Apr 26 2016, 3:29 PM
  • Add utility function to replace boilerplate get-target-of-relocation code
ELF/MarkLive.cpp
28 ↗(On Diff #55029)

We still need it in (e.g.) InputSection<ELFT>::getThunksSize().

ELF/OutputSections.cpp
1155 ↗(On Diff #55029)

I found that the two lines that retrieved the replacement SymbolBody were duplicated in several places, so I pulled that out into a utility function and updated the users. The rest of the code is only duplicated here and in MarkLive, so it's probably simplest to keep the duplication.

rafael accepted this revision.Apr 26 2016, 4:44 PM
rafael edited edge metadata.

lgtm

ELF/ICF.cpp
250 ↗(On Diff #55111)

Do you really need the cast?

ELF/InputFiles.h
132 ↗(On Diff #55111)

I moved the repl to geSymbolBody. Please remember to drop it here when you merge.

This revision is now accepted and ready to land.Apr 26 2016, 4:44 PM
pcc marked an inline comment as done.Apr 26 2016, 4:58 PM
pcc added inline comments.
ELF/ICF.cpp
250 ↗(On Diff #55111)

No, removed.

This revision was automatically updated to reflect the committed changes.