[yaml2obj] - Change how we handle implicit sections.
authorGeorge Rimar <grimar@accesssoftek.com>
Wed, 5 Jun 2019 13:16:53 +0000 (13:16 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Wed, 5 Jun 2019 13:16:53 +0000 (13:16 +0000)
commit66296dc3e4c5356b9c2b8443125b10b9ca41e435
tree0ebce203afece44932e49d6d52cd0e3d969a0126
parentf95e6c06534298a522088df30a6d9a4145834049
[yaml2obj] - Change how we handle implicit sections.

We have a few sections that can be added implicitly to the output:
".dynsym", ".dynstr", ".symtab", ".strtab" and ".shstrtab".

Problem appears when such section is listed explicitly in YAML.
In that case it's content is written twice:
first time during writing of regular sections listed in the document
and second time during special handling.

Because of that their file offsets can become unexpectedly broken:
(yaml file for sample below lists .dynsym explicitly before .text.foo)

Before patch:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .dynsym           DYNSYM           0000000000000100  00000250
       0000000000000030  0000000000000018   A       6     0     8
  [ 2] .text.foo         PROGBITS         0000000000000200  00000200
       0000000000000000  0000000000000000  AX       0     0     0

After patch:
Section Headers:
  [Nr] Name         Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .dynsym           DYNSYM           0000000000000100  00000200
       0000000000000030  0000000000000018   A       6     0     8
  [ 2] .text.foo         PROGBITS         0000000000000200  00000230
       0000000000000000  0000000000000000  AX       0     0     0

This patch reorganizes our code and fixes the issue described.

Differential revision: https://reviews.llvm.org/D62809

llvm-svn: 362602
llvm/test/tools/yaml2obj/implicit-sections.test [new file with mode: 0644]
llvm/tools/yaml2obj/yaml2elf.cpp