mirror of
https://github.com/intel/llvm.git
synced 2026-01-20 10:58:11 +08:00
[ELF] Replace config-> with ctx.arg. in Driver.cpp and Target.h
This commit is contained in:
@@ -85,7 +85,7 @@ static void setConfigs(Ctx &ctx, opt::InputArgList &args);
|
||||
static void readConfigs(Ctx &ctx, opt::InputArgList &args);
|
||||
|
||||
void elf::errorOrWarn(const Twine &msg) {
|
||||
if (config->noinhibitExec)
|
||||
if (ctx.arg.noinhibitExec)
|
||||
warn(msg);
|
||||
else
|
||||
error(msg);
|
||||
@@ -172,7 +172,7 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
|
||||
ctx.partitions.clear();
|
||||
ctx.partitions.emplace_back();
|
||||
|
||||
config->progName = args[0];
|
||||
ctx.arg.progName = args[0];
|
||||
|
||||
ctx.driver.linkerMain(args);
|
||||
|
||||
@@ -853,7 +853,7 @@ static ICFLevel getICF(opt::InputArgList &args) {
|
||||
static StripPolicy getStrip(opt::InputArgList &args) {
|
||||
if (args.hasArg(OPT_relocatable))
|
||||
return StripPolicy::None;
|
||||
if (!config->zSectionHeader)
|
||||
if (!ctx.arg.zSectionHeader)
|
||||
return StripPolicy::All;
|
||||
|
||||
auto *arg = args.getLastArg(OPT_strip_all, OPT_strip_debug);
|
||||
@@ -964,7 +964,7 @@ static void readCallGraph(MemoryBufferRef mb) {
|
||||
auto findSection = [&](StringRef name) -> InputSectionBase * {
|
||||
Symbol *sym = map.lookup(name);
|
||||
if (!sym) {
|
||||
if (config->warnSymbolOrdering)
|
||||
if (ctx.arg.warnSymbolOrdering)
|
||||
warn(mb.getBufferIdentifier() + ": no such symbol: " + name);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -987,7 +987,7 @@ static void readCallGraph(MemoryBufferRef mb) {
|
||||
|
||||
if (InputSectionBase *from = findSection(fields[0]))
|
||||
if (InputSectionBase *to = findSection(fields[1]))
|
||||
config->callGraphProfile[std::make_pair(from, to)] += count;
|
||||
ctx.arg.callGraphProfile[std::make_pair(from, to)] += count;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1025,14 +1025,14 @@ processCallGraphRelocations(SmallVector<uint32_t, 32> &symbolIndices,
|
||||
ArrayRef<typename ELFT::Rela> relas =
|
||||
CHECK(obj.relas(sec), "could not retrieve cg profile rela section");
|
||||
for (const typename ELFT::Rela &rel : relas)
|
||||
symbolIndices.push_back(rel.getSymbol(config->isMips64EL));
|
||||
symbolIndices.push_back(rel.getSymbol(ctx.arg.isMips64EL));
|
||||
break;
|
||||
}
|
||||
if (sec.sh_type == SHT_REL) {
|
||||
ArrayRef<typename ELFT::Rel> rels =
|
||||
CHECK(obj.rels(sec), "could not retrieve cg profile rel section");
|
||||
for (const typename ELFT::Rel &rel : rels)
|
||||
symbolIndices.push_back(rel.getSymbol(config->isMips64EL));
|
||||
symbolIndices.push_back(rel.getSymbol(ctx.arg.isMips64EL));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1065,7 +1065,7 @@ template <class ELFT> static void readCallGraphsFromObjectFiles() {
|
||||
auto *from = dyn_cast_or_null<InputSectionBase>(fromSym->section);
|
||||
auto *to = dyn_cast_or_null<InputSectionBase>(toSym->section);
|
||||
if (from && to)
|
||||
config->callGraphProfile[{from, to}] += cgpe.cgp_weight;
|
||||
ctx.arg.callGraphProfile[{from, to}] += cgpe.cgp_weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1188,7 +1188,7 @@ getOldNewOptionsExtra(opt::InputArgList &args, unsigned id) {
|
||||
static SmallVector<StringRef, 0> getSymbolOrderingFile(MemoryBufferRef mb) {
|
||||
SetVector<StringRef, SmallVector<StringRef, 0>> names;
|
||||
for (StringRef s : args::getLines(mb))
|
||||
if (!names.insert(s) && config->warnSymbolOrdering)
|
||||
if (!names.insert(s) && ctx.arg.warnSymbolOrdering)
|
||||
warn(mb.getBufferIdentifier() + ": duplicate ordered symbol: " + s);
|
||||
|
||||
return names.takeVector();
|
||||
@@ -1198,7 +1198,7 @@ static bool getIsRela(opt::InputArgList &args) {
|
||||
// The psABI specifies the default relocation entry format.
|
||||
bool rela = is_contained({EM_AARCH64, EM_AMDGPU, EM_HEXAGON, EM_LOONGARCH,
|
||||
EM_PPC, EM_PPC64, EM_RISCV, EM_S390, EM_X86_64},
|
||||
config->emachine);
|
||||
ctx.arg.emachine);
|
||||
// If -z rel or -z rela is specified, use the last option.
|
||||
for (auto *arg : args.filtered(OPT_z)) {
|
||||
StringRef s(arg->getValue());
|
||||
@@ -1217,7 +1217,7 @@ static void parseClangOption(StringRef opt, const Twine &msg) {
|
||||
std::string err;
|
||||
raw_string_ostream os(err);
|
||||
|
||||
const char *argv[] = {config->progName.data(), opt.data()};
|
||||
const char *argv[] = {ctx.arg.progName.data(), opt.data()};
|
||||
if (cl::ParseCommandLineOptions(2, argv, "", &os))
|
||||
return;
|
||||
error(msg + ": " + StringRef(err).trim());
|
||||
@@ -1237,9 +1237,9 @@ static bool remapInputs(StringRef line, const Twine &location) {
|
||||
return true;
|
||||
}
|
||||
if (!hasWildcard(fields[0]))
|
||||
config->remapInputs[fields[0]] = fields[1];
|
||||
ctx.arg.remapInputs[fields[0]] = fields[1];
|
||||
else if (Expected<GlobPattern> pat = GlobPattern::create(fields[0]))
|
||||
config->remapInputsWildcards.emplace_back(std::move(*pat), fields[1]);
|
||||
ctx.arg.remapInputsWildcards.emplace_back(std::move(*pat), fields[1]);
|
||||
else {
|
||||
error(location + ": " + toString(pat.takeError()) + ": " + fields[0]);
|
||||
return true;
|
||||
@@ -2093,14 +2093,14 @@ static uint64_t getCommonPageSize(Ctx &ctx, opt::InputArgList &args) {
|
||||
error("common-page-size: value isn't a power of 2");
|
||||
return ctx.target->defaultCommonPageSize;
|
||||
}
|
||||
if (config->nmagic || config->omagic) {
|
||||
if (ctx.arg.nmagic || ctx.arg.omagic) {
|
||||
if (val != ctx.target->defaultCommonPageSize)
|
||||
warn("-z common-page-size set, but paging disabled by omagic or nmagic");
|
||||
return 1;
|
||||
}
|
||||
// commonPageSize can't be larger than maxPageSize.
|
||||
if (val > config->maxPageSize)
|
||||
val = config->maxPageSize;
|
||||
if (val > ctx.arg.maxPageSize)
|
||||
val = ctx.arg.maxPageSize;
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -2381,7 +2381,7 @@ static void markAddrsig(Symbol *s) {
|
||||
if (d->section)
|
||||
// We don't need to keep text sections unique under --icf=all even if they
|
||||
// are address-significant.
|
||||
if (config->icf == ICFLevel::Safe || !(d->section->flags & SHF_EXECINSTR))
|
||||
if (ctx.arg.icf == ICFLevel::Safe || !(d->section->flags & SHF_EXECINSTR))
|
||||
d->section->keepUnique = true;
|
||||
}
|
||||
|
||||
@@ -2477,10 +2477,10 @@ static void readSymbolPartitionSection(InputSectionBase *s) {
|
||||
if (ctx.script->hasPhdrsCommands())
|
||||
error(toString(s->file) +
|
||||
": partitions cannot be used with the PHDRS command");
|
||||
if (!config->sectionStartMap.empty())
|
||||
if (!ctx.arg.sectionStartMap.empty())
|
||||
error(toString(s->file) + ": partitions cannot be used with "
|
||||
"--section-start, -Ttext, -Tdata or -Tbss");
|
||||
if (config->emachine == EM_MIPS)
|
||||
if (ctx.arg.emachine == EM_MIPS)
|
||||
error(toString(s->file) + ": partitions cannot be used on this target");
|
||||
|
||||
// Impose a limit of no more than 254 partitions. This limit comes from the
|
||||
@@ -2651,7 +2651,7 @@ static void combineVersionedSymbol(Symbol &sym,
|
||||
sym.isUsedInRegularObj = false;
|
||||
} else if (auto *sym1 = dyn_cast<Defined>(&sym)) {
|
||||
if (sym2->versionId > VER_NDX_GLOBAL
|
||||
? config->versionDefinitions[sym2->versionId].name == suffix1 + 1
|
||||
? ctx.arg.versionDefinitions[sym2->versionId].name == suffix1 + 1
|
||||
: sym1->section == sym2->section && sym1->value == sym2->value) {
|
||||
// Due to an assembler design flaw, if foo is defined, .symver foo,
|
||||
// foo@v1 defines both foo and foo@v1. Unless foo is bound to a
|
||||
@@ -2728,14 +2728,14 @@ static void checkAndReportMissingFeature(StringRef config, uint32_t features,
|
||||
// match. Missing info for some object files with matching info for remaining
|
||||
// ones can be allowed (see -z pauth-report).
|
||||
static void readSecurityNotes() {
|
||||
if (config->emachine != EM_386 && config->emachine != EM_X86_64 &&
|
||||
config->emachine != EM_AARCH64)
|
||||
if (ctx.arg.emachine != EM_386 && ctx.arg.emachine != EM_X86_64 &&
|
||||
ctx.arg.emachine != EM_AARCH64)
|
||||
return;
|
||||
|
||||
config->andFeatures = -1;
|
||||
ctx.arg.andFeatures = -1;
|
||||
|
||||
StringRef referenceFileName;
|
||||
if (config->emachine == EM_AARCH64) {
|
||||
if (ctx.arg.emachine == EM_AARCH64) {
|
||||
auto it = llvm::find_if(ctx.objectFiles, [](const ELFFileBase *f) {
|
||||
return !f->aarch64PauthAbiCoreInfo.empty();
|
||||
});
|
||||
@@ -2749,49 +2749,49 @@ static void readSecurityNotes() {
|
||||
uint32_t features = f->andFeatures;
|
||||
|
||||
checkAndReportMissingFeature(
|
||||
config->zBtiReport, features, GNU_PROPERTY_AARCH64_FEATURE_1_BTI,
|
||||
ctx.arg.zBtiReport, features, GNU_PROPERTY_AARCH64_FEATURE_1_BTI,
|
||||
toString(f) + ": -z bti-report: file does not have "
|
||||
"GNU_PROPERTY_AARCH64_FEATURE_1_BTI property");
|
||||
|
||||
checkAndReportMissingFeature(
|
||||
config->zGcsReport, features, GNU_PROPERTY_AARCH64_FEATURE_1_GCS,
|
||||
ctx.arg.zGcsReport, features, GNU_PROPERTY_AARCH64_FEATURE_1_GCS,
|
||||
toString(f) + ": -z gcs-report: file does not have "
|
||||
"GNU_PROPERTY_AARCH64_FEATURE_1_GCS property");
|
||||
|
||||
checkAndReportMissingFeature(
|
||||
config->zCetReport, features, GNU_PROPERTY_X86_FEATURE_1_IBT,
|
||||
ctx.arg.zCetReport, features, GNU_PROPERTY_X86_FEATURE_1_IBT,
|
||||
toString(f) + ": -z cet-report: file does not have "
|
||||
"GNU_PROPERTY_X86_FEATURE_1_IBT property");
|
||||
|
||||
checkAndReportMissingFeature(
|
||||
config->zCetReport, features, GNU_PROPERTY_X86_FEATURE_1_SHSTK,
|
||||
ctx.arg.zCetReport, features, GNU_PROPERTY_X86_FEATURE_1_SHSTK,
|
||||
toString(f) + ": -z cet-report: file does not have "
|
||||
"GNU_PROPERTY_X86_FEATURE_1_SHSTK property");
|
||||
|
||||
if (config->zForceBti && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) {
|
||||
if (ctx.arg.zForceBti && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) {
|
||||
features |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI;
|
||||
if (config->zBtiReport == "none")
|
||||
if (ctx.arg.zBtiReport == "none")
|
||||
warn(toString(f) + ": -z force-bti: file does not have "
|
||||
"GNU_PROPERTY_AARCH64_FEATURE_1_BTI property");
|
||||
} else if (config->zForceIbt &&
|
||||
} else if (ctx.arg.zForceIbt &&
|
||||
!(features & GNU_PROPERTY_X86_FEATURE_1_IBT)) {
|
||||
if (config->zCetReport == "none")
|
||||
if (ctx.arg.zCetReport == "none")
|
||||
warn(toString(f) + ": -z force-ibt: file does not have "
|
||||
"GNU_PROPERTY_X86_FEATURE_1_IBT property");
|
||||
features |= GNU_PROPERTY_X86_FEATURE_1_IBT;
|
||||
}
|
||||
if (config->zPacPlt && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_PAC)) {
|
||||
if (ctx.arg.zPacPlt && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_PAC)) {
|
||||
warn(toString(f) + ": -z pac-plt: file does not have "
|
||||
"GNU_PROPERTY_AARCH64_FEATURE_1_PAC property");
|
||||
features |= GNU_PROPERTY_AARCH64_FEATURE_1_PAC;
|
||||
}
|
||||
config->andFeatures &= features;
|
||||
ctx.arg.andFeatures &= features;
|
||||
|
||||
if (ctx.aarch64PauthAbiCoreInfo.empty())
|
||||
continue;
|
||||
|
||||
if (f->aarch64PauthAbiCoreInfo.empty()) {
|
||||
reportMissingFeature(config->zPauthReport,
|
||||
reportMissingFeature(ctx.arg.zPauthReport,
|
||||
toString(f) +
|
||||
": -z pauth-report: file does not have AArch64 "
|
||||
"PAuth core info while '" +
|
||||
@@ -2808,14 +2808,14 @@ static void readSecurityNotes() {
|
||||
}
|
||||
|
||||
// Force enable Shadow Stack.
|
||||
if (config->zShstk)
|
||||
config->andFeatures |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
|
||||
if (ctx.arg.zShstk)
|
||||
ctx.arg.andFeatures |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
|
||||
|
||||
// Force enable/disable GCS
|
||||
if (config->zGcs == GcsPolicy::Always)
|
||||
config->andFeatures |= GNU_PROPERTY_AARCH64_FEATURE_1_GCS;
|
||||
else if (config->zGcs == GcsPolicy::Never)
|
||||
config->andFeatures &= ~GNU_PROPERTY_AARCH64_FEATURE_1_GCS;
|
||||
if (ctx.arg.zGcs == GcsPolicy::Always)
|
||||
ctx.arg.andFeatures |= GNU_PROPERTY_AARCH64_FEATURE_1_GCS;
|
||||
else if (ctx.arg.zGcs == GcsPolicy::Never)
|
||||
ctx.arg.andFeatures &= ~GNU_PROPERTY_AARCH64_FEATURE_1_GCS;
|
||||
}
|
||||
|
||||
static void initSectionsAndLocalSyms(ELFFileBase *file, bool ignoreComdats) {
|
||||
@@ -2869,7 +2869,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
|
||||
|
||||
// Handle -u/--undefined before input files. If both a.a and b.so define foo,
|
||||
// -u foo a.a b.so will extract a.a.
|
||||
for (StringRef name : config->undefined)
|
||||
for (StringRef name : ctx.arg.undefined)
|
||||
symtab.addUnusedUndefined(name)->referenced = true;
|
||||
|
||||
parseFiles(files, armCmseImpLib);
|
||||
|
||||
@@ -132,7 +132,7 @@ public:
|
||||
RelType tlsGotRel;
|
||||
RelType tlsModuleIndexRel;
|
||||
RelType tlsOffsetRel;
|
||||
unsigned gotEntrySize = config->wordsize;
|
||||
unsigned gotEntrySize = ctx.arg.wordsize;
|
||||
unsigned pltEntrySize;
|
||||
unsigned pltHeaderSize;
|
||||
unsigned ipltEntrySize;
|
||||
@@ -282,27 +282,27 @@ inline void checkAlignment(uint8_t *loc, uint64_t v, int n,
|
||||
|
||||
// Endianness-aware read/write.
|
||||
inline uint16_t read16(const void *p) {
|
||||
return llvm::support::endian::read16(p, config->endianness);
|
||||
return llvm::support::endian::read16(p, ctx.arg.endianness);
|
||||
}
|
||||
|
||||
inline uint32_t read32(const void *p) {
|
||||
return llvm::support::endian::read32(p, config->endianness);
|
||||
return llvm::support::endian::read32(p, ctx.arg.endianness);
|
||||
}
|
||||
|
||||
inline uint64_t read64(const void *p) {
|
||||
return llvm::support::endian::read64(p, config->endianness);
|
||||
return llvm::support::endian::read64(p, ctx.arg.endianness);
|
||||
}
|
||||
|
||||
inline void write16(void *p, uint16_t v) {
|
||||
llvm::support::endian::write16(p, v, config->endianness);
|
||||
llvm::support::endian::write16(p, v, ctx.arg.endianness);
|
||||
}
|
||||
|
||||
inline void write32(void *p, uint32_t v) {
|
||||
llvm::support::endian::write32(p, v, config->endianness);
|
||||
llvm::support::endian::write32(p, v, ctx.arg.endianness);
|
||||
}
|
||||
|
||||
inline void write64(void *p, uint64_t v) {
|
||||
llvm::support::endian::write64(p, v, config->endianness);
|
||||
llvm::support::endian::write64(p, v, ctx.arg.endianness);
|
||||
}
|
||||
|
||||
// Overwrite a ULEB128 value and keep the original length.
|
||||
@@ -321,7 +321,7 @@ inline uint64_t overwriteULEB128(uint8_t *bufLoc, uint64_t val) {
|
||||
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
|
||||
#endif
|
||||
#define invokeELFT(f, ...) \
|
||||
switch (config->ekind) { \
|
||||
switch (ctx.arg.ekind) { \
|
||||
case lld::elf::ELF32LEKind: \
|
||||
f<llvm::object::ELF32LE>(__VA_ARGS__); \
|
||||
break; \
|
||||
@@ -335,7 +335,7 @@ inline uint64_t overwriteULEB128(uint8_t *bufLoc, uint64_t val) {
|
||||
f<llvm::object::ELF64BE>(__VA_ARGS__); \
|
||||
break; \
|
||||
default: \
|
||||
llvm_unreachable("unknown config->ekind"); \
|
||||
llvm_unreachable("unknown ctx.arg.ekind"); \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user