File tree 2 files changed +44
-0
lines changed
2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -1782,6 +1782,12 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
1782
1782
for (StringRef pat : args::getStrings (args, OPT_undefined_glob))
1783
1783
handleUndefinedGlob (pat);
1784
1784
1785
+ // Mark -init and -fini symbols so that the LTO doesn't eliminate them.
1786
+ if (Symbol *sym = symtab->find (config->init ))
1787
+ sym->isUsedInRegularObj = true ;
1788
+ if (Symbol *sym = symtab->find (config->fini ))
1789
+ sym->isUsedInRegularObj = true ;
1790
+
1785
1791
// If any of our inputs are bitcode files, the LTO code generator may create
1786
1792
// references to certain library functions that might not be explicit in the
1787
1793
// bitcode file's symbol table. If any of those library functions are defined
Original file line number Diff line number Diff line change
1
+ ; REQUIRES: x86
2
+ ; RUN: llvm-as %s -o %t.o
3
+
4
+ ;;
5
+ ;; Verify that symbols given by -init and -fini are preserved and
6
+ ;; DT_INIT/DT_FINI are created.
7
+ ;;
8
+
9
+ ; RUN: ld.lld -o %t.exe -pie %t.o
10
+ ; RUN: llvm-nm %t.exe | FileCheck -check-prefix=TEST1 --allow-empty %s
11
+ ; RUN: llvm-readelf -d %t.exe | FileCheck -check-prefix=TEST2 %s
12
+
13
+ ; TEST1-NOT: foo
14
+ ; TEST1-NOT: bar
15
+
16
+ ; TEST2-NOT: INIT
17
+ ; TEST2-NOT: FINI
18
+
19
+ ; RUN: ld.lld -o %t.exe -pie -init=foo -fini=bar %t.o
20
+ ; RUN: llvm-nm %t.exe | FileCheck -check-prefix=TEST3 %s
21
+ ; RUN: llvm-readelf -d %t.exe | FileCheck -check-prefix=TEST4 %s
22
+
23
+ ; TEST3: bar
24
+ ; TEST3: foo
25
+
26
+ ; TEST4: INIT
27
+ ; TEST4: FINI
28
+
29
+ target triple = "x86_64-unknown-linux-gnu"
30
+ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
31
+
32
+ define void @foo () {
33
+ ret void
34
+ }
35
+
36
+ define void @bar () {
37
+ ret void
38
+ }
You can’t perform that action at this time.
0 commit comments