Skip to content

Commit 1444e6e

Browse files
committed
Re-apply "[ELF] Allow getErrPlace() to work before Out::bufferStart is set"
This time with a fix for the UBSAN failure. Differential Revision: https://reviews.llvm.org/D70659
1 parent 4e003aa commit 1444e6e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lld/ELF/Target.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "OutputSections.h"
2929
#include "SymbolTable.h"
3030
#include "Symbols.h"
31+
#include "SyntheticSections.h"
3132
#include "lld/Common/ErrorHandler.h"
3233
#include "llvm/Object/ELF.h"
3334

@@ -91,15 +92,20 @@ TargetInfo *getTarget() {
9192
}
9293

9394
template <class ELFT> static ErrorPlace getErrPlace(const uint8_t *loc) {
94-
if (!Out::bufferStart)
95-
return {};
96-
95+
assert(loc != nullptr);
9796
for (InputSectionBase *d : inputSections) {
9897
auto *isec = cast<InputSection>(d);
9998
if (!isec->getParent())
10099
continue;
101100

102-
uint8_t *isecLoc = Out::bufferStart + isec->getParent()->offset + isec->outSecOff;
101+
const uint8_t *isecLoc =
102+
Out::bufferStart
103+
? (Out::bufferStart + isec->getParent()->offset + isec->outSecOff)
104+
: isec->data().data();
105+
if (isecLoc == nullptr) {
106+
assert(isa<SyntheticSection>(isec) && "No data but not synthetic?");
107+
continue;
108+
}
103109
if (isecLoc <= loc && loc < isecLoc + isec->getSize())
104110
return {isec, isec->template getLocation<ELFT>(loc - isecLoc) + ": "};
105111
}

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

Lines changed: 2 additions & 2 deletions
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)