aboutsummaryrefslogtreecommitdiff
path: root/lld/ELF/SyntheticSections.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2021-12-22 21:34:25 -0800
committerFangrui Song <i@maskray.me>2021-12-22 21:34:26 -0800
commite48b1c8a27f0fbd791edc8e45756b268caadfa66 (patch)
tree12b0d5427f4028022cb66b3bca29a8094e86b4f5 /lld/ELF/SyntheticSections.cpp
parent9f3aca7eaefe66f501141446c44dee0447322e3d (diff)
downloadllvm-e48b1c8a27f0fbd791edc8e45756b268caadfa66.zip
llvm-e48b1c8a27f0fbd791edc8e45756b268caadfa66.tar.gz
llvm-e48b1c8a27f0fbd791edc8e45756b268caadfa66.tar.bz2
[ELF] Make Partition members unique_ptr and remove associate make<XXX>
See D116143 for benefits. My lld executable (x86-64) is 103+KiB smaller.
Diffstat (limited to 'lld/ELF/SyntheticSections.cpp')
-rw-r--r--lld/ELF/SyntheticSections.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 047546e..dd4c5f7 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(RelocationBaseSection *relaDyn) {
- size_t size = relaDyn->getSize();
- if (in.relaIplt->getParent() == relaDyn->getParent())
+static uint64_t addRelaSz(const 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,7 +1375,8 @@ 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,
@@ -1626,7 +1627,7 @@ void RelocationBaseSection::addReloc(const DynamicReloc &reloc) {
}
void RelocationBaseSection::finalizeContents() {
- SymbolTableBaseSection *symTab = getPartition().dynSymTab;
+ SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
// 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
@@ -1677,7 +1678,7 @@ RelocationSection<ELFT>::RelocationSection(StringRef name, bool sort)
}
template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *buf) {
- SymbolTableBaseSection *symTab = getPartition().dynSymTab;
+ SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
parallelForEach(relocs,
[symTab](DynamicReloc &rel) { rel.computeRaw(symTab); });
@@ -1772,8 +1773,8 @@ bool AndroidPackedRelocationSection<ELFT>::updateAllocSize() {
for (const DynamicReloc &rel : relocs) {
Elf_Rela r;
r.r_offset = rel.getOffset();
- r.setSymbolAndType(rel.getSymIndex(getPartition().dynSymTab), rel.type,
- false);
+ r.setSymbolAndType(rel.getSymIndex(getPartition().dynSymTab.get()),
+ rel.type, false);
if (config->isRela)
r.r_addend = rel.computeAddend();
@@ -2099,7 +2100,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) {
+ if (this == mainPart->dynSymTab.get()) {
size_t i = 0;
for (const SymbolTableEntry &s : symbols)
s.sym->dynsymIndex = ++i;
@@ -2146,7 +2147,7 @@ void SymbolTableBaseSection::addSymbol(Symbol *b) {
}
size_t SymbolTableBaseSection::getSymbolIndex(Symbol *sym) {
- if (this == mainPart->dynSymTab)
+ if (this == mainPart->dynSymTab.get())
return sym->dynsymIndex;
// Initializes symbol lookup tables lazily. This is used only for -r,
@@ -2481,7 +2482,7 @@ HashTableSection::HashTableSection()
}
void HashTableSection::finalizeContents() {
- SymbolTableBaseSection *symTab = getPartition().dynSymTab;
+ SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
if (OutputSection *sec = symTab->getParent())
getParent()->link = sec->sectionIndex;
@@ -2495,7 +2496,7 @@ void HashTableSection::finalizeContents() {
}
void HashTableSection::writeTo(uint8_t *buf) {
- SymbolTableBaseSection *symTab = getPartition().dynSymTab;
+ SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
// See comment in GnuHashTableSection::writeTo.
memset(buf, 0, size);
@@ -3803,7 +3804,7 @@ void PartitionIndexSection::writeTo(uint8_t *buf) {
SyntheticSection *next = i == partitions.size() - 1
? in.partEnd.get()
- : partitions[i + 1].elfHeader;
+ : partitions[i + 1].elfHeader.get();
write32(buf + 8, next->getVA() - partitions[i].elfHeader->getVA());
va += 12;