File: comdat-mixed-archive.test

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 (74 lines) | stat: -rw-r--r-- 2,144 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
REQUIRES: x86

;; This checks a case when an archive contains a bitcode and a regular object
;; files, and a comdat symbol is defined and used in both of them. Previously,
;; lld could lose the flag that the symbol is used in a regular object file
;; which led to the LTO backend internalizing the symbol and the linker
;; reporting an "undefined symbol" error.

;; In this test, group "foo" in "obj.o" is rejected in favor of "bc.bc" but we
;; need to prevent LTO from internalizing "foo" as there is still a reference
;; from outside the group in "obj.o".

RUN: rm -rf %t.dir
RUN: split-file %s %t.dir
RUN: cd %t.dir

RUN: llvm-mc -filetype=obj -triple=x86_64 start.s -o start.o
RUN: llvm-mc -filetype=obj -triple=x86_64 obj.s -o obj.o
RUN: llvm-as bc.ll -o bc.bc
RUN: llvm-nm bc.bc --no-sort | FileCheck %s --check-prefix=BCSYM
RUN: llvm-ar rc lib.a obj.o bc.bc
RUN: ld.lld start.o lib.a -y foo -y bar -o /dev/null | FileCheck %s --check-prefix=TRACE

;; "bar" should be encountered before "foo" so that it triggers the loading of
;; "obj.o" while "foo" is still lazy.
BCSYM:      U bar
BCSYM-NEXT: W foo

;; Check that the symbols are handled in the expected order.
TRACE:      lib.a(obj.o): lazy definition of foo
TRACE-NEXT: lib.a(obj.o): lazy definition of bar
TRACE-NEXT: lib.a(bc.bc): definition of foo
TRACE-NEXT: lib.a(bc.bc): reference to bar
TRACE-NEXT: lib.a(obj.o): definition of bar
TRACE-NEXT: lib.a(obj.o): reference to foo
TRACE-NEXT: <internal>: reference to foo
;; The definition of "foo" is visible outside the LTO result.
TRACE-NEXT: lto.tmp: definition of foo
TRACE-NEXT: lto.tmp: reference to bar

;--- start.s
  .global _start, baz
_start:
  call baz

;--- obj.s
  .weak foo
  .global bar

  .section .text.foo,"axG",@progbits,foo,comdat
foo:
  ret

  .section .text.bar,"ax",@progbits
bar:
  call foo

;--- bc.ll
target triple = "x86_64-unknown-linux-gnu"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"

$foo = comdat any

declare void @bar()

define linkonce_odr void @foo() comdat {
  ret void
}

define void @baz() {
  call void @foo()
  call void @bar()
  ret void
}