Skip to content

Commit a522516

Browse files
committed
[ELF] Pass Ctx & to Target.cpp
1 parent 29783f7 commit a522516

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

lld/ELF/Arch/ARM.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,10 @@ bool ARM::inBranchRange(RelType type, uint64_t src, uint64_t dst) const {
491491
// Helper to produce message text when LLD detects that a CALL relocation to
492492
// a non STT_FUNC symbol that may result in incorrect interworking between ARM
493493
// or Thumb.
494-
static void stateChangeWarning(uint8_t *loc, RelType relt, const Symbol &s) {
494+
static void stateChangeWarning(Ctx &ctx, uint8_t *loc, RelType relt,
495+
const Symbol &s) {
495496
assert(!s.isFunc());
496-
const ErrorPlace place = getErrorPlace(loc);
497+
const ErrorPlace place = getErrorPlace(ctx, loc);
497498
std::string hint;
498499
if (!place.srcLoc.empty())
499500
hint = "; " + place.srcLoc;
@@ -630,7 +631,7 @@ void ARM::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
630631
// lld 10.0 and before always used bit0Thumb when deciding to write a BLX
631632
// even when type not STT_FUNC.
632633
if (!rel.sym->isFunc() && isBlx != bit0Thumb)
633-
stateChangeWarning(loc, rel.type, *rel.sym);
634+
stateChangeWarning(ctx, loc, rel.type, *rel.sym);
634635
if (rel.sym->isFunc() ? bit0Thumb : isBlx) {
635636
// The BLX encoding is 0xfa:H:imm24 where Val = imm24:H:'1'
636637
checkInt(loc, val, 26, rel);
@@ -687,7 +688,7 @@ void ARM::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
687688
// lld 10.0 and before always used bit0Thumb when deciding to write a BLX
688689
// even when type not STT_FUNC.
689690
if (!rel.sym->isFunc() && !rel.sym->isInPlt() && isBlx == useThumb)
690-
stateChangeWarning(loc, rel.type, *rel.sym);
691+
stateChangeWarning(ctx, loc, rel.type, *rel.sym);
691692
if ((rel.sym->isFunc() || rel.sym->isInPlt()) ? !useThumb : isBlx) {
692693
// We are writing a BLX. Ensure BLX destination is 4-byte aligned. As
693694
// the BLX instruction may only be two byte aligned. This must be done

lld/ELF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3122,7 +3122,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
31223122
// The Target instance handles target-specific stuff, such as applying
31233123
// relocations or writing a PLT section. It also contains target-dependent
31243124
// values such as a default image base address.
3125-
ctx.target = getTarget();
3125+
ctx.target = getTarget(ctx);
31263126

31273127
ctx.arg.eflags = ctx.target->calcEFlags();
31283128
// maxPageSize (sometimes called abi page size) is the maximum page size that

lld/ELF/Relocations.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static std::string getLocation(Ctx &ctx, InputSectionBase &s, const Symbol &sym,
9999

100100
void elf::reportRangeError(uint8_t *loc, const Relocation &rel, const Twine &v,
101101
int64_t min, uint64_t max) {
102-
ErrorPlace errPlace = getErrorPlace(loc);
102+
ErrorPlace errPlace = getErrorPlace(ctx, loc);
103103
std::string hint;
104104
if (rel.sym) {
105105
if (!rel.sym->isSection())
@@ -130,7 +130,7 @@ void elf::reportRangeError(uint8_t *loc, const Relocation &rel, const Twine &v,
130130

131131
void elf::reportRangeError(Ctx &ctx, uint8_t *loc, int64_t v, int n,
132132
const Symbol &sym, const Twine &msg) {
133-
ErrorPlace errPlace = getErrorPlace(loc);
133+
ErrorPlace errPlace = getErrorPlace(ctx, loc);
134134
std::string hint;
135135
if (!sym.getName().empty())
136136
hint = "; references '" + lld::toString(sym) + '\'' +

lld/ELF/Target.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ std::string lld::toString(RelType type) {
4545
return std::string(s);
4646
}
4747

48-
TargetInfo *elf::getTarget() {
48+
TargetInfo *elf::getTarget(Ctx &ctx) {
4949
switch (ctx.arg.emachine) {
5050
case EM_386:
5151
case EM_IAMCU:
@@ -94,7 +94,7 @@ TargetInfo *elf::getTarget() {
9494
}
9595
}
9696

97-
ErrorPlace elf::getErrorPlace(const uint8_t *loc) {
97+
ErrorPlace elf::getErrorPlace(Ctx &ctx, const uint8_t *loc) {
9898
assert(loc != nullptr);
9999
for (InputSectionBase *d : ctx.inputSections) {
100100
auto *isec = dyn_cast<InputSection>(d);

lld/ELF/Target.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ struct ErrorPlace {
200200
};
201201

202202
// Returns input section and corresponding source string for the given location.
203-
ErrorPlace getErrorPlace(const uint8_t *loc);
203+
ErrorPlace getErrorPlace(Ctx &ctx, const uint8_t *loc);
204204

205205
static inline std::string getErrorLocation(const uint8_t *loc) {
206-
return getErrorPlace(loc).loc;
206+
return getErrorPlace(ctx, loc).loc;
207207
}
208208

209209
void processArmCmseSymbols();
@@ -241,7 +241,7 @@ void convertArmInstructionstoBE8(InputSection *sec, uint8_t *buf);
241241
void createTaggedSymbols(const SmallVector<ELFFileBase *, 0> &files);
242242
void initSymbolAnchors();
243243

244-
TargetInfo *getTarget();
244+
TargetInfo *getTarget(Ctx &ctx);
245245

246246
template <class ELFT> bool isMipsPIC(const Defined *sym);
247247

0 commit comments

Comments
 (0)