xref: /llvm-project/lld/test/ELF/wrap-extract-real.ll (revision 13816e0358123baa411419048a9ce5c432ddab55)
1# REQUIRES: x86
2## --wrap=xxx should trigger archive extraction for symbol xxx for references to __real_xxx.
3
4# RUN: rm -rf %t && split-file %s %t && cd %t
5# RUN: llvm-as _start.ll -o _start.o
6# RUN: llvm-as _start_ref__real_foo.ll -o _start_ref__real_foo.o
7# RUN: llvm-as wrap.ll -o wrap.o
8# RUN: llvm-as foo.ll -o foo.o
9
10## Test when the reference to __real_foo is not in __wrap_foo.
11# RUN: ld.lld _start_ref__real_foo.o --start-lib foo.o --end-lib --wrap foo -o %t_real.elf
12# RUN: llvm-readelf --symbols %t_real.elf | FileCheck %s --check-prefix=REAL
13
14# REAL:      Symbol table '.symtab' contains 5 entries:
15# REAL-NEXT:        Value              Size Type    Bind   Vis       Ndx Name
16# REAL-NEXT:        {{.*}}           {{.*}} NOTYPE  LOCAL  DEFAULT   UND
17# REAL-NEXT:        {{.*}}           {{.*}} FILE    LOCAL  DEFAULT   ABS ld-temp.o
18# REAL-NEXT:        {{.*}}           {{.*}} FUNC    GLOBAL DEFAULT [[#]] _start
19# REAL-NEXT:        {{.*}}           {{.*}} FUNC    WEAK   DEFAULT [[#]] foo
20# REAL-NEXT:        {{.*}}           {{.*}} NOTYPE  GLOBAL DEFAULT   UND __wrap_foo
21
22## Test when the reference to __real_foo is in __wrap_foo.
23# RUN: ld.lld _start.o --start-lib wrap.o --end-lib --start-lib foo.o --end-lib --wrap foo -o %t_wrap_real.elf
24# RUN: llvm-readelf --symbols %t_wrap_real.elf | FileCheck %s --check-prefix=WRAP_REAL
25
26# WRAP_REAL:      Symbol table '.symtab' contains 5 entries:
27# WRAP_REAL-NEXT:    Value              Size Type    Bind   Vis       Ndx Name
28# WRAP_REAL-NEXT:    {{.*}}           {{.*}} NOTYPE  LOCAL  DEFAULT   UND
29# WRAP_REAL-NEXT:    {{.*}}           {{.*}} FILE    LOCAL  DEFAULT   ABS ld-temp.o
30# WRAP_REAL-NEXT:    {{.*}}           {{.*}} FUNC    GLOBAL DEFAULT [[#]] _start
31# WRAP_REAL-NEXT:    {{.*}}           {{.*}} FUNC    GLOBAL DEFAULT [[#]] __wrap_foo
32# WRAP_REAL-NEXT:    {{.*}}           {{.*}} FUNC    WEAK   DEFAULT [[#]] foo
33
34#--- _start.ll
35target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
36target triple = "x86_64-elf"
37define void @_start() {
38  ret void
39}
40
41#--- _start_ref__real_foo.ll
42target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
43target triple = "x86_64-elf"
44define void @_start() {
45  call void @__real_foo()
46  ret void
47}
48
49declare void @__real_foo()
50
51#--- wrap.ll
52target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
53target triple = "x86_64-elf"
54define void @__wrap_foo() {
55  call void @__real_foo()
56  ret void
57}
58
59declare void @__real_foo()
60
61#--- foo.ll
62target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
63target triple = "x86_64-elf"
64define void @foo() {
65  ret void
66}
67