Skip to content

Commit bd448f0

Browse files
committed
[ELF] BitcodeFile: resolve defined symbols before undefined symbols
This ports D95985 for ELF relocatable object files to BitcodeFile.
1 parent 6982c38 commit bd448f0

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,10 +1666,18 @@ template <class ELFT> void BitcodeFile::parse() {
16661666
}
16671667

16681668
symbols.resize(obj->symbols().size());
1669-
for (auto it : llvm::enumerate(obj->symbols())) {
1670-
Symbol *&sym = symbols[it.index()];
1671-
createBitcodeSymbol<ELFT>(sym, keptComdats, it.value(), *this);
1672-
}
1669+
// Process defined symbols first. See the comment in
1670+
// ObjFile<ELFT>::initializeSymbols.
1671+
for (auto it : llvm::enumerate(obj->symbols()))
1672+
if (!it.value().isUndefined()) {
1673+
Symbol *&sym = symbols[it.index()];
1674+
createBitcodeSymbol<ELFT>(sym, keptComdats, it.value(), *this);
1675+
}
1676+
for (auto it : llvm::enumerate(obj->symbols()))
1677+
if (it.value().isUndefined()) {
1678+
Symbol *&sym = symbols[it.index()];
1679+
createBitcodeSymbol<ELFT>(sym, keptComdats, it.value(), *this);
1680+
}
16731681

16741682
for (auto l : obj->getDependentLibraries())
16751683
addDependentLibrary(l, this);

lld/test/ELF/lto/comdat-mixed-archive.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ BCSYM-NEXT: W foo
2929
;; Check that the symbols are handled in the expected order.
3030
TRACE: lib.a(obj.o): lazy definition of foo
3131
TRACE-NEXT: lib.a(obj.o): lazy definition of bar
32+
TRACE-NEXT: lib.a(bc.bc): definition of foo
3233
TRACE-NEXT: lib.a(bc.bc): reference to bar
3334
TRACE-NEXT: lib.a(obj.o): reference to foo
3435
TRACE-NEXT: lib.a(obj.o): definition of bar
35-
TRACE-NEXT: lib.a(bc.bc): definition of foo
3636
TRACE-NEXT: <internal>: reference to foo
3737
;; The definition of "foo" is visible outside the LTO result.
3838
TRACE-NEXT: lto.tmp: definition of foo

lld/test/ELF/lto/start-lib.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
;
77
; RUN: ld.lld -shared -o %t3 %t1.o %t2.o %t3.o
88
; RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST1 %s
9-
; TEST1: Name: bar
109
; TEST1: Name: foo
10+
; TEST1: Name: bar
1111
;
1212
; RUN: ld.lld -shared -o %t3 -u bar %t1.o --start-lib %t2.o %t3.o
1313
; RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST2 %s
14-
; TEST2: Name: bar
1514
; TEST2-NOT: Name: foo
15+
; TEST2: Name: bar
1616
;
1717
; RUN: ld.lld -shared -o %t3 %t1.o --start-lib %t2.o %t3.o
1818
; RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST3 %s
19-
; TEST3-NOT: Name: bar
2019
; TEST3-NOT: Name: foo
20+
; TEST3-NOT: Name: bar
2121

2222
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
2323
target triple = "x86_64-unknown-linux-gnu"

lld/test/ELF/lto/visibility.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55
; RUN: llvm-dis < %t.so.0.2.internalize.bc | FileCheck --check-prefix=IR %s
66
; RUN: llvm-readobj --symbols %t.so | FileCheck %s
77

8-
; CHECK: Name: g
8+
; CHECK: Name: a
99
; CHECK-NEXT: Value:
1010
; CHECK-NEXT: Size: 0
1111
; CHECK-NEXT: Binding: Local
1212
; CHECK-NEXT: Type: None
1313
; CHECK-NEXT: Other [ (0x2)
1414
; CHECK-NEXT: STV_HIDDEN
1515
; CHECK-NEXT: ]
16-
; CHECK-NEXT: Section: .text
16+
; CHECK-NEXT: Section: .data
1717

18-
; CHECK: Name: a
18+
; CHECK: Name: g
1919
; CHECK-NEXT: Value:
2020
; CHECK-NEXT: Size: 0
2121
; CHECK-NEXT: Binding: Local
2222
; CHECK-NEXT: Type: None
2323
; CHECK-NEXT: Other [ (0x2)
2424
; CHECK-NEXT: STV_HIDDEN
2525
; CHECK-NEXT: ]
26-
; CHECK-NEXT: Section: .data
26+
; CHECK-NEXT: Section: .text
2727

2828
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
2929
target triple = "x86_64-unknown-linux-gnu"

0 commit comments

Comments
 (0)