1REQUIRES: x86 2 3;; This checks a case when an archive contains a bitcode and a regular object 4;; files, and a comdat symbol is defined and used in both of them. Previously, 5;; lld could lose the flag that the symbol is used in a regular object file 6;; which led to the LTO backend internalizing the symbol and the linker 7;; reporting an "undefined symbol" error. 8 9;; In this test, group "foo" in "obj.o" is rejected in favor of "bc.bc" but we 10;; need to prevent LTO from internalizing "foo" as there is still a reference 11;; from outside the group in "obj.o". 12 13RUN: rm -rf %t.dir 14RUN: split-file %s %t.dir 15RUN: cd %t.dir 16 17RUN: llvm-mc -filetype=obj -triple=x86_64 start.s -o start.o 18RUN: llvm-mc -filetype=obj -triple=x86_64 obj.s -o obj.o 19RUN: llvm-as bc.ll -o bc.bc 20RUN: llvm-nm bc.bc --no-sort | FileCheck %s --check-prefix=BCSYM 21RUN: llvm-ar rc lib.a obj.o bc.bc 22RUN: ld.lld start.o lib.a -y foo -y bar -o /dev/null | FileCheck %s --check-prefix=TRACE 23 24;; "bar" should be encountered before "foo" so that it triggers the loading of 25;; "obj.o" while "foo" is still lazy. 26BCSYM: U bar 27BCSYM-NEXT: W foo 28 29;; Check that the symbols are handled in the expected order. 30TRACE: lib.a(obj.o): lazy definition of foo 31TRACE-NEXT: lib.a(obj.o): lazy definition of bar 32TRACE-NEXT: lib.a(bc.bc): definition of foo 33TRACE-NEXT: lib.a(bc.bc): reference to bar 34TRACE-NEXT: lib.a(obj.o): definition of bar 35TRACE-NEXT: lib.a(obj.o): reference to foo 36TRACE-NEXT: <internal>: reference to foo 37;; The definition of "foo" is visible outside the LTO result. 38TRACE-NEXT: {{.*}}.lto.o: definition of foo 39TRACE-NEXT: {{.*}}.lto.o: reference to bar 40 41;--- start.s 42 .global _start, baz 43_start: 44 call baz 45 46;--- obj.s 47 .weak foo 48 .global bar 49 50 .section .text.foo,"axG",@progbits,foo,comdat 51foo: 52 ret 53 54 .section .text.bar,"ax",@progbits 55bar: 56 call foo 57 58;--- bc.ll 59target triple = "x86_64-unknown-linux-gnu" 60target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 61 62$foo = comdat any 63 64declare void @bar() 65 66define linkonce_odr void @foo() comdat { 67 ret void 68} 69 70define void @baz() { 71 call void @foo() 72 call void @bar() 73 ret void 74} 75