Skip to content

Commit 2bbd32f

Browse files
committed
[ELF] Allow getErrPlace() to work before Out::bufferStart is set
Summary: So far it seems like the only test affected by this change is the one I recently added for R_MIPS_JALR relocations since the other test cases that use this function early (unknown-relocation-*) do not have a valid input section for the relocation offset. Reviewers: ruiu, grimar, MaskRay, espindola Reviewed By: ruiu, MaskRay Subscribers: emaste, sdardis, jrtc27, atanasyan, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70659
1 parent e91420e commit 2bbd32f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lld/ELF/Target.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ TargetInfo *getTarget() {
9191
}
9292

9393
template <class ELFT> static ErrorPlace getErrPlace(const uint8_t *loc) {
94-
if (!Out::bufferStart)
95-
return {};
96-
9794
for (InputSectionBase *d : inputSections) {
9895
auto *isec = cast<InputSection>(d);
9996
if (!isec->getParent())
10097
continue;
10198

102-
uint8_t *isecLoc = Out::bufferStart + isec->getParent()->offset + isec->outSecOff;
99+
const uint8_t *isecLoc =
100+
Out::bufferStart
101+
? (Out::bufferStart + isec->getParent()->offset + isec->outSecOff)
102+
: isec->data().data();
103103
if (isecLoc <= loc && loc < isecLoc + isec->getSize())
104104
return {isec, isec->template getLocation<ELFT>(loc - isecLoc) + ": "};
105105
}

lld/test/ELF/mips-jalr-non-functions.s

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ test:
1515
.Ltmp1:
1616
jr $t9
1717
nop
18-
# WARNING-MESSAGE: warning: found R_MIPS_JALR relocation against non-function symbol tls_obj. This is invalid and most likely a compiler bug.
18+
# WARNING-MESSAGE: warning: {{.+}}.tmp.o:(.text+0x0): found R_MIPS_JALR relocation against non-function symbol tls_obj. This is invalid and most likely a compiler bug.
1919

2020
.reloc .Ltmp2, R_MIPS_JALR, reg_obj
2121
.Ltmp2:
2222
jr $t9
2323
nop
24-
# WARNING-MESSAGE: warning: found R_MIPS_JALR relocation against non-function symbol reg_obj. This is invalid and most likely a compiler bug.
24+
# WARNING-MESSAGE: warning: {{.+}}.tmp.o:(.text+0x8): found R_MIPS_JALR relocation against non-function symbol reg_obj. This is invalid and most likely a compiler bug.
2525

2626
.reloc .Ltmp3, R_MIPS_JALR, untyped
2727
.Ltmp3:

0 commit comments

Comments
 (0)