File: comdat-jumptable.s

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (70 lines) | stat: -rw-r--r-- 2,112 bytes parent folder | download | duplicates (25)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# REQUIRES: x86
# RUN: llvm-mc -triple=x86_64-windows-gnu %s -filetype=obj -o %t1.obj
# RUN: llvm-mc -triple=x86_64-windows-gnu %S/Inputs/comdat-jumptable2.s -filetype=obj -o %t2.obj

# RUN: llvm-objdump -s %t1.obj | FileCheck --check-prefix=OBJ1 %s
# RUN: llvm-objdump -s %t2.obj | FileCheck --check-prefix=OBJ2 %s

# RUN: lld-link -lldmingw -entry:main %t1.obj %t2.obj -out:%t.exe
# RUN: llvm-objdump -s %t.exe | FileCheck --check-prefix=EXE %s

# Test linking cases where comdat functions have an associated jump table
# in a non-comdat rdata (which GCC produces for functions with jump tables).
# In these cases, ld.bfd keeps all rdata sections, but the relocations that
# refer to discarded comdat sections just are emitted as they were originally.

# In real scenarios, the jump table .rdata section should be identical across
# all object files; here it is different to illustrate more clearly what
# the linker actually does.

# OBJ1: Contents of section .rdata:
# OBJ1:  0000 aaaaaaaa 14000000 1e000000 28000000
# OBJ1:  0010 bbbbbbbb

# OBJ2: Contents of section .rdata:
# OBJ2:  0000 cccccccc 14000000 1e000000 28000000
# OBJ2:  0010 dddddddd

# EXE: Contents of section .rdata:
# EXE:  140002000 aaaaaaaa 0c100000 12100000 18100000
# EXE:  140002010 bbbbbbbb cccccccc 14000000 1e000000
# EXE:  140002020 28000000 dddddddd


        .section .text@comdatfunc, "x"
        .linkonce discard
        .globl comdatfunc
comdatfunc:
        leaq .Ljumptable(%rip), %rax
        movslq (%rax, %rcx, 4), %rcx
        addq %rcx, %rax
        jmp *%rax

        .section .rdata, "dr"
        .long 0xaaaaaaaa
.Ljumptable:
        .long .Ltail1-.Ljumptable
        .long .Ltail2-.Ljumptable
        .long .Ltail3-.Ljumptable
        .long 0xbbbbbbbb

        .section .text@comdatfunc, "x"
# If assembled with binutils, the following line can be kept in:
#       .linkonce discard
.Ltail1:
        movl $1, %eax
        ret
.Ltail2:
        movl $2, %eax
        ret
.Ltail3:
        movl $3, %eax
        ret


        .text
        .globl main
main:
        call comdatfunc
        call otherfunc
        ret