Fix -gz=zlib options for linker
gcc translates -gz=zlib to --compress-debug-options=zlib for both assembler and linker but clang only does this for assembler. The linker needs --compress-debug-options=zlib option to compress the debug sections in the generated executable or shared library. Due to this bug, -gz=zlib has no effect on the generated executable or shared library. This patch fixes that. Differential Revision: https://reviews.llvm.org/D87321
This commit is contained in:
@@ -351,6 +351,7 @@ void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
|
||||
|
||||
std::string Linker = getToolChain().GetProgramPath(getShortName());
|
||||
ArgStringList CmdArgs;
|
||||
addLinkerCompressDebugSectionsOption(getToolChain(), Args, CmdArgs);
|
||||
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
|
||||
CmdArgs.push_back("-shared");
|
||||
CmdArgs.push_back("-o");
|
||||
|
||||
@@ -214,6 +214,24 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
|
||||
}
|
||||
}
|
||||
|
||||
void tools::addLinkerCompressDebugSectionsOption(
|
||||
const ToolChain &TC, const llvm::opt::ArgList &Args,
|
||||
llvm::opt::ArgStringList &CmdArgs) {
|
||||
// GNU ld supports --compress-debug-sections=none|zlib|zlib-gnu|zlib-gabi
|
||||
// whereas zlib is an alias to zlib-gabi. Therefore -gz=none|zlib|zlib-gnu
|
||||
// are translated to --compress-debug-sections=none|zlib|zlib-gnu.
|
||||
// -gz is not translated since ld --compress-debug-sections option requires an
|
||||
// argument.
|
||||
if (const Arg *A = Args.getLastArg(options::OPT_gz_EQ)) {
|
||||
StringRef V = A->getValue();
|
||||
if (V == "none" || V == "zlib" || V == "zlib-gnu")
|
||||
CmdArgs.push_back(Args.MakeArgString("--compress-debug-sections=" + V));
|
||||
else
|
||||
TC.getDriver().Diag(diag::err_drv_unsupported_option_argument)
|
||||
<< A->getOption().getName() << V;
|
||||
}
|
||||
}
|
||||
|
||||
void tools::AddTargetFeature(const ArgList &Args,
|
||||
std::vector<StringRef> &Features,
|
||||
OptSpecifier OnOpt, OptSpecifier OffOpt,
|
||||
|
||||
@@ -27,6 +27,10 @@ void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
|
||||
const llvm::opt::ArgList &Args,
|
||||
llvm::opt::ArgStringList &CmdArgs, const JobAction &JA);
|
||||
|
||||
void addLinkerCompressDebugSectionsOption(const ToolChain &TC,
|
||||
const llvm::opt::ArgList &Args,
|
||||
llvm::opt::ArgStringList &CmdArgs);
|
||||
|
||||
void claimNoWarnArgs(const llvm::opt::ArgList &Args);
|
||||
|
||||
bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args,
|
||||
|
||||
@@ -556,6 +556,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
|
||||
|
||||
bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
|
||||
bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
|
||||
addLinkerCompressDebugSectionsOption(ToolChain, Args, CmdArgs);
|
||||
AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
|
||||
// The profile runtime also needs access to system libraries.
|
||||
getToolChain().addProfileRTLibs(Args, CmdArgs);
|
||||
|
||||
@@ -89,6 +89,8 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA,
|
||||
if (C.getDriver().isSaveTempsEnabled())
|
||||
LldArgs.push_back("-save-temps");
|
||||
|
||||
addLinkerCompressDebugSectionsOption(TC, Args, LldArgs);
|
||||
|
||||
LldArgs.append({"-o", Output.getFilename()});
|
||||
for (auto Input : Inputs)
|
||||
LldArgs.push_back(Input.getFilename());
|
||||
|
||||
16
clang/test/Driver/amdgcn-gz-options.cl
Normal file
16
clang/test/Driver/amdgcn-gz-options.cl
Normal file
@@ -0,0 +1,16 @@
|
||||
// REQUIRES: zlib, amdgpu-registered-target
|
||||
|
||||
// RUN: %clang -### -target amdgcn-amd-amdhsa -gz=none -x assembler %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s
|
||||
// RUN: %clang -### -target amdgcn-amd-amdhsa -gz=none %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s
|
||||
// CHECK-OPT_GZ_EQ_NONE: {{".*clang.*".* "--compress-debug-sections=none"}}
|
||||
// CHECK-OPT_GZ_EQ_NONE: "--compress-debug-sections=none"
|
||||
|
||||
// RUN: %clang -### -target amdgcn-amd-amdhsa -gz=zlib -x assembler %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s
|
||||
// RUN: %clang -### -target amdgcn-amd-amdhsa -gz=zlib %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s
|
||||
// CHECK-OPT_GZ_EQ_ZLIB: {{".*clang.*".* "--compress-debug-sections=zlib"}}
|
||||
// CHECK-OPT_GZ_EQ_ZLIB: "--compress-debug-sections=zlib"
|
||||
|
||||
// RUN: %clang -### -target amdgcn-amd-amdhsa -gz=zlib-gnu -x assembler %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s
|
||||
// RUN: %clang -### -target amdgcn-amd-amdhsa -gz=zlib-gnu %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s
|
||||
// CHECK-OPT_GZ_EQ_ZLIB_GNU: {{".*clang.*".* "--compress-debug-sections=zlib-gnu"}}
|
||||
// CHECK-OPT_GZ_EQ_ZLIB_GNU: "--compress-debug-sections=zlib-gnu"
|
||||
@@ -18,19 +18,21 @@
|
||||
// RUN: %clang -### -fintegrated-as -gz -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ %s
|
||||
// CHECK-OPT_GZ: "--compress-debug-sections"
|
||||
|
||||
// RUN: %clang -### -fintegrated-as -gz=none -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s
|
||||
// RUN: %clang -### -fintegrated-as -gz=none -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s
|
||||
// RUN: %clang -### -target x86_64-unknown-linux-gnu -gz=none -x assembler %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s
|
||||
// RUN: %clang -### -target x86_64-unknown-linux-gnu -gz=none %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s
|
||||
// CHECK-OPT_GZ_EQ_NONE: {{".*clang.*".* "--compress-debug-sections=none"}}
|
||||
// CHECK-OPT_GZ_EQ_NONE: "--compress-debug-sections=none"
|
||||
|
||||
// RUN: %clang -### -fintegrated-as -gz=zlib -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s
|
||||
// RUN: %clang -### -fintegrated-as -gz=zlib -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s
|
||||
// RUN: %clang -### -target x86_64-unknown-linux-gnu -gz=zlib -x assembler %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s
|
||||
// RUN: %clang -### -target x86_64-unknown-linux-gnu -gz=zlib %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s
|
||||
// CHECK-OPT_GZ_EQ_ZLIB: {{".*clang.*".* "--compress-debug-sections=zlib"}}
|
||||
// CHECK-OPT_GZ_EQ_ZLIB: "--compress-debug-sections=zlib"
|
||||
|
||||
// RUN: %clang -### -fintegrated-as -gz=zlib-gnu -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s
|
||||
// RUN: %clang -### -fintegrated-as -gz=zlib-gnu -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s
|
||||
// RUN: %clang -### -target x86_64-unknown-linux-gnu -gz=zlib-gnu -x assembler %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s
|
||||
// RUN: %clang -### -target x86_64-unknown-linux-gnu -gz=zlib-gnu %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s
|
||||
// CHECK-OPT_GZ_EQ_ZLIB_GNU: {{".*clang.*".* "--compress-debug-sections=zlib-gnu"}}
|
||||
// CHECK-OPT_GZ_EQ_ZLIB_GNU: "--compress-debug-sections=zlib-gnu"
|
||||
|
||||
// RUN: %clang -### -fintegrated-as -gz=invalid -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_INVALID %s
|
||||
// RUN: %clang -### -fintegrated-as -gz=invalid -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_INVALID %s
|
||||
// CHECK-OPT_GZ_EQ_INVALID: error: unsupported argument 'invalid' to option 'gz='
|
||||
|
||||
|
||||
14
clang/test/Driver/hip-gz-options.hip
Normal file
14
clang/test/Driver/hip-gz-options.hip
Normal file
@@ -0,0 +1,14 @@
|
||||
// REQUIRES: zlib, clang-driver, amdgpu-registered-target
|
||||
|
||||
// RUN: %clang -### -target x86_64-unknown-linux-gnu \
|
||||
// RUN: --offload-arch=gfx906 %s -nogpulib -nogpuinc \
|
||||
// RUN: -ggdb -gz=zlib 2>&1 | FileCheck %s
|
||||
|
||||
// RUN: %clang -### -target x86_64-unknown-linux-gnu \
|
||||
// RUN: -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
|
||||
// RUN: -ggdb -gz=zlib 2>&1 | FileCheck %s
|
||||
|
||||
// CHECK: {{".*clang.*" .* "--compress-debug-sections=zlib"}}
|
||||
// CHECK-DAG: {{".*lld.*" .* "--compress-debug-sections=zlib"}}
|
||||
// CHECK-DAG: {{".*clang.*" .* "--compress-debug-sections=zlib"}}
|
||||
// CHECK: "--compress-debug-sections=zlib"
|
||||
Reference in New Issue
Block a user