This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] - Fix --compress-debug-sections when there are relocations.
ClosedPublic

Authored by grimar on Mar 5 2019, 4:34 AM.

Details

Summary

When --compress-debug-sections is given,
llvm-objcopy removes the uncompressed sections and adds compressed to the section list.
This makes all the pointers to old sections to be outdated.

Currently, code already has logic for replacing the target sections of the relocation
sections. But we also have to update the relocations by themselves.

This fixes https://bugs.llvm.org/show_bug.cgi?id=40885.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Mar 5 2019, 4:34 AM
jhenderson added inline comments.Mar 5 2019, 4:43 AM
test/tools/llvm-objcopy/ELF/compress-debug-sections-relocations.test
1 ↗(On Diff #189300)

Could you reuse the Inputs/compress-debug-sections.yaml input file? Does that cover enough here, if updated with an actual symbol (see the update to that file in D58510)? I vaguely remember requesting that the relocation existed, so that it would test relocation behaviour, but it turns out the yaml was not quite correct.

tools/llvm-objcopy/ELF/ELFObjcopy.cpp
257 ↗(On Diff #189300)

"update target" -> "update the target"

258 ↗(On Diff #189300)

itself -> themselves.

Perhaps also worth mentioning how you are updating them (i.e. updating the symbol references).

tools/llvm-objcopy/ELF/Object.h
599 ↗(On Diff #189300)

A more in-keeping with the llvm-objcopy Object design might be to provide a do-nothing virtual function for all sections "replaceSectionReferences" or similar, and then override it for section types that actually need some work, like relocation sections.

In particular, I could imagine some issues with things like group sections referencing debug data or similar.

grimar updated this revision to Diff 189310.Mar 5 2019, 6:01 AM
grimar marked 5 inline comments as done.
  • Addressed review comments.
test/tools/llvm-objcopy/ELF/compress-debug-sections-relocations.test
1 ↗(On Diff #189300)

Done.

tools/llvm-objcopy/ELF/Object.h
599 ↗(On Diff #189300)

Reasonable. Done.

grimar marked an inline comment as done.Mar 5 2019, 7:03 AM
grimar added inline comments.
test/tools/llvm-objcopy/ELF/Inputs/compress-debug-sections.yaml
20 ↗(On Diff #189310)

I thought about adding one more section .debug_bar and do something like:

- Offset:          0x3
  Symbol:          .debug_bar
  Type:            R_X86_64_32

i.e. to show that if relocation section .rela.X has target X and relocation that references Y,
where X and Y are replaced debug section then we handle it correctly.

But I am not sure it worth doing that actually since the existent test covers the all code
added I think. I.e. it tests that if relocation section .rela.X has target X and relocation that references X,
where X is a replaced debug section then we handle it correctly.
Since both the code pieces that fixes section target and relocations themselves are different and both used,
maybe it is already enough here.

jhenderson accepted this revision.Mar 5 2019, 7:19 AM

This LGTM, but I'd like to get a thumbs up from @jakehehrlich or @rupprecht to confirm that the replaceSectionReferences method makes sense to them too.

This revision is now accepted and ready to land.Mar 5 2019, 7:19 AM

This LGTM, but I'd like to get a thumbs up from @jakehehrlich or @rupprecht to confirm that the replaceSectionReferences method makes sense to them too.

Oh, or @alexshap too (sorry Alex!).

This looks good to me but it is perhaps confusing that the replaceSectionReferences method is unimplemented for many types where it makes sense. Implementing it for all types makes --only-keep-debug possible for instance.

tools/llvm-objcopy/ELF/Object.h
284 ↗(On Diff #189310)

Nice! This has actually been a blocker for correctly implementing --only-keep-debug anyhow.

jakehehrlich accepted this revision.Mar 8 2019, 11:59 AM

It's probably worth adding a TODO or filing an enhancement bug for the other section types this makes sense for, e.g. symbol tables (to move symbols to the new section) or group sections (update referred-to symbol table/change group contents etc).

It's probably worth adding a TODO or filing an enhancement bug for the other section types this makes sense for, e.g. symbol tables (to move symbols to the new section) or group sections (update referred-to symbol table/change group contents etc).

I need a bit more time to investigate these scenarios. I'll try to take a look during this week.

It's probably worth adding a TODO or filing an enhancement bug for the other section types this makes sense for, e.g. symbol tables (to move symbols to the new section) or group sections (update referred-to symbol table/change group contents etc).

I need a bit more time to investigate these scenarios. I'll try to take a look during this week.

Great, cool. No need for that to block this landing though necessarily.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2019, 4:00 AM