mirror of
https://git.FreeBSD.org/ports.git
synced 2025-01-26 09:46:09 +00:00
Fix creation of position independent executables (-fPIE -pie).
There were two bugs here. First, -pie was not passed to ld. Second, non-relocatable versions of three *crt*.o archives were used in the pie case. Additionally, link with crtbeginT.o in the -static case. Shift style towards that of the Linux code since much of the new login was cribbed from it. Reported by: jonathan
This commit is contained in:
parent
d35acc5f42
commit
badfe4d42c
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=303233
@ -7,6 +7,7 @@
|
||||
|
||||
PORTNAME= clang
|
||||
PORTVERSION= 3.2.r${SVN_REV}
|
||||
PORTREVISION= 1
|
||||
CATEGORIES= lang devel
|
||||
MASTER_SITES= ${MASTER_SITE_LOCAL}
|
||||
MASTER_SITE_SUBDIR= brooks
|
||||
|
@ -60,3 +60,146 @@ $FreeBSD$
|
||||
|
||||
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
|
||||
options::OPT_Xassembler);
|
||||
@@ -5153,7 +5184,9 @@
|
||||
const InputInfoList &Inputs,
|
||||
const ArgList &Args,
|
||||
const char *LinkingOutput) const {
|
||||
- const Driver &D = getToolChain().getDriver();
|
||||
+ const toolchains::Linux& ToolChain =
|
||||
+ static_cast<const toolchains::Linux&>(getToolChain());
|
||||
+ const Driver &D = ToolChain.getDriver();
|
||||
ArgStringList CmdArgs;
|
||||
|
||||
// Silence warning for "clang -g foo.o -o foo"
|
||||
@@ -5167,6 +5200,9 @@
|
||||
if (!D.SysRoot.empty())
|
||||
CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
|
||||
|
||||
+ if (Args.hasArg(options::OPT_pie))
|
||||
+ CmdArgs.push_back("-pie");
|
||||
+
|
||||
if (Args.hasArg(options::OPT_static)) {
|
||||
CmdArgs.push_back("-Bstatic");
|
||||
} else {
|
||||
@@ -5179,8 +5215,8 @@
|
||||
CmdArgs.push_back("-dynamic-linker");
|
||||
CmdArgs.push_back("/libexec/ld-elf.so.1");
|
||||
}
|
||||
- if (getToolChain().getTriple().getOSMajorVersion() >= 9) {
|
||||
- llvm::Triple::ArchType Arch = getToolChain().getArch();
|
||||
+ if (ToolChain.getTriple().getOSMajorVersion() >= 9) {
|
||||
+ llvm::Triple::ArchType Arch = ToolChain.getArch();
|
||||
if (Arch == llvm::Triple::arm || Arch == llvm::Triple::sparc ||
|
||||
Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) {
|
||||
CmdArgs.push_back("--hash-style=both");
|
||||
@@ -5191,12 +5227,12 @@
|
||||
|
||||
// When building 32-bit code on FreeBSD/amd64, we have to explicitly
|
||||
// instruct ld in the base system to link 32-bit code.
|
||||
- if (getToolChain().getArchName() == "i386") {
|
||||
+ if (ToolChain.getArchName() == "i386") {
|
||||
CmdArgs.push_back("-m");
|
||||
CmdArgs.push_back("elf_i386_fbsd");
|
||||
}
|
||||
|
||||
- if (getToolChain().getArchName() == "powerpc") {
|
||||
+ if (ToolChain.getArchName() == "powerpc") {
|
||||
CmdArgs.push_back("-m");
|
||||
CmdArgs.push_back("elf32ppc_fbsd");
|
||||
}
|
||||
@@ -5210,29 +5246,32 @@
|
||||
|
||||
if (!Args.hasArg(options::OPT_nostdlib) &&
|
||||
!Args.hasArg(options::OPT_nostartfiles)) {
|
||||
- if (!Args.hasArg(options::OPT_shared)) {
|
||||
+ const char *crt1 = NULL;
|
||||
+ if (!Args.hasArg(options::OPT_shared)){
|
||||
if (Args.hasArg(options::OPT_pg))
|
||||
- CmdArgs.push_back(Args.MakeArgString(
|
||||
- getToolChain().GetFilePath("gcrt1.o")));
|
||||
- else {
|
||||
- const char *crt = Args.hasArg(options::OPT_pie) ? "Scrt1.o" : "crt1.o";
|
||||
- CmdArgs.push_back(Args.MakeArgString(
|
||||
- getToolChain().GetFilePath(crt)));
|
||||
- }
|
||||
- CmdArgs.push_back(Args.MakeArgString(
|
||||
- getToolChain().GetFilePath("crti.o")));
|
||||
- CmdArgs.push_back(Args.MakeArgString(
|
||||
- getToolChain().GetFilePath("crtbegin.o")));
|
||||
- } else {
|
||||
- CmdArgs.push_back(Args.MakeArgString(
|
||||
- getToolChain().GetFilePath("crti.o")));
|
||||
- CmdArgs.push_back(Args.MakeArgString(
|
||||
- getToolChain().GetFilePath("crtbeginS.o")));
|
||||
+ crt1 = "gcrt1.o";
|
||||
+ else if (Args.hasArg(options::OPT_pie))
|
||||
+ crt1 = "Scrt1.o";
|
||||
+ else
|
||||
+ crt1 = "crt1.o";
|
||||
}
|
||||
+ if (crt1)
|
||||
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1)));
|
||||
+
|
||||
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
|
||||
+
|
||||
+ const char *crtbegin;
|
||||
+ if (Args.hasArg(options::OPT_static))
|
||||
+ crtbegin = "crtbeginT.o";
|
||||
+ else if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
|
||||
+ crtbegin = "crtbeginS.o";
|
||||
+ else
|
||||
+ crtbegin = "crtbegin.o";
|
||||
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
|
||||
}
|
||||
|
||||
Args.AddAllArgs(CmdArgs, options::OPT_L);
|
||||
- const ToolChain::path_list Paths = getToolChain().getFilePaths();
|
||||
+ const ToolChain::path_list Paths = ToolChain.getFilePaths();
|
||||
for (ToolChain::path_list::const_iterator i = Paths.begin(), e = Paths.end();
|
||||
i != e; ++i)
|
||||
CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + *i));
|
||||
@@ -5243,12 +5282,12 @@
|
||||
Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag);
|
||||
Args.AddAllArgs(CmdArgs, options::OPT_r);
|
||||
|
||||
- AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
|
||||
+ AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs);
|
||||
|
||||
if (!Args.hasArg(options::OPT_nostdlib) &&
|
||||
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
||||
if (D.CCCIsCXX) {
|
||||
- getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
|
||||
+ ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
|
||||
if (Args.hasArg(options::OPT_pg))
|
||||
CmdArgs.push_back("-lm_p");
|
||||
else
|
||||
@@ -5301,20 +5340,20 @@
|
||||
|
||||
if (!Args.hasArg(options::OPT_nostdlib) &&
|
||||
!Args.hasArg(options::OPT_nostartfiles)) {
|
||||
- if (!Args.hasArg(options::OPT_shared))
|
||||
- CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(
|
||||
- "crtend.o")));
|
||||
+ const char *crtend;
|
||||
+ if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
|
||||
+ crtend = "crtendS.o";
|
||||
else
|
||||
- CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(
|
||||
- "crtendS.o")));
|
||||
- CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(
|
||||
- "crtn.o")));
|
||||
+ crtend = "crtend.o";
|
||||
+
|
||||
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend)));
|
||||
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
|
||||
}
|
||||
|
||||
- addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
|
||||
+ addProfileRT(ToolChain, Args, CmdArgs, ToolChain.getTriple());
|
||||
|
||||
const char *Exec =
|
||||
- Args.MakeArgString(getToolChain().GetProgramPath("ld"));
|
||||
+ Args.MakeArgString(ToolChain.GetProgramPath("ld"));
|
||||
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user