Skip to content

[Clang] Fix Hurd toolchain test on a two-stage build with ThinLTO #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 11 additions & 9 deletions clang/lib/Driver/ToolChains/Gnu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,25 +309,24 @@ static const char *getLDMOption(const llvm::Triple &T, const ArgList &Args) {
}
}

static bool getPIE(const ArgList &Args, const toolchains::Linux &ToolChain) {
static bool getPIE(const ArgList &Args, const ToolChain &TC) {
if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static) ||
Args.hasArg(options::OPT_r) || Args.hasArg(options::OPT_static_pie))
return false;

Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
options::OPT_nopie);
if (!A)
return ToolChain.isPIEDefault();
return TC.isPIEDefault();
return A->getOption().matches(options::OPT_pie);
}

static bool getStaticPIE(const ArgList &Args,
const toolchains::Linux &ToolChain) {
static bool getStaticPIE(const ArgList &Args, const ToolChain &TC) {
bool HasStaticPIE = Args.hasArg(options::OPT_static_pie);
// -no-pie is an alias for -nopie. So, handling -nopie takes care of
// -no-pie as well.
if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
const Driver &D = ToolChain.getDriver();
const Driver &D = TC.getDriver();
const llvm::opt::OptTable &Opts = D.getOpts();
const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
Expand All @@ -346,8 +345,12 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfoList &Inputs,
const ArgList &Args,
const char *LinkingOutput) const {
const toolchains::Linux &ToolChain =
static_cast<const toolchains::Linux &>(getToolChain());
// FIXME: The Linker class constructor takes a ToolChain and not a
// Generic_ELF, so the static_cast might return a reference to a invalid
// instance (see PR45061). Ideally, the Linker constructor needs to take a
// Generic_ELF instead.
const toolchains::Generic_ELF &ToolChain =
static_cast<const toolchains::Generic_ELF &>(getToolChain());
const Driver &D = ToolChain.getDriver();

const llvm::Triple &Triple = getToolChain().getEffectiveTriple();
Expand Down Expand Up @@ -418,8 +421,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (isAndroid)
CmdArgs.push_back("--warn-shared-textrel");

for (const auto &Opt : ToolChain.ExtraOpts)
CmdArgs.push_back(Opt.c_str());
ToolChain.addExtraOpts(CmdArgs);

CmdArgs.push_back("--eh-frame-hdr");

Expand Down
6 changes: 6 additions & 0 deletions clang/lib/Driver/ToolChains/Gnu.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
Action::OffloadKind DeviceOffloadKind) const override;

virtual std::string getDynamicLinker(const llvm::opt::ArgList &Args) const {
return {};
}

virtual void addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const {}
};

} // end namespace toolchains
Expand Down
8 changes: 6 additions & 2 deletions clang/lib/Driver/ToolChains/Hurd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) {
return Triple.isArch32Bit() ? "lib" : "lib64";
}

Hurd::Hurd(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
Hurd::Hurd(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
: Generic_ELF(D, Triple, Args) {
std::string SysRoot = computeSysRoot();
path_list &Paths = getFilePaths();
Expand Down Expand Up @@ -170,3 +169,8 @@ void Hurd::AddClangSystemIncludeArgs(const ArgList &DriverArgs,

addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
}

void Hurd::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const {
for (const auto &Opt : ExtraOpts)
CmdArgs.push_back(Opt.c_str());
}
6 changes: 4 additions & 2 deletions clang/lib/Driver/ToolChains/Hurd.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ class LLVM_LIBRARY_VISIBILITY Hurd : public Generic_ELF {
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;

virtual std::string computeSysRoot() const;
std::string computeSysRoot() const;

virtual std::string getDynamicLinker(const llvm::opt::ArgList &Args) const;
std::string getDynamicLinker(const llvm::opt::ArgList &Args) const override;

void addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const override;

std::vector<std::string> ExtraOpts;

Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Driver/ToolChains/Linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,3 +986,8 @@ void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args,
Twine("-u", llvm::getInstrProfRuntimeHookVarName())));
ToolChain::addProfileRTLibs(Args, CmdArgs);
}

void Linux::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const {
for (const auto &Opt : ExtraOpts)
CmdArgs.push_back(Opt.c_str());
}
4 changes: 3 additions & 1 deletion clang/lib/Driver/ToolChains/Linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
llvm::opt::ArgStringList &CmdArgs) const override;
virtual std::string computeSysRoot() const;

virtual std::string getDynamicLinker(const llvm::opt::ArgList &Args) const;
std::string getDynamicLinker(const llvm::opt::ArgList &Args) const override;

void addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const override;

std::vector<std::string> ExtraOpts;

Expand Down