[PATCH] D116838: [ELF] -Map --why-extract=: print despite errors

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 7 14:08:24 PST 2022


MaskRay updated this revision to Diff 398235.
MaskRay retitled this revision from "[ELF] -Map --why-extract=: print despite errors

Fix https://github.com/llvm/llvm-project/issues/53073

In case of a relocation error, GNU ld's link map includes
the archive member extraction information but not the section layout.
This change..." to "[ELF] -Map --why-extract=: print despite errors".
MaskRay edited the summary of this revision.
MaskRay added a comment.

.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116838/new/

https://reviews.llvm.org/D116838

Files:
  lld/ELF/Writer.cpp
  lld/test/ELF/map-file.s
  lld/test/ELF/why-extract.s


Index: lld/test/ELF/why-extract.s
===================================================================
--- lld/test/ELF/why-extract.s
+++ 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
Index: lld/test/ELF/map-file.s
===================================================================
--- lld/test/ELF/map-file.s
+++ 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,10 @@
 # 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. Some passes are skipped so
+## some information is lost, e.g. there is no synthetic section.
+# 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 +107,16 @@
 # CHECK-NEXT:               0                0       71     1 .strtab
 # CHECK-NEXT:               0                0       71     1         <internal>:(.strtab)
 
+# CHECK2:                 VMA              LMA     Size Align Out     In      Symbol
+# CHECK2-NEXT:              0                0        0    16 .bss
+# CHECK2-NEXT:              0                0        4    16         {{.*}}{{/|\\}}map-file.s.tmp1.o:(COMMON)
+# CHECK2-NEXT:              0                0        4     1                 common
+# CHECK2-NEXT:              0                0        0     1         <internal>:(.bss)
+# CHECK2-NEXT:              0                0        4     1         <internal>:(.bss)
+# CHECK2-NEXT:              0                0        4     1                 sharedFoo
+# CHECK2-NEXT:              0                0        8     1         <internal>:(.bss)
+# CHECK2-NEXT:              0                0        8     1                 sharedBar
+
 # 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 /
Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116838.398235.patch
Type: text/x-patch
Size: 3854 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220107/87aef6db/attachment.bin>


More information about the llvm-commits mailing list