diff options
-rw-r--r-- | clang/lib/Driver/Tools.cpp | 19 | ||||
-rw-r--r-- | clang/test/Driver/netbsd.c | 36 |
2 files changed, 46 insertions, 9 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index b7ac24f..b39d117 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -8181,6 +8181,7 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (Args.hasArg(options::OPT_shared)) { CmdArgs.push_back("-Bshareable"); } else { + Args.AddAllArgs(CmdArgs, options::OPT_pie); CmdArgs.push_back("-dynamic-linker"); CmdArgs.push_back("/libexec/ld.elf_so"); } @@ -8282,15 +8283,15 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_shared)) { CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crt0.o"))); + } + CmdArgs.push_back( + Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); + if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) { CmdArgs.push_back( - Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); - CmdArgs.push_back( - Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o"))); + Args.MakeArgString(getToolChain().GetFilePath("crtbeginS.o"))); } else { CmdArgs.push_back( - Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); - CmdArgs.push_back( - Args.MakeArgString(getToolChain().GetFilePath("crtbeginS.o"))); + Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o"))); } } @@ -8356,12 +8357,12 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, } if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) { - if (!Args.hasArg(options::OPT_shared)) + if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) CmdArgs.push_back( - Args.MakeArgString(getToolChain().GetFilePath("crtend.o"))); + Args.MakeArgString(getToolChain().GetFilePath("crtendS.o"))); else CmdArgs.push_back( - Args.MakeArgString(getToolChain().GetFilePath("crtendS.o"))); + Args.MakeArgString(getToolChain().GetFilePath("crtend.o"))); CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o"))); } diff --git a/clang/test/Driver/netbsd.c b/clang/test/Driver/netbsd.c index 351fbdf..34757b5 100644 --- a/clang/test/Driver/netbsd.c +++ b/clang/test/Driver/netbsd.c @@ -1,5 +1,15 @@ // RUN: %clang -no-canonical-prefixes -target x86_64--netbsd \ // RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=STATIC %s +// RUN: %clang -no-canonical-prefixes -target x86_64--netbsd \ +// RUN: -pie --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=PIE %s +// RUN: %clang -no-canonical-prefixes -target x86_64--netbsd \ +// RUN: -shared --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=SHARED %s + +// RUN: %clang -no-canonical-prefixes -target x86_64--netbsd \ +// RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=X86_64 %s // RUN: %clang -no-canonical-prefixes -target x86_64--netbsd7.0.0 \ // RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ @@ -105,6 +115,32 @@ // RUN: --sysroot=%S/Inputs/basic_netbsd_tree %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=S-POWERPC64 %s +// STATIC: ld{{.*}}" +// STATIC-NOT: "-pie" +// STATIC-NOT: "-Bshareable" +// STATIC: "-dynamic-linker" "/libexec/ld.elf_so" +// STATIC-NOT: "-pie" +// STATIC-NOT: "-Bshareable" +// STATIC: "{{.*}}/usr/lib{{/|\\\\}}crt0.o" +// STATIC: "{{.*}}/usr/lib{{/|\\\\}}crti.o" "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" +// STATIC: "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o" + +// SHARED: ld{{.*}}" +// SHARED-NOT: "-pie" +// SHARED-NOT: "-dynamic-linker" +// SHARED-NOT: "{{.*}}/usr/lib{{/|\\\\}}crt0.o" +// SHARED: "{{.*}}/usr/lib{{/|\\\\}}crti.o" "{{.*}}/usr/lib{{/|\\\\}}crtbeginS.o" +// SHARED: "{{.*}}/usr/lib{{/|\\\\}}crtendS.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o" + +// PIE: ld{{.*}}" +// PIE-NOT: "-Bshareable" +// PIE "-pie" "-dynamic-linker" "/libexec/ld.elf_so" +// PIE-NOT: "-Bshareable" +// PIE: "{{.*}}/usr/lib{{/|\\\\}}crt0.o" "{{.*}}/usr/lib{{/|\\\\}}crti.o" +// PIE: "{{.*}}/usr/lib{{/|\\\\}}crtbeginS.o" +// PIE: "{{.*}}/usr/lib{{/|\\\\}}crtendS.o" +// PIE: "{{.*}}/usr/lib{{/|\\\\}}crtn.o" + // X86_64: clang{{.*}}" "-cc1" "-triple" "x86_64--netbsd" // X86_64: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so" // X86_64: "-o" "a.out" "{{.*}}/usr/lib{{/|\\\\}}crt0.o" "{{.*}}/usr/lib{{/|\\\\}}crti.o" |