Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Driver] Support -Wa,--fdpic for ARM FDPIC ABI #82188

Open
wants to merge 1 commit into
base: users/MaskRay/spr/main.driver-support-wa-fdpic-for-arm-fdpic-abi
Choose a base branch
from

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Feb 18, 2024

arm-linux-gnueabihf-gcc -c -fpic -mfdpic -Wa,--fdpic a.c compiles
a.c with FDPIC codegen and assembles the assembly file with --fdpic.
This patch implements -Wa,--fdpic for the driver when using the
integrated assembler.

Created using spr 1.3.4
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Feb 18, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 18, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Fangrui Song (MaskRay)

Changes

arm-linux-gnueabihf-gcc -c -fpic -mfdpic -Wa,--fdpic a.c compiles
a.c with FDPIC codegen and assembles the assembly file with --fdpic.
This patch implements -Wa,--fdpic for the driver when using the
integrated assembler.


Full diff: https://github.com/llvm/llvm-project/pull/82188.diff

5 Files Affected:

  • (modified) clang/include/clang/Driver/Options.td (+2)
  • (modified) clang/lib/Driver/ToolChains/Clang.cpp (+4)
  • (modified) clang/test/Driver/arm-ias-Wa.s (+2)
  • (added) clang/test/Misc/cc1as-arm-fdpic.s (+10)
  • (modified) clang/tools/driver/cc1as_main.cpp (+4)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 53f23f9abb4c96..da0ebbc1f0b607 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -7954,6 +7954,8 @@ def dwarf_debug_producer : Separate<["-"], "dwarf-debug-producer">,
 def defsym : Separate<["-"], "defsym">,
   HelpText<"Define a value for a symbol">;
 
+def fdpic : Flag<["--"], "fdpic">, HelpText<"Enable FDPIC ABI (ARM only)">;
+
 } // let Visibility = [CC1AsOption]
 
 //===----------------------------------------------------------------------===//
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 47305f798c5fee..b4cc79df8dab7b 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2530,6 +2530,10 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
       case llvm::Triple::thumbeb:
       case llvm::Triple::arm:
       case llvm::Triple::armeb:
+        if (Value == "--fdpic") {
+          CmdArgs.push_back("--fdpic");
+          continue;
+        }
         if (Value.starts_with("-mimplicit-it=")) {
           // Only store the value; the last value set takes effect.
           ImplicitIt = Value.split("=").second;
diff --git a/clang/test/Driver/arm-ias-Wa.s b/clang/test/Driver/arm-ias-Wa.s
index b82ce8dfb31ab3..73d6bb88045176 100644
--- a/clang/test/Driver/arm-ias-Wa.s
+++ b/clang/test/Driver/arm-ias-Wa.s
@@ -79,3 +79,5 @@
 // RUN:   | FileCheck -check-prefix=CHECK-M-PROFILE %s
 // CHECK-M-PROFILE: "-triple" "thumbv7m-{{.*}}"
 
+// RUN: %clang --target=arm-unknown-linuxfdpiceabi -Wa,--fdpic -c %s -### 2>&1 | FileCheck --check-prefix=FDPIC %s
+// FDPIC: "--fdpic"
diff --git a/clang/test/Misc/cc1as-arm-fdpic.s b/clang/test/Misc/cc1as-arm-fdpic.s
new file mode 100644
index 00000000000000..cc6438558eeb58
--- /dev/null
+++ b/clang/test/Misc/cc1as-arm-fdpic.s
@@ -0,0 +1,10 @@
+// REQUIRES: arm-registered-target
+
+// RUN: %clang -cc1as -triple armv7-unknown-linuxfdpiceabi -filetype obj --fdpic %s -o %t
+// RUN: llvm-readelf -h -r %t | FileCheck %s
+
+// CHECK: OS/ABI: ARM FDPIC
+// CHECK: R_ARM_FUNCDESC
+
+.data
+.word f(FUNCDESC)
diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp
index a55e06500d9d92..2d97769b786265 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -154,6 +154,8 @@ struct AssemblerInvocation {
   LLVM_PREFERRED_TYPE(bool)
   unsigned IncrementalLinkerCompatible : 1;
   LLVM_PREFERRED_TYPE(bool)
+  unsigned FDPIC : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned EmbedBitcode : 1;
 
   /// Whether to emit DWARF unwind info.
@@ -346,6 +348,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
   Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings);
   Opts.NoWarn = Args.hasArg(OPT_massembler_no_warn);
   Opts.NoTypeCheck = Args.hasArg(OPT_mno_type_check);
+  Opts.FDPIC = Args.hasArg(OPT_fdpic);
   Opts.RelocationModel =
       std::string(Args.getLastArgValue(OPT_mrelocation_model, "pic"));
   Opts.TargetABI = std::string(Args.getLastArgValue(OPT_target_abi));
@@ -520,6 +523,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
   MCOptions.MCNoWarn = Opts.NoWarn;
   MCOptions.MCFatalWarnings = Opts.FatalWarnings;
   MCOptions.MCNoTypeCheck = Opts.NoTypeCheck;
+  MCOptions.FDPIC = Opts.FDPIC;
   MCOptions.ABIName = Opts.TargetABI;
 
   // FIXME: There is a bit of code duplication with addPassesToEmitFile.

MaskRay added a commit to MaskRay/llvm-project that referenced this pull request Mar 1, 2024
`arm-linux-gnueabihf-gcc -c -fpic -mfdpic -Wa,--fdpic a.c` compiles
a.c with FDPIC codegen and assembles the assembly file with `--fdpic`.
This patch implements -Wa,--fdpic for the driver when using the
integrated assembler.

Pull Request: llvm#82188
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants