[PATCH] D151186: [Driver] Properly handle -pie and -nopie on Fuchsia
Petr Hosek via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 23 00:55:12 PDT 2023
phosek created this revision.
phosek added a reviewer: phosek.
Herald added a subscriber: abrachet.
Herald added a project: All.
phosek requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.
Prior to this patch we would ignore -pie and -nopie options but that
could lead to issues when compiling code that uses either of these
flags.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D151186
Files:
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/test/Driver/fuchsia.c
Index: clang/test/Driver/fuchsia.c
===================================================================
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -75,6 +75,14 @@
// RUN: | FileCheck %s -check-prefix=CHECK-RTLIB
// CHECK-RTLIB: error: invalid runtime library name in argument '-rtlib=libgcc'
+// RUN: %clang -### %s --target=x86_64-unknown-fuchsia -pie -fuse-ld=lld 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-PIE
+// CHECK-PIE: "-pie"
+
+// RUN: %clang -### %s --target=x86_64-unknown-fuchsia -nopie -fuse-ld=lld 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-NOPIE
+// CHECK-NOPIE: "-no-pie"
+
// RUN: %clang -### %s --target=x86_64-unknown-fuchsia -static -fuse-ld=lld 2>&1 \
// RUN: | FileCheck %s -check-prefix=CHECK-STATIC
// CHECK-STATIC: "-Bstatic"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -71,8 +71,14 @@
if (!D.SysRoot.empty())
CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
- if (!Args.hasArg(options::OPT_shared) && !Args.hasArg(options::OPT_r))
- CmdArgs.push_back("-pie");
+ if (!Args.hasArg(options::OPT_shared) && !Args.hasArg(options::OPT_r)) {
+ Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
+ options::OPT_nopie);
+ if (!A || A->getOption().matches(options::OPT_pie))
+ CmdArgs.push_back("-pie");
+ else
+ CmdArgs.push_back("-no-pie");
+ }
if (Args.hasArg(options::OPT_rdynamic))
CmdArgs.push_back("-export-dynamic");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151186.524594.patch
Type: text/x-patch
Size: 1668 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230523/cc225e54/attachment.bin>
More information about the cfe-commits
mailing list