[ELF] Change std::vector<InputSectionBase *> to SmallVector

There is no remaining std::vector<InputSectionBase> now. My x86-64 lld
executable is 2KiB small.
This commit is contained in:
Fangrui Song 2022-01-17 10:25:07 -08:00
parent 5acd6e0522
commit ac0986f880
4 changed files with 10 additions and 10 deletions

View File

@ -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))

View File

@ -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;

View File

@ -86,7 +86,7 @@ public:
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);

View File

@ -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())