[PATCH] D137044: [ClangFE] Add support for option -mno-pic-data-is-text-relative
Jonas Paulsson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 14 08:55:35 PST 2022
jonpa updated this revision to Diff 475166.
jonpa marked an inline comment as done.
jonpa added a comment.
Check both versions of the option when emitting an error for unsupported option/target.
> Off the top of my head:
>
> Other code could create internal globals
> Name conflict if multiple globals have the same name
> C++ name mangling might get confused.
Ah, I see - that makes sense.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137044/new/
https://reviews.llvm.org/D137044
Files:
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/pic.c
Index: clang/test/Driver/pic.c
===================================================================
--- clang/test/Driver/pic.c
+++ clang/test/Driver/pic.c
@@ -1,5 +1,5 @@
-// Test the driver's control over the PIC behavior. These consist of tests of
-// the relocation model flags and the pic level flags passed to CC1.
+// Test the driver's control over the PIC behavior. These mainly consist of
+// tests of the relocation model flags and the pic level flags passed to CC1.
//
// CHECK-NO-PIC: "-mrelocation-model" "static"
// CHECK-NO-PIC-NOT: "-pic-level"
@@ -45,6 +45,11 @@
//
// CHECK-NO-UNUSED-ARG-NOT: argument unused during compilation
//
+// CHECK-NO-PIC-DATA-TEXT-REL: "-mcmodel=medium"
+// CHECK-PIC-DATA-TEXT-REL-NOT: "-mcmodel=medium"
+// CHECK-NO-PIC-DATA-TEXT-REL-NON-SYSTEMZ: error: unsupported option '-mno-pic-data-is-text-relative' for target 'arm-arm-none-eabi'
+// CHECK-PIC-DATA-TEXT-REL-NON-SYSTEMZ: error: unsupported option '-mpic-data-is-text-relative' for target 'arm-arm-none-eabi'
+//
// RUN: %clang -c %s -target i386-unknown-unknown -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-NO-PIC
// RUN: %clang -c %s -target i386-unknown-unknown -fpic -### 2>&1 \
@@ -313,3 +318,12 @@
// RUN: | FileCheck %s --check-prefix=CHECK-PIC2
// RUN: %clang -fPIC -c %s -target armv7-pc-windows-gnu -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-NO-PIC
+
+// RUN: %clang -c --target=s390x-linux-gnu -mno-pic-data-is-text-relative %s \
+// RUN: -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-PIC-DATA-TEXT-REL
+// RUN: %clang -c --target=s390x-linux-gnu -mpic-data-is-text-relative %s -### \
+// RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-PIC-DATA-TEXT-REL
+// RUN: %clang -c --target=arm-arm-none-eabi -mno-pic-data-is-text-relative %s \
+// RUN: -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-PIC-DATA-TEXT-REL-NON-SYSTEMZ
+// RUN: %clang -c --target=arm-arm-none-eabi -mpic-data-is-text-relative %s \
+// RUN: -### 2>&1 | FileCheck %s --check-prefix=CHECK-PIC-DATA-TEXT-REL-NON-SYSTEMZ
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5104,6 +5104,25 @@
unsigned PICLevel;
bool IsPIE;
std::tie(RelocationModel, PICLevel, IsPIE) = ParsePICArgs(TC, Args);
+ Arg *LastPICDataRelArg =
+ Args.getLastArg(options::OPT_mno_pic_data_is_text_relative,
+ options::OPT_mpic_data_is_text_relative);
+ bool NoPICDataIsTextRelative = false;
+ if (LastPICDataRelArg) {
+ if (LastPICDataRelArg->getOption().matches(
+ options::OPT_mno_pic_data_is_text_relative)) {
+ NoPICDataIsTextRelative = true;
+ if (!PICLevel)
+ D.Diag(diag::err_drv_argument_only_allowed_with)
+ << "-mno-pic-data-is-text-relative"
+ << "-fpic/-fpie";
+ }
+ if (!Triple.isSystemZ())
+ D.Diag(diag::err_drv_unsupported_opt_for_target)
+ << (NoPICDataIsTextRelative ? "-mno-pic-data-is-text-relative"
+ : "-mpic-data-is-text-relative")
+ << RawTriple.str();
+ }
bool IsROPI = RelocationModel == llvm::Reloc::ROPI ||
RelocationModel == llvm::Reloc::ROPI_RWPI;
@@ -5132,6 +5151,8 @@
CmdArgs.push_back(PICLevel == 1 ? "1" : "2");
if (IsPIE)
CmdArgs.push_back("-pic-is-pie");
+ if (NoPICDataIsTextRelative)
+ CmdArgs.push_back("-mcmodel=medium");
}
if (RelocationModel == llvm::Reloc::ROPI ||
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2697,6 +2697,8 @@
def fno_pic : Flag<["-"], "fno-pic">, Group<f_Group>;
def fpie : Flag<["-"], "fpie">, Group<f_Group>;
def fno_pie : Flag<["-"], "fno-pie">, Group<f_Group>;
+defm pic_data_is_text_relative : SimpleMFlag<"pic-data-is-text-relative",
+ "Assume", "Don't assume", " data segments are relative to text segment">;
def fdirect_access_external_data : Flag<["-"], "fdirect-access-external-data">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Don't use GOT indirection to reference external data symbols">;
def fno_direct_access_external_data : Flag<["-"], "fno-direct-access-external-data">, Group<f_Group>, Flags<[CC1Option]>,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137044.475166.patch
Type: text/x-patch
Size: 4426 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221114/37361366/attachment.bin>
More information about the llvm-commits
mailing list