File: comdat-discarded-lazy.s

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-20
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,496,436 kB
  • sloc: cpp: 5,593,990; ansic: 986,873; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,547; xml: 953; cs: 573; fortran: 567
file content (60 lines) | stat: -rw-r--r-- 2,760 bytes parent folder | download | duplicates (5)
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
# REQUIRES: x86
## Test that lazy symbols in a section group can be demoted to Undefined,
## so that we can report a "discarded section" error.

# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
# RUN: echo '.globl f1, foo; f1: call foo; \
# RUN:   .section .text.foo,"axG",@progbits,foo,comdat; foo:' | \
# RUN:   llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o

## Test the case when the symbol causing a "discarded section" is ordered
## *before* the symbol fetching the lazy object.
## The test relies on the symbol table order of llvm-mc (lexical), which will
## need adjustment if llvm-mc changes its behavior.
# RUN: echo '.globl aa, f2; f2: .weak foo; foo: call aa; \
# RUN:   .section .text.foo,"axG",@progbits,foo,comdat; aa:' | \
# RUN:   llvm-mc -filetype=obj -triple=x86_64 - -o %taa.o
# RUN: llvm-nm -p %taa.o | FileCheck --check-prefix=AA-NM %s
# RUN: not ld.lld %t.o --start-lib %t1.o %taa.o --end-lib -o /dev/null 2>&1 | FileCheck --check-prefix=AA %s
# RUN: rm -f %taa.a && llvm-ar rc %taa.a %taa.o
# RUN: not ld.lld %t.o --start-lib %t1.o --end-lib %taa.a -o /dev/null 2>&1 | FileCheck --check-prefix=AA %s

# AA-NM: aa
# AA-NM: f2

# AA:      error: relocation refers to a symbol in a discarded section: aa
# AA-NEXT: >>> defined in {{.*}}aa.o
# AA-NEXT: >>> section group signature: foo
# AA-NEXT: >>> prevailing definition is in {{.*}}1.o
# AA-NEXT: >>> referenced by {{.*}}aa.o:(.text+0x1)

## Test the case when the symbol causing a "discarded section" is ordered
## *after* the symbol fetching the lazy object.
# RUN: echo '.globl f2, zz; .weak foo; foo: f2: call zz; \
# RUN:   .section .text.foo,"axG",@progbits,foo,comdat; zz:' | \
# RUN:   llvm-mc -filetype=obj -triple=x86_64 - -o %tzz.o
# RUN: llvm-nm -p %tzz.o | FileCheck --check-prefix=ZZ-NM %s
# RUN: not ld.lld %t.o --start-lib %t1.o %tzz.o --end-lib -o /dev/null 2>&1 | FileCheck --check-prefix=ZZ %s
# RUN: rm -f %tzz.a && llvm-ar rc %tzz.a %tzz.o
# RUN: not ld.lld %t.o --start-lib %t1.o --end-lib %tzz.a -o /dev/null 2>&1 | FileCheck --check-prefix=ZZ %s

# ZZ-NM: f2
# ZZ-NM: zz

# ZZ:      error: relocation refers to a symbol in a discarded section: zz
# ZZ-NEXT: >>> defined in {{.*}}zz.o
# ZZ-NEXT: >>> section group signature: foo
# ZZ-NEXT: >>> prevailing definition is in {{.*}}1.o
# ZZ-NEXT: >>> referenced by {{.*}}zz.o:(.text+0x1)

## Don't error if the symbol which would cause "discarded section"
## was inserted before %tzz.o
# RUN: echo '.globl zz; zz:' | llvm-mc -filetype=obj -triple=x86_64 - -o %tdef.o
# RUN: ld.lld %t.o --start-lib %t1.o %tdef.o %tzz.o --end-lib -o /dev/null
# RUN: rm -f %tdef.a && llvm-ar rc %tdef.a %tdef.o
# RUN: ld.lld %t.o --start-lib %t1.o %tdef.a %tzz.o --end-lib -o /dev/null

.globl _start
_start:
  call f1
  call f2