[yaml2obj] - Automatically assign sh_addr for allocatable sections.
authorGeorgii Rymar <grimar@accesssoftek.com>
Tue, 18 Feb 2020 13:49:12 +0000 (16:49 +0300)
committerGeorgii Rymar <grimar@accesssoftek.com>
Sat, 22 Feb 2020 11:43:54 +0000 (14:43 +0300)
commit31f2ad9c368d47721508cbd0d120d626f9041715
treeeb18f6ad2dcea370a8fd11fb150945b5a4a473f5
parent635034f19387427e7df60efb985d2de7766a1e58
[yaml2obj] - Automatically assign sh_addr for allocatable sections.

I've noticed that it is not convenient to create YAMLs from
binaries (using obj2yaml) that have to be test cases for obj2yaml
later (after applying yaml2obj).

The problem, for example is that obj2yaml emits "DynamicSymbols:"
key instead of .dynsym. It also does not create .dynstr.
And when a YAML document without explicitly defined .dynsym/.dynstr
is given to yaml2obj, we have issues:

1) These sections are placed after non-allocatable sections (I've fixed it in D74756).
2) They have VA == 0. User needs create descriptions for such sections explicitly manually
    to set a VA.

This patch addresses (2). I suggest to let yaml2obj assign virtual addresses by itself.
It makes an output binary to be much closer to "normal" ELF.
(It is still possible to use "Address: 0x0" for a section to get the original behavior
if it is needed)

Differential revision: https://reviews.llvm.org/D74764
llvm/include/llvm/ObjectYAML/ELFYAML.h
llvm/lib/ObjectYAML/ELFEmitter.cpp
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/test/tools/llvm-objcopy/ELF/only-keep-debug.test
llvm/test/tools/llvm-readobj/ELF/verneed-invalid.test
llvm/test/tools/llvm-readobj/ELF/versioninfo.test
llvm/test/tools/obj2yaml/elf-gnu-hash-section.yaml
llvm/test/tools/yaml2obj/ELF/section-address-assign.yaml [new file with mode: 0644]
llvm/tools/obj2yaml/elf2yaml.cpp