[PATCH] D128705: [llvm-objdump] Create fake sections for a ELF core file

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 30 02:09:49 PDT 2022


jhenderson added a comment.

In D128705#3620539 <https://reviews.llvm.org/D128705#3620539>, @namhyung wrote:

> Also there's no way to specify contents of segment without sections.

As noted in the yaml2obj review, you can use a special section type of "Fill" in your YAML to suppress the section header, whilst still getting contents. This is the canonical way of writing data that isn't covered by a section header.

In D128705#3621084 <https://reviews.llvm.org/D128705#3621084>, @namhyung wrote:

> But I found another problem that yaml2obj always generates some section headers (for string tables) even if there's no section.  It annoys fake section handling..  I think yaml2obj should not generate sections for core files as it has no sections.

You can suppress the section header table entirely by adding the following snippet to the YAML, inside the `Sections` block:

  - Type: SectionHeaderTable
    NoHeaders: true

See https://github.com/llvm/llvm-project/blob/main/llvm/test/tools/yaml2obj/ELF/section-headers.yaml for more details on how to customise the section header table.

(Yes, the name `Sections` is somewhat misleading, since it now contains information about things other than just the sections directly, but we haven't got around to renaming it due to the mass turbulence it would cause).



================
Comment at: llvm/include/llvm/Object/ELF.h:790
+    if (!FakeSections.empty())
+      return makeArrayRef(&FakeSections[0], FakeSections.size());
     return ArrayRef<Elf_Shdr>();
----------------
This is more "modern" C++ style, I believe. (Functionally, it's the same thing, unless FakeSections is empty)


================
Comment at: llvm/include/llvm/Object/ELFObjectFile.h:264
   bool ContentValid = false;
+  bool FakeSectionsUsed = false;
 
----------------
I think this boolean is probably superfluous: you coudl check within `createFakeSections` whether the FakeSections vector is empty and just end early if it is.


================
Comment at: llvm/tools/llvm-objdump/llvm-objdump.cpp:1131-1132
 
+static void
+createFakeELFSections(ObjectFile *Obj) {
+  assert(Obj->isELF());
----------------
Is this clang-formatted? Seems like it's wrapped a bit prematurely.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128705/new/

https://reviews.llvm.org/D128705



More information about the llvm-commits mailing list