Skip to content

Commit d4ae050

Browse files
[ObjectYAML][ELF] Allow verdaux entry offset to be user-defined
1 parent f112c1e commit d4ae050

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

Diff for: llvm/include/llvm/ObjectYAML/ELFYAML.h

+1
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ struct VerdefEntry {
582582
std::optional<uint16_t> Flags;
583583
std::optional<uint16_t> VersionNdx;
584584
std::optional<uint32_t> Hash;
585+
std::optional<uint16_t> VDAux;
585586
std::vector<StringRef> VerNames;
586587
};
587588

Diff for: llvm/lib/ObjectYAML/ELFEmitter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
16551655
VerDef.vd_flags = E.Flags.value_or(0);
16561656
VerDef.vd_ndx = E.VersionNdx.value_or(0);
16571657
VerDef.vd_hash = E.Hash.value_or(0);
1658-
VerDef.vd_aux = sizeof(Elf_Verdef);
1658+
VerDef.vd_aux = E.VDAux.value_or(sizeof(Elf_Verdef));
16591659
VerDef.vd_cnt = E.VerNames.size();
16601660
if (I == Section.Entries->size() - 1)
16611661
VerDef.vd_next = 0;

Diff for: llvm/lib/ObjectYAML/ELFYAML.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1921,6 +1921,7 @@ void MappingTraits<ELFYAML::VerdefEntry>::mapping(IO &IO,
19211921
IO.mapOptional("Flags", E.Flags);
19221922
IO.mapOptional("VersionNdx", E.VersionNdx);
19231923
IO.mapOptional("Hash", E.Hash);
1924+
IO.mapOptional("VDAux", E.VDAux);
19241925
IO.mapRequired("Names", E.VerNames);
19251926
}
19261927

Diff for: llvm/test/tools/obj2yaml/ELF/verdef-section.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ Sections:
4848
Flags: 0
4949
VersionNdx: 0
5050
Hash: 0
51+
VDAux: 20
5152
Names:
5253
- VERSION_0
5354
## An entry with arbitrary values.
5455
- Flags: 2
5556
VersionNdx: 2
5657
Hash: 108387921
58+
VDAux: [[VDAUX=20]]
5759
Names:
5860
- VERSION_1
5961
## Another entry with arbitrary values and version predecessors.
@@ -81,3 +83,9 @@ DynamicSymbols: []
8183
# RUN: FileCheck %s -DFILE=%t.version --check-prefix=VERSION-ERR
8284

8385
# VERSION-ERR: Error reading file: [[FILE]]: invalid SHT_GNU_verdef section version: 2
86+
87+
# RUN: yaml2obj %s -DVDAUX=100 -o %t.vdaux
88+
# RUN: not obj2yaml %t.vdaux 2>&1 | \
89+
# RUN: FileCheck %s -DFILE=%t.vdaux --check-prefix=VDAUX-ERR
90+
91+
# VDAUX-ERR: Error reading file: [[FILE]]: corrupted section: vd_aux value 100 in section verdef points past end of the section

Diff for: llvm/tools/obj2yaml/elf2yaml.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,15 @@ ELFDumper<ELFT>::dumpVerdefSection(const Elf_Shdr *Shdr) {
14511451
if (Verdef->vd_hash != 0)
14521452
Entry.Hash = Verdef->vd_hash;
14531453

1454+
if (Verdef->vd_aux != sizeof(Elf_Verdef))
1455+
Entry.VDAux = Verdef->vd_aux;
1456+
14541457
const uint8_t *BufAux = Buf + Verdef->vd_aux;
1458+
if (BufAux > Data.end())
1459+
return createStringError(
1460+
errc::invalid_argument,
1461+
"corrupted section: vd_aux value " + Twine(Verdef->vd_aux) +
1462+
" in section verdef points past end of the section");
14551463
while (BufAux) {
14561464
const Elf_Verdaux *Verdaux =
14571465
reinterpret_cast<const Elf_Verdaux *>(BufAux);

0 commit comments

Comments
 (0)