Skip to content

Commit 0e7ed91

Browse files
author
George Rimar
committedFeb 9, 2019
[yaml2obj][obj2yaml] - Add support for dumping/parsing .dynamic sections.
This teaches the tools to parse and dump the .dynamic section and its dynamic tags. Differential revision: https://reviews.llvm.org/D57691 llvm-svn: 353606
1 parent 283d103 commit 0e7ed91

19 files changed

+623
-125
lines changed
 

‎llvm/include/llvm/ObjectYAML/ELFYAML.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFDATA)
4343
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFOSABI)
4444
// Just use 64, since it can hold 32-bit values too.
4545
LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_EF)
46+
// Just use 64, since it can hold 32-bit values too.
47+
LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_DYNTAG)
4648
LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_PF)
4749
LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_SHT)
4850
LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_REL)
@@ -107,8 +109,14 @@ struct SectionOrType {
107109
StringRef sectionNameOrType;
108110
};
109111

112+
struct DynamicEntry {
113+
ELF_DYNTAG Tag;
114+
llvm::yaml::Hex64 Val;
115+
};
116+
110117
struct Section {
111118
enum class SectionKind {
119+
Dynamic,
112120
Group,
113121
RawContent,
114122
Relocation,
@@ -128,6 +136,17 @@ struct Section {
128136
Section(SectionKind Kind) : Kind(Kind) {}
129137
virtual ~Section();
130138
};
139+
140+
struct DynamicSection : Section {
141+
std::vector<DynamicEntry> Entries;
142+
143+
DynamicSection() : Section(SectionKind::Dynamic) {}
144+
145+
static bool classof(const Section *S) {
146+
return S->Kind == SectionKind::Dynamic;
147+
}
148+
};
149+
131150
struct RawContentSection : Section {
132151
yaml::BinaryRef Content;
133152
llvm::yaml::Hex64 Size;
@@ -214,6 +233,7 @@ struct Object {
214233
} // end namespace ELFYAML
215234
} // end namespace llvm
216235

236+
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::DynamicEntry)
217237
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::ProgramHeader)
218238
LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::ELFYAML::Section>)
219239
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Symbol)
@@ -296,6 +316,11 @@ struct ScalarEnumerationTraits<ELFYAML::ELF_REL> {
296316
static void enumeration(IO &IO, ELFYAML::ELF_REL &Value);
297317
};
298318

319+
template <>
320+
struct ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG> {
321+
static void enumeration(IO &IO, ELFYAML::ELF_DYNTAG &Value);
322+
};
323+
299324
template <>
300325
struct ScalarEnumerationTraits<ELFYAML::ELF_RSS> {
301326
static void enumeration(IO &IO, ELFYAML::ELF_RSS &Value);
@@ -351,6 +376,10 @@ struct MappingTraits<ELFYAML::LocalGlobalWeakSymbols> {
351376
static void mapping(IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols);
352377
};
353378

379+
template <> struct MappingTraits<ELFYAML::DynamicEntry> {
380+
static void mapping(IO &IO, ELFYAML::DynamicEntry &Rel);
381+
};
382+
354383
template <> struct MappingTraits<ELFYAML::Relocation> {
355384
static void mapping(IO &IO, ELFYAML::Relocation &Rel);
356385
};

‎llvm/lib/ObjectYAML/ELFYAML.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,33 @@ void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
661661
IO.enumFallback<Hex32>(Value);
662662
}
663663

664+
void ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG>::enumeration(
665+
IO &IO, ELFYAML::ELF_DYNTAG &Value) {
666+
const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
667+
assert(Object && "The IO context is not initialized");
668+
669+
// TODO: For simplicity we do not handle target specific flags. They are
670+
// still supported and will be shown as a raw numeric values in the output.
671+
#define MIPS_DYNAMIC_TAG(name, value)
672+
#define HEXAGON_DYNAMIC_TAG(name, value)
673+
#define PPC64_DYNAMIC_TAG(name, value)
674+
// Also ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
675+
#define DYNAMIC_TAG_MARKER(name, value)
676+
677+
#define STRINGIFY(X) (#X)
678+
#define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X);
679+
#include "llvm/BinaryFormat/DynamicTags.def"
680+
681+
#undef MIPS_DYNAMIC_TAG
682+
#undef HEXAGON_DYNAMIC_TAG
683+
#undef PPC64_DYNAMIC_TAG
684+
#undef DYNAMIC_TAG_MARKER
685+
#undef STRINGIFY
686+
#undef DYNAMIC_TAG
687+
688+
IO.enumFallback<Hex64>(Value);
689+
}
690+
664691
void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG>::enumeration(
665692
IO &IO, ELFYAML::MIPS_AFL_REG &Value) {
666693
#define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
@@ -831,6 +858,11 @@ static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
831858
IO.mapOptional("Info", Section.Info, StringRef());
832859
}
833860

