diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -561,8 +561,11 @@ } void LinkerScript::discard(InputSectionBase &s) { - if (&s == in.shStrTab.get() || &s == mainPart->relrDyn.get()) + if (&s == in.shStrTab.get() || &s == mainPart->relrDyn.get()) { error("discarding " + s.name + " section is not allowed"); + if (&s == mainPart->relrDyn.get()) + mainPart->relrDyn.reset(); + } // You can discard .hash and .gnu.hash sections by linker scripts. Since // they are synthesized sections, we need to handle them differently than diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -538,8 +538,6 @@ // finalizeSections does that. finalizeSections(); checkExecuteOnly(); - if (errorCount()) - return; // If --compressed-debug-sections is specified, compress .debug_* sections. // Do it right now because it changes the size of output sections. @@ -1998,10 +1996,6 @@ } } - // Do not proceed if there was an undefined symbol. - if (errorCount()) - return; - if (in.mipsGot) in.mipsGot->build(); diff --git a/lld/test/ELF/map-file.s b/lld/test/ELF/map-file.s --- a/lld/test/ELF/map-file.s +++ b/lld/test/ELF/map-file.s @@ -6,6 +6,7 @@ # RUN: echo '.global baz; baz: ret' | llvm-mc -filetype=obj -triple=x86_64 - -o %t4.o # RUN: llvm-mc -filetype=obj -triple=x86_64 %p/Inputs/map-file5.s -o %t5.o # RUN: echo '.global hey; hey: ret' | llvm-mc -filetype=obj -triple=x86_64 - -o %t6.o +# RUN: echo '.reloc ., R_X86_64_RELATIVE, 0' | llvm-mc -filetype=obj -triple=x86_64 - -o %t7.o # RUN: ld.lld -shared %t5.o -o %t5.so -soname dso # RUN: rm -f %t4.a # RUN: llvm-ar rc %t4.a %t4.o @@ -16,6 +17,9 @@ # RUN: ld.lld %t1.o %t2.o %t3.o %t4.a %t5.so %t6.a -o %t -Map=%t.map # RUN: FileCheck -match-full-lines -strict-whitespace %s < %t.map +## A relocation error does not suppress the output. +# RUN: not ld.lld %t1.o %t2.o %t3.o %t4.a %t5.so %t6.a %t7.o -o /dev/null -M | FileCheck --strict-whitespace --check-prefix=CHECK2 %s + .global _start _start: .cfi_startproc @@ -102,6 +106,12 @@ # CHECK-NEXT: 0 0 71 1 .strtab # CHECK-NEXT: 0 0 71 1 :(.strtab) +# CHECK2: VMA LMA Size Align Out In Symbol +# CHECK2-NEXT: 200200 200200 78 8 .dynsym +# CHECK2-NEXT: 200200 200200 78 8 :(.dynsym) +# CHECK2-NEXT: 200278 200278 2c 8 .gnu.hash +# CHECK2-NEXT: 200278 200278 2c 8 :(.gnu.hash) + # RUN: not ld.lld %t1.o %t2.o %t3.o %t4.a -o /dev/null -Map=/ 2>&1 \ # RUN: | FileCheck --check-prefix=FAIL %s # FAIL: cannot open map file / diff --git a/lld/test/ELF/why-extract.s b/lld/test/ELF/why-extract.s --- a/lld/test/ELF/why-extract.s +++ b/lld/test/ELF/why-extract.s @@ -5,6 +5,7 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o # RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a_b.s -o %t/a_b.o # RUN: llvm-mc -filetype=obj -triple=x86_64 %t/b.s -o %t/b.o +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/err.s -o %t/err.o # RUN: llvm-ar rc %t/a.a %t/a.o # RUN: llvm-ar rc %t/a_b.a %t/a_b.o # RUN: llvm-ar rc %t/b.a %t/b.o @@ -21,6 +22,10 @@ # RUN: ld.lld main.o a_b.a b.a -o /dev/null --why-extract=why2.txt # RUN: FileCheck %s --input-file=why2.txt --check-prefix=CHECK2 --match-full-lines --strict-whitespace +## A relocation error does not suppress the output. +# RUN: rm -f why2.txt && not ld.lld main.o a_b.a b.a err.o -o /dev/null --why-extract=why2.txt +# RUN: FileCheck %s --input-file=why2.txt --check-prefix=CHECK2 --match-full-lines --strict-whitespace + # CHECK2:reference extracted symbol # CHECK2-NEXT:main.o a_b.a(a_b.o) a # CHECK2-NEXT:a_b.a(a_b.o) b.a(b.o) b() @@ -84,3 +89,6 @@ #--- a.lds a = _Z1bv; + +#--- err.s +.reloc ., R_X86_64_RELATIVE, 0