[yaml2obj] - Do not ignore explicit addresses for .dynsym and .dynstr
This fixes https://bugs.llvm.org/show_bug.cgi?id=40339
Previously if the addresses were set in YAML they were ignored for
.dynsym and .dynstr sections. The patch fixes that.
Differential revision: https://reviews.llvm.org/D58168
llvm-svn: 354318
diff --git a/llvm/tools/yaml2obj/yaml2elf.cpp b/llvm/tools/yaml2obj/yaml2elf.cpp
index 5198a75..ac1626a 100644
--- a/llvm/tools/yaml2obj/yaml2elf.cpp
+++ b/llvm/tools/yaml2obj/yaml2elf.cpp
@@ -321,6 +321,15 @@
SHeader.sh_entsize = sizeof(Elf_Sym);
SHeader.sh_addralign = 8;
+ // If .dynsym section is explicitly described in the YAML
+ // then we want to use its section address.
+ if (!IsStatic) {
+ // Take section index and ignore the SHT_NULL section.
+ unsigned SecNdx = getDotDynSymSecNo() - 1;
+ if (SecNdx < Doc.Sections.size())
+ SHeader.sh_addr = Doc.Sections[SecNdx]->Address;
+ }
+
std::vector<Elf_Sym> Syms;
{
// Ensure STN_UNDEF is present
@@ -358,6 +367,15 @@
STB.write(CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign));
SHeader.sh_size = STB.getSize();
SHeader.sh_addralign = 1;
+
+ // If .dynstr section is explicitly described in the YAML
+ // then we want to use its section address.
+ if (Name == ".dynstr") {
+ // Take section index and ignore the SHT_NULL section.
+ unsigned SecNdx = getDotDynStrSecNo() - 1;
+ if (SecNdx < Doc.Sections.size())
+ SHeader.sh_addr = Doc.Sections[SecNdx]->Address;
+ }
}
template <class ELFT>