861+
static void sectionMapping(IO &IO, ELFYAML::DynamicSection &Section) {
862+
commonSectionMapping(IO, Section);
863+
IO.mapOptional("Entries", Section.Entries);
864+
}
865+
834866
static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) {
835867
commonSectionMapping(IO, Section);
836868
IO.mapOptional("Content", Section.Content);
@@ -891,6 +923,11 @@ void MappingTraits<std::unique_ptr<ELFYAML::Section>>::mapping(
891923
IO.mapRequired("Type", sectionType);
892924

893925
switch (sectionType) {
926+
case ELF::SHT_DYNAMIC:
927+
if (!IO.outputting())
928+
Section.reset(new ELFYAML::DynamicSection());
929+
sectionMapping(IO, *cast<ELFYAML::DynamicSection>(Section.get()));
930+
break;
894931
case ELF::SHT_REL:
895932
case ELF::SHT_RELA:
896933
if (!IO.outputting())
@@ -952,6 +989,15 @@ struct NormalizedMips64RelType {
952989

953990
} // end anonymous namespace
954991

992+
void MappingTraits<ELFYAML::DynamicEntry>::mapping(IO &IO,
993+
ELFYAML::DynamicEntry &Rel) {
994+
const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
995+
assert(Object && "The IO context is not initialized");
996+
997+
IO.mapRequired("Tag", Rel.Tag);
998+
IO.mapRequired("Value", Rel.Val);
999+
}
1000+
9551001
void MappingTraits<ELFYAML::Relocation>::mapping(IO &IO,
9561002
ELFYAML::Relocation &Rel) {
9571003
const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());

‎llvm/test/tools/llvm-elfabi/binary-read-add-soname.test

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ Sections:
1616
- Name: .dynamic
1717
Type: SHT_DYNAMIC
1818
Flags: [ SHF_ALLOC ]
19-
Address: 0x0008
20-
AddressAlign: 8
21-
Content: "0a000000000000000100000000000000050000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000"
22-
# DT_STRSZ 1 (0x1)
23-
# DT_STRTAB 0x0
24-
# DT_SYMTAB 0x0
25-
# DT_NULL 0x0
26-
Size: 64
19+
Address: 0x0000000000000008
2720
Link: .dynstr
21+
AddressAlign: 0x0000000000000008
22+
EntSize: 0x0000000000000010
23+
Entries:
24+
- Tag: DT_STRSZ
25+
Value: 0x0000000000000001
26+
- Tag: DT_STRTAB
27+
Value: 0x0000000000000000
28+
- Tag: DT_SYMTAB
29+
Value: 0x0000000000000000
30+
- Tag: DT_NULL
31+
Value: 0x0000000000000000
2832
ProgramHeaders:
2933
- Type: PT_LOAD
3034
Flags: [ PF_R ]

‎llvm/test/tools/llvm-elfabi/binary-read-arch.test

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ Sections:
1616
- Name: .dynamic
1717
Type: SHT_DYNAMIC
1818
Flags: [ SHF_ALLOC ]
19-
Address: 0x0008
20-
AddressAlign: 8
21-
Content: "0a000000000000000100000000000000050000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000"
22-
# DT_STRSZ 1 (0x1)
23-
# DT_STRTAB 0x0
24-
# DT_SYMTAB 0x0
25-
# DT_NULL 0x0
26-
Size: 64
19+
Address: 0x0000000000000008
2720
Link: .dynstr
21+
AddressAlign: 0x0000000000000008
22+
EntSize: 0x0000000000000010
23+
Entries:
24+
- Tag: DT_STRSZ
25+
Value: 0x0000000000000001
26+
- Tag: DT_STRTAB
27+
Value: 0x0000000000000000
28+
- Tag: DT_SYMTAB
29+
Value: 0x0000000000000000
30+
- Tag: DT_NULL
31+
Value: 0x0000000000000000
2832
ProgramHeaders:
2933
- Type: PT_LOAD
3034
Flags: [ PF_R ]

‎llvm/test/tools/llvm-elfabi/binary-read-bad-soname.test

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@ Sections:
1616
- Name: .dynamic
1717
Type: SHT_DYNAMIC
1818
Flags: [ SHF_ALLOC ]
19-
Address: 0x0008
20-
AddressAlign: 8
21-
Content: "0e000000000000000d000000000000000a000000000000000100000000000000050000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000"
22-
# DT_SONAME 13 (0x0d)
23-
# DT_STRSZ 1 (0x01)
24-
# DT_STRTAB 0x0
25-
# DT_SYMTAB 0x0
26-
# DT_NULL 0x0
27-
Size: 80
19+
Address: 0x0000000000000008
2820
Link: .dynstr
21+
AddressAlign: 0x0000000000000008
22+
EntSize: 0x0000000000000010
23+
Entries:
24+
- Tag: DT_SONAME
25+
Value: 0x000000000000000D
26+
- Tag: DT_STRSZ
27+
Value: 0x0000000000000001
28+
- Tag: DT_STRTAB
29+
Value: 0x0000000000000000
30+
- Tag: DT_SYMTAB
31+
Value: 0x0000000000000000
32+
- Tag: DT_NULL
33+
Value: 0x0000000000000000
2934
ProgramHeaders:
3035
- Type: PT_LOAD
3136
Flags: [ PF_R ]

‎llvm/test/tools/llvm-elfabi/binary-read-bad-vaddr.test

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@ Sections:
1616
- Name: .dynamic
1717
Type: SHT_DYNAMIC
1818
Flags: [ SHF_ALLOC ]
19-
Address: 0x1008
20-
AddressAlign: 8
21-
Content: "0e0000000000000000000000000000000a000000000000000100000000000000050000000000000060020000000000000600000000000000001000000000000000000000000000000000000000000000"
22-
# DT_SONAME 0
23-
# DT_STRSZ 1
24-
# DT_STRTAB 0x0260 # Bad vaddr (no PT_LOAD for 0x0000 to 0x0FFF)
25-
# DT_SYMTAB 0x1000
26-
# DT_NULL 0x0
27-
Size: 80
19+
Address: 0x0000000000001008
2820
Link: .dynstr
21+
AddressAlign: 0x0000000000000008
22+
EntSize: 0x0000000000000010
23+
Entries:
24+
- Tag: DT_SONAME
25+
Value: 0x0000000000000000
26+
- Tag: DT_STRSZ
27+
Value: 0x0000000000000001
28+
- Tag: DT_STRTAB
29+
Value: 0x0000000000000260 # Bad vaddr (no PT_LOAD for 0x0000 to 0x0FFF)
30+
- Tag: DT_SYMTAB
31+
Value: 0x0000000000001000
32+
- Tag: DT_NULL
33+
Value: 0x0000000000000000
2934
ProgramHeaders:
3035
- Type: PT_LOAD
3136
Flags: [ PF_R ]

‎llvm/test/tools/llvm-elfabi/binary-read-neededlibs-bad-offset.test

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,24 @@ Sections:
1717
- Name: .dynamic
1818
Type: SHT_DYNAMIC
1919
Flags: [ SHF_ALLOC ]
20-
Address: 0x1024
21-
Content: "010000000000000001000000000000000e0000000000000015000000000000000100000000000000ffff0000000000000a000000000000002400000000000000050000000000000000100000000000000600000000000000001000000000000000000000000000000000000000000000"
22-
# DT_NEEDED 1 (0x01)
23-
# DT_SONAME 21 (0x15)
20+
Address: 0x0000000000001024
21+
EntSize: 0x0000000000000010
22+
Entries:
23+
- Tag: DT_NEEDED
24+
Value: 0x0000000000000001
25+
- Tag: DT_SONAME
26+
Value: 0x0000000000000015
2427
# Bad DT_NEEDED entry (offset outside string table):
25-
# DT_NEEDED 65535 (0xffff)
26-
# DT_STRSZ 36 (0x24)
27-
# DT_STRTAB 0x1000
28-
# DT_SYMTAB 0x1000
29-
# DT_NULL 0x0
30-
Size: 112
28+
- Tag: DT_NEEDED
29+
Value: 0x000000000000FFFF
30+
- Tag: DT_STRSZ
31+
Value: 0x0000000000000024
32+
- Tag: DT_STRTAB
33+
Value: 0x0000000000001000
34+
- Tag: DT_SYMTAB
35+
Value: 0x0000000000001000
36+
- Tag: DT_NULL
37+
Value: 0x0000000000000000
3138
ProgramHeaders:
3239
- Type: PT_LOAD
3340
Flags: [ PF_R ]

‎llvm/test/tools/llvm-elfabi/binary-read-neededlibs.test

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,23 @@ Sections:
1717
- Name: .dynamic
1818
Type: SHT_DYNAMIC
1919
Flags: [ SHF_ALLOC ]
20-
Address: 0x1024
21-
Content: "010000000000000001000000000000000e00000000000000150000000000000001000000000000000b000000000000000a000000000000002400000000000000050000000000000000100000000000000600000000000000001000000000000000000000000000000000000000000000"
22-
# DT_NEEDED 1 (0x01)
23-
# DT_SONAME 21 (0x15)
24-
# DT_NEEDED 11 (0x0b)
25-
# DT_STRSZ 36 (0x24)
26-
# DT_STRTAB 0x1000
27-
# DT_SYMTAB 0x1000
28-
# DT_NULL 0x0
29-
Size: 112
20+
Address: 0x0000000000001024
21+
EntSize: 0x0000000000000010
22+
Entries:
23+
- Tag: DT_NEEDED
24+
Value: 0x0000000000000001
25+
- Tag: DT_SONAME
26+
Value: 0x0000000000000015
27+
- Tag: DT_NEEDED
28+
Value: 0x000000000000000B
29+
- Tag: DT_STRSZ
30+
Value: 0x0000000000000024
31+
- Tag: DT_STRTAB
32+
Value: 0x0000000000001000
33+
- Tag: DT_SYMTAB
34+
Value: 0x0000000000001000
35+
- Tag: DT_NULL
36+
Value: 0x0000000000000000
3037
ProgramHeaders:
3138
- Type: PT_LOAD
3239
Flags: [ PF_R ]

‎llvm/test/tools/llvm-elfabi/binary-read-no-dt-strsz.test

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ Sections:
1717
- Name: .dynamic
1818
Type: SHT_DYNAMIC
1919
Flags: [ SHF_ALLOC ]
20-
Address: 0x0008
21-
AddressAlign: 8
22-
Content: "0500000000000000000000000000000000000000000000000000000000000000"
23-
# DT_STRTAB 0x0
24-
# DT_NULL 0x0
25-
Size: 32
20+
Address: 0x0000000000000008
2621
Link: .dynstr
22+
AddressAlign: 0x0000000000000008
23+
EntSize: 0x0000000000000010
24+
Entries:
25+
- Tag: DT_STRTAB
26+
Value: 0x0000000000000000
27+
- Tag: DT_NULL
28+
Value: 0x0000000000000000
2729
ProgramHeaders:
2830
- Type: PT_LOAD
2931
Flags: [ PF_R ]

‎llvm/test/tools/llvm-elfabi/binary-read-no-dt-strtab.test

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ Sections:
1616
- Name: .dynamic
1717
Type: SHT_DYNAMIC
1818
Flags: [ SHF_ALLOC ]
19-
Address: 0x0008
20-
AddressAlign: 8
21-
Content: "0a00000000000000010000000000000000000000000000000000000000000000"
22-
# DT_STRSZ 1 (0x1)
23-
# DT_NULL 0x0
24-
Size: 32
19+
Address: 0x0000000000000008
2520
Link: .dynstr
21+
AddressAlign: 0x0000000000000008
22+
EntSize: 0x0000000000000010
23+
Entries:
24+
- Tag: DT_STRSZ
25+
Value: 0x0000000000000001
26+
- Tag: DT_NULL
27+
Value: 0x0000000000000000
2628
ProgramHeaders:
2729
- Type: PT_LOAD
2830
Flags: [ PF_R ]

‎llvm/test/tools/llvm-elfabi/binary-read-replace-soname.test

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,21 @@ Sections:
1818
- Name: .dynamic
1919
Type: SHT_DYNAMIC
2020
Flags: [ SHF_ALLOC ]
21-
Address: 0x1018
22-
AddressAlign: 8
23-
Content: "0e0000000000000005000000000000000a000000000000001400000000000000050000000000000000100000000000000600000000000000001000000000000000000000000000000000000000000000"
24-
# DT_SONAME 5 (0x05)
25-
# DT_STRSZ 20 (0x14)
26-
# DT_STRTAB 0x1000
27-
# DT_SYMTAB 0x1000
28-
# DT_NULL 0x0
29-
Size: 80
21+
Address: 0x0000000000001018
3022
Link: .dynstr
23+
AddressAlign: 0x0000000000000008
24+
EntSize: 0x0000000000000010
25+
Entries:
26+
- Tag: DT_SONAME
27+
Value: 0x0000000000000005
28+
- Tag: DT_STRSZ
29+
Value: 0x0000000000000014
30+
- Tag: DT_STRTAB
31+
Value: 0x0000000000001000
32+
- Tag: DT_SYMTAB
33+
Value: 0x0000000000001000
34+
- Tag: DT_NULL
35+
Value: 0x0000000000000000
3136
ProgramHeaders:
3237
- Type: PT_LOAD
3338
Flags: [ PF_R ]

‎llvm/test/tools/llvm-elfabi/binary-read-soname-no-null.test

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,21 @@ Sections:
1717
- Name: .dynamic
1818
Type: SHT_DYNAMIC
1919
Flags: [ SHF_ALLOC ]
20-
Address: 0x1018
21-
AddressAlign: 8
22-
Content: "0e0000000000000005000000000000000a000000000000000f00000000000000050000000000000000100000000000000600000000000000001000000000000000000000000000000000000000000000"
23-
# DT_SONAME 5 (0x05)
24-
# DT_STRSZ 15 (0x0F)
25-
# DT_STRTAB 0x1000
26-
# DT_SYMTAB 0x1000
27-
# DT_NULL 0x0
28-
Size: 80
20+
Address: 0x0000000000001018
2921
Link: .dynstr
22+
AddressAlign: 0x0000000000000008
23+
EntSize: 0x0000000000000010
24+
Entries:
25+
- Tag: DT_SONAME
26+
Value: 0x0000000000000005
27+
- Tag: DT_STRSZ
28+
Value: 0x000000000000000F
29+
- Tag: DT_STRTAB
30+
Value: 0x0000000000001000
31+
- Tag: DT_SYMTAB
32+
Value: 0x0000000000001000
33+
- Tag: DT_NULL
34+
Value: 0x0000000000000000
3035
ProgramHeaders:
3136
- Type: PT_LOAD
3237
Flags: [ PF_R ]

‎llvm/test/tools/llvm-elfabi/binary-read-soname.test

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,21 @@ Sections:
1717
- Name: .dynamic
1818
Type: SHT_DYNAMIC
1919
Flags: [ SHF_ALLOC ]
20-
Address: 0x1018
21-
AddressAlign: 8
22-
Content: "0e0000000000000005000000000000000a000000000000001400000000000000050000000000000000100000000000000600000000000000001000000000000000000000000000000000000000000000"
23-
# DT_SONAME 5 (0x05)
24-
# DT_STRSZ 20 (0x14)
25-
# DT_STRTAB 0x1000
26-
# DT_SYMTAB 0x1000
27-
# DT_NULL 0x0
28-
Size: 80
20+
Address: 0x0000000000001018
2921
Link: .dynstr
22+
AddressAlign: 0x0000000000000008
23+
EntSize: 0x0000000000000010
24+
Entries:
25+
- Tag: DT_SONAME
26+
Value: 0x0000000000000005
27+
- Tag: DT_STRSZ
28+
Value: 0x0000000000000014
29+
- Tag: DT_STRTAB
30+
Value: 0x0000000000001000
31+
- Tag: DT_SYMTAB
32+
Value: 0x0000000000001000
33+
- Tag: DT_NULL
34+
Value: 0x0000000000000000
3035
ProgramHeaders:
3136
- Type: PT_LOAD
3237
Flags: [ PF_R ]

‎llvm/test/tools/llvm-objdump/private-headers-no-dynamic-segment.test

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,65 @@ FileHeader:
1010
Sections:
1111
- Name: .dynamic
1212
Type: SHT_DYNAMIC
13-
Flags: [ SHF_ALLOC, SHF_WRITE ]
14-
Content: 0c00000000000000a0060000000000000d0000000000000024090000000000001900000000000000a80d2000000000001b0000000000000010000000000000001a00000000000000b80d2000000000001c000000000000000800000000000000f5feff6f0000000098020000000000000500000000000000c8030000000000000600000000000000c0020000000000000a000000000000002f010000000000000b0000000000000018000000000000001500000000000000000000000000000003000000000000000010200000000000020000000000000048000000000000001400000000000000070000000000000017000000000000005806000000000000070000000000000050050000000000000800000000000000080100000000000009000000000000001800000000000000fbffff6f000000000000000800000000feffff6f000000001005000000000000ffffff6f000000000200000000000000f0ffff6f00000000f804000000000000f9ffff6f0000000004000000000000002300000000000000140000000000000024000000000000002143658700000000250000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000
13+
Flags: [ SHF_WRITE, SHF_ALLOC ]
14+
EntSize: 0x0000000000000010
15+
Entries:
16+
- Tag: DT_INIT
17+
Value: 0x00000000000006A0
18+
- Tag: DT_FINI
19+
Value: 0x0000000000000924
20+
- Tag: DT_INIT_ARRAY
21+
Value: 0x0000000000200DA8
22+
- Tag: DT_INIT_ARRAYSZ
23+
Value: 0x0000000000000010
24+
- Tag: DT_FINI_ARRAY
25+
Value: 0x0000000000200DB8
26+
- Tag: DT_FINI_ARRAYSZ
27+
Value: 0x0000000000000008
28+
- Tag: DT_GNU_HASH
29+
Value: 0x0000000000000298
30+
- Tag: DT_STRTAB
31+
Value: 0x00000000000003C8
32+
- Tag: DT_SYMTAB
33+
Value: 0x00000000000002C0
34+
- Tag: DT_STRSZ
35+
Value: 0x000000000000012F
36+
- Tag: DT_SYMENT
37+
Value: 0x0000000000000018
38+
- Tag: DT_DEBUG
39+
Value: 0x0000000000000000
40+
- Tag: DT_PLTGOT
41+
Value: 0x0000000000201000
42+
- Tag: DT_PLTRELSZ
43+
Value: 0x0000000000000048
44+
- Tag: DT_PLTREL
45+
Value: 0x0000000000000007
46+
- Tag: DT_JMPREL
47+
Value: 0x0000000000000658
48+
- Tag: DT_RELA
49+
Value: 0x0000000000000550
50+
- Tag: DT_RELASZ
51+
Value: 0x0000000000000108
52+
- Tag: DT_RELAENT
53+
Value: 0x0000000000000018
54+
- Tag: DT_FLAGS_1
55+
Value: 0x0000000008000000
56+
- Tag: DT_VERNEED
57+
Value: 0x0000000000000510
58+
- Tag: DT_VERNEEDNUM
59+
Value: 0x0000000000000002
60+
- Tag: DT_VERSYM
61+
Value: 0x00000000000004F8
62+
- Tag: DT_RELACOUNT
63+
Value: 0x0000000000000004
64+
- Tag: DT_RELRSZ
65+
Value: 0x0000000000000014
66+
- Tag: DT_RELR
67+
Value: 0x0000000087654321
68+
- Tag: DT_RELRENT
69+
Value: 0x0000000000000010
70+
- Tag: DT_NULL
71+
Value: 0x0000000000000000
1572

1673
# CHECK: INIT 0x00000000000006a0
1774
# CHECK: FINI 0x0000000000000924

‎llvm/test/tools/llvm-readobj/demangle.test

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,30 @@ Sections:
156156
Symbol: _Z3fooc
157157
Type: R_X86_64_PC32
158158
Addend: 0x4
159-
- Name: .dynamic
160-
Type: SHT_DYNAMIC
161-
Flags: [ SHF_ALLOC ]
162-
Link: .dynstr
163-
Address: 0x1000
164-
AddressAlign: 0x1000
165-
## DT_STRTAB - 0x0
166-
## DT_STRSZ - 0x9
167-
## DT_SYMTAB - 0x100
168-
## DT_SYMENT - 0x18
169-
## DT_RELA - 0x200
170-
## DT_RELASZ - 0x18
171-
## DT_RELAENT - 0x18
172-
## DT_NULL - 0x0
173-
Content: "050000000000000000000000000000000a000000000000000900000000000000060000000000000000010000000000000b00000000000000180000000000000007000000000000000002000000000000080000000000000018000000000000000900000000000000180000000000000000000000000000000000000000000000"
159+
- Name: .dynamic
160+
Type: SHT_DYNAMIC
161+
Flags: [ SHF_ALLOC ]
162+
Address: 0x0000000000001000
163+
Link: .dynstr
164+
AddressAlign: 0x0000000000001000
165+
EntSize: 0x0000000000000010
166+
Entries:
167+
- Tag: DT_STRTAB
168+
Value: 0x0000000000000000
169+
- Tag: DT_STRSZ
170+
Value: 0x0000000000000009
171+
- Tag: DT_SYMTAB
172+
Value: 0x0000000000000100
173+
- Tag: DT_SYMENT
174+
Value: 0x0000000000000018
175+
- Tag: DT_RELA
176+
Value: 0x0000000000000200
177+
- Tag: DT_RELASZ
178+
Value: 0x0000000000000018
179+
- Tag: DT_RELAENT
180+
Value: 0x0000000000000018
181+
- Tag: DT_NULL
182+
Value: 0x0000000000000000
174183
- Name: .text.foo
175184
Type: SHT_PROGBITS
176185
Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ]

‎llvm/test/tools/llvm-readobj/gnu-hash-symbols.test

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,24 @@ Sections:
7171
## st_name: 1; st_info: Global | Func; st_other: 0;
7272
## st_shndx: .text.foo; st_value: 0x2000; st_size: 0
7373
Content: "000000000000000000000000000000000000000000000000010000001200040000200000000000000000000000000000"
74-
- Name: .dynamic
75-
Type: SHT_DYNAMIC
76-
Flags: [ SHF_ALLOC ]
77-
Link: .dynstr
78-
Address: 0x1000
79-
AddressAlign: 0x1000
80-
## DT_STRTAB - 0x0
81-
## DT_STRSZ - 0x9
82-
## DT_SYMTAB - 0x100
83-
## DT_SYMENT - 0x18
84-
## DT_NULL - 0x0
85-
Content: "050000000000000000000000000000000a000000000000000900000000000000060000000000000000010000000000000b00000000000000180000000000000000000000000000000000000000000000"
74+
- Name: .dynamic
75+
Type: SHT_DYNAMIC
76+
Flags: [ SHF_ALLOC ]
77+
Address: 0x0000000000001000
78+
Link: .dynstr
79+
AddressAlign: 0x0000000000001000
80+
EntSize: 0x0000000000000010
81+
Entries:
82+
- Tag: DT_STRTAB
83+
Value: 0x0000000000000000
84+
- Tag: DT_STRSZ
85+
Value: 0x0000000000000009
86+
- Tag: DT_SYMTAB
87+
Value: 0x0000000000000100
88+
- Tag: DT_SYMENT
89+
Value: 0x0000000000000018
90+
- Tag: DT_NULL
91+
Value: 0x0000000000000000
8692
- Name: .text.foo
8793
Type: SHT_PROGBITS
8894
Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ]
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
# RUN: yaml2obj %s -o %t
2+
# RUN: obj2yaml %t | FileCheck %s
3+
4+
## Check we can use obj2yaml to yamalize the object containing
5+
## .dynamic section. Check that resulting section has the
6+
## proper attributes and dynamic tags.
7+
8+
# CHECK: Sections:
9+
# CHECK-NEXT: - Name: .dynamic
10+
# CHECK-NEXT: Type: SHT_DYNAMIC
11+
# CHECK-NEXT: Address: 0x0000000000001000
12+
# CHECK-NEXT: AddressAlign: 0x0000000000002000
13+
# CHECK-NEXT: EntSize: 0x0000000000000010
14+
# CHECK-NEXT: Entries:
15+
# CHECK-NEXT: - Tag: DT_NULL
16+
# CHECK-NEXT: Value: 0x0000000000000000
17+
# CHECK-NEXT: - Tag: DT_NEEDED
18+
# CHECK-NEXT: Value: 0x0000000000000001
19+
# CHECK-NEXT: - Tag: DT_PLTRELSZ
20+
# CHECK-NEXT: Value: 0x0000000000000002
21+
# CHECK-NEXT: - Tag: DT_PLTGOT
22+
# CHECK-NEXT: Value: 0x0000000000000003
23+
# CHECK-NEXT: - Tag: DT_HASH
24+
# CHECK-NEXT: Value: 0x0000000000000004
25+
# CHECK-NEXT: - Tag: DT_STRTAB
26+
# CHECK-NEXT: Value: 0x0000000000000005
27+
# CHECK-NEXT: - Tag: DT_SYMTAB
28+
# CHECK-NEXT: Value: 0x0000000000000006
29+
# CHECK-NEXT: - Tag: DT_RELA
30+
# CHECK-NEXT: Value: 0x0000000000000007
31+
# CHECK-NEXT: - Tag: DT_RELASZ
32+
# CHECK-NEXT: Value: 0x0000000000000008
33+
# CHECK-NEXT: - Tag: DT_RELAENT
34+
# CHECK-NEXT: Value: 0x0000000000000009
35+
# CHECK-NEXT: - Tag: DT_STRSZ
36+
# CHECK-NEXT: Value: 0x000000000000000A
37+
# CHECK-NEXT: - Tag: DT_SYMENT
38+
# CHECK-NEXT: Value: 0x000000000000000B
39+
# CHECK-NEXT: - Tag: DT_INIT
40+
# CHECK-NEXT: Value: 0x000000000000000C
41+
# CHECK-NEXT: - Tag: DT_FINI
42+
# CHECK-NEXT: Value: 0x000000000000000D
43+
# CHECK-NEXT: - Tag: DT_SONAME
44+
# CHECK-NEXT: Value: 0x000000000000000E
45+
# CHECK-NEXT: - Tag: DT_RPATH
46+
# CHECK-NEXT: Value: 0x000000000000000F
47+
# CHECK-NEXT: - Tag: DT_SYMBOLIC
48+
# CHECK-NEXT: Value: 0x0000000000000010
49+
# CHECK-NEXT: - Tag: DT_REL
50+
# CHECK-NEXT: Value: 0x0000000000000011
51+
# CHECK-NEXT: - Tag: DT_RELSZ
52+
# CHECK-NEXT: Value: 0x0000000000000012
53+
# CHECK-NEXT: - Tag: DT_RELENT
54+
# CHECK-NEXT: Value: 0x0000000000000013
55+
# CHECK-NEXT: - Tag: DT_PLTREL
56+
# CHECK-NEXT: Value: 0x0000000000000014
57+
# CHECK-NEXT: - Tag: DT_DEBUG
58+
# CHECK-NEXT: Value: 0x0000000000000015
59+
# CHECK-NEXT: - Tag: DT_TEXTREL
60+
# CHECK-NEXT: Value: 0x0000000000000016
61+
# CHECK-NEXT: - Tag: DT_JMPREL
62+
# CHECK-NEXT: Value: 0x0000000000000017
63+
# CHECK-NEXT: - Tag: DT_BIND_NOW
64+
# CHECK-NEXT: Value: 0x0000000000000018
65+
# CHECK-NEXT: - Tag: DT_INIT_ARRAY
66+
# CHECK-NEXT: Value: 0x0000000000000019
67+
# CHECK-NEXT: - Tag: DT_FINI_ARRAY
68+
# CHECK-NEXT: Value: 0x000000000000001A
69+
# CHECK-NEXT: - Tag: DT_INIT_ARRAYSZ
70+
# CHECK-NEXT: Value: 0x000000000000001B
71+
# CHECK-NEXT: - Tag: DT_FINI_ARRAYSZ
72+
# CHECK-NEXT: Value: 0x000000000000001C
73+
# CHECK-NEXT: - Tag: DT_RUNPATH
74+
# CHECK-NEXT: Value: 0x000000000000001D
75+
# CHECK-NEXT: - Tag: DT_FLAGS
76+
# CHECK-NEXT: Value: 0x000000000000001E
77+
# CHECK-NEXT: - Tag: DT_PREINIT_ARRAY
78+
# CHECK-NEXT: Value: 0x000000000000001F
79+
# CHECK-NEXT: - Tag: DT_PREINIT_ARRAYSZ
80+
# CHECK-NEXT: Value: 0x0000000000000020
81+
# CHECK-NEXT: - Tag: DT_SYMTAB_SHNDX
82+
# CHECK-NEXT: Value: 0x0000000000000021
83+
# CHECK-NEXT: - Tag: DT_RELRSZ
84+
# CHECK-NEXT: Value: 0x0000000000000022
85+
# CHECK-NEXT: - Tag: DT_RELR
86+
# CHECK-NEXT: Value: 0x0000000000000023
87+
# CHECK-NEXT: - Tag: DT_RELRENT
88+
# CHECK-NEXT: Value: 0x0000000000000024
89+
# CHECK-NEXT: - Tag: DT_ANDROID_REL
90+
# CHECK-NEXT: Value: 0x0000000000000025
91+
# CHECK-NEXT: - Tag: DT_ANDROID_RELSZ
92+
# CHECK-NEXT: Value: 0x0000000000000026
93+
# CHECK-NEXT: - Tag: DT_ANDROID_RELA
94+
# CHECK-NEXT: Value: 0x0000000000000027
95+
# CHECK-NEXT: - Tag: DT_ANDROID_RELASZ
96+
# CHECK-NEXT: Value: 0x0000000000000028
97+
# CHECK-NEXT: - Tag: DT_ANDROID_RELR
98+
# CHECK-NEXT: Value: 0x0000000000000029
99+
# CHECK-NEXT: - Tag: DT_ANDROID_RELRSZ
100+
# CHECK-NEXT: Value: 0x000000000000002A
101+
# CHECK-NEXT: - Tag: DT_ANDROID_RELRENT
102+
# CHECK-NEXT: Value: 0x000000000000002B
103+
# CHECK-NEXT: - Tag: DT_GNU_HASH
104+
# CHECK-NEXT: Value: 0x000000000000002C
105+
# CHECK-NEXT: - Tag: DT_TLSDESC_PLT
106+
# CHECK-NEXT: Value: 0x000000000000002D
107+
# CHECK-NEXT: - Tag: DT_TLSDESC_GOT
108+
# CHECK-NEXT: Value: 0x000000000000002E
109+
# CHECK-NEXT: - Tag: DT_RELACOUNT
110+
# CHECK-NEXT: Value: 0x000000000000002F
111+
# CHECK-NEXT: - Tag: DT_RELCOUNT
112+
# CHECK-NEXT: Value: 0x0000000000000030
113+
# CHECK-NEXT: - Tag: DT_FLAGS_1
114+
# CHECK-NEXT: Value: 0x0000000000000031
115+
# CHECK-NEXT: - Tag: DT_VERSYM
116+
# CHECK-NEXT: Value: 0x0000000000000032
117+
# CHECK-NEXT: - Tag: DT_VERDEF
118+
# CHECK-NEXT: Value: 0x0000000000000033
119+
# CHECK-NEXT: - Tag: DT_VERDEFNUM
120+
# CHECK-NEXT: Value: 0x0000000000000034
121+
# CHECK-NEXT: - Tag: DT_VERNEED
122+
# CHECK-NEXT: Value: 0x0000000000000035
123+
# CHECK-NEXT: - Tag: DT_VERNEEDNUM
124+
# CHECK-NEXT: Value: 0x0000000000000036
125+
126+
!ELF
127+
FileHeader:
128+
Class: ELFCLASS64
129+
Data: ELFDATA2LSB
130+
Type: ET_DYN
131+
Machine: EM_X86_64
132+
Sections:
133+
- Name: .dynamic
134+
Type: SHT_DYNAMIC
135+
Address: 0x0000000000001000
136+
AddressAlign: 0x0000000000002000
137+
EntSize: 0x0000000000000010
138+
Entries:
139+
- Tag: DT_NULL
140+
Value: 0x0000000000000000
141+
- Tag: DT_NEEDED
142+
Value: 0x0000000000000001
143+
- Tag: DT_PLTRELSZ
144+
Value: 0x0000000000000002
145+
- Tag: DT_PLTGOT
146+
Value: 0x0000000000000003
147+
- Tag: DT_HASH
148+
Value: 0x0000000000000004
149+
- Tag: DT_STRTAB
150+
Value: 0x0000000000000005
151+
- Tag: DT_SYMTAB
152+
Value: 0x0000000000000006
153+
- Tag: DT_RELA
154+
Value: 0x0000000000000007
155+
- Tag: DT_RELASZ
156+
Value: 0x0000000000000008
157+
- Tag: DT_RELAENT
158+
Value: 0x0000000000000009
159+
- Tag: DT_STRSZ
160+
Value: 0x000000000000000A
161+
- Tag: DT_SYMENT
162+
Value: 0x000000000000000B
163+
- Tag: DT_INIT
164+
Value: 0x000000000000000C
165+
- Tag: DT_FINI
166+
Value: 0x000000000000000D
167+
- Tag: DT_SONAME
168+
Value: 0x000000000000000E
169+
- Tag: DT_RPATH
170+
Value: 0x000000000000000F
171+
- Tag: DT_SYMBOLIC
172+
Value: 0x0000000000000010
173+
- Tag: DT_REL
174+
Value: 0x0000000000000011
175+
- Tag: DT_RELSZ
176+
Value: 0x0000000000000012
177+
- Tag: DT_RELENT
178+
Value: 0x0000000000000013
179+
- Tag: DT_PLTREL
180+
Value: 0x0000000000000014
181+
- Tag: DT_DEBUG
182+
Value: 0x0000000000000015
183+
- Tag: DT_TEXTREL
184+
Value: 0x0000000000000016
185+
- Tag: DT_JMPREL
186+
Value: 0x0000000000000017
187+
- Tag: DT_BIND_NOW
188+
Value: 0x0000000000000018
189+
- Tag: DT_INIT_ARRAY
190+
Value: 0x0000000000000019
191+
- Tag: DT_FINI_ARRAY
192+
Value: 0x000000000000001A
193+
- Tag: DT_INIT_ARRAYSZ
194+
Value: 0x000000000000001B
195+
- Tag: DT_FINI_ARRAYSZ
196+
Value: 0x000000000000001C
197+
- Tag: DT_RUNPATH
198+
Value: 0x000000000000001D
199+
- Tag: DT_FLAGS
200+
Value: 0x000000000000001E
201+
- Tag: DT_PREINIT_ARRAY
202+
Value: 0x000000000000001F
203+
- Tag: DT_PREINIT_ARRAYSZ
204+
Value: 0x0000000000000020
205+
- Tag: DT_SYMTAB_SHNDX
206+
Value: 0x0000000000000021
207+
- Tag: DT_RELRSZ
208+
Value: 0x0000000000000022
209+
- Tag: DT_RELR
210+
Value: 0x0000000000000023
211+
- Tag: DT_RELRENT
212+
Value: 0x0000000000000024
213+
- Tag: DT_ANDROID_REL
214+
Value: 0x0000000000000025
215+
- Tag: DT_ANDROID_RELSZ
216+
Value: 0x0000000000000026
217+
- Tag: DT_ANDROID_RELA
218+
Value: 0x0000000000000027
219+
- Tag: DT_ANDROID_RELASZ
220+
Value: 0x0000000000000028
221+
- Tag: DT_ANDROID_RELR
222+
Value: 0x0000000000000029
223+
- Tag: DT_ANDROID_RELRSZ
224+
Value: 0x000000000000002A
225+
- Tag: DT_ANDROID_RELRENT
226+
Value: 0x000000000000002B
227+
- Tag: DT_GNU_HASH
228+
Value: 0x000000000000002C
229+
- Tag: DT_TLSDESC_PLT
230+
Value: 0x000000000000002D
231+
- Tag: DT_TLSDESC_GOT
232+
Value: 0x000000000000002E
233+
- Tag: DT_RELACOUNT
234+
Value: 0x000000000000002F
235+
- Tag: DT_RELCOUNT
236+
Value: 0x0000000000000030
237+
- Tag: DT_FLAGS_1
238+
Value: 0x0000000000000031
239+
- Tag: DT_VERSYM
240+
Value: 0x0000000000000032
241+
- Tag: DT_VERDEF
242+
Value: 0x0000000000000033
243+
- Tag: DT_VERDEFNUM
244+
Value: 0x0000000000000034
245+
- Tag: DT_VERNEED
246+
Value: 0x0000000000000035
247+
- Tag: DT_VERNEEDNUM
248+
Value: 0x0000000000000036

‎llvm/tools/obj2yaml/elf2yaml.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace {
2121
template <class ELFT>
2222
class ELFDumper {
2323
typedef object::Elf_Sym_Impl<ELFT> Elf_Sym;
24+
typedef typename ELFT::Dyn Elf_Dyn;
2425
typedef typename ELFT::Shdr Elf_Shdr;
2526
typedef typename ELFT::Word Elf_Word;
2627
typedef typename ELFT::Rel Elf_Rel;
@@ -50,7 +51,8 @@ class ELFDumper {
5051
template <class RelT>
5152
std::error_code dumpRelocation(const RelT *Rel, const Elf_Shdr *SymTab,
5253
ELFYAML::Relocation &R);
53-
54+
55+
ErrorOr<ELFYAML::DynamicSection *> dumpDynamicSection(const Elf_Shdr *Shdr);
5456
ErrorOr<ELFYAML::RelocationSection *> dumpRelocSection(const Elf_Shdr *Shdr);
5557
ErrorOr<ELFYAML::RawContentSection *>
5658
dumpContentSection(const Elf_Shdr *Shdr);
@@ -129,6 +131,13 @@ template <class ELFT> ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
129131
SectionNames.resize(Sections.size());
130132
for (const Elf_Shdr &Sec : Sections) {
131133
switch (Sec.sh_type) {
134+
case ELF::SHT_DYNAMIC: {
135+
ErrorOr<ELFYAML::DynamicSection *> S = dumpDynamicSection(&Sec);
136+
if (std::error_code EC = S.getError())
137+
return EC;
138+
Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get()));
139+
break;
140+
}
132141
case ELF::SHT_NULL:
133142
case ELF::SHT_STRTAB:
134143
// Do not dump these sections.
@@ -350,6 +359,23 @@ ELFDumper<ELFT>::dumpCommonRelocationSection(const Elf_Shdr *Shdr,
350359
return obj2yaml_error::success;
351360
}
352361

362+
template <class ELFT>
363+
ErrorOr<ELFYAML::DynamicSection *>
364+
ELFDumper<ELFT>::dumpDynamicSection(const Elf_Shdr *Shdr) {
365+
auto S = make_unique<ELFYAML::DynamicSection>();
366+
if (std::error_code EC = dumpCommonSection(Shdr, *S))
367+
return EC;
368+
369+
auto DynTagsOrErr = Obj.template getSectionContentsAsArray<Elf_Dyn>(Shdr);
370+
if (!DynTagsOrErr)
371+
return errorToErrorCode(DynTagsOrErr.takeError());
372+
373+
for (const Elf_Dyn &Dyn : *DynTagsOrErr)
374+
S->Entries.push_back({(ELFYAML::ELF_DYNTAG)Dyn.getTag(), Dyn.getVal()});
375+
376+
return S.release();
377+
}
378+
353379
template <class ELFT>
354380
ErrorOr<ELFYAML::RelocationSection *>
355381
ELFDumper<ELFT>::dumpRelocSection(const Elf_Shdr *Shdr) {

‎llvm/tools/yaml2obj/yaml2elf.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ class ELFState {
159159
bool writeSectionContent(Elf_Shdr &SHeader,
160160
const ELFYAML::MipsABIFlags &Section,
161161
ContiguousBlobAccumulator &CBA);
162+
void writeSectionContent(Elf_Shdr &SHeader,
163+
const ELFYAML::DynamicSection &Section,
164+
ContiguousBlobAccumulator &CBA);
162165
bool hasDynamicSymbols() const;
163166
SmallVector<const char *, 5> implicitSectionNames() const;
164167

@@ -291,6 +294,8 @@ bool ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
291294
// SHT_NOBITS section does not have content
292295
// so just to setup the section offset.
293296
CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
297+
} else if (auto S = dyn_cast<ELFYAML::DynamicSection>(Sec.get())) {
298+
writeSectionContent(SHeader, *S, CBA);
294299
} else
295300
llvm_unreachable("Unknown section type");
296301

@@ -465,8 +470,6 @@ ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
465470
SHeader.sh_entsize = *Section.EntSize;
466471
else if (Section.Type == llvm::ELF::SHT_RELR)
467472
SHeader.sh_entsize = sizeof(Elf_Relr);
468-
else if (Section.Type == llvm::ELF::SHT_DYNAMIC)
469-
SHeader.sh_entsize = sizeof(Elf_Dyn);
470473
else
471474
SHeader.sh_entsize = 0;
472475
SHeader.sh_size = Section.Size;
@@ -575,6 +578,29 @@ bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
575578
return true;
576579
}
577580

581+
template <class ELFT>
582+
void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
583+
const ELFYAML::DynamicSection &Section,
584+
ContiguousBlobAccumulator &CBA) {
585+
typedef typename ELFT::uint uintX_t;
586+
assert(Section.Type == llvm::ELF::SHT_DYNAMIC &&
587+
"Section type is not SHT_DYNAMIC");
588+
589+
SHeader.sh_size = 2 * sizeof(uintX_t) * Section.Entries.size();
590+
if (Section.EntSize)
591+
SHeader.sh_entsize = *Section.EntSize;
592+
else
593+
SHeader.sh_entsize = sizeof(Elf_Dyn);
594+
595+
auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
596+
for (const ELFYAML::DynamicEntry &DE : Section.Entries) {
597+
uintX_t Tag = DE.Tag;
598+
OS.write((const char *)&Tag, sizeof(uintX_t));
599+
uintX_t Val = DE.Val;
600+
OS.write((const char *)&Val, sizeof(uintX_t));
601+
}
602+
}
603+
578604
template <class ELFT> bool ELFState<ELFT>::buildSectionIndex() {
579605
for (unsigned i = 0, e = Doc.Sections.size(); i != e; ++i) {
580606
StringRef Name = Doc.Sections[i]->Name;

0 commit comments

Comments
 (0)
Please sign in to comment.