xref: /llvm-project/lld/test/ELF/weak-undef-shared.s (revision e49c417ed1847a3b8e7595ddb8212ea8d13df5df)
1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
3# RUN: ld.lld -shared %t.o -o %t.so
4
5# RUN: echo '.data; .weak foo; .quad foo' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
6# RUN: echo '.data; .quad foo' | llvm-mc -filetype=obj -triple=x86_64 - -o %t2.o
7# RUN: ld.lld -shared %t2.o -o %t2.so
8
9## If the first undefined reference is weak, the binding changes to
10## STB_WEAK.
11# RUN: ld.lld %t1.o %t.so -o %t
12# RUN: llvm-readelf --dyn-syms %t | FileCheck --check-prefix=WEAK %s
13# RUN: ld.lld %t.so %t1.o -o %t
14# RUN: llvm-readelf --dyn-syms %t | FileCheck --check-prefix=WEAK %s
15
16## The binding remains STB_WEAK if there is no STB_GLOBAL undefined reference.
17# RUN: ld.lld %t1.o %t.so %t1.o -o %t
18# RUN: llvm-readelf --dyn-syms %t | FileCheck --check-prefix=WEAK %s
19# RUN: ld.lld %t.so %t1.o %t1.o -o %t
20# RUN: llvm-readelf --dyn-syms %t | FileCheck --check-prefix=WEAK %s
21
22## The binding changes back to STB_GLOBAL if there is a STB_GLOBAL undefined reference.
23# RUN: ld.lld %t1.o %t.so %t2.o -o %t
24# RUN: llvm-readelf --dyn-syms %t | FileCheck --check-prefix=GLOBAL %s
25# RUN: ld.lld %t2.o %t.so %t1.o -o %t
26# RUN: llvm-readelf --dyn-syms %t | FileCheck --check-prefix=GLOBAL %s
27
28## Check the binding (weak) is not affected by the STB_GLOBAL undefined
29## reference in %t2.so
30# RUN: ld.lld %t1.o %t2.so -o %t
31# RUN: llvm-readelf --dyn-syms %t | FileCheck --check-prefix=WEAK %s
32
33# RUN: ld.lld %t2.so %t1.o -o %t
34# RUN: llvm-readelf --dyn-syms %t | FileCheck --check-prefix=WEAK %s
35
36# WEAK:   NOTYPE WEAK   DEFAULT UND foo
37# GLOBAL: NOTYPE GLOBAL DEFAULT UND foo
38
39.globl foo
40foo:
41