[PATCH] D93362: [llvm-elfabi] Support ELF file that lacks .gnu.hash section

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 14 23:51:48 PST 2021


grimar added inline comments.


================
Comment at: llvm/test/tools/llvm-elfabi/read-elf-dynsym.test:10
+# RUN: yaml2obj --docnum=1 %s -o %tw.gnu.hash
+# RUN: llvm-strip --strip-sections %tw.gnu.hash
+# RUN: llvm-elfabi --elf %tw.gnu.hash --emit-tbe=- | FileCheck %s
----------------
haowei wrote:
> jhenderson wrote:
> > You don't need to call llvm-strip - yaml2obj can emit an object without the section header table, as pointed out in my earlier comment:
> > 
> > >>! In D93362#2486135, @jhenderson wrote:
> > > For example, yaml2obj has recently gained the ability to not emit the section header table, rather than needing to use llvm-strip to remove it. See llvm\test\tools\yaml2obj\ELF\section-headers.yaml for an example.
> > 
> If I add
> 
> ```
> SectionHeaderTable:
>   Sections:  []
> ```
> it will report errors:
> ```
> yaml2obj: error: section '.text' should be present in the 'Sections' or 'Excluded' lists
> yaml2obj: error: section '.data' should be present in the 'Sections' or 'Excluded' lists
> yaml2obj: error: section '.dynsym' should be present in the 'Sections' or 'Excluded' lists
> yaml2obj: error: section '.hash' should be present in the 'Sections' or 'Excluded' lists
> yaml2obj: error: section '.gnu.hash' should be present in the 'Sections' or 'Excluded' lists
> yaml2obj: error: section '.dynstr' should be present in the 'Sections' or 'Excluded' lists
> yaml2obj: error: section '.dynamic' should be present in the 'Sections' or 'Excluded' lists
> yaml2obj: error: section '.strtab' should be present in the 'Sections' or 'Excluded' lists
> yaml2obj: error: section '.shstrtab' should be present in the 'Sections' or 'Excluded' lists
> ```
> 
> If I try to use:
> 
> ```
> SectionHeaderTable:
>   NoHeaders: true
> ```
> 
> Similar errors will be raised:
> 
> ```
> yaml2obj: error: excluded section referenced: '.text'  by symbol 'foo'
> yaml2obj: error: excluded section referenced: '.data'  by symbol 'bar'
> ```
> 
> That's why I used llvm-strip instead of using this new yaml2obj feature. 
Using of `Sections:  []` is not what you want, it doesn't remove the section headers. It can be used to create a
section headers table with a null section only:

```
SectionHeaderTable:
  Sections: []
  Excluded:
    - Name: .strtab
    - Name: .shstrtab
```

Though, you don`t actually need it, as you can write just the following to achieve the same:

```
SectionHeaderTable:
  Excluded:
    - Name: .strtab
    - Name: .shstrtab
```

So, to exclude the section header table you need to use `NoHeaders: true`.
The errors you see:

```
yaml2obj: error: excluded section referenced: '.text'  by symbol 'foo'
yaml2obj: error: excluded section referenced: '.data'  by symbol 'bar'
```

are because your dynamic symbols specify sections:

```
DynamicSymbols:
  - Name:    foo
    Type:    STT_FUNC
    Section: .text
    Value:   0x100
    Binding: 1
  - Name:    bar
    Type:    STT_OBJECT
    Section: .data
    Value:   0x200
    Binding: 1
```

Can't you just remove `Section: .text` and `Section: .data`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93362



More information about the llvm-commits mailing list