File tree 2 files changed +56
-3
lines changed
2 files changed +56
-3
lines changed Original file line number Diff line number Diff line change @@ -2291,9 +2291,16 @@ void BitcodeFile::parse() {
2291
2291
// Convert LTO Symbols to LLD Symbols in order to perform resolution. The
2292
2292
// "winning" symbol will then be marked as Prevailing at LTO compilation
2293
2293
// time.
2294
- symbols.clear ();
2295
- for (const lto::InputFile::Symbol &objSym : obj->symbols ())
2296
- symbols.push_back (createBitcodeSymbol (objSym, *this ));
2294
+ symbols.resize (obj->symbols ().size ());
2295
+
2296
+ // Process defined symbols first. See the comment at the end of
2297
+ // ObjFile<>::parseSymbols.
2298
+ for (auto it : llvm::enumerate (obj->symbols ()))
2299
+ if (!it.value ().isUndefined ())
2300
+ symbols[it.index ()] = createBitcodeSymbol (it.value (), *this );
2301
+ for (auto it : llvm::enumerate (obj->symbols ()))
2302
+ if (it.value ().isUndefined ())
2303
+ symbols[it.index ()] = createBitcodeSymbol (it.value (), *this );
2297
2304
}
2298
2305
2299
2306
void BitcodeFile::parseLazy () {
Original file line number Diff line number Diff line change
1
+ ; REQUIRES: aarch64
2
+ ; RUN: rm -rf %t; split-file %s %t
3
+
4
+ ;; Test that a weak symbol in a direct .o file wins over
5
+ ;; a weak symbol in a .a file.
6
+ ;; Like weak-definition-in-main-file.s, but in bitcode.
7
+
8
+ ; RUN: llvm-as %t/test.ll -o %t/test.o
9
+ ; RUN: llvm-as %t/weakfoo.ll -o %t/weakfoo.o
10
+
11
+ ; RUN: llvm-ar --format=darwin rcs %t/weakfoo.a %t/weakfoo.o
12
+
13
+ ; PREFER-DIRECT-OBJECT-NOT: O __TEXT,weak _foo
14
+
15
+ ; RUN: %lld -lSystem -o %t/out %t/weakfoo.a %t/test.o
16
+ ; RUN: llvm-objdump --syms %t/out | FileCheck %s --check-prefix=PREFER-DIRECT-OBJECT
17
+
18
+ ;--- weakfoo.ll
19
+ target triple = "x86_64-apple-macosx10.15.0"
20
+ target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
21
+
22
+ define void @baz () noinline optnone {
23
+ ret void
24
+ }
25
+
26
+ define weak void @foo () noinline optnone section "__TEXT,weak" {
27
+ ret void
28
+ }
29
+
30
+ ;--- test.ll
31
+ target triple = "x86_64-apple-macosx10.15.0"
32
+ target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
33
+
34
+ declare void @baz ();
35
+
36
+ define weak void @foo () noinline optnone {
37
+ ret void
38
+ }
39
+
40
+ define void @main () {
41
+ ; This pulls in weakfoo.a due to the __baz undef, but __foo should
42
+ ; still be resolved against the weak symbol in this file.
43
+ call void @baz ()
44
+ call void @foo ()
45
+ ret void
46
+ }
You can’t perform that action at this time.
0 commit comments