[llvm-branch-commits] [Driver] Support -Wa, --fdpic for ARM FDPIC ABI (PR #82188)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Feb 18 11:28:23 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver
Author: Fangrui Song (MaskRay)
<details>
<summary>Changes</summary>
`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
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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/82188
More information about the llvm-branch-commits
mailing list