|
9 | 9 | # RUN: ld.lld -r -T a.lds a.o b.o -o a.ro 2>&1 | FileCheck %s --check-prefix=WARNING --implicit-check-not=warning:
|
10 | 10 | # RUN: llvm-readelf -r -s a.ro | FileCheck %s --check-prefix=RELOC
|
11 | 11 |
|
| 12 | +# RUN: ld.lld -r --gc-sections -T a.lds a.o b.o -o a.gc.ro --no-fatal-warnings |
| 13 | +# RUN: llvm-readelf -r -s a.gc.ro | FileCheck %s --check-prefix=RELOC-GC |
| 14 | + |
12 | 15 | # LOCAL: error: relocation refers to a discarded section: .aaa
|
13 | 16 | # LOCAL-NEXT: >>> defined in a.o
|
14 | 17 | # LOCAL-NEXT: >>> referenced by a.o:(.bbb+0x0)
|
|
32 | 35 | # WARNING: warning: relocation refers to a discarded section: .aaa
|
33 | 36 | # WARNING-NEXT: >>> referenced by a.o:(.rela.bbb+0x0)
|
34 | 37 |
|
| 38 | +## GNU ld reports "defined in discarded secion" errors even in -r mode. |
| 39 | +## We set the symbol index to 0. |
35 | 40 | # RELOC: Relocation section '.rela.bbb' at offset {{.*}} contains 1 entries:
|
36 | 41 | # RELOC-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
|
37 | 42 | # RELOC-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE 0
|
38 | 43 | # RELOC-EMPTY:
|
39 | 44 | # RELOC-NEXT: Relocation section '.rela.data' at offset {{.*}} contains 4 entries:
|
40 | 45 | # RELOC-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
|
41 |
| -# RELOC-NEXT: 0000000000000000 0000000500000001 R_X86_64_64 0000000000000000 global + 0 |
42 |
| -# RELOC-NEXT: 0000000000000008 0000000700000001 R_X86_64_64 0000000000000000 weak + 0 |
43 |
| -# RELOC-NEXT: 0000000000000010 0000000600000001 R_X86_64_64 0000000000000000 weakref1 + 0 |
44 |
| -# RELOC-NEXT: 0000000000000018 0000000800000001 R_X86_64_64 0000000000000000 weakref2 + 0 |
| 46 | +# RELOC-NEXT: 0000000000000000 0000000000000001 R_X86_64_64 0 |
| 47 | +# RELOC-NEXT: 0000000000000008 0000000000000001 R_X86_64_64 0 |
| 48 | +# RELOC-NEXT: 0000000000000010 0000000000000001 R_X86_64_64 0 |
| 49 | +# RELOC-NEXT: 0000000000000018 0000000000000001 R_X86_64_64 0 |
45 | 50 |
|
46 | 51 | # RELOC: Num: Value Size Type Bind Vis Ndx Name
|
47 | 52 | # RELOC-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
|
48 | 53 | # RELOC-NEXT: 1: 0000000000000000 0 SECTION LOCAL DEFAULT 1 .text
|
49 | 54 | # RELOC-NEXT: 2: 0000000000000000 0 SECTION LOCAL DEFAULT 2 .bbb
|
50 | 55 | # RELOC-NEXT: 3: 0000000000000000 0 SECTION LOCAL DEFAULT 4 .data
|
51 | 56 | # RELOC-NEXT: 4: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 1 _start
|
52 |
| -# RELOC-NEXT: 5: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND global |
53 |
| -# RELOC-NEXT: 6: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND weakref1 |
54 |
| -# RELOC-NEXT: 7: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND weak |
55 |
| -# RELOC-NEXT: 8: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND weakref2 |
56 | 57 | # RELOC-EMPTY:
|
57 | 58 |
|
| 59 | +# RELOC-GC: There are no relocations in this file. |
| 60 | + |
58 | 61 | #--- a.s
|
59 | 62 | .globl _start
|
60 | 63 | _start:
|
61 | 64 |
|
62 | 65 | .section .aaa,"a"
|
63 |
| -.globl global, weakref1 |
| 66 | +.globl global, weakref1, unused |
64 | 67 | .weak weak, weakref2
|
65 | 68 | global:
|
66 | 69 | weak:
|
67 | 70 | weakref1:
|
68 | 71 | weakref2:
|
| 72 | +## Eliminate `unused` just like GC discarded definitions. |
| 73 | +## Linux kernel's CONFIG_DEBUG_FORCE_WEAK_PER_CPU=y configuration expects |
| 74 | +## that the unreferenced `unused` is not emitted to .symtab. |
| 75 | +unused: |
69 | 76 | .quad 0
|
70 | 77 |
|
71 | 78 | .section .bbb,"aw"
|
|
0 commit comments