Skip to content

Commit eba30b3

Browse files
committed
[ELF] Replace config-> with ctx.arg. in [IS]*.cpp
1 parent f379b63 commit eba30b3

File tree

9 files changed

+312
-312
lines changed

9 files changed

+312
-312
lines changed

lld/ELF/ICF.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ bool ICF<ELFT>::constantEq(const InputSection *secA, Relocs<RelTy> ra,
242242
auto rai = ra.begin(), rae = ra.end(), rbi = rb.begin();
243243
for (; rai != rae; ++rai, ++rbi) {
244244
if (rai->r_offset != rbi->r_offset ||
245-
rai->getType(config->isMips64EL) != rbi->getType(config->isMips64EL))
245+
rai->getType(ctx.arg.isMips64EL) != rbi->getType(ctx.arg.isMips64EL))
246246
return false;
247247

248248
uint64_t addA = getAddend<ELFT>(*rai);
@@ -458,7 +458,7 @@ static void combineRelocHashes(unsigned cnt, InputSection *isec,
458458
}
459459

460460
static void print(const Twine &s) {
461-
if (config->printIcfSections)
461+
if (ctx.arg.printIcfSections)
462462
message(s);
463463
}
464464

@@ -467,7 +467,7 @@ template <class ELFT> void ICF<ELFT>::run() {
467467
// Compute isPreemptible early. We may add more symbols later, so this loop
468468
// cannot be merged with the later computeIsPreemptible() pass which is used
469469
// by scanRelocations().
470-
if (config->hasDynSymTab)
470+
if (ctx.arg.hasDynSymTab)
471471
for (Symbol *sym : symtab.getSymbols())
472472
sym->isPreemptible = computeIsPreemptible(*sym);
473473

lld/ELF/InputFiles.cpp

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ static void updateARMVFPArgs(const ARMAttributeParser &attributes,
135135
return;
136136
}
137137
// Follow ld.bfd and error if there is a mix of calling conventions.
138-
if (config->armVFPArgs != arg && config->armVFPArgs != ARMVFPArgKind::Default)
138+
if (ctx.arg.armVFPArgs != arg && ctx.arg.armVFPArgs != ARMVFPArgKind::Default)
139139
error(toString(f) + ": incompatible Tag_ABI_VFP_args");
140140
else
141-
config->armVFPArgs = arg;
141+
ctx.arg.armVFPArgs = arg;
142142
}
143143

144144
// The ARM support in lld makes some use of instructions that are not available
@@ -168,19 +168,19 @@ static void updateSupportedARMFeatures(const ARMAttributeParser &attributes) {
168168
case ARMBuildAttrs::v6:
169169
case ARMBuildAttrs::v6KZ:
170170
case ARMBuildAttrs::v6K:
171-
config->armHasBlx = true;
171+
ctx.arg.armHasBlx = true;
172172
// Architectures used in pre-Cortex processors do not support
173173
// The J1 = 1 J2 = 1 Thumb branch range extension, with the exception
174174
// of Architecture v6T2 (arm1156t2-s and arm1156t2f-s) that do.
175175
break;
176176
default:
177177
// All other Architectures have BLX and extended branch encoding
178-
config->armHasBlx = true;
179-
config->armJ1J2BranchEncoding = true;
178+
ctx.arg.armHasBlx = true;
179+
ctx.arg.armJ1J2BranchEncoding = true;
180180
if (arch != ARMBuildAttrs::v6_M && arch != ARMBuildAttrs::v6S_M)
181181
// All Architectures used in Cortex processors with the exception
182182
// of v6-M and v6S-M have the MOVT and MOVW instructions.
183-
config->armHasMovtMovw = true;
183+
ctx.arg.armHasMovtMovw = true;
184184
break;
185185
}
186186

@@ -191,7 +191,7 @@ static void updateSupportedARMFeatures(const ARMAttributeParser &attributes) {
191191
return;
192192
if (arch >= ARMBuildAttrs::CPUArch::v8_M_Base &&
193193
profile == ARMBuildAttrs::MicroControllerProfile)
194-
config->armCMSESupport = true;
194+
ctx.arg.armCMSESupport = true;
195195

196196
// The thumb PLT entries require Thumb2 which can be used on multiple archs.
197197
// For now, let's limit it to ones where ARM isn't available and we know have
@@ -200,8 +200,8 @@ static void updateSupportedARMFeatures(const ARMAttributeParser &attributes) {
200200
attributes.getAttributeValue(ARMBuildAttrs::ARM_ISA_use);
201201
std::optional<unsigned> thumb =
202202
attributes.getAttributeValue(ARMBuildAttrs::THUMB_ISA_use);
203-
config->armHasArmISA |= armISA && *armISA >= ARMBuildAttrs::Allowed;
204-
config->armHasThumb2ISA |= thumb && *thumb >= ARMBuildAttrs::AllowThumb32;
203+
ctx.arg.armHasArmISA |= armISA && *armISA >= ARMBuildAttrs::Allowed;
204+
ctx.arg.armHasThumb2ISA |= thumb && *thumb >= ARMBuildAttrs::AllowThumb32;
205205
}
206206

207207
InputFile::InputFile(Kind k, MemoryBufferRef m)
@@ -217,16 +217,16 @@ std::optional<MemoryBufferRef> elf::readFile(StringRef path) {
217217

218218
// The --chroot option changes our virtual root directory.
219219
// This is useful when you are dealing with files created by --reproduce.
220-
if (!config->chroot.empty() && path.starts_with("/"))
221-
path = saver().save(config->chroot + path);
220+
if (!ctx.arg.chroot.empty() && path.starts_with("/"))
221+
path = saver().save(ctx.arg.chroot + path);
222222

223223
bool remapped = false;
224-
auto it = config->remapInputs.find(path);
225-
if (it != config->remapInputs.end()) {
224+
auto it = ctx.arg.remapInputs.find(path);
225+
if (it != ctx.arg.remapInputs.end()) {
226226
path = it->second;
227227
remapped = true;
228228
} else {
229-
for (const auto &[pat, toFile] : config->remapInputsWildcards) {
229+
for (const auto &[pat, toFile] : ctx.arg.remapInputsWildcards) {
230230
if (pat.match(path)) {
231231
path = toFile;
232232
remapped = true;
@@ -244,7 +244,7 @@ std::optional<MemoryBufferRef> elf::readFile(StringRef path) {
244244
}
245245

246246
log(path);
247-
config->dependencyFiles.insert(llvm::CachedHashString(path));
247+
ctx.arg.dependencyFiles.insert(llvm::CachedHashString(path));
248248

249249
auto mbOrErr = MemoryBuffer::getFile(path, /*IsText=*/false,
250250
/*RequiresNullTerminator=*/false);
@@ -268,15 +268,15 @@ static bool isCompatible(InputFile *file) {
268268
if (!file->isElf() && !isa<BitcodeFile>(file))
269269
return true;
270270

271-
if (file->ekind == config->ekind && file->emachine == config->emachine) {
272-
if (config->emachine != EM_MIPS)
271+
if (file->ekind == ctx.arg.ekind && file->emachine == ctx.arg.emachine) {
272+
if (ctx.arg.emachine != EM_MIPS)
273273
return true;
274-
if (isMipsN32Abi(file) == config->mipsN32Abi)
274+
if (isMipsN32Abi(file) == ctx.arg.mipsN32Abi)
275275
return true;
276276
}
277277

278278
StringRef target =
279-
!config->bfdname.empty() ? config->bfdname : config->emulation;
279+
!ctx.arg.bfdname.empty() ? ctx.arg.bfdname : ctx.arg.emulation;
280280
if (!target.empty()) {
281281
error(toString(file) + " is incompatible with " + target);
282282
return false;
@@ -311,7 +311,7 @@ template <class ELFT> static void doParseFile(InputFile *file) {
311311
return;
312312
}
313313

314-
if (config->trace)
314+
if (ctx.arg.trace)
315315
message(toString(file));
316316

317317
if (file->kind() == InputFile::ObjKind) {
@@ -419,7 +419,7 @@ StringRef InputFile::getNameForScript() const {
419419
// is a form of autolinking and is called `dependent libraries`. It is currently
420420
// unique to LLVM and lld.
421421
static void addDependentLibrary(StringRef specifier, const InputFile *f) {
422-
if (!config->dependentLibraries)
422+
if (!ctx.arg.dependentLibraries)
423423
return;
424424
if (std::optional<std::string> s = searchLibraryBaseName(specifier))
425425
ctx.driver.addFile(saver().save(*s), /*withLOption=*/true);
@@ -599,7 +599,7 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
599599
sections.resize(size);
600600
for (size_t i = 0; i != size; ++i) {
601601
const Elf_Shdr &sec = objSections[i];
602-
if (sec.sh_type == SHT_LLVM_DEPENDENT_LIBRARIES && !config->relocatable) {
602+
if (sec.sh_type == SHT_LLVM_DEPENDENT_LIBRARIES && !ctx.arg.relocatable) {
603603
StringRef name = check(obj.getSectionName(sec, shstrtab));
604604
ArrayRef<char> data = CHECK(
605605
this->getObj().template getSectionContentsAsArray<char>(sec), this);
@@ -619,7 +619,7 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
619619
continue;
620620
}
621621

622-
if (sec.sh_type == SHT_ARM_ATTRIBUTES && config->emachine == EM_ARM) {
622+
if (sec.sh_type == SHT_ARM_ATTRIBUTES && ctx.arg.emachine == EM_ARM) {
623623
ARMAttributeParser attributes;
624624
ArrayRef<uint8_t> contents =
625625
check(this->getObj().getSectionContents(sec));
@@ -672,7 +672,7 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
672672
symtab.comdatGroups.try_emplace(CachedHashStringRef(signature), this)
673673
.second;
674674
if (keepGroup) {
675-
if (!config->resolveGroups)
675+
if (!ctx.arg.resolveGroups)
676676
this->sections[i] = createInputSection(
677677
i, sec, check(obj.getSectionName(sec, shstrtab)));
678678
continue;
@@ -718,7 +718,7 @@ bool ObjFile<ELFT>::shouldMerge(const Elf_Shdr &sec, StringRef name) {
718718
// SHF_MERGE sections based both on their name and sh_entsize, but that seems
719719
// to be more trouble than it is worth. Instead, we just use the regular (-O1)
720720
// logic for -r.
721-
if (config->optimize == 0 && !config->relocatable)
721+
if (ctx.arg.optimize == 0 && !ctx.arg.relocatable)
722722
return false;
723723

724724
// A mergeable section with size 0 is useless because they don't have
@@ -786,7 +786,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
786786
// SHF_EXCLUDE'ed sections are discarded by the linker. However,
787787
// if -r is given, we'll let the final link discard such sections.
788788
// This is compatible with GNU.
789-
if ((sec.sh_flags & SHF_EXCLUDE) && !config->relocatable) {
789+
if ((sec.sh_flags & SHF_EXCLUDE) && !ctx.arg.relocatable) {
790790
if (type == SHT_LLVM_CALL_GRAPH_PROFILE)
791791
cgProfileSectionIndex = i;
792792
if (type == SHT_LLVM_ADDRSIG) {
@@ -796,7 +796,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
796796
// in the address-significance table, which refers to symbols by index.
797797
if (sec.sh_link != 0)
798798
this->addrsigSec = &sec;
799-
else if (config->icf == ICFLevel::Safe)
799+
else if (ctx.arg.icf == ICFLevel::Safe)
800800
warn(toString(this) +
801801
": --icf=safe conservatively ignores "
802802
"SHT_LLVM_ADDRSIG [index " +
@@ -810,7 +810,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
810810

811811
switch (type) {
812812
case SHT_GROUP: {
813-
if (!config->relocatable)
813+
if (!ctx.arg.relocatable)
814814
sections[i] = &InputSection::discarded;
815815
StringRef signature =
816816
cantFail(this->getELFSyms<ELFT>()[sec.sh_info].getName(stringTable));
@@ -846,7 +846,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
846846
// The concatenated output does not properly reflect the linking
847847
// semantics. In addition, since we do not use the bitcode wrapper format,
848848
// the concatenated raw bitcode would be invalid.
849-
if (config->relocatable && !config->fatLTOObjects) {
849+
if (ctx.arg.relocatable && !ctx.arg.fatLTOObjects) {
850850
sections[i] = &InputSection::discarded;
851851
break;
852852
}
@@ -856,7 +856,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
856856
createInputSection(i, sec, check(obj.getSectionName(sec, shstrtab)));
857857
if (type == SHT_LLVM_SYMPART)
858858
ctx.hasSympart.store(true, std::memory_order_relaxed);
859-
else if (config->rejectMismatch &&
859+
else if (ctx.arg.rejectMismatch &&
860860
!isKnownSpecificSectionType(type, sec.sh_flags))
861861
errorOrWarn(toString(this->sections[i]) + ": unknown section type 0x" +
862862
Twine::utohexstr(type));
@@ -909,7 +909,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
909909
// `nullptr` for the normal case. However, if -r or --emit-relocs is
910910
// specified, we need to copy them to the output. (Some post link analysis
911911
// tools specify --emit-relocs to obtain the information.)
912-
if (config->copyRelocs) {
912+
if (ctx.arg.copyRelocs) {
913913
auto *isec = makeThreadLocal<InputSection>(
914914
*this, sec, check(obj.getSectionName(sec, shstrtab)));
915915
// If the relocated section is discarded (due to /DISCARD/ or
@@ -973,7 +973,7 @@ void readGnuProperty(const InputSection &sec, ObjFile<ELFT> &f) {
973973
continue;
974974
}
975975

976-
uint32_t featureAndType = config->emachine == EM_AARCH64
976+
uint32_t featureAndType = ctx.arg.emachine == EM_AARCH64
977977
? GNU_PROPERTY_AARCH64_FEATURE_1_AND
978978
: GNU_PROPERTY_X86_FEATURE_1_AND;
979979

@@ -996,7 +996,7 @@ void readGnuProperty(const InputSection &sec, ObjFile<ELFT> &f) {
996996
if (size < 4)
997997
reportFatal(place, "FEATURE_1_AND entry is too short");
998998
f.andFeatures |= read32<ELFT::Endianness>(desc.data());
999-
} else if (config->emachine == EM_AARCH64 &&
999+
} else if (ctx.arg.emachine == EM_AARCH64 &&
10001000
type == GNU_PROPERTY_AARCH64_FEATURE_PAUTH) {
10011001
if (!f.aarch64PauthAbiCoreInfo.empty()) {
10021002
reportFatal(data.data(),
@@ -1080,7 +1080,7 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(uint32_t idx,
10801080
// see https://gcc.gnu.org/wiki/SplitStacks. An object file compiled
10811081
// for split stack will include a .note.GNU-split-stack section.
10821082
if (name == ".note.GNU-split-stack") {
1083-
if (config->relocatable) {
1083+
if (ctx.arg.relocatable) {
10841084
error(
10851085
"cannot mix split-stack and non-split-stack in a relocatable link");
10861086
return &InputSection::discarded;
@@ -1109,7 +1109,7 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(uint32_t idx,
11091109
// The linker merges EH (exception handling) frames and creates a
11101110
// .eh_frame_hdr section for runtime. So we handle them with a special
11111111
// class. For relocatable outputs, they are just passed through.
1112-
if (name == ".eh_frame" && !config->relocatable)
1112+
if (name == ".eh_frame" && !ctx.arg.relocatable)
11131113
return makeThreadLocal<EhInputSection>(*this, sec, name);
11141114

11151115
if ((sec.sh_flags & SHF_MERGE) && shouldMerge(sec, name))
@@ -1358,7 +1358,7 @@ unsigned SharedFile::vernauxNum;
13581358

13591359
SharedFile::SharedFile(MemoryBufferRef m, StringRef defaultSoName)
13601360
: ELFFileBase(SharedKind, getELFKind(m, ""), m), soName(defaultSoName),
1361-
isNeeded(!config->asNeeded) {}
1361+
isNeeded(!ctx.arg.asNeeded) {}
13621362

13631363
// Parse the version definitions in the object file if present, and return a
13641364
// vector whose nth element contains a pointer to the Elf_Verdef for version
@@ -1578,7 +1578,7 @@ template <class ELFT> void SharedFile::parse() {
15781578
Undefined{this, name, sym.getBinding(), sym.st_other, sym.getType()});
15791579
s->exportDynamic = true;
15801580
if (sym.getBinding() != STB_WEAK &&
1581-
config->unresolvedSymbolsInShlib != UnresolvedPolicy::Ignore)
1581+
ctx.arg.unresolvedSymbolsInShlib != UnresolvedPolicy::Ignore)
15821582
requiredSymbols.push_back(s);
15831583
continue;
15841584
}
@@ -1588,7 +1588,7 @@ template <class ELFT> void SharedFile::parse() {
15881588
// In GNU ld < 2.31 (before 3be08ea4728b56d35e136af4e6fd3086ade17764), the
15891589
// MIPS port puts _gp_disp symbol into DSO files and incorrectly assigns
15901590
// VER_NDX_LOCAL. Workaround this bug.
1591-
if (config->emachine == EM_MIPS && name == "_gp_disp")
1591+
if (ctx.arg.emachine == EM_MIPS && name == "_gp_disp")
15921592
continue;
15931593
error("corrupt input file: version definition index " + Twine(idx) +
15941594
" for symbol " + name + " is out of bounds\n>>> defined in " +
@@ -1702,7 +1702,7 @@ BitcodeFile::BitcodeFile(MemoryBufferRef mb, StringRef archiveName,
17021702
this->lazy = lazy;
17031703

17041704
std::string path = mb.getBufferIdentifier().str();
1705-
if (config->thinLTOIndexOnly)
1705+
if (ctx.arg.thinLTOIndexOnly)
17061706
path = replaceThinLTOSuffix(mb.getBufferIdentifier());
17071707

17081708
// ThinLTO assumes that all MemoryBufferRefs given to it have a unique
@@ -1917,7 +1917,7 @@ bool InputFile::shouldExtractForCommon(StringRef name) const {
19171917
}
19181918

19191919
std::string elf::replaceThinLTOSuffix(StringRef path) {
1920-
auto [suffix, repl] = config->thinLTOObjectSuffixReplace;
1920+
auto [suffix, repl] = ctx.arg.thinLTOObjectSuffixReplace;
19211921
if (path.consume_back(suffix))
19221922
return (path + repl).str();
19231923
return std::string(path);

lld/ELF/InputFiles.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class InputFile {
105105
}
106106

107107
template <typename RelT> Symbol &getRelocTargetSym(const RelT &rel) const {
108-
uint32_t symIndex = rel.getSymbol(config->isMips64EL);
108+
uint32_t symIndex = rel.getSymbol(ctx.arg.isMips64EL);
109109
return getSymbol(symIndex);
110110
}
111111

0 commit comments

Comments
 (0)