This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj] Fallback to PT_NOTE if file doesn't have sections
ClosedPublic

Authored by phosek on Aug 16 2019, 11:55 AM.

Details

Summary

This is useful when trying to read notes from stripped files and matches
the behavior of GNU readelf and eu-readelf.

Diff Detail

Repository
rL LLVM

Event Timeline

phosek created this revision.Aug 16 2019, 11:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 16 2019, 11:55 AM

I can't reproduce the test case -- it seems llvm-readelf already prints the NT_GNU_BUILD_ID when I follow the test steps.

llvm/test/tools/llvm-readobj/gnu-notes.test
6 ↗(On Diff #215651)

Copy this to %t2.so so the original %t1.so is unaffected - e.g. if someone reruns one of these commands to debug a test failure, they should get the unstripped one with %t1.so even if the rest of the test case runs.

7 ↗(On Diff #215651)

Can you add the corresponding FileCheck for llvm-readelf?

llvm/tools/llvm-readobj/ELFDumper.cpp
4505 ↗(On Diff #215651)

Can you add this to LLVMStyle<ELFT>::printNotes too?

phosek updated this revision to Diff 215658.Aug 16 2019, 1:05 PM
phosek marked 3 inline comments as done.

It should reproduce now.

rupprecht accepted this revision.Aug 16 2019, 4:13 PM
This revision is now accepted and ready to land.Aug 16 2019, 4:13 PM
This revision was automatically updated to reflect the committed changes.

Thanks for doing this. This was something on my radar too as an odd inconsistency.

llvm/trunk/test/tools/llvm-readobj/gnu-notes.test
7

Not that it matters that much, but I don't think you needed the --strict-whitespace and --match-full-lines, since the format would be the same as the unstripped case.

72–75

Could you make a follow-up commit to share this with the above GNU case, please? This could be achieved with something like:

# RUN: ... | FileCheck %s --check-prefixes=GNU,UNSTRIPPED -DOFFSET=0x00000238
# RUN: ... | FileCheck %s --check-prefix=GNU --implicit-check-not={{.}} -DOFFSET=0x00000040

#      GNU:Displaying notes found at file offset [[OFFSET]] with length 0x00000020:
# GNU-NEXT:  Owner                Data size   Description
# GNU-NEXT:  GNU                  0x00000010  NT_GNU_ABI_TAG (ABI version tag)
# GNU-NEXT:    OS: Linux, ABI: 2.6.32

#      UNSTRIPPED:Displaying notes found at file offset 0x00000258 with length 0x00000020:
# UNSTRIPPED-NEXT:  Owner                Data size   Description
...

The same sort of thing should work with the LLVM output. By doing this, you avoid the duplicate contents, and illustrate that the part covered by the program header should be identical.