This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objdump] - Implement the --adjust-vma option.
ClosedPublic

Authored by grimar on Jan 22 2019, 5:57 AM.

Details

Summary

GNU objdump's help says: "--adjust-vma: Add OFFSET to all displayed section addresses"
In real life what it does is a bit more complicated
(and IMO not always reasonable. For example, GNU objdump prints not only VMA, but also LMA
for sections. And with --adjust-vma it adjusts LMA, but only when a section has relocations.
llvm-objsump does not seem to support printing LMAs yet, but GNU's logic anyways does not
make sense for me here).

This patch tries to adjust VMA. I tried to implement a reasonable approach.
I am not adjusting sections that are not allocatable. As, for example, adjusting debug sections
VA's and rel[a] sections VA's should not make sense. This behavior seems to be GNU compatible.

Diff Detail

Event Timeline

grimar created this revision.Jan 22 2019, 5:57 AM

I'm a little confused as to what the purpose of this option is? I think it can be used to produce disassembly that can then be grepped when loading at a variable address (e.g. due to ASLR), but am wondering if that's the intent?

I am adjusting sections that are not allocatable. As, for example, adjusting debug sections VA's and rel[a] sections VA's should not make sense.

Do you mean you are NOT adjusting non-alloc sections (i.e. what your patch actually does)?

test/tools/llvm-objdump/X86/adjust-vma.test
33

a -> are

tools/llvm-objdump/llvm-objdump.cpp
74

AdjustVma -> AdjustVMA (since it's an abbreviation)

75

I'd rephrase this as "Increase the displayed address by the specified offset"

878

adjust the non-allocatable -> adjust non-allocatable

880

targets -> file formats

1048–1050

This seems to be done rather early given its use-site. Could it be moved closer?

I'm not a fan of the variable name, as it isn't really a noun. Perhaps VMAAdjustment would be better?

1433

used update -> used, update

grimar edited the summary of this revision. (Show Details)Jan 23 2019, 7:23 AM

I'm a little confused as to what the purpose of this option is? I think it can be used to produce disassembly that can then be grepped when loading at a variable address (e.g. due to ASLR), but am wondering if that's the intent?

Yes, I was thinking that it can be used for printing DSO dumps for example when you know their load addresses. My real intention was a bit different though. Recently I compared differences between GNU objdump and llvm-objdump,
and found we do not support this option though it looked potentially useful to me. So I tried to improve compatibility with the GNU objdump command line.

I am adjusting sections that are not allocatable. As, for example, adjusting debug sections VA's and rel[a] sections VA's should not make sense.

Do you mean you are NOT adjusting non-alloc sections (i.e. what your patch actually does)?

Oh, right. I updated the description.

grimar updated this revision to Diff 183520.Jan 25 2019, 4:47 AM
grimar marked 7 inline comments as done.
  • Addressed review comments.
jhenderson accepted this revision.Jan 25 2019, 5:38 AM

LGTM.

tools/llvm-objdump/llvm-objdump.cpp
1429

Unrelated nit: There are a couple of issues with this comment, namely it uses a stale variable name, and "address" instead of "offset".

This revision is now accepted and ready to land.Jan 25 2019, 5:38 AM
This revision was automatically updated to reflect the committed changes.
grimar marked 2 inline comments as done.Jan 28 2019, 2:49 AM
grimar added inline comments.
tools/llvm-objdump/llvm-objdump.cpp
1429

Fixed in rl352348.