xref: /llvm-project/lld/test/ELF/comdat-discarded-reloc.s (revision 0f298ec6ccc0877117e4ee8036a58d10e5ff1ac3)
1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
3# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/comdat-discarded-reloc.s -o %t2.o
4# RUN: ld.lld -gc-sections --noinhibit-exec %t2.o %t.o -o /dev/null
5# RUN: ld.lld -r %t2.o %t.o -o %t 2>&1 | FileCheck --check-prefix=WARN %s
6# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC %s
7
8## ELF spec doesn't allow a relocation to point to a deduplicated
9## COMDAT section. Unfortunately this happens in practice (e.g. .eh_frame)
10## Test case checks we do not crash.
11
12# WARN: warning: relocation refers to a discarded section: .text.bar1
13# WARN-NEXT: >>> referenced by {{.*}}.o:(.rela.text.bar2+0x0)
14# WARN-NOT: warning
15
16# RELOC:      .rela.eh_frame {
17# RELOC-NEXT:   R_X86_64_NONE
18# RELOC-NEXT: }
19# RELOC-NEXT: .rela.debug_foo {
20# RELOC-NEXT:   R_X86_64_NONE
21# RELOC-NEXT: }
22# RELOC-NEXT: .rela.gcc_except_table {
23# RELOC-NEXT:   R_X86_64_NONE
24# RELOC-NEXT: }
25
26.globl group
27group:
28.section .text.bar1,"aG",@progbits,group,comdat
29
30## .text.bar1 in this file is discarded. Warn on the relocation.
31.section .text.bar2,"ax"
32.globl bar
33bar:
34  .quad .text.bar1
35
36## Don't warn on .eh_frame, .debug*, .zdebug*, or .gcc_except_table
37.section .eh_frame,"a",@unwind
38  .quad .text.bar1
39
40.section .debug_foo
41  .quad .text.bar1
42
43.section .gcc_except_table,"a"
44  .quad .text.bar1
45