[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:37:46 PST 2021


grimar added a comment.

In D93362#2499834 <https://reviews.llvm.org/D93362#2499834>, @haowei wrote:

> The reason is that `.strtab` and `.shstrtab` are placed at the end of elf file automatically by yaml2obj and there will almost always be cases to make `(*It) & 1 != 0`, preventing the code from reach the error message. I think the only way would be placing .gnu.hash at the end of the ELF, and remove the terminator, but that seems to be not possible with yaml2obj.  For the case to test error message when `sh_size % sh_entsize is not 0`, I didn't find any good examples that I can manipulate the `sh_entsize` through yaml2obj. Do you have good suggestions to write unit tests for these cases?

It is not a problem for yaml2obj to place the `.gnu.hash` to be the last sections. Yes, it adds implicit sections like `.strtab` and `.shstrtab` at the end of automatically, but you can explicitly specify them in the "Sections" at any position you need. E.g. before the `.gnu.hash`.
See `broken-dynamic-reloc.test` from `llvm-readelf` test suite:

  ## Place all implicit sections here to make the .dynsym section to be the
  ## last in the file. This makes the task of validating offsets a bit easier.
    - Name: .dynstr
      Type: SHT_STRTAB
    - Name: .strtab
      Type: SHT_STRTAB
    - Name: .shstrtab
      Type: SHT_STRTAB
    - Name:    .dynsym
      Type:    SHT_DYNSYM
      Flags:   [ SHF_ALLOC ]
      Address: 0x300
      Offset:  0x300


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