[lld] a522516 - [ELF] Pass Ctx & to Target.cpp
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 28 19:24:00 PDT 2024
Author: Fangrui Song
Date: 2024-09-28T19:23:56-07:00
New Revision: a52251675f001115b225f57362d37e92b7355ef9
URL: https://github.com/llvm/llvm-project/commit/a52251675f001115b225f57362d37e92b7355ef9
DIFF: https://github.com/llvm/llvm-project/commit/a52251675f001115b225f57362d37e92b7355ef9.diff
LOG: [ELF] Pass Ctx & to Target.cpp
Added:
Modified:
lld/ELF/Arch/ARM.cpp
lld/ELF/Driver.cpp
lld/ELF/Relocations.cpp
lld/ELF/Target.cpp
lld/ELF/Target.h
Removed:
################################################################################
diff --git a/lld/ELF/Arch/ARM.cpp b/lld/ELF/Arch/ARM.cpp
index 1bbd2e1f21d7c3..29f0b7c71d43c1 100644
--- a/lld/ELF/Arch/ARM.cpp
+++ b/lld/ELF/Arch/ARM.cpp
@@ -491,9 +491,10 @@ bool ARM::inBranchRange(RelType type, uint64_t src, uint64_t dst) const {
// Helper to produce message text when LLD detects that a CALL relocation to
// a non STT_FUNC symbol that may result in incorrect interworking between ARM
// or Thumb.
-static void stateChangeWarning(uint8_t *loc, RelType relt, const Symbol &s) {
+static void stateChangeWarning(Ctx &ctx, uint8_t *loc, RelType relt,
+ const Symbol &s) {
assert(!s.isFunc());
- const ErrorPlace place = getErrorPlace(loc);
+ const ErrorPlace place = getErrorPlace(ctx, loc);
std::string hint;
if (!place.srcLoc.empty())
hint = "; " + place.srcLoc;
@@ -630,7 +631,7 @@ void ARM::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
// lld 10.0 and before always used bit0Thumb when deciding to write a BLX
// even when type not STT_FUNC.
if (!rel.sym->isFunc() && isBlx != bit0Thumb)
- stateChangeWarning(loc, rel.type, *rel.sym);
+ stateChangeWarning(ctx, loc, rel.type, *rel.sym);
if (rel.sym->isFunc() ? bit0Thumb : isBlx) {
// The BLX encoding is 0xfa:H:imm24 where Val = imm24:H:'1'
checkInt(loc, val, 26, rel);
@@ -687,7 +688,7 @@ void ARM::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
// lld 10.0 and before always used bit0Thumb when deciding to write a BLX
// even when type not STT_FUNC.
if (!rel.sym->isFunc() && !rel.sym->isInPlt() && isBlx == useThumb)
- stateChangeWarning(loc, rel.type, *rel.sym);
+ stateChangeWarning(ctx, loc, rel.type, *rel.sym);
if ((rel.sym->isFunc() || rel.sym->isInPlt()) ? !useThumb : isBlx) {
// We are writing a BLX. Ensure BLX destination is 4-byte aligned. As
// the BLX instruction may only be two byte aligned. This must be done
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 8f34b156c9c4e8..64f4489987b007 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -3122,7 +3122,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
// The Target instance handles target-specific stuff, such as applying
// relocations or writing a PLT section. It also contains target-dependent
// values such as a default image base address.
- ctx.target = getTarget();
+ ctx.target = getTarget(ctx);
ctx.arg.eflags = ctx.target->calcEFlags();
// maxPageSize (sometimes called abi page size) is the maximum page size that
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 58344b75accdce..5ce2df22c22859 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -99,7 +99,7 @@ static std::string getLocation(Ctx &ctx, InputSectionBase &s, const Symbol &sym,
void elf::reportRangeError(uint8_t *loc, const Relocation &rel, const Twine &v,
int64_t min, uint64_t max) {
- ErrorPlace errPlace = getErrorPlace(loc);
+ ErrorPlace errPlace = getErrorPlace(ctx, loc);
std::string hint;
if (rel.sym) {
if (!rel.sym->isSection())
@@ -130,7 +130,7 @@ void elf::reportRangeError(uint8_t *loc, const Relocation &rel, const Twine &v,
void elf::reportRangeError(Ctx &ctx, uint8_t *loc, int64_t v, int n,
const Symbol &sym, const Twine &msg) {
- ErrorPlace errPlace = getErrorPlace(loc);
+ ErrorPlace errPlace = getErrorPlace(ctx, loc);
std::string hint;
if (!sym.getName().empty())
hint = "; references '" + lld::toString(sym) + '\'' +
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp
index d895757ad4e49f..ea8dc98e9a2e73 100644
--- a/lld/ELF/Target.cpp
+++ b/lld/ELF/Target.cpp
@@ -45,7 +45,7 @@ std::string lld::toString(RelType type) {
return std::string(s);
}
-TargetInfo *elf::getTarget() {
+TargetInfo *elf::getTarget(Ctx &ctx) {
switch (ctx.arg.emachine) {
case EM_386:
case EM_IAMCU:
@@ -94,7 +94,7 @@ TargetInfo *elf::getTarget() {
}
}
-ErrorPlace elf::getErrorPlace(const uint8_t *loc) {
+ErrorPlace elf::getErrorPlace(Ctx &ctx, const uint8_t *loc) {
assert(loc != nullptr);
for (InputSectionBase *d : ctx.inputSections) {
auto *isec = dyn_cast<InputSection>(d);
diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h
index 1c3c293be2f329..951b2f36fdda93 100644
--- a/lld/ELF/Target.h
+++ b/lld/ELF/Target.h
@@ -200,10 +200,10 @@ struct ErrorPlace {
};
// Returns input section and corresponding source string for the given location.
-ErrorPlace getErrorPlace(const uint8_t *loc);
+ErrorPlace getErrorPlace(Ctx &ctx, const uint8_t *loc);
static inline std::string getErrorLocation(const uint8_t *loc) {
- return getErrorPlace(loc).loc;
+ return getErrorPlace(ctx, loc).loc;
}
void processArmCmseSymbols();
@@ -241,7 +241,7 @@ void convertArmInstructionstoBE8(InputSection *sec, uint8_t *buf);
void createTaggedSymbols(const SmallVector<ELFFileBase *, 0> &files);
void initSymbolAnchors();
-TargetInfo *getTarget();
+TargetInfo *getTarget(Ctx &ctx);
template <class ELFT> bool isMipsPIC(const Defined *sym);
More information about the llvm-commits
mailing list