Skip to content

Commit 83cec14

Browse files
committed
[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 (c41a18c). 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.
1 parent 8dc7366 commit 83cec14

File tree

9 files changed

+15
-16
lines changed

9 files changed

+15
-16
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ CODEGENOPT(Name, Bits, Default)
3030
CODEGENOPT(DisableIntegratedAS, 1, 0) ///< -no-integrated-as
3131
ENUM_CODEGENOPT(CompressDebugSections, llvm::DebugCompressionType, 2,
3232
llvm::DebugCompressionType::None)
33-
CODEGENOPT(RelaxELFRelocations, 1, 0) ///< -Wa,--mrelax-relocations
33+
CODEGENOPT(RelaxELFRelocations, 1, 1) ///< -Wa,-mrelax-relocations={yes,no}
3434
CODEGENOPT(AsmVerbose , 1, 0) ///< -dA, -fverbose-asm.
3535
CODEGENOPT(Dwarf64 , 1, 0) ///< -gdwarf64.
3636
CODEGENOPT(Dwarf32 , 1, 1) ///< -gdwarf32.

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5384,9 +5384,9 @@ def massembler_no_warn : Flag<["-"], "massembler-no-warn">,
53845384
def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">,
53855385
HelpText<"Make assembler warnings fatal">,
53865386
MarshallingInfoFlag<CodeGenOpts<"FatalWarnings">>;
5387-
def mrelax_relocations : Flag<["--"], "mrelax-relocations">,
5388-
HelpText<"Use relaxable elf relocations">,
5389-
MarshallingInfoFlag<CodeGenOpts<"RelaxELFRelocations">>;
5387+
def mrelax_relocations_no : Flag<["-"], "mrelax-relocations=no">,
5388+
HelpText<"Disable x86 relax relocations">,
5389+
MarshallingInfoNegativeFlag<CodeGenOpts<"RelaxELFRelocations">>;
53905390
def msave_temp_labels : Flag<["-"], "msave-temp-labels">,
53915391
HelpText<"Save temporary labels in the symbol table. "
53925392
"Note this may change .s semantics and shouldn't generally be used "

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,8 +2641,8 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
26412641
}
26422642
if (ImplicitIt.size())
26432643
AddARMImplicitITArgs(Args, CmdArgs, ImplicitIt);
2644-
if (UseRelaxRelocations)
2645-
CmdArgs.push_back("--mrelax-relocations");
2644+
if (!UseRelaxRelocations)
2645+
CmdArgs.push_back("-mrelax-relocations=no");
26462646
if (UseNoExecStack)
26472647
CmdArgs.push_back("-mnoexecstack");
26482648
if (MipsTargetFeature != nullptr) {

clang/test/CodeGen/relax.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// REQUIRES: x86-registered-target
2-
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-obj --mrelax-relocations %s -mrelocation-model pic -o %t
2+
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-obj %s -mrelocation-model pic -o %t
33
// RUN: llvm-readobj -r %t | FileCheck %s
44

55
// CHECK: R_X86_64_REX_GOTPCRELX foo

clang/test/Driver/fuchsia.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
// CHECK-X86_64: "-triple" "x86_64-unknown-fuchsia"
2727
// CHECK-AARCH64: "-triple" "aarch64-unknown-fuchsia"
2828
// CHECK-RISCV64: "-triple" "riscv64-unknown-fuchsia"
29-
// CHECK: "--mrelax-relocations"
3029
// CHECK: "-funwind-tables=2"
3130
// CHECK: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
3231
// CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"

clang/test/Driver/ps4-ps5-relax-relocations.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
// RUN: %clang -### -x assembler -target x86_64-sie-ps5 -Wa,-mrelax-relocations=no %s -o - 2>&1 | \
2525
// RUN: FileCheck -check-prefix=UNSET %s
2626

27-
// CHECK: "--mrelax-relocations"
27+
// CHECK-NOT: "-mrelax-relocations
2828

29-
// UNSET-NOT: "--mrelax-relocations"
29+
// UNSET: "-mrelax-relocations=no"

clang/test/Driver/relax.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang -### -c -integrated-as -Wa,--mrelax-relocations=yes %s 2>&1 | FileCheck %s
1+
// RUN: %clang -### -c -integrated-as -Wa,--mrelax-relocations=no %s 2>&1 | FileCheck %s
22

33
// CHECK: "-cc1"
4-
// CHECK: "--mrelax-relocations"
4+
// CHECK: "-mrelax-relocations=no"

clang/test/Driver/relax.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// REQUIRES: x86-registered-target
2-
// RUN: %clang -### -c -integrated-as -Wa,--mrelax-relocations=yes %s 2>&1 | FileCheck %s
2+
// RUN: %clang -### -c -integrated-as -Wa,--mrelax-relocations=no %s 2>&1 | FileCheck %s
33

44
// CHECK: "-cc1as"
5-
// CHECK: "--mrelax-relocations"
5+
// CHECK: "-mrelax-relocations=no"
66

7-
// RUN: %clang -cc1as -triple x86_64-pc-linux --mrelax-relocations %s -o %t -filetype obj
7+
// RUN: %clang -cc1as -triple x86_64-pc-linux %s -o %t -filetype obj
88
// RUN: llvm-readobj -r %t | FileCheck --check-prefix=REL %s
99

1010
// REL: R_X86_64_REX_GOTPCRELX foo

clang/tools/driver/cc1as_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
259259
.Default(llvm::DebugCompressionType::None);
260260
}
261261

262-
Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);
262+
Opts.RelaxELFRelocations = !Args.hasArg(OPT_mrelax_relocations_no);
263263
if (auto *DwarfFormatArg = Args.getLastArg(OPT_gdwarf64, OPT_gdwarf32))
264264
Opts.Dwarf64 = DwarfFormatArg->getOption().matches(OPT_gdwarf64);
265265
Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags);

0 commit comments

Comments
 (0)