[lld] ac0986f - [ELF] Change std::vector<InputSectionBase *> to SmallVector
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 17 10:25:12 PST 2022
Author: Fangrui Song
Date: 2022-01-17T10:25:07-08:00
New Revision: ac0986f88058b5d82559ca84c607c7a664827cbc
URL: https://github.com/llvm/llvm-project/commit/ac0986f88058b5d82559ca84c607c7a664827cbc
DIFF: https://github.com/llvm/llvm-project/commit/ac0986f88058b5d82559ca84c607c7a664827cbc.diff
LOG: [ELF] Change std::vector<InputSectionBase *> to SmallVector
There is no remaining std::vector<InputSectionBase> now. My x86-64 lld
executable is 2KiB small.
Added:
Modified:
lld/ELF/LinkerScript.cpp
lld/ELF/SyntheticSections.cpp
lld/ELF/SyntheticSections.h
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 30bf9abc8fafd..3dd3df80e36f4 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -574,8 +574,9 @@ void LinkerScript::discardSynthetic(OutputSection &outCmd) {
for (Partition &part : partitions) {
if (!part.armExidx || !part.armExidx->isLive())
continue;
- std::vector<InputSectionBase *> secs(part.armExidx->exidxSections.begin(),
- part.armExidx->exidxSections.end());
+ SmallVector<InputSectionBase *, 0> secs(
+ part.armExidx->exidxSections.begin(),
+ part.armExidx->exidxSections.end());
for (SectionCommand *cmd : outCmd.commands)
if (auto *isd = dyn_cast<InputSectionDescription>(cmd))
for (InputSectionBase *s : computeInputSections(isd, secs))
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 3e67735451423..c1eb53e9d44b0 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -171,7 +171,7 @@ MipsOptionsSection<ELFT> *MipsOptionsSection<ELFT>::create() {
if (!ELFT::Is64Bits)
return nullptr;
- std::vector<InputSectionBase *> sections;
+ SmallVector<InputSectionBase *, 0> sections;
for (InputSectionBase *sec : inputSections)
if (sec->type == SHT_MIPS_OPTIONS)
sections.push_back(sec);
@@ -228,7 +228,7 @@ MipsReginfoSection<ELFT> *MipsReginfoSection<ELFT>::create() {
if (ELFT::Is64Bits)
return nullptr;
- std::vector<InputSectionBase *> sections;
+ SmallVector<InputSectionBase *, 0> sections;
for (InputSectionBase *sec : inputSections)
if (sec->type == SHT_MIPS_REGINFO)
sections.push_back(sec);
@@ -550,9 +550,9 @@ void EhFrameSection::finalizeContents() {
// Returns data for .eh_frame_hdr. .eh_frame_hdr is a binary search table
// to get an FDE from an address to which FDE is applied. This function
// returns a list of such pairs.
-std::vector<EhFrameSection::FdeData> EhFrameSection::getFdeData() const {
+SmallVector<EhFrameSection::FdeData, 0> EhFrameSection::getFdeData() const {
uint8_t *buf = Out::bufferStart + getParent()->offset + outSecOff;
- std::vector<FdeData> ret;
+ SmallVector<FdeData, 0> ret;
uint64_t va = getPartition().ehFrameHdr->getVA();
for (CieRecord *rec : cieRecords) {
@@ -3030,8 +3030,7 @@ void EhFrameHeader::writeTo(uint8_t *buf) {
void EhFrameHeader::write() {
uint8_t *buf = Out::bufferStart + getParent()->offset + outSecOff;
using FdeData = EhFrameSection::FdeData;
-
- std::vector<FdeData> fdes = getPartition().ehFrame->getFdeData();
+ SmallVector<FdeData, 0> fdes = getPartition().ehFrame->getFdeData();
buf[0] = 1;
buf[1] = DW_EH_PE_pcrel | DW_EH_PE_sdata4;
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 6f8453288a8eb..9f4073048ce57 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -86,7 +86,7 @@ class EhFrameSection final : public SyntheticSection {
uint32_t fdeVARel;
};
- std::vector<FdeData> getFdeData() const;
+ SmallVector<FdeData, 0> getFdeData() const;
ArrayRef<CieRecord *> getCieRecords() const { return cieRecords; }
template <class ELFT>
void iterateFDEWithLSDA(llvm::function_ref<void(InputSection &)> fn);
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index ba69189eeccd4..9eefe5c84a114 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -120,7 +120,7 @@ static void removeEmptyPTLoad(SmallVector<PhdrEntry *, 0> &phdrs) {
}
void elf::copySectionsIntoPartitions() {
- std::vector<InputSectionBase *> newSections;
+ SmallVector<InputSectionBase *, 0> newSections;
for (unsigned part = 2; part != partitions.size() + 1; ++part) {
for (InputSectionBase *s : inputSections) {
if (!(s->flags & SHF_ALLOC) || !s->isLive())
More information about the llvm-commits
mailing list