clang: Fix -gz=zlib options for linker
Clang commit ccb4124a4172bf2cb2e1cd7c253f0f1654fce294: 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. Clang commit 462cf39a5c180621b56f7602270ce33eb7b68d23: [Driver] Fix -gz=zlib options for linker also on FreeBSD ccb4124a4172 fixed translating -gz=zlib to --compress-debug-sections for linker invocation for several ToolChains, but omitted FreeBSD. Approved by: dim MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D29028
This commit is contained in:
parent
448732b8e2
commit
19587d7422
@ -350,6 +350,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,
|
||||
|
@ -283,6 +283,7 @@ void freebsd::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);
|
||||
|
||||
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
|
||||
|
@ -568,6 +568,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);
|
||||
|
@ -88,6 +88,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());
|
||||
|
Loading…
Reference in New Issue
Block a user