Skip to content

Commit a98371a

Browse files
committed
[X86] Implement disabling APX relocations and EPGR/NDD instrs for them
Introduce an option (-mapx-relax-relocations) to control the emission of the new APX relocations. It's off by default to keep backward compatibility with older version of ld and other linkers without APX support. And EGPR and NDD are also suppressed to avoid the instructions updated incorrectly by older version of linker.
1 parent b6820c3 commit a98371a

37 files changed

+635
-110
lines changed

clang/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld")
219219
set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL
220220
"enable x86 relax relocations by default")
221221

222+
set(ENABLE_X86_APX_RELAX_RELOCATIONS OFF CACHE BOOL
223+
"Enable x86 APX relax relocations by default")
224+
222225
set(PPC_LINUX_DEFAULT_IEEELONGDOUBLE OFF CACHE BOOL
223226
"Enable IEEE binary128 as default long double format on PowerPC Linux.")
224227

clang/cmake/caches/Fuchsia-stage2.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
4949

5050
set(ENABLE_LINKER_BUILD_ID ON CACHE BOOL "")
5151
set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
52+
set(ENABLE_X86_APX_RELAX_RELOCATIONS OFF CACHE BOOL "")
5253

5354
# TODO(#67176): relative-vtables doesn't play well with different default
5455
# visibilities. Making everything hidden visibility causes other complications

clang/cmake/caches/Fuchsia.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
8989

9090
set(ENABLE_LINKER_BUILD_ID ON CACHE BOOL "")
9191
set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
92+
set(ENABLE_X86_APX_RELAX_RELOCATIONS OFF CACHE BOOL "")
9293

9394
set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
9495
set(LLVM_ENABLE_BACKTRACES ON CACHE BOOL "")

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Internal Linkage symbols get u
201201
CODEGENOPT(SplitMachineFunctions, 1, 0) ///< Split machine functions using profile information.
202202
CODEGENOPT(PPCUseFullRegisterNames, 1, 0) ///< Print full register names in assembly
203203
CODEGENOPT(X86RelaxRelocations, 1, 1) ///< -Wa,-mrelax-relocations={yes,no}
204+
CODEGENOPT(X86APXRelaxRelocations, 1, 0) ///< -Wa,-mrelax-relocations={yes,no}
204205
CODEGENOPT(X86Sse2Avx , 1, 0) ///< -Wa,-msse2avx
205206

206207
/// When false, this attempts to generate code as if the result of an

clang/include/clang/Config/config.h.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
/* enable x86 relax relocations by default */
7373
#cmakedefine01 ENABLE_X86_RELAX_RELOCATIONS
7474

75+
/* enable x86 APX relax relocations by default */
76+
#cmakedefine01 ENABLE_X86_APX_RELAX_RELOCATIONS
77+
7578
/* Enable IEEE binary128 as default long double format on PowerPC Linux. */
7679
#cmakedefine01 PPC_LINUX_DEFAULT_IEEELONGDOUBLE
7780

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7442,6 +7442,9 @@ def mmapsyms_implicit : Flag<["-"], "mmapsyms=implicit">,
74427442
def mrelax_relocations_no : Flag<["-"], "mrelax-relocations=no">,
74437443
HelpText<"Disable x86 relax relocations">,
74447444
MarshallingInfoNegativeFlag<CodeGenOpts<"X86RelaxRelocations">>;
7445+
def mapx_relax_relocations_yes : Flag<["-"], "mapx-relax-relocations=yes">,
7446+
HelpText<"Enable x86 APX relax relocations">,
7447+
MarshallingInfoNegativeFlag<CodeGenOpts<"X86APXRelaxRelocations">>;
74457448
def msave_temp_labels : Flag<["-"], "msave-temp-labels">,
74467449
HelpText<"Save temporary labels in the symbol table. "
74477450
"Note this may change .s semantics and shouldn't generally be used "

clang/include/clang/Driver/ToolChain.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,9 @@ class ToolChain {
473473
/// Check whether to enable x86 relax relocations by default.
474474
virtual bool useRelaxRelocations() const;
475475

476+
/// Check whether to enable x86 APX relax relocations by default.
477+
virtual bool useAPXRelaxRelocations() const;
478+
476479
/// Check whether use IEEE binary128 as long double format by default.
477480
bool defaultToIEEELongDouble() const;
478481

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ static bool initTargetOptions(const CompilerInstance &CI,
513513
Options.MCOptions.Crel = CodeGenOpts.Crel;
514514
Options.MCOptions.ImplicitMapSyms = CodeGenOpts.ImplicitMapSyms;
515515
Options.MCOptions.X86RelaxRelocations = CodeGenOpts.X86RelaxRelocations;
516+
Options.MCOptions.X86APXRelaxRelocations = CodeGenOpts.X86APXRelaxRelocations;
516517
Options.MCOptions.CompressDebugSections =
517518
CodeGenOpts.getCompressDebugSections();
518519
if (CodeGenOpts.OutputAsmVariant != 3) // 3 (default): not specified

clang/lib/Driver/ToolChain.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ bool ToolChain::useRelaxRelocations() const {
192192
return ENABLE_X86_RELAX_RELOCATIONS;
193193
}
194194

195+
bool ToolChain::useAPXRelaxRelocations() const {
196+
return ENABLE_X86_APX_RELAX_RELOCATIONS;
197+
}
198+
195199
bool ToolChain::defaultToIEEELongDouble() const {
196200
return PPC_LINUX_DEFAULT_IEEELONGDOUBLE && getTriple().isOSLinux();
197201
}

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,6 +2602,8 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
26022602
bool Crel = false, ExperimentalCrel = false;
26032603
bool ImplicitMapSyms = false;
26042604
bool UseRelaxRelocations = C.getDefaultToolChain().useRelaxRelocations();
2605+
bool UseAPXRelaxRelocations =
2606+
C.getDefaultToolChain().useAPXRelaxRelocations();
26052607
bool UseNoExecStack = false;
26062608
bool Msa = false;
26072609
const char *MipsTargetFeature = nullptr;
@@ -2663,6 +2665,12 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
26632665
checkArg(IsELF, {"yes", "no"});
26642666
continue;
26652667
}
2668+
if (Equal.first == "-mapx-relax-relocations" ||
2669+
Equal.first == "--mapx-relax-relocations") {
2670+
UseAPXRelaxRelocations = Equal.second == "yes";
2671+
checkArg(IsELF, {"yes", "no"});
2672+
continue;
2673+
}
26662674
if (Value == "-msse2avx") {
26672675
CmdArgs.push_back("-msse2avx");
26682676
continue;
@@ -2874,6 +2882,8 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
28742882
CmdArgs.push_back("-mmsa");
28752883
if (!UseRelaxRelocations)
28762884
CmdArgs.push_back("-mrelax-relocations=no");
2885+
if (UseAPXRelaxRelocations)
2886+
CmdArgs.push_back("-mapx-relax-relocations=yes");
28772887
if (UseNoExecStack)
28782888
CmdArgs.push_back("-mnoexecstack");
28792889
if (MipsTargetFeature != nullptr) {

0 commit comments

Comments
 (0)