[clang] 83cec14 - [clang] Change CodeGenOptions::RelaxELFRelocations/assembler defaults to match MC default
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Sat Dec 31 22:24:43 PST 2022
Author: Fangrui Song
Date: 2022-12-31T22:24:37-08:00
New Revision: 83cec143c76f4c76fe8ae28d6d836e8f7bd67891
URL: https://github.com/llvm/llvm-project/commit/83cec143c76f4c76fe8ae28d6d836e8f7bd67891
DIFF: https://github.com/llvm/llvm-project/commit/83cec143c76f4c76fe8ae28d6d836e8f7bd67891.diff
LOG: [clang] Change CodeGenOptions::RelaxELFRelocations/assembler defaults to match MC default
MC default was flipped in 2016.
CMake ENABLE_X86_RELAX_RELOCATIONS defaults to on in 2020 (c41a18cf61790fc898dcda1055c3efbf442c14c0).
It makes sense for the CodeGenOptions::RelaxELFRelocations to match, so
that most -cc1/-cc1as command lines won't have this option.
This also fixes a minor issue: -fno-plt -S will now use GOT for
__tls_get_addr calls, matching -fno-plt -c.
Added:
Modified:
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGen/relax.c
clang/test/Driver/fuchsia.c
clang/test/Driver/ps4-ps5-relax-relocations.c
clang/test/Driver/relax.c
clang/test/Driver/relax.s
clang/tools/driver/cc1as_main.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def
index 0545a4d2d17fe..436226c6f178f 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -30,7 +30,7 @@ CODEGENOPT(Name, Bits, Default)
CODEGENOPT(DisableIntegratedAS, 1, 0) ///< -no-integrated-as
ENUM_CODEGENOPT(CompressDebugSections, llvm::DebugCompressionType, 2,
llvm::DebugCompressionType::None)
-CODEGENOPT(RelaxELFRelocations, 1, 0) ///< -Wa,--mrelax-relocations
+CODEGENOPT(RelaxELFRelocations, 1, 1) ///< -Wa,-mrelax-relocations={yes,no}
CODEGENOPT(AsmVerbose , 1, 0) ///< -dA, -fverbose-asm.
CODEGENOPT(Dwarf64 , 1, 0) ///< -gdwarf64.
CODEGENOPT(Dwarf32 , 1, 1) ///< -gdwarf32.
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index f6f8e08712dab..cf204ae6b441a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5384,9 +5384,9 @@ def massembler_no_warn : Flag<["-"], "massembler-no-warn">,
def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">,
HelpText<"Make assembler warnings fatal">,
MarshallingInfoFlag<CodeGenOpts<"FatalWarnings">>;
-def mrelax_relocations : Flag<["--"], "mrelax-relocations">,
- HelpText<"Use relaxable elf relocations">,
- MarshallingInfoFlag<CodeGenOpts<"RelaxELFRelocations">>;
+def mrelax_relocations_no : Flag<["-"], "mrelax-relocations=no">,
+ HelpText<"Disable x86 relax relocations">,
+ MarshallingInfoNegativeFlag<CodeGenOpts<"RelaxELFRelocations">>;
def msave_temp_labels : Flag<["-"], "msave-temp-labels">,
HelpText<"Save temporary labels in the symbol table. "
"Note this may change .s semantics and shouldn't generally be used "
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 199796ea7570d..3635748ab9aa1 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2641,8 +2641,8 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
}
if (ImplicitIt.size())
AddARMImplicitITArgs(Args, CmdArgs, ImplicitIt);
- if (UseRelaxRelocations)
- CmdArgs.push_back("--mrelax-relocations");
+ if (!UseRelaxRelocations)
+ CmdArgs.push_back("-mrelax-relocations=no");
if (UseNoExecStack)
CmdArgs.push_back("-mnoexecstack");
if (MipsTargetFeature != nullptr) {
diff --git a/clang/test/CodeGen/relax.c b/clang/test/CodeGen/relax.c
index 07b7589be9753..b9ed5031b4ed3 100644
--- a/clang/test/CodeGen/relax.c
+++ b/clang/test/CodeGen/relax.c
@@ -1,5 +1,5 @@
// REQUIRES: x86-registered-target
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-obj --mrelax-relocations %s -mrelocation-model pic -o %t
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-obj %s -mrelocation-model pic -o %t
// RUN: llvm-readobj -r %t | FileCheck %s
// CHECK: R_X86_64_REX_GOTPCRELX foo
diff --git a/clang/test/Driver/fuchsia.c b/clang/test/Driver/fuchsia.c
index 9c023329edb5f..25a2f841a9cb0 100644
--- a/clang/test/Driver/fuchsia.c
+++ b/clang/test/Driver/fuchsia.c
@@ -26,7 +26,6 @@
// CHECK-X86_64: "-triple" "x86_64-unknown-fuchsia"
// CHECK-AARCH64: "-triple" "aarch64-unknown-fuchsia"
// CHECK-RISCV64: "-triple" "riscv64-unknown-fuchsia"
-// CHECK: "--mrelax-relocations"
// CHECK: "-funwind-tables=2"
// CHECK: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
// CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
diff --git a/clang/test/Driver/ps4-ps5-relax-relocations.c b/clang/test/Driver/ps4-ps5-relax-relocations.c
index 22490e486052f..41ed3f22b19c8 100644
--- a/clang/test/Driver/ps4-ps5-relax-relocations.c
+++ b/clang/test/Driver/ps4-ps5-relax-relocations.c
@@ -24,6 +24,6 @@
// RUN: %clang -### -x assembler -target x86_64-sie-ps5 -Wa,-mrelax-relocations=no %s -o - 2>&1 | \
// RUN: FileCheck -check-prefix=UNSET %s
-// CHECK: "--mrelax-relocations"
+// CHECK-NOT: "-mrelax-relocations
-// UNSET-NOT: "--mrelax-relocations"
+// UNSET: "-mrelax-relocations=no"
diff --git a/clang/test/Driver/relax.c b/clang/test/Driver/relax.c
index 170d2751b2910..48d22fede12d7 100644
--- a/clang/test/Driver/relax.c
+++ b/clang/test/Driver/relax.c
@@ -1,4 +1,4 @@
-// RUN: %clang -### -c -integrated-as -Wa,--mrelax-relocations=yes %s 2>&1 | FileCheck %s
+// RUN: %clang -### -c -integrated-as -Wa,--mrelax-relocations=no %s 2>&1 | FileCheck %s
// CHECK: "-cc1"
-// CHECK: "--mrelax-relocations"
+// CHECK: "-mrelax-relocations=no"
diff --git a/clang/test/Driver/relax.s b/clang/test/Driver/relax.s
index d2941e2f173f3..01ae9d87c39b2 100644
--- a/clang/test/Driver/relax.s
+++ b/clang/test/Driver/relax.s
@@ -1,10 +1,10 @@
// REQUIRES: x86-registered-target
-// RUN: %clang -### -c -integrated-as -Wa,--mrelax-relocations=yes %s 2>&1 | FileCheck %s
+// RUN: %clang -### -c -integrated-as -Wa,--mrelax-relocations=no %s 2>&1 | FileCheck %s
// CHECK: "-cc1as"
-// CHECK: "--mrelax-relocations"
+// CHECK: "-mrelax-relocations=no"
-// RUN: %clang -cc1as -triple x86_64-pc-linux --mrelax-relocations %s -o %t -filetype obj
+// RUN: %clang -cc1as -triple x86_64-pc-linux %s -o %t -filetype obj
// RUN: llvm-readobj -r %t | FileCheck --check-prefix=REL %s
// REL: R_X86_64_REX_GOTPCRELX foo
diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp
index 2bac511109cb4..b0fca509b0c66 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -259,7 +259,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
.Default(llvm::DebugCompressionType::None);
}
- Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);
+ Opts.RelaxELFRelocations = !Args.hasArg(OPT_mrelax_relocations_no);
if (auto *DwarfFormatArg = Args.getLastArg(OPT_gdwarf64, OPT_gdwarf32))
Opts.Dwarf64 = DwarfFormatArg->getOption().matches(OPT_gdwarf64);
Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags);
More information about the cfe-commits
mailing list