1# REQUIRES: x86 2 3# RUN: rm -rf %t && split-file %s %t && cd %t 4# RUN: llvm-mc -filetype=obj -triple=x86_64 main.s -o main.o 5# RUN: llvm-mc -filetype=obj -triple=x86_64 def.s -o def.o 6# RUN: llvm-mc -filetype=obj -triple=x86_64 def-hidden.s -o def-hidden.o 7# RUN: llvm-mc -filetype=obj -triple=x86_64 ref.s -o ref.o 8# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o && ld.lld -shared a.o -o a.so 9# RUN: cp a.so b.so 10# RUN: llvm-mc -filetype=obj -triple=x86_64 empty.s -o empty.o && ld.lld -shared empty.o -o empty.so 11 12# RUN: ld.lld --allow-shlib-undefined main.o a.so -o /dev/null 13# RUN: not ld.lld --no-allow-shlib-undefined main.o a.so -o /dev/null 2>&1 | FileCheck %s 14## Executable linking defaults to --no-allow-shlib-undefined. 15# RUN: not ld.lld main.o a.so -o /dev/null 2>&1 | FileCheck %s 16# RUN: ld.lld main.o a.so --noinhibit-exec -o /dev/null 2>&1 | FileCheck %s --check-prefix=WARN 17# RUN: ld.lld main.o a.so --warn-unresolved-symbols -o /dev/null 2>&1 | FileCheck %s --check-prefix=WARN 18## -shared linking defaults to --allow-shlib-undefined. 19# RUN: ld.lld -shared main.o a.so -o /dev/null 20 21## DSO with undefines should link with or without any of these options. 22# RUN: ld.lld -shared --allow-shlib-undefined a.o -o /dev/null 23# RUN: ld.lld -shared --no-allow-shlib-undefined a.o -o /dev/null 24 25## Perform checking even if an unresolved symbol is first seen in a regular object file. 26# RUN: not ld.lld --gc-sections main.o ref.o a.so -o /dev/null 2>&1 | FileCheck %s 27 28## Check that the error is reported for each shared library where the symbol 29## is referenced. 30# RUN: not ld.lld main.o a.so empty.so b.so -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK2 31 32## Test some cases when a relocatable object file provides a non-exported definition. 33# RUN: not ld.lld main.o a.so def-hidden.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=NONEXPORTED 34# RUN: not ld.lld main.o def-hidden.o a.so -o /dev/null 2>&1 | FileCheck %s --check-prefix=NONEXPORTED 35# RUN: not ld.lld main.o a.so def-hidden.o -shared --no-allow-shlib-undefined -o /dev/null 2>&1 | FileCheck %s --check-prefix=NONEXPORTED 36# RUN: ld.lld main.o a.so def-hidden.o --allow-shlib-undefined --fatal-warnings -o /dev/null 37## Test a relocatable object file definition that is converted to STB_LOCAL. 38# RUN: not ld.lld main.o a.so def-hidden.o --version-script=local.ver -o /dev/null 2>&1 | FileCheck %s --check-prefix=NONEXPORTED 39# RUN: not ld.lld main.o def-hidden.o a.so --version-script=local.ver -o /dev/null 2>&1 | FileCheck %s --check-prefix=NONEXPORTED 40 41## The section containing the definition is discarded, and we report an error. 42# RUN: not ld.lld --gc-sections main.o a.so def-hidden.o -o /dev/null 2>&1 | FileCheck %s 43## The definition def.so is ignored. 44# RUN: ld.lld -shared def.o -o def.so 45# RUN: ld.lld --gc-sections main.o a.so def.so def-hidden.o --fatal-warnings -o /dev/null 46 47# CHECK-NOT: error: 48# CHECK: error: undefined reference: x1{{$}} 49# CHECK-NEXT: >>> referenced by a.so (disallowed by --no-allow-shlib-undefined){{$}} 50# CHECK-NOT: {{.}} 51 52# CHECK2-NOT: error: 53# CHECK2: error: undefined reference: x1 54# CHECK2-NEXT: >>> referenced by a.so (disallowed by --no-allow-shlib-undefined) 55# CHECK2: error: undefined reference: x1 56# CHECK2-NEXT: >>> referenced by b.so (disallowed by --no-allow-shlib-undefined) 57# CHECK2-NOT: {{.}} 58 59# WARN: warning: undefined reference: x1 60# WARN-NEXT: >>> referenced by a.so (disallowed by --no-allow-shlib-undefined) 61 62# NONEXPORTED-NOT: error: 63# NONEXPORTED: error: non-exported symbol 'x1' in 'def-hidden.o' is referenced by DSO 'a.so' 64# NONEXPORTED-NOT: {{.}} 65 66#--- main.s 67.globl _start 68_start: 69 callq shared@PLT 70#--- ref.s 71 callq x1@PLT 72#--- def.s 73.globl x1 74x1: 75#--- def-hidden.s 76.globl x1 77.hidden x1 78x1: 79 80#--- a.s 81.globl shared 82.weak x2 83shared: 84 callq x1@PLT 85 movq x2@GOTPCREL(%rip), %rax 86 87#--- empty.s 88#--- local.ver 89v1 { local: x1; }; 90