• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# REQUIRES: x86
2# RUN: llvm-mc -triple=x86_64-windows-gnu %s -filetype=obj -o %t1.obj
3# RUN: llvm-mc -triple=x86_64-windows-gnu %S/Inputs/comdat-jumptable2.s -filetype=obj -o %t2.obj
4
5# RUN: llvm-objdump -s %t1.obj | FileCheck --check-prefix=OBJ1 %s
6# RUN: llvm-objdump -s %t2.obj | FileCheck --check-prefix=OBJ2 %s
7
8# RUN: lld-link -lldmingw -entry:main %t1.obj %t2.obj -out:%t.exe
9# RUN: llvm-objdump -s %t.exe | FileCheck --check-prefix=EXE %s
10
11# Test linking cases where comdat functions have an associated jump table
12# in a non-comdat rdata (which GCC produces for functions with jump tables).
13# In these cases, ld.bfd keeps all rdata sections, but the relocations that
14# refer to discarded comdat sections just are emitted as they were originally.
15
16# In real scenarios, the jump table .rdata section should be identical across
17# all object files; here it is different to illustrate more clearly what
18# the linker actually does.
19
20# OBJ1: Contents of section .rdata:
21# OBJ1:  0000 aaaaaaaa 14000000 1e000000 28000000
22# OBJ1:  0010 bbbbbbbb
23
24# OBJ2: Contents of section .rdata:
25# OBJ2:  0000 cccccccc 14000000 1e000000 28000000
26# OBJ2:  0010 dddddddd
27
28# EXE: Contents of section .rdata:
29# EXE:  140002000 aaaaaaaa 0c100000 12100000 18100000
30# EXE:  140002010 bbbbbbbb cccccccc 14000000 1e000000
31# EXE:  140002020 28000000 dddddddd
32
33
34        .section .text@comdatfunc, "x"
35        .linkonce discard
36        .globl comdatfunc
37comdatfunc:
38        leaq .Ljumptable(%rip), %rax
39        movslq (%rax, %rcx, 4), %rcx
40        addq %rcx, %rax
41        jmp *%rax
42
43        .section .rdata, "dr"
44        .long 0xaaaaaaaa
45.Ljumptable:
46        .long .Ltail1-.Ljumptable
47        .long .Ltail2-.Ljumptable
48        .long .Ltail3-.Ljumptable
49        .long 0xbbbbbbbb
50
51        .section .text@comdatfunc, "x"
52# If assembled with binutils, the following line can be kept in:
53#       .linkonce discard
54.Ltail1:
55        movl $1, %eax
56        ret
57.Ltail2:
58        movl $2, %eax
59        ret
60.Ltail3:
61        movl $3, %eax
62        ret
63
64
65        .text
66        .globl main
67main:
68        call comdatfunc
69        call otherfunc
70        ret
71