From: Aaron Enye Shi Date: Fri, 4 Jan 2019 19:05:41 +0000 (+0000) Subject: [HIP][DRIVER][OFFLOAD] Do not unbundle unsupported file types X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5aa017b125e501db919c6c62be03f0a275ebc63f;p=clang [HIP][DRIVER][OFFLOAD] Do not unbundle unsupported file types The offload bundler action should not unbundle the input file types that does not match the action type. This fixes an issue where .so files are unbundled when the action type is object files. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@350425 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 725bf273ed..977bff5bf7 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -2323,6 +2323,18 @@ class OffloadingActionBuilder final { // If this is an unbundling action use it as is for each CUDA toolchain. if (auto *UA = dyn_cast(HostAction)) { CudaDeviceActions.clear(); + auto *IA = cast(UA->getInputs().back()); + std::string FileName = IA->getInputArg().getAsString(Args); + // Check if the type of the file is the same as the action. Do not + // unbundle it if it is not. Do not unbundle .so files, for example, + // which are not object files. + if (IA->getType() == types::TY_Object && + (!llvm::sys::path::has_extension(FileName) || + types::lookupTypeForExtension( + llvm::sys::path::extension(FileName).drop_front()) != + types::TY_Object)) + return ABRT_Inactive; + for (auto Arch : GpuArchList) { CudaDeviceActions.push_back(UA); UA->registerDependentActionInfo(ToolChains[0], CudaArchToString(Arch), diff --git a/test/Driver/hip-link-shared-library.hip b/test/Driver/hip-link-shared-library.hip new file mode 100644 index 0000000000..2e36dff369 --- /dev/null +++ b/test/Driver/hip-link-shared-library.hip @@ -0,0 +1,11 @@ +// RUN: touch %t.o +// RUN: %clang --hip-link -ccc-print-bindings -target x86_64-linux-gnu \ +// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %t.o %S/Inputs/in.so \ +// RUN: 2>&1 | FileCheck %s + +// CHECK: # "amdgcn-amd-amdhsa" - "offload bundler", inputs: ["[[IN:.*o]]"], outputs: ["[[OBJ1:.*o]]", "[[OBJ2:.*o]]", "[[OBJ3:.*o]]"] +// CHECK: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[OBJ2]]"], output: "[[IMG2:.*out]]" +// CHECK-NOT: offload bundler +// CHECK: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[OBJ3]]"], output: "[[IMG3:.*out]]" +// CHECK-NOT: offload bundler +// CHECK: # "x86_64-unknown-linux-gnu" - "GNU::Linker", inputs: ["[[OBJ1]]", "{{.*}}/Inputs/in.so", "[[IMG2]]", "[[IMG3]]"], output: "a.out"