Skip to content

Commit

Permalink
[ObjectYAML][ELF] Allow verdaux entry offset to be user-defined
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniofrighetto committed Nov 8, 2024
1 parent f7eba08 commit 60972a8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions llvm/include/llvm/ObjectYAML/ELFYAML.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ struct VerdefEntry {
std::optional<uint16_t> Flags;
std::optional<uint16_t> VersionNdx;
std::optional<uint32_t> Hash;
std::optional<uint16_t> VDAux;
std::vector<StringRef> VerNames;
};

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ObjectYAML/ELFEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
VerDef.vd_flags = E.Flags.value_or(0);
VerDef.vd_ndx = E.VersionNdx.value_or(0);
VerDef.vd_hash = E.Hash.value_or(0);
VerDef.vd_aux = sizeof(Elf_Verdef);
VerDef.vd_aux = E.VDAux.value_or(sizeof(Elf_Verdef));
VerDef.vd_cnt = E.VerNames.size();
if (I == Section.Entries->size() - 1)
VerDef.vd_next = 0;
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/ObjectYAML/ELFYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,7 @@ void MappingTraits<ELFYAML::VerdefEntry>::mapping(IO &IO,
IO.mapOptional("Flags", E.Flags);
IO.mapOptional("VersionNdx", E.VersionNdx);
IO.mapOptional("Hash", E.Hash);
IO.mapOptional("VDAux", E.VDAux);
IO.mapRequired("Names", E.VerNames);
}

Expand Down
8 changes: 8 additions & 0 deletions llvm/test/tools/obj2yaml/ELF/verdef-section.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ Sections:
Flags: 0
VersionNdx: 0
Hash: 0
VDAux: 20
Names:
- VERSION_0
## An entry with arbitrary values.
- Flags: 2
VersionNdx: 2
Hash: 108387921
VDAux: [[VDAUX=20]]
Names:
- VERSION_1
## Another entry with arbitrary values and version predecessors.
Expand Down Expand Up @@ -81,3 +83,9 @@ DynamicSymbols: []
# RUN: FileCheck %s -DFILE=%t.version --check-prefix=VERSION-ERR

# VERSION-ERR: Error reading file: [[FILE]]: invalid SHT_GNU_verdef section version: 2

# RUN: yaml2obj %s -DVDAUX=100 -o %t.vdaux
# RUN: not obj2yaml %t.vdaux 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.vdaux --check-prefix=VDAUX-ERR

# VDAUX-ERR: Error reading file: [[FILE]]: corrupted section: vd_aux value 100 in section verdef points past end of the section
8 changes: 8 additions & 0 deletions llvm/tools/obj2yaml/elf2yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,15 @@ ELFDumper<ELFT>::dumpVerdefSection(const Elf_Shdr *Shdr) {
if (Verdef->vd_hash != 0)
Entry.Hash = Verdef->vd_hash;

if (Verdef->vd_aux != sizeof(Elf_Verdef))
Entry.VDAux = Verdef->vd_aux;

const uint8_t *BufAux = Buf + Verdef->vd_aux;
if (BufAux > Data.end())
return createStringError(
errc::invalid_argument,
"corrupted section: vd_aux value " + Twine(Verdef->vd_aux) +
" in section verdef points past end of the section");
while (BufAux) {
const Elf_Verdaux *Verdaux =
reinterpret_cast<const Elf_Verdaux *>(BufAux);
Expand Down

0 comments on commit 60972a8

Please sign in to comment.