Skip to content

Commit 10316a6

Browse files
committed
[ELF] Change InputSectionDescription members from vector to SmallVector
This decreases sizeof(lld::elf::InputSectionDescription) from 264 to 232.
1 parent 511726c commit 10316a6

File tree

5 files changed

+23
-26
lines changed

5 files changed

+23
-26
lines changed

lld/ELF/AArch64ErrataFix.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ void AArch64Err843419Patcher::insertPatches(
512512
// determine the insertion point. This is ok as we only merge into an
513513
// InputSectionDescription once per pass, and at the end of the pass
514514
// assignAddresses() will recalculate all the outSecOff values.
515-
std::vector<InputSection *> tmp;
515+
SmallVector<InputSection *, 0> tmp;
516516
tmp.reserve(isd.sections.size() + patches.size());
517517
auto mergeCmp = [](const InputSection *a, const InputSection *b) {
518518
if (a->outSecOff != b->outSecOff)

lld/ELF/ARMErrataFix.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ void ARMErr657417Patcher::insertPatches(
395395
// determine the insertion point. This is ok as we only merge into an
396396
// InputSectionDescription once per pass, and at the end of the pass
397397
// assignAddresses() will recalculate all the outSecOff values.
398-
std::vector<InputSection *> tmp;
398+
SmallVector<InputSection *, 0> tmp;
399399
tmp.reserve(isd.sections.size() + patches.size());
400400
auto mergeCmp = [](const InputSection *a, const InputSection *b) {
401401
if (a->outSecOff != b->outSecOff)

lld/ELF/LinkerScript.cpp

+9-12
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ using SymbolAssignmentMap =
270270

271271
// Collect section/value pairs of linker-script-defined symbols. This is used to
272272
// check whether symbol values converge.
273-
static SymbolAssignmentMap getSymbolAssignmentValues(
274-
const std::vector<SectionCommand *> &sectionCommands) {
273+
static SymbolAssignmentMap
274+
getSymbolAssignmentValues(ArrayRef<SectionCommand *> sectionCommands) {
275275
SymbolAssignmentMap ret;
276276
for (SectionCommand *cmd : sectionCommands) {
277277
if (auto *assign = dyn_cast<SymbolAssignment>(cmd)) {
@@ -486,10 +486,10 @@ static void sortInputSections(MutableArrayRef<InputSectionBase *> vec,
486486
}
487487

488488
// Compute and remember which sections the InputSectionDescription matches.
489-
std::vector<InputSectionBase *>
489+
SmallVector<InputSectionBase *, 0>
490490
LinkerScript::computeInputSections(const InputSectionDescription *cmd,
491491
ArrayRef<InputSectionBase *> sections) {
492-
std::vector<InputSectionBase *> ret;
492+
SmallVector<InputSectionBase *, 0> ret;
493493
std::vector<size_t> indexes;
494494
DenseSet<size_t> seen;
495495
auto sortByPositionThenCommandLine = [&](size_t begin, size_t end) {
@@ -585,18 +585,15 @@ void LinkerScript::discardSynthetic(OutputSection &outCmd) {
585585
std::vector<InputSectionBase *> secs(part.armExidx->exidxSections.begin(),
586586
part.armExidx->exidxSections.end());
587587
for (SectionCommand *cmd : outCmd.commands)
588-
if (auto *isd = dyn_cast<InputSectionDescription>(cmd)) {
589-
std::vector<InputSectionBase *> matches =
590-
computeInputSections(isd, secs);
591-
for (InputSectionBase *s : matches)
588+
if (auto *isd = dyn_cast<InputSectionDescription>(cmd))
589+
for (InputSectionBase *s : computeInputSections(isd, secs))
592590
discard(*s);
593-
}
594591
}
595592
}
596593

597-
std::vector<InputSectionBase *>
594+
SmallVector<InputSectionBase *, 0>
598595
LinkerScript::createInputSectionList(OutputSection &outCmd) {
599-
std::vector<InputSectionBase *> ret;
596+
SmallVector<InputSectionBase *, 0> ret;
600597

601598
for (SectionCommand *cmd : outCmd.commands) {
602599
if (auto *isd = dyn_cast<InputSectionDescription>(cmd)) {
@@ -612,7 +609,7 @@ LinkerScript::createInputSectionList(OutputSection &outCmd) {
612609
// Create output sections described by SECTIONS commands.
613610
void LinkerScript::processSectionCommands() {
614611
auto process = [this](OutputSection *osec) {
615-
std::vector<InputSectionBase *> v = createInputSectionList(*osec);
612+
SmallVector<InputSectionBase *, 0> v = createInputSectionList(*osec);
616613

617614
// The output section name `/DISCARD/' is special.
618615
// Any input section assigned to it is discarded.

lld/ELF/LinkerScript.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,20 @@ class InputSectionDescription : public SectionCommand {
203203

204204
// Input sections that matches at least one of SectionPatterns
205205
// will be associated with this InputSectionDescription.
206-
std::vector<SectionPattern> sectionPatterns;
206+
SmallVector<SectionPattern, 0> sectionPatterns;
207207

208208
// Includes InputSections and MergeInputSections. Used temporarily during
209209
// assignment of input sections to output sections.
210-
std::vector<InputSectionBase *> sectionBases;
210+
SmallVector<InputSectionBase *, 0> sectionBases;
211211

212212
// Used after the finalizeInputSections() pass. MergeInputSections have been
213213
// merged into MergeSyntheticSections.
214-
std::vector<InputSection *> sections;
214+
SmallVector<InputSection *, 0> sections;
215215

216216
// Temporary record of synthetic ThunkSection instances and the pass that
217217
// they were created in. This is used to insert newly created ThunkSections
218218
// into Sections at the end of a createThunks() pass.
219-
std::vector<std::pair<ThunkSection *, uint32_t>> thunkSections;
219+
SmallVector<std::pair<ThunkSection *, uint32_t>, 0> thunkSections;
220220

221221
// SectionPatterns can be filtered with the INPUT_SECTION_FLAGS command.
222222
uint64_t withFlags;
@@ -279,11 +279,11 @@ class LinkerScript final {
279279
void expandOutputSection(uint64_t size);
280280
void expandMemoryRegions(uint64_t size);
281281

282-
std::vector<InputSectionBase *>
282+
SmallVector<InputSectionBase *, 0>
283283
computeInputSections(const InputSectionDescription *,
284284
ArrayRef<InputSectionBase *>);
285285

286-
std::vector<InputSectionBase *> createInputSectionList(OutputSection &cmd);
286+
SmallVector<InputSectionBase *, 0> createInputSectionList(OutputSection &cmd);
287287

288288
void discardSynthetic(OutputSection &);
289289

@@ -347,23 +347,23 @@ class LinkerScript final {
347347

348348
// List of section patterns specified with KEEP commands. They will
349349
// be kept even if they are unused and --gc-sections is specified.
350-
std::vector<InputSectionDescription *> keptSections;
350+
SmallVector<InputSectionDescription *, 0> keptSections;
351351

352352
// A map from memory region name to a memory region descriptor.
353353
llvm::MapVector<llvm::StringRef, MemoryRegion *> memoryRegions;
354354

355355
// A list of symbols referenced by the script.
356-
std::vector<llvm::StringRef> referencedSymbols;
356+
SmallVector<llvm::StringRef, 0> referencedSymbols;
357357

358358
// Used to implement INSERT [AFTER|BEFORE]. Contains output sections that need
359359
// to be reordered.
360-
std::vector<InsertCommand> insertCommands;
360+
SmallVector<InsertCommand, 0> insertCommands;
361361

362362
// OutputSections specified by OVERWRITE_SECTIONS.
363-
std::vector<OutputSection *> overwriteSections;
363+
SmallVector<OutputSection *, 0> overwriteSections;
364364

365365
// Sections that will be warned/errored by --orphan-handling.
366-
std::vector<const InputSectionBase *> orphanSections;
366+
SmallVector<const InputSectionBase *, 0> orphanSections;
367367
};
368368

369369
extern std::unique_ptr<LinkerScript> script;

lld/ELF/Relocations.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ void ThunkCreator::mergeThunks(ArrayRef<OutputSection *> outputSections) {
18161816
});
18171817

18181818
// Merge sorted vectors of Thunks and InputSections by outSecOff
1819-
std::vector<InputSection *> tmp;
1819+
SmallVector<InputSection *, 0> tmp;
18201820
tmp.reserve(isd->sections.size() + newThunks.size());
18211821

18221822
std::merge(isd->sections.begin(), isd->sections.end(),

0 commit comments

Comments
 (0)