Skip to content

Commit c4c34f0

Browse files
committed
[ELF] Pass Ctx & to InputFiles
1 parent df8795c commit c4c34f0

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static ELFKind getELFKind(MemoryBufferRef mb, StringRef archiveName) {
102102
// For ARM only, to set the EF_ARM_ABI_FLOAT_SOFT or EF_ARM_ABI_FLOAT_HARD
103103
// flag in the ELF Header we need to look at Tag_ABI_VFP_args to find out how
104104
// the input objects have been compiled.
105-
static void updateARMVFPArgs(const ARMAttributeParser &attributes,
105+
static void updateARMVFPArgs(Ctx &ctx, const ARMAttributeParser &attributes,
106106
const InputFile *f) {
107107
std::optional<unsigned> attr =
108108
attributes.getAttributeValue(ARMBuildAttrs::ABI_VFP_args);
@@ -150,7 +150,8 @@ static void updateARMVFPArgs(const ARMAttributeParser &attributes,
150150
// at compile time. We follow the convention that if at least one input object
151151
// is compiled with an architecture that supports these features then lld is
152152
// permitted to use them.
153-
static void updateSupportedARMFeatures(const ARMAttributeParser &attributes) {
153+
static void updateSupportedARMFeatures(Ctx &ctx,
154+
const ARMAttributeParser &attributes) {
154155
std::optional<unsigned> attr =
155156
attributes.getAttributeValue(ARMBuildAttrs::CPU_arch);
156157
if (!attr)
@@ -264,7 +265,7 @@ std::optional<MemoryBufferRef> elf::readFile(StringRef path) {
264265
// All input object files must be for the same architecture
265266
// (e.g. it does not make sense to link x86 object files with
266267
// MIPS object files.) This function checks for that error.
267-
static bool isCompatible(InputFile *file) {
268+
static bool isCompatible(Ctx &ctx, InputFile *file) {
268269
if (!file->isElf() && !isa<BitcodeFile>(file))
269270
return true;
270271

@@ -297,7 +298,7 @@ static bool isCompatible(InputFile *file) {
297298
}
298299

299300
template <class ELFT> static void doParseFile(Ctx &ctx, InputFile *file) {
300-
if (!isCompatible(file))
301+
if (!isCompatible(ctx, file))
301302
return;
302303

303304
// Lazy object file
@@ -418,7 +419,8 @@ StringRef InputFile::getNameForScript() const {
418419
// the various ways that a library can be specified to LLD. This ELF extension
419420
// is a form of autolinking and is called `dependent libraries`. It is currently
420421
// unique to LLVM and lld.
421-
static void addDependentLibrary(StringRef specifier, const InputFile *f) {
422+
static void addDependentLibrary(Ctx &ctx, StringRef specifier,
423+
const InputFile *f) {
422424
if (!ctx.arg.dependentLibraries)
423425
return;
424426
if (std::optional<std::string> s = searchLibraryBaseName(specifier))
@@ -611,7 +613,7 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
611613
} else {
612614
for (const char *d = data.begin(), *e = data.end(); d < e;) {
613615
StringRef s(d);
614-
addDependentLibrary(s, this);
616+
addDependentLibrary(ctx, s, this);
615617
d += s.size() + 1;
616618
}
617619
}
@@ -631,8 +633,8 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
631633
InputSection isec(*this, sec, name);
632634
warn(toString(&isec) + ": " + llvm::toString(std::move(e)));
633635
} else {
634-
updateSupportedARMFeatures(attributes);
635-
updateARMVFPArgs(attributes, this);
636+
updateSupportedARMFeatures(ctx, attributes);
637+
updateARMVFPArgs(ctx, attributes, this);
636638

637639
// FIXME: Retain the first attribute section we see. The eglibc ARM
638640
// dynamic loaders require the presence of an attribute section for
@@ -1704,7 +1706,7 @@ BitcodeFile::BitcodeFile(MemoryBufferRef mb, StringRef archiveName,
17041706

17051707
std::string path = mb.getBufferIdentifier().str();
17061708
if (ctx.arg.thinLTOIndexOnly)
1707-
path = replaceThinLTOSuffix(mb.getBufferIdentifier());
1709+
path = replaceThinLTOSuffix(ctx, mb.getBufferIdentifier());
17081710

17091711
// ThinLTO assumes that all MemoryBufferRefs given to it have a unique
17101712
// name. If two archives define two members with the same name, this
@@ -1738,9 +1740,10 @@ static uint8_t mapVisibility(GlobalValue::VisibilityTypes gvVisibility) {
17381740
llvm_unreachable("unknown visibility");
17391741
}
17401742

1741-
static void
1742-
createBitcodeSymbol(Symbol *&sym, const std::vector<bool> &keptComdats,
1743-
const lto::InputFile::Symbol &objSym, BitcodeFile &f) {
1743+
static void createBitcodeSymbol(Ctx &ctx, Symbol *&sym,
1744+
const std::vector<bool> &keptComdats,
1745+
const lto::InputFile::Symbol &objSym,
1746+
BitcodeFile &f) {
17441747
uint8_t binding = objSym.isWeak() ? STB_WEAK : STB_GLOBAL;
17451748
uint8_t type = objSym.isTLS() ? STT_TLS : STT_NOTYPE;
17461749
uint8_t visibility = mapVisibility(objSym.getVisibility());
@@ -1791,13 +1794,13 @@ void BitcodeFile::parse() {
17911794
// ObjFile<ELFT>::initializeSymbols.
17921795
for (auto [i, irSym] : llvm::enumerate(obj->symbols()))
17931796
if (!irSym.isUndefined())
1794-
createBitcodeSymbol(symbols[i], keptComdats, irSym, *this);
1797+
createBitcodeSymbol(ctx, symbols[i], keptComdats, irSym, *this);
17951798
for (auto [i, irSym] : llvm::enumerate(obj->symbols()))
17961799
if (irSym.isUndefined())
1797-
createBitcodeSymbol(symbols[i], keptComdats, irSym, *this);
1800+
createBitcodeSymbol(ctx, symbols[i], keptComdats, irSym, *this);
17981801

17991802
for (auto l : obj->getDependentLibraries())
1800-
addDependentLibrary(l, this);
1803+
addDependentLibrary(ctx, l, this);
18011804
}
18021805

18031806
void BitcodeFile::parseLazy() {
@@ -1917,7 +1920,7 @@ bool InputFile::shouldExtractForCommon(StringRef name) const {
19171920
return isNonCommonDef(mb, name, archiveName);
19181921
}
19191922

1920-
std::string elf::replaceThinLTOSuffix(StringRef path) {
1923+
std::string elf::replaceThinLTOSuffix(Ctx &ctx, StringRef path) {
19211924
auto [suffix, repl] = ctx.arg.thinLTOObjectSuffixReplace;
19221925
if (path.consume_back(suffix))
19231926
return (path + repl).str();

lld/ELF/InputFiles.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ InputFile *createInternalFile(StringRef name);
382382
ELFFileBase *createObjFile(MemoryBufferRef mb, StringRef archiveName = "",
383383
bool lazy = false);
384384

385-
std::string replaceThinLTOSuffix(StringRef path);
385+
std::string replaceThinLTOSuffix(Ctx &, StringRef path);
386386

387387
} // namespace elf
388388
} // namespace lld

lld/ELF/LTO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ static void thinLTOCreateEmptyIndexFiles(Ctx &ctx) {
292292
if (linkedBitCodeFiles.contains(f->getName()))
293293
continue;
294294
std::string path =
295-
replaceThinLTOSuffix(getThinLTOOutputFile(ctx, f->obj->getName()));
295+
replaceThinLTOSuffix(ctx, getThinLTOOutputFile(ctx, f->obj->getName()));
296296
std::unique_ptr<raw_fd_ostream> os = openFile(path + ".thinlto.bc");
297297
if (!os)
298298
continue;

0 commit comments

Comments
 (0)