Skip to content

Commit 441410b

Browse files
committed
[ELF] Avoid false-positive assert in getErrPlace()
This assertion was added as part of D70659 but did not account for .bss input sections. I noticed that this assert was incorrectly triggering while building FreeBSD for MIPS64. Fixed by relaxing the assert to also account for SHT_NOBITS input sections and adjust the test mips-jalr-non-function.s to link a file with a .bss section first. Reviewed By: MaskRay, grimar Differential Revision: https://reviews.llvm.org/D72567
1 parent 4d14bfa commit 441410b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lld/ELF/Target.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ template <class ELFT> static ErrorPlace getErrPlace(const uint8_t *loc) {
9595
assert(loc != nullptr);
9696
for (InputSectionBase *d : inputSections) {
9797
auto *isec = cast<InputSection>(d);
98-
if (!isec->getParent())
98+
if (!isec->getParent() || (isec->type & SHT_NOBITS))
9999
continue;
100100

101101
const uint8_t *isecLoc =

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
## relocations to avoid generating binaries that crash when executed.
77

88
# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t.o
9-
# RUN: ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -check-prefix WARNING-MESSAGE
9+
## Link in another object file with a .bss as a regression test:
10+
## Previously LLD asserted when skipping over .bss sections when determining the
11+
## location for a warning/error message. By adding another file with a .bss
12+
## section before the actual %t.o we can reproduce this case.
13+
# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %S/Inputs/common.s -o %t-common.o
14+
# RUN: ld.lld -shared %t-common.o %t.o -o %t.so 2>&1 | FileCheck %s -check-prefix WARNING-MESSAGE
1015
# RUN: llvm-objdump --no-show-raw-insn --no-leading-addr -d %t.so | FileCheck %s
1116

1217
.set noreorder

0 commit comments

Comments
 (0)