[PATCH] D137044: [ClangFE] Add support for option -mno-pic-data-is-text-relative

2022-11-22 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

In D137044#3944010 , @jonpa wrote:

> In D137044#3943829 , @Fznamznon 
> wrote:
>
>> In D137044#3943680 , @jonpa wrote:
>>
>>> In D137044#3942990 , 
>>> @pcwang-thead wrote:
>>>
 The test `clang/test/Driver/pic.c` failed when we compiled Clang/LLVM with 
 `-DCLANG_DEFAULT_PIE_ON_LINUX=False`.
>>>
>>> Ah... I suppose that must be because -mno-pic-data-is-text-relative 
>>> requires PIC (this is per GCC behavior). Does it help if you add -fpic to 
>>> the RUN lines that were added by this patch? I was not aware of the cmake 
>>> flag, sorry.
>>
>> For me it does. Can we make this change?
>
> Yes, that should be fine as the test is assuming pic by default. Thanks.

I pushed the fix - 
https://github.com/llvm/llvm-project/commit/0ffcd243a42bff13966e455582d2db6c337628a2
 . Thank you.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137044/new/

https://reviews.llvm.org/D137044

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137044: [ClangFE] Add support for option -mno-pic-data-is-text-relative

2022-11-22 Thread Jonas Paulsson via Phabricator via cfe-commits
jonpa added a comment.

In D137044#3943829 , @Fznamznon wrote:

> In D137044#3943680 , @jonpa wrote:
>
>> In D137044#3942990 , @pcwang-thead 
>> wrote:
>>
>>> The test `clang/test/Driver/pic.c` failed when we compiled Clang/LLVM with 
>>> `-DCLANG_DEFAULT_PIE_ON_LINUX=False`.
>>
>> Ah... I suppose that must be because -mno-pic-data-is-text-relative requires 
>> PIC (this is per GCC behavior). Does it help if you add -fpic to the RUN 
>> lines that were added by this patch? I was not aware of the cmake flag, 
>> sorry.
>
> For me it does. Can we make this change?

Yes, that should be fine as the test is assuming pic by default. Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137044/new/

https://reviews.llvm.org/D137044

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137044: [ClangFE] Add support for option -mno-pic-data-is-text-relative

2022-11-22 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

In D137044#3943680 , @jonpa wrote:

> In D137044#3942990 , @pcwang-thead 
> wrote:
>
>> The test `clang/test/Driver/pic.c` failed when we compiled Clang/LLVM with 
>> `-DCLANG_DEFAULT_PIE_ON_LINUX=False`.
>
> Ah... I suppose that must be because -mno-pic-data-is-text-relative requires 
> PIC (this is per GCC behavior). Does it help if you add -fpic to the RUN 
> lines that were added by this patch? I was not aware of the cmake flag, sorry.

For me it does. Can we make this change?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137044/new/

https://reviews.llvm.org/D137044

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137044: [ClangFE] Add support for option -mno-pic-data-is-text-relative

2022-11-22 Thread Jonas Paulsson via Phabricator via cfe-commits
jonpa added a comment.

In D137044#3942990 , @pcwang-thead 
wrote:

> The test `clang/test/Driver/pic.c` failed when we compiled Clang/LLVM with 
> `-DCLANG_DEFAULT_PIE_ON_LINUX=False`.

Ah... I suppose that must be because -mno-pic-data-is-text-relative requires 
PIC (this is per GCC behavior). Does it help if you add -fpic to the RUN lines 
that were added by this patch? I was not aware of the cmake flag, sorry.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137044/new/

https://reviews.llvm.org/D137044

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137044: [ClangFE] Add support for option -mno-pic-data-is-text-relative

2022-11-22 Thread Wang Pengcheng via Phabricator via cfe-commits
pcwang-thead added a comment.

The test `clang/test/Driver/pic.c` failed when we compiled Clang/LLVM with 
`-DCLANG_DEFAULT_PIE_ON_LINUX=False`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137044/new/

https://reviews.llvm.org/D137044

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137044: [ClangFE] Add support for option -mno-pic-data-is-text-relative

2022-11-17 Thread Jonas Paulsson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG858f347c1758: [Clang, SystemZ] Add support for option 
-mno-pic-data-is-text-relative. (authored by jonpa).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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;
 def fpie : Flag<["-"], "fpie">, Group;
 def fno_pie : Flag<["-"], "fno-pie">, 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, 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, Flags<[CC1Option]>,


Index: clang/test/Driver/pic.c