Skip to content

Commit

Permalink
[ELF] Avoid false-positive assert in getErrPlace()
Browse files Browse the repository at this point in the history
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

(cherry picked from commit 441410b)
  • Loading branch information
arichardson authored and zmodem committed Jan 17, 2020
1 parent f06cd8c commit afbebff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lld/ELF/Target.cpp
Expand Up @@ -95,7 +95,7 @@ template <class ELFT> static ErrorPlace getErrPlace(const uint8_t *loc) {
assert(loc != nullptr);
for (InputSectionBase *d : inputSections) {
auto *isec = cast<InputSection>(d);
if (!isec->getParent())
if (!isec->getParent() || (isec->type & SHT_NOBITS))
continue;

const uint8_t *isecLoc =
Expand Down
7 changes: 6 additions & 1 deletion lld/test/ELF/mips-jalr-non-functions.s
Expand Up @@ -6,7 +6,12 @@
## relocations to avoid generating binaries that crash when executed.

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

.set noreorder
Expand Down

0 comments on commit afbebff

Please sign in to comment.