Skip to content

Commit

Permalink
[ELF] Pass Ctx & to Target.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Sep 29, 2024
1 parent 29783f7 commit a522516
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
9 changes: 5 additions & 4 deletions lld/ELF/Arch/ARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lld/ELF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lld/ELF/Relocations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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) + '\'' +
Expand Down
4 changes: 2 additions & 2 deletions lld/ELF/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions lld/ELF/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit a522516

Please sign in to comment.