This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj][RISCV] Support dumping PT_RISCV_ATTRIBUTES
ClosedPublic

Authored by StephenFan on Jun 23 2022, 10:27 PM.

Details

Summary

This patch drops the prefix PT_RISCV_ when dumping PT_RISCV_ATTRIBUTES.

GNU readelf dumps it as RISCV_ATTRIBUT. Because GNU readelf uses
something like %-14.14s so only the first 14 bytes are printed.

Diff Detail

Event Timeline

StephenFan created this revision.Jun 23 2022, 10:27 PM
StephenFan requested review of this revision.Jun 23 2022, 10:27 PM
jhenderson accepted this revision.Jun 23 2022, 11:29 PM

LGTM. Does llvm-objdump need something equivalent? (I don't remember whether we interpret platform-specific program headers in llvm-objdump)

llvm/test/tools/llvm-readobj/ELF/program-headers.test
611

Nit: delete extra blank line.

This revision is now accepted and ready to land.Jun 23 2022, 11:29 PM
MaskRay requested changes to this revision.EditedJun 24 2022, 12:07 AM

Supporting dump PT_RISCV_ATTRIBUTES

Support dumping

But it is weird that riscv gnu toolchain's readelf dumps PT_RISCV_ATTRIBUTES as RISCV_ATTRIBUT.

riscv gnu toolchain's readelf => GNU readelf

When describing binutils-gdb behavior, prefer the official binutils-gdb to a downstream repository like riscv-gnu-toolchain.

But it is weird that riscv gnu toolchain's readelf dumps PT_RISCV_ATTRIBUTES as RISCV_ATTRIBUT.

Because it uses something like %-14.14s so only the first 14 bytes are printed. Many long program header types like PT_AARCH64_MEMTAG_MTE are affected as well.

For target specific program headers, we generally drop the PT_xxxx_prefix. This patch also adopts this approach.

Actually I am unsure we should drop the machine prefix. GNU readelf uses the prefix and it seems clearer to have the prefix.

llvm/tools/llvm-readobj/ELFDumper.cpp
1436
if (Seg.consume_front("PT_RISCV_"))
  return Seg.str();
This revision now requires changes to proceed.Jun 24 2022, 12:07 AM
  1. Remove blank line.
  2. Replace drop_front with consume_front
StephenFan retitled this revision from [llvm-readobj][RISCV] Supporting dump PT_RISCV_ATTRIBUTES to [llvm-readobj][RISCV] Support dumping PT_RISCV_ATTRIBUTES.Jun 28 2022, 8:12 PM
StephenFan edited the summary of this revision. (Show Details)
StephenFan added a comment.EditedJun 28 2022, 8:14 PM

Supporting dump PT_RISCV_ATTRIBUTES

Support dumping

But it is weird that riscv gnu toolchain's readelf dumps PT_RISCV_ATTRIBUTES as RISCV_ATTRIBUT.

riscv gnu toolchain's readelf => GNU readelf

When describing binutils-gdb behavior, prefer the official binutils-gdb to a downstream repository like riscv-gnu-toolchain.

But it is weird that riscv gnu toolchain's readelf dumps PT_RISCV_ATTRIBUTES as RISCV_ATTRIBUT.

Because it uses something like %-14.14s so only the first 14 bytes are printed. Many long program header types like PT_AARCH64_MEMTAG_MTE are affected as well.

For target specific program headers, we generally drop the PT_xxxx_prefix. This patch also adopts this approach.

Actually I am unsure we should drop the machine prefix. GNU readelf uses the prefix and it seems clearer to have the prefix.

Thanks for such a detailed explanation!

MaskRay accepted this revision.Jun 28 2022, 11:09 PM

ATTRIBUTES may be fine for now since the GNU readelf output isn't ideal RISCV_ATTRIBUT.

This revision is now accepted and ready to land.Jun 28 2022, 11:09 PM
This revision was landed with ongoing or failed builds.Jun 29 2022, 12:16 AM
This revision was automatically updated to reflect the committed changes.