Skip to content

Commit 6947acd

Browse files
author
George Rimar
committedFeb 19, 2019
[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
1 parent 55d41a7 commit 6947acd

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# RUN: yaml2obj %s -o %t
2+
# RUN: llvm-readobj -sections %t | FileCheck %s
3+
4+
## Check yaml2obj does not ignore the address of the
5+
## explicitly listed .dynstr and .dynsym sections.
6+
7+
# CHECK: Name: .dynstr
8+
# CHECK-NEXT: Type: SHT_STRTAB
9+
# CHECK-NEXT: Flags [
10+
# CHECK-NEXT: SHF_ALLOC
11+
# CHECK-NEXT: ]
12+
# CHECK-NEXT: Address: 0x1000
13+
14+
# CHECK: Name: .dynsym
15+
# CHECK-NEXT: Type: SHT_DYNSYM
16+
# CHECK-NEXT: Flags [
17+
# CHECK-NEXT: SHF_ALLOC
18+
# CHECK-NEXT: ]
19+
# CHECK-NEXT: Address: 0x2000
20+
21+
!ELF
22+
FileHeader:
23+
Class: ELFCLASS64
24+
Data: ELFDATA2LSB
25+
Type: ET_DYN
26+
Machine: EM_X86_64
27+
Sections:
28+
- Name: .dynstr
29+
Type: SHT_STRTAB
30+
Flags: [ SHF_ALLOC ]
31+
Address: 0x1000
32+
EntSize: 0x1
33+
- Name: .dynsym
34+
Type: SHT_DYNSYM
35+
Flags: [ SHF_ALLOC ]
36+
Address: 0x2000
37+
EntSize: 0x18
38+
DynamicSymbols:
39+
Global:
40+
- Name: foo

‎llvm/tools/yaml2obj/yaml2elf.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,15 @@ void ELFState<ELFT>::initSymtabSectionHeader(Elf_Shdr &SHeader,
321321
SHeader.sh_entsize = sizeof(Elf_Sym);
322322
SHeader.sh_addralign = 8;
323323

324+
// If .dynsym section is explicitly described in the YAML
325+
// then we want to use its section address.
326+
if (!IsStatic) {
327+
// Take section index and ignore the SHT_NULL section.
328+
unsigned SecNdx = getDotDynSymSecNo() - 1;
329+
if (SecNdx < Doc.Sections.size())
330+
SHeader.sh_addr = Doc.Sections[SecNdx]->Address;
331+
}
332+
324333
std::vector<Elf_Sym> Syms;
325334
{
326335
// Ensure STN_UNDEF is present
@@ -358,6 +367,15 @@ void ELFState<ELFT>::initStrtabSectionHeader(Elf_Shdr &SHeader, StringRef Name,
358367
STB.write(CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign));
359368
SHeader.sh_size = STB.getSize();
360369
SHeader.sh_addralign = 1;
370+
371+
// If .dynstr section is explicitly described in the YAML
372+
// then we want to use its section address.
373+
if (Name == ".dynstr") {
374+
// Take section index and ignore the SHT_NULL section.
375+
unsigned SecNdx = getDotDynStrSecNo() - 1;
376+
if (SecNdx < Doc.Sections.size())
377+
SHeader.sh_addr = Doc.Sections[SecNdx]->Address;
378+
}
361379
}
362380

363381
template <class ELFT>

0 commit comments

Comments
 (0)
Please sign in to comment.