Skip to content

Commit 840246a

Browse files
author
git apple-llvm automerger
committed
Merge commit '4f9964738b9c' from llvm.org/main into next
2 parents aae25ae + 4f99647 commit 840246a

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

clang/test/Driver/linker-wrapper-libs.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,28 @@ int bar() { return weak; }
132132
// LIBRARY-GLOBAL-DEFINED: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
133133
// LIBRARY-GLOBAL-DEFINED-NOT: {{.*}}gfx1030{{.*}}.o
134134
// LIBRARY-GLOBAL-DEFINED: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.s {{.*}}.o
135+
136+
//
137+
// Check that we can use --[no-]whole-archive to control extraction.
138+
//
139+
// RUN: %clang -cc1 %s -triple nvptx64-nvidia-cuda -emit-llvm-bc -DGLOBAL -o %t.nvptx.global.bc
140+
// RUN: %clang -cc1 %s -triple amdgcn-amd-amdhsa -emit-llvm-bc -DGLOBAL -o %t.amdgpu.global.bc
141+
// RUN: clang-offload-packager -o %t-lib.out \
142+
// RUN: --image=file=%t.nvptx.global.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \
143+
// RUN: --image=file=%t.nvptx.global.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_52 \
144+
// RUN: --image=file=%t.amdgpu.global.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 \
145+
// RUN: --image=file=%t.amdgpu.global.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx90a
146+
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t-lib.out
147+
// RUN: llvm-ar rcs %t.a %t.o
148+
// RUN: clang-offload-packager -o %t.out \
149+
// RUN: --image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \
150+
// RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030
151+
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t.out
152+
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
153+
// RUN: --linker-path=/usr/bin/ld -- %t.o --whole-archive %t.a -o a.out 2>&1 \
154+
// RUN: | FileCheck %s --check-prefix=LIBRARY-WHOLE-ARCHIVE
155+
156+
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
157+
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_52 {{.*}}.s
158+
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a {{.*}}.o
159+
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.s {{.*}}.o

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,15 @@ Expected<SmallVector<OffloadFile>> getDeviceInput(const ArgList &Args) {
12671267
// Try to extract device code from the linker input files.
12681268
SmallVector<OffloadFile> InputFiles;
12691269
DenseMap<OffloadFile::TargetID, DenseMap<StringRef, Symbol>> Syms;
1270-
for (const opt::Arg *Arg : Args.filtered(OPT_INPUT, OPT_library)) {
1270+
bool WholeArchive = false;
1271+
for (const opt::Arg *Arg : Args.filtered(
1272+
OPT_INPUT, OPT_library, OPT_whole_archive, OPT_no_whole_archive)) {
1273+
if (Arg->getOption().matches(OPT_whole_archive) ||
1274+
Arg->getOption().matches(OPT_no_whole_archive)) {
1275+
WholeArchive = Arg->getOption().matches(OPT_whole_archive);
1276+
continue;
1277+
}
1278+
12711279
std::optional<std::string> Filename =
12721280
Arg->getOption().matches(OPT_library)
12731281
? searchLibrary(Arg->getValue(), Root, LibraryPaths)
@@ -1306,17 +1314,17 @@ Expected<SmallVector<OffloadFile>> getDeviceInput(const ArgList &Args) {
13061314

13071315
// If we don't have an object file for this architecture do not
13081316
// extract.
1309-
if (IsArchive && !Syms.count(Binary))
1317+
if (IsArchive && !WholeArchive && !Syms.count(Binary))
13101318
continue;
13111319

13121320
Expected<bool> ExtractOrErr =
13131321
getSymbols(Binary.getBinary()->getImage(), Saver, Syms[Binary]);
13141322
if (!ExtractOrErr)
13151323
return ExtractOrErr.takeError();
13161324

1317-
Extracted = IsArchive && *ExtractOrErr;
1325+
Extracted = IsArchive && !WholeArchive && *ExtractOrErr;
13181326

1319-
if (!IsArchive || Extracted)
1327+
if (!IsArchive || WholeArchive || Extracted)
13201328
InputFiles.emplace_back(std::move(Binary));
13211329

13221330
// If we extracted any files we need to check all the symbols again.

clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,6 @@ def rpath_EQ : Joined<["--", "-"], "rpath=">, Flags<[HelpHidden]>, Alias<rpath>;
116116

117117
def v : Flag<["--", "-"], "v">, HelpText<"Display the version number and exit">;
118118
def version : Flag<["--", "-"], "version">, Flags<[HelpHidden]>, Alias<v>;
119+
120+
def whole_archive : Flag<["--", "-"], "whole-archive">, Flags<[HelpHidden]>;
121+
def no_whole_archive : Flag<["--", "-"], "no-whole-archive">, Flags<[HelpHidden]>;

0 commit comments

Comments
 (0)