91 lines · plain
1# REQUIRES: x862## Test relocations referencing symbols defined relative to sections discarded by /DISCARD/.3 4# RUN: rm -rf %t && split-file %s %t && cd %t5# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o6# RUN: llvm-mc -filetype=obj -triple=x86_64 b.s -o b.o7# RUN: not ld.lld --threads=1 -T a.lds a.o b.o -z undefs 2>&1 | FileCheck %s --check-prefix=LOCAL --implicit-check-not=error:8# RUN: not ld.lld --threads=1 -T a.lds a.o b.o 2>&1 | FileCheck %s --check-prefixes=LOCAL,NONLOCAL --implicit-check-not=error: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# RUN: llvm-readelf -r -s a.ro | FileCheck %s --check-prefix=RELOC11 12# RUN: ld.lld -r --gc-sections -T a.lds a.o b.o -o a.gc.ro --no-fatal-warnings13# RUN: llvm-readelf -r -s a.gc.ro | FileCheck %s --check-prefix=RELOC-GC14 15# LOCAL: error: relocation refers to a discarded section: .aaa16# LOCAL-NEXT: >>> defined in a.o17# LOCAL-NEXT: >>> referenced by a.o:(.bbb+0x0)18 19# NONLOCAL: error: relocation refers to a symbol in a discarded section: global20# NONLOCAL-NEXT: >>> defined in a.o21# NONLOCAL-NEXT: >>> referenced by b.o:(.data+0x0)22 23# NONLOCAL: error: relocation refers to a symbol in a discarded section: weak24# NONLOCAL-NEXT: >>> defined in a.o25# NONLOCAL-NEXT: >>> referenced by b.o:(.data+0x8)26 27# NONLOCAL: error: relocation refers to a symbol in a discarded section: weakref128# NONLOCAL-NEXT: >>> defined in a.o29# NONLOCAL-NEXT: >>> referenced by b.o:(.data+0x10)30 31# NONLOCAL: error: relocation refers to a symbol in a discarded section: weakref232# NONLOCAL-NEXT: >>> defined in a.o33# NONLOCAL-NEXT: >>> referenced by b.o:(.data+0x18)34 35# WARNING: warning: relocation refers to a discarded section: .aaa36# WARNING-NEXT: >>> referenced by a.o:(.rela.bbb+0x0)37 38## GNU ld reports "defined in discarded secion" errors even in -r mode.39## We set the symbol index to 0.40# RELOC: Relocation section '.rela.bbb' at offset {{.*}} contains 1 entries:41# RELOC-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend42# RELOC-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE 043# RELOC-EMPTY:44# RELOC-NEXT: Relocation section '.rela.data' at offset {{.*}} contains 4 entries:45# RELOC-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend46# RELOC-NEXT: 0000000000000000 0000000000000001 R_X86_64_64 047# RELOC-NEXT: 0000000000000008 0000000000000001 R_X86_64_64 048# RELOC-NEXT: 0000000000000010 0000000000000001 R_X86_64_64 049# RELOC-NEXT: 0000000000000018 0000000000000001 R_X86_64_64 050 51# RELOC: Num: Value Size Type Bind Vis Ndx Name52# RELOC-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND53# RELOC-NEXT: 1: 0000000000000000 0 SECTION LOCAL DEFAULT 1 .text54# RELOC-NEXT: 2: 0000000000000000 0 SECTION LOCAL DEFAULT 2 .bbb55# RELOC-NEXT: 3: 0000000000000000 0 SECTION LOCAL DEFAULT 4 .data56# RELOC-NEXT: 4: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 1 _start57# RELOC-EMPTY:58 59# RELOC-GC: There are no relocations in this file.60 61#--- a.s62.globl _start63_start:64 65.section .aaa,"a"66.globl global, weakref1, unused67.weak weak, weakref268global:69weak:70weakref1:71weakref2:72## Eliminate `unused` just like GC discarded definitions.73## Linux kernel's CONFIG_DEBUG_FORCE_WEAK_PER_CPU=y configuration expects74## that the unreferenced `unused` is not emitted to .symtab.75unused:76 .quad 077 78.section .bbb,"aw"79 .quad .aaa80 81#--- b.s82.weak weakref1, weakref283.section .data,"aw"84 .quad global85 .quad weak86 .quad weakref187 .quad weakref288 89#--- a.lds90SECTIONS { /DISCARD/ : { *(.aaa) } }91