aboutsummaryrefslogtreecommitdiff
path: root/lld/ELF/SyntheticSections.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2021-12-22 23:55:11 -0800
committerFangrui Song <i@maskray.me>2021-12-22 23:55:11 -0800
commitad26b0b233d5dc4b792012e7f42e04b1a865c865 (patch)
tree3dc0f5450f3cb7188338179bcfd45b4c8f35f9e1 /lld/ELF/SyntheticSections.cpp
parentd39d2acfdd9f4d09d29752a75f37e756ddb60764 (diff)
downloadllvm-ad26b0b233d5dc4b792012e7f42e04b1a865c865.zip
llvm-ad26b0b233d5dc4b792012e7f42e04b1a865c865.tar.gz
llvm-ad26b0b233d5dc4b792012e7f42e04b1a865c865.tar.bz2
Revert "[ELF] Make Partition/InStruct members unique_ptr and remove associate make<XXX>"
This reverts commit e48b1c8a27f0fbd791edc8e45756b268caadfa66. This reverts commit d019de23a1d761225fdaf0c47394ba58143aea9a. The changes caused memory leaks (non-final classes cannot use unique_ptr).
Diffstat (limited to 'lld/ELF/SyntheticSections.cpp')
-rw-r--r--lld/ELF/SyntheticSections.cpp36
1 files changed, 17 insertions, 19 deletions
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 93d6ed3..9bf6118 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1265,11 +1265,11 @@ DynamicSection<ELFT>::DynamicSection()
// .rela.dyn
//
// DT_RELASZ is the total size of the included sections.
-static uint64_t addRelaSz(const RelocationBaseSection &relaDyn) {
- size_t size = relaDyn.getSize();
- if (in.relaIplt->getParent() == relaDyn.getParent())
+static uint64_t addRelaSz(RelocationBaseSection *relaDyn) {
+ size_t size = relaDyn->getSize();
+ if (in.relaIplt->getParent() == relaDyn->getParent())
size += in.relaIplt->getSize();
- if (in.relaPlt->getParent() == relaDyn.getParent())
+ if (in.relaPlt->getParent() == relaDyn->getParent())
size += in.relaPlt->getSize();
return size;
}
@@ -1375,8 +1375,7 @@ DynamicSection<ELFT>::computeContents() {
(in.relaIplt->isNeeded() &&
part.relaDyn->getParent() == in.relaIplt->getParent())) {
addInSec(part.relaDyn->dynamicTag, *part.relaDyn);
- entries.emplace_back(part.relaDyn->sizeDynamicTag,
- addRelaSz(*part.relaDyn));
+ entries.emplace_back(part.relaDyn->sizeDynamicTag, addRelaSz(part.relaDyn));
bool isRela = config->isRela;
addInt(isRela ? DT_RELAENT : DT_RELENT,
@@ -1627,7 +1626,7 @@ void RelocationBaseSection::addReloc(const DynamicReloc &reloc) {
}
void RelocationBaseSection::finalizeContents() {
- SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
+ SymbolTableBaseSection *symTab = getPartition().dynSymTab;
// When linking glibc statically, .rel{,a}.plt contains R_*_IRELATIVE
// relocations due to IFUNC (e.g. strcpy). sh_link will be set to 0 in that
@@ -1637,11 +1636,11 @@ void RelocationBaseSection::finalizeContents() {
else
getParent()->link = 0;
- if (in.relaPlt.get() == this && in.gotPlt->getParent()) {
+ if (in.relaPlt == this && in.gotPlt->getParent()) {
getParent()->flags |= ELF::SHF_INFO_LINK;
getParent()->info = in.gotPlt->getParent()->sectionIndex;
}
- if (in.relaIplt.get() == this && in.igotPlt->getParent()) {
+ if (in.relaIplt == this && in.igotPlt->getParent()) {
getParent()->flags |= ELF::SHF_INFO_LINK;
getParent()->info = in.igotPlt->getParent()->sectionIndex;
}
@@ -1678,7 +1677,7 @@ RelocationSection<ELFT>::RelocationSection(StringRef name, bool sort)
}
template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *buf) {
- SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
+ SymbolTableBaseSection *symTab = getPartition().dynSymTab;
parallelForEach(relocs,
[symTab](DynamicReloc &rel) { rel.computeRaw(symTab); });
@@ -1773,8 +1772,8 @@ bool AndroidPackedRelocationSection<ELFT>::updateAllocSize() {
for (const DynamicReloc &rel : relocs) {
Elf_Rela r;
r.r_offset = rel.getOffset();
- r.setSymbolAndType(rel.getSymIndex(getPartition().dynSymTab.get()),
- rel.type, false);
+ r.setSymbolAndType(rel.getSymIndex(getPartition().dynSymTab), rel.type,
+ false);
if (config->isRela)
r.r_addend = rel.computeAddend();
@@ -2100,7 +2099,7 @@ void SymbolTableBaseSection::finalizeContents() {
// Only the main partition's dynsym indexes are stored in the symbols
// themselves. All other partitions use a lookup table.
- if (this == mainPart->dynSymTab.get()) {
+ if (this == mainPart->dynSymTab) {
size_t i = 0;
for (const SymbolTableEntry &s : symbols)
s.sym->dynsymIndex = ++i;
@@ -2147,7 +2146,7 @@ void SymbolTableBaseSection::addSymbol(Symbol *b) {
}
size_t SymbolTableBaseSection::getSymbolIndex(Symbol *sym) {
- if (this == mainPart->dynSymTab.get())
+ if (this == mainPart->dynSymTab)
return sym->dynsymIndex;
// Initializes symbol lookup tables lazily. This is used only for -r,
@@ -2482,7 +2481,7 @@ HashTableSection::HashTableSection()
}
void HashTableSection::finalizeContents() {
- SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
+ SymbolTableBaseSection *symTab = getPartition().dynSymTab;
if (OutputSection *sec = symTab->getParent())
getParent()->link = sec->sectionIndex;
@@ -2496,7 +2495,7 @@ void HashTableSection::finalizeContents() {
}
void HashTableSection::writeTo(uint8_t *buf) {
- SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
+ SymbolTableBaseSection *symTab = getPartition().dynSymTab;
// See comment in GnuHashTableSection::writeTo.
memset(buf, 0, size);
@@ -3802,9 +3801,8 @@ void PartitionIndexSection::writeTo(uint8_t *buf) {
write32(buf, mainPart->dynStrTab->getVA() + partitions[i].nameStrTab - va);
write32(buf + 4, partitions[i].elfHeader->getVA() - (va + 4));
- SyntheticSection *next = i == partitions.size() - 1
- ? in.partEnd.get()
- : partitions[i + 1].elfHeader.get();
+ SyntheticSection *next =
+ i == partitions.size() - 1 ? in.partEnd : partitions[i + 1].elfHeader;
write32(buf + 8, next->getVA() - partitions[i].elfHeader->getVA());
va += 12;