Skip to content

[lld/COFF] Fix -start-lib / -end-lib more after reviews.llvm.org/D116434 #124294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lld/COFF/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ void ArchiveFile::addMember(const Archive::Symbol &sym) {
toCOFFString(symtab.ctx, sym));

// Return an empty buffer if we have already returned the same buffer.
// FIXME: Remove this once we resolve all defineds before all undefineds in
// ObjFile::initializeSymbols().
if (!seen.insert(c.getChildOffset()).second)
return;

Expand Down
4 changes: 4 additions & 0 deletions lld/COFF/SymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ static void forceLazy(Symbol *s) {
}
case Symbol::Kind::LazyObjectKind: {
InputFile *file = cast<LazyObject>(s)->file;
// FIXME: Remove this once we resolve all defineds before all undefineds in
// ObjFile::initializeSymbols().
if (!file->lazy)
return;
file->lazy = false;
file->symtab.ctx.driver.addFile(file);
break;
Expand Down
69 changes: 69 additions & 0 deletions lld/test/COFF/start-lib.ll
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,72 @@ target triple = "x86_64-pc-windows-msvc"
define void @baz() {
ret void
}


; Check cycles between symbols in two /start-lib files.
; If the links succeed and does not emit duplicate symbol diagnostics,
; that's enough.

; RUN: llc -filetype=obj %t.dir/main3.ll -o %t-main3.obj
; RUN: llc -filetype=obj %t.dir/cycle1.ll -o %t-cycle1.obj
; RUN: llc -filetype=obj %t.dir/cycle2.ll -o %t-cycle2.obj
; RUN: opt -thinlto-bc %t.dir/main3.ll -o %t-main3.bc
; RUN: opt -thinlto-bc %t.dir/cycle1.ll -o %t-cycle1.bc
; RUN: opt -thinlto-bc %t.dir/cycle2.ll -o %t-cycle2.bc

; RUN: lld-link -out:%t3.exe -entry:main \
; RUN: %t-main3.obj %t-cycle1.obj %t-cycle2.obj
; RUN: lld-link -out:%t3.exe -entry:main \
; RUN: %t-main3.obj /start-lib %t-cycle1.obj %t-cycle2.obj /end-lib
; RUN: lld-link -out:%t3.exe -entry:main \
; RUN: /start-lib %t-cycle1.obj %t-cycle2.obj /end-lib %t-main3.obj

; RUN: lld-link -out:%t3.exe -entry:main \
; RUN: %t-main3.bc %t-cycle1.bc %t-cycle2.bc
; RUN: lld-link -out:%t3.exe -entry:main \
; RUN: %t-main3.bc /start-lib %t-cycle1.bc %t-cycle2.bc /end-lib
; RUN: lld-link -out:%t3.exe -entry:main \
; RUN: /start-lib %t-cycle1.bc %t-cycle2.bc /end-lib %t-main3.bc

#--- main3.ll

target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc"

declare void @foo1()

define void @main() {
call void () @foo1()
ret void
}

#--- cycle1.ll

target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc"

declare void @bar()

define void @foo1() {
; cycle1.ll pulls in cycle2.ll for bar(), and cycle2.ll then pulls in
; cycle1.ll again for foo2().
call void () @bar()
ret void
}

define void @foo2() {
ret void
}


#--- cycle2.ll

target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc"

declare void @foo2()

define void @bar() {
call void () @foo2()
ret void
}
Loading