Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion lld/COFF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,12 @@ void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> mb,

int memberIndex = 0;
for (MemoryBufferRef m : getArchiveMembers(ctx, archive))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add braces to the for to enclose the code below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks.

addArchiveBuffer(m, "<whole-archive>", filename, memberIndex++);
if (!archive->isThin())
addArchiveBuffer(m, "<whole-archive>", filename, memberIndex++);
else
// Pass empty string as archive name so that the original filename is
// used as the buffer identifier.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you could also add a short comment about why we're setting 0 for the offset, as you did in the description, it'd be great.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I now use a common function to add thin archive members so that I don't have to duplicate this comment in two places.

addArchiveBuffer(m, "<whole-archive>", "", /*OffsetInArchive=*/0);
return;
}
addFile(make<ArchiveFile>(ctx, mbref));
Expand Down
39 changes: 25 additions & 14 deletions lld/test/COFF/thin-archive.s
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,34 @@
# SYMTAB: ?f@@YAHXZ in
# NO-SYMTAB-NOT: ?f@@YAHXZ in

# RUN: lld-link /entry:main %t.main.obj %t.lib /out:%t.exe 2>&1 | \
# RUN: FileCheck --allow-empty %s
# RUN: lld-link /entry:main %t.main.obj %t_thin.lib /out:%t.exe 2>&1 | \
# RUN: FileCheck --allow-empty %s
# RUN: lld-link /entry:main %t.main.obj /wholearchive:%t_thin.lib /out:%t.exe 2>&1 | \
# RUN: FileCheck --allow-empty %s
# RUN: echo /entry:main %t.main.obj /out:%t.exe > %t.rsp

# RUN: lld-link @%t.rsp %t.lib /verbose 2>&1 | \
# RUN: FileCheck %s --check-prefix=LOAD_NON_THIN
# RUN: lld-link @%t.rsp %t_thin.lib /verbose 2>&1 | \
# RUN: FileCheck %s --check-prefix=LOAD_THIN_SYM
# RUN: lld-link @%t.rsp /wholearchive:%t_thin.lib /verbose 2>&1 | \
# RUN: FileCheck %s --check-prefix=LOAD_THIN_WHOLE
# RUN: lld-link @%t.rsp /wholearchive %t_thin.lib /verbose 2>&1 | \
# RUN: FileCheck %s --check-prefix=LOAD_THIN_WHOLE

# LOAD_NON_THIN: Loaded {{.*}}.lib({{.*}}.obj) for int __cdecl f(void)
# LOAD_THIN_SYM: Loaded {{.*}}.obj for int __cdecl f(void)
# LOAD_THIN_WHOLE: Loaded {{.*}}.obj for <whole-archive>

# RUN: rm %t.lib.obj
# RUN: lld-link /entry:main %t.main.obj %t.lib /out:%t.exe 2>&1 | \
# RUN: FileCheck --allow-empty %s
# RUN: env LLD_IN_TEST=1 not lld-link /entry:main %t.main.obj %t_thin.lib \
# RUN: /out:%t.exe 2>&1 | FileCheck --check-prefix=NOOBJ %s
# RUN: env LLD_IN_TEST=1 not lld-link /entry:main %t.main.obj %t_thin.lib /out:%t.exe \
# RUN: /demangle:no 2>&1 | FileCheck --check-prefix=NOOBJNODEMANGLE %s

# CHECK-NOT: error: could not get the buffer for the member defining
# RUN: lld-link @%t.rsp %t.lib /out:%t.exe 2>&1 | \
# RUN: FileCheck --check-prefix=ERR --allow-empty %s
# RUN: env LLD_IN_TEST=1 not lld-link @%t.rsp %t_thin.lib 2>&1 | \
# RUN: FileCheck --check-prefix=NOOBJ %s
# RUN: env LLD_IN_TEST=1 not lld-link @%t.rsp /wholearchive:%t_thin.lib 2>&1 | \
# RUN: FileCheck --check-prefix=NOOBJWHOLE %s
# RUN: env LLD_IN_TEST=1 not lld-link @%t.rsp %t_thin.lib /demangle:no 2>&1 | \
# RUN: FileCheck --check-prefix=NOOBJNODEMANGLE %s

# ERR-NOT: error: could not get the buffer for the member defining
# NOOBJ: error: could not get the buffer for the member defining symbol int __cdecl f(void): {{.*}}.lib({{.*}}.lib.obj):
# NOOBJWHOLE: error: {{.*}}.lib: could not get the buffer for a child of the archive: '{{.*}}.obj'
# NOOBJNODEMANGLE: error: could not get the buffer for the member defining symbol ?f@@YAHXZ: {{.*}}.lib({{.*}}.lib.obj):

.text
Expand Down
Loading