[ELF] BitcodeFile: resolve defined symbols before undefined symbols

This ports D95985 for ELF relocatable object files to BitcodeFile.
This commit is contained in:
Fangrui Song 2022-02-27 05:37:08 +00:00
parent 6982c38cb1
commit bd448f01a6
4 changed files with 26 additions and 18 deletions

View File

@ -1666,10 +1666,18 @@ template <class ELFT> void BitcodeFile::parse() {
}
symbols.resize(obj->symbols().size());
for (auto it : llvm::enumerate(obj->symbols())) {
Symbol *&sym = symbols[it.index()];
createBitcodeSymbol<ELFT>(sym, keptComdats, it.value(), *this);
}
// Process defined symbols first. See the comment in
// ObjFile<ELFT>::initializeSymbols.
for (auto it : llvm::enumerate(obj->symbols()))
if (!it.value().isUndefined()) {
Symbol *&sym = symbols[it.index()];
createBitcodeSymbol<ELFT>(sym, keptComdats, it.value(), *this);
}
for (auto it : llvm::enumerate(obj->symbols()))
if (it.value().isUndefined()) {
Symbol *&sym = symbols[it.index()];
createBitcodeSymbol<ELFT>(sym, keptComdats, it.value(), *this);
}
for (auto l : obj->getDependentLibraries())
addDependentLibrary(l, this);

View File

@ -29,10 +29,10 @@ BCSYM-NEXT: W foo
;; Check that the symbols are handled in the expected order.
TRACE: lib.a(obj.o): lazy definition of foo
TRACE-NEXT: lib.a(obj.o): lazy definition of bar
TRACE-NEXT: lib.a(bc.bc): definition of foo
TRACE-NEXT: lib.a(bc.bc): reference to bar
TRACE-NEXT: lib.a(obj.o): reference to foo
TRACE-NEXT: lib.a(obj.o): definition of bar
TRACE-NEXT: lib.a(bc.bc): definition of foo
TRACE-NEXT: <internal>: reference to foo
;; The definition of "foo" is visible outside the LTO result.
TRACE-NEXT: lto.tmp: definition of foo

View File

@ -6,18 +6,18 @@
;
; RUN: ld.lld -shared -o %t3 %t1.o %t2.o %t3.o
; RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST1 %s
; TEST1: Name: bar
; TEST1: Name: foo
; TEST1: Name: bar
;
; RUN: ld.lld -shared -o %t3 -u bar %t1.o --start-lib %t2.o %t3.o
; RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST2 %s
; TEST2: Name: bar
; TEST2-NOT: Name: foo
; TEST2: Name: bar
;
; RUN: ld.lld -shared -o %t3 %t1.o --start-lib %t2.o %t3.o
; RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST3 %s
; TEST3-NOT: Name: bar
; TEST3-NOT: Name: foo
; TEST3-NOT: Name: bar
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

View File

@ -5,16 +5,6 @@
; RUN: llvm-dis < %t.so.0.2.internalize.bc | FileCheck --check-prefix=IR %s
; RUN: llvm-readobj --symbols %t.so | FileCheck %s
; CHECK: Name: g
; CHECK-NEXT: Value:
; CHECK-NEXT: Size: 0
; CHECK-NEXT: Binding: Local
; CHECK-NEXT: Type: None
; CHECK-NEXT: Other [ (0x2)
; CHECK-NEXT: STV_HIDDEN
; CHECK-NEXT: ]
; CHECK-NEXT: Section: .text
; CHECK: Name: a
; CHECK-NEXT: Value:
; CHECK-NEXT: Size: 0
@ -25,6 +15,16 @@
; CHECK-NEXT: ]
; CHECK-NEXT: Section: .data
; CHECK: Name: g
; CHECK-NEXT: Value:
; CHECK-NEXT: Size: 0
; CHECK-NEXT: Binding: Local
; CHECK-NEXT: Type: None
; CHECK-NEXT: Other [ (0x2)
; CHECK-NEXT: STV_HIDDEN
; CHECK-NEXT: ]
; CHECK-NEXT: Section: .text
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"