aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objcopy/ELF/Object.cpp
diff options
context:
space:
mode:
authorEugene Leviant <eleviant@accesssoftek.com>2019-04-12 11:59:30 +0000
committerEugene Leviant <eleviant@accesssoftek.com>2019-04-12 11:59:30 +0000
commit88089fed9c79857ce6bb17669c694912f6523955 (patch)
treee6fef7e416fdd7ec4d343c32de61c8fc04681cb1 /llvm/tools/llvm-objcopy/ELF/Object.cpp
parentfb79ff6ab5b79238cc41bd622c139916762631be (diff)
downloadllvm-88089fed9c79857ce6bb17669c694912f6523955.zip
llvm-88089fed9c79857ce6bb17669c694912f6523955.tar.gz
llvm-88089fed9c79857ce6bb17669c694912f6523955.tar.bz2
[llvm-objcopy] Fill .symtab_shndx section correctly
Differential revision: https://reviews.llvm.org/D60555 llvm-svn: 358278
Diffstat (limited to 'llvm/tools/llvm-objcopy/ELF/Object.cpp')
-rw-r--r--llvm/tools/llvm-objcopy/ELF/Object.cpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/llvm/tools/llvm-objcopy/ELF/Object.cpp b/llvm/tools/llvm-objcopy/ELF/Object.cpp
index de51851..979ab0a 100644
--- a/llvm/tools/llvm-objcopy/ELF/Object.cpp
+++ b/llvm/tools/llvm-objcopy/ELF/Object.cpp
@@ -486,22 +486,30 @@ void SymbolTableSection::finalize() {
}
void SymbolTableSection::prepareForLayout() {
- // Add all potential section indexes before file layout so that the section
- // index section has the approprite size.
- if (SectionIndexTable != nullptr) {
- for (const auto &Sym : Symbols) {
- if (Sym->DefinedIn != nullptr && Sym->DefinedIn->Index >= SHN_LORESERVE)
- SectionIndexTable->addIndex(Sym->DefinedIn->Index);
- else
- SectionIndexTable->addIndex(SHN_UNDEF);
- }
- }
+ // Reserve proper amount of space in section index table, so we can
+ // layout sections correctly. We will fill the table with correct
+ // indexes later in fillShdnxTable.
+ if (SectionIndexTable)
+ SectionIndexTable->reserve(Symbols.size());
// Add all of our strings to SymbolNames so that SymbolNames has the right
// size before layout is decided.
for (auto &Sym : Symbols)
SymbolNames->addString(Sym->Name);
}
+void SymbolTableSection::fillShndxTable() {
+ if (SectionIndexTable == nullptr)
+ return;
+ // Fill section index table with real section indexes. This function must
+ // be called after assignOffsets.
+ for (const auto &Sym : Symbols) {
+ if (Sym->DefinedIn != nullptr && Sym->DefinedIn->Index >= SHN_LORESERVE)
+ SectionIndexTable->addIndex(Sym->DefinedIn->Index);
+ else
+ SectionIndexTable->addIndex(SHN_UNDEF);
+ }
+}
+
const Symbol *SymbolTableSection::getSymbolByIndex(uint32_t Index) const {
if (Symbols.size() <= Index)
error("Invalid symbol index: " + Twine(Index));
@@ -1661,6 +1669,11 @@ template <class ELFT> Error ELFWriter<ELFT>::finalize() {
assignOffsets();
+ // layoutSections could have modified section indexes, so we need
+ // to fill the index table after assignOffsets.
+ if (Obj.SymbolTable != nullptr)
+ Obj.SymbolTable->fillShndxTable();
+
// Finally now that all offsets and indexes have been set we can finalize any
// remaining issues.
uint64_t Offset = Obj.SHOffset + sizeof(Elf_Shdr);