]> granicus.if.org Git - clang/commitdiff
[Driver] Make the use of relax relocations a per target option
authorPetr Hosek <phosek@chromium.org>
Wed, 22 Nov 2017 01:38:31 +0000 (01:38 +0000)
committerPetr Hosek <phosek@chromium.org>
Wed, 22 Nov 2017 01:38:31 +0000 (01:38 +0000)
The support for relax relocations is dependent on the linker and
different toolchains within the same compiler can be using different
linkers some of which may or may not support relax relocations.

Give toolchains the option to control whether they want to use relax
relocations in addition to the existing (global) build system option.

Differential Revision: https://reviews.llvm.org/D39831

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@318816 91177308-0d34-0410-b5e6-96231b3b80d8

cmake/caches/Fuchsia-stage2.cmake
include/clang/Driver/ToolChain.h
lib/Driver/ToolChain.cpp
lib/Driver/ToolChains/Clang.cpp
lib/Driver/ToolChains/Fuchsia.h
test/Driver/fuchsia.c

index d2f19fd6d04ffc20c6a1d367ed9559ac41beedb3..b5841e257fca92d4ce6267c1466659098f013eb8 100644 (file)
@@ -18,13 +18,6 @@ if(NOT APPLE)
   set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
 endif()
 
-# This is a "Does your linker support it?" option that only applies
-# to x86-64 ELF targets.  All Fuchsia target linkers do support it.
-# For x86-64 Linux, it's supported by LLD and by GNU linkers since
-# binutils 2.27, so one can hope that all Linux hosts in use handle it.
-# Ideally this would be settable as a per-target option.
-set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
-
 if(APPLE)
   set(LLDB_CODESIGN_IDENTITY "" CACHE STRING "")
 endif()
index 1206794e93db655068bd07c3081b6ab264d6f774..bd710387980a8e6363af459a33c3cf8b1281e4a8 100644 (file)
@@ -316,6 +316,9 @@ public:
   /// mixed dispatch method be used?
   virtual bool UseObjCMixedDispatch() const { return false; }
 
+  /// \brief Check whether to enable x86 relax relocations by default.
+  virtual bool useRelaxRelocations() const;
+
   /// GetDefaultStackProtectorLevel - Get the default stack protector level for
   /// this tool chain (0=off, 1=on, 2=strong, 3=all).
   virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
index fac0a5bbff5f053401d96596ea65d06f22ee2adb..741f4284cbbc518e723ff8488fc5f280a730c40d 100644 (file)
@@ -90,6 +90,10 @@ bool ToolChain::useIntegratedAs() const {
                       IsIntegratedAssemblerDefault());
 }
 
+bool ToolChain::useRelaxRelocations() const {
+  return ENABLE_X86_RELAX_RELOCATIONS;
+}
+
 const SanitizerArgs& ToolChain::getSanitizerArgs() const {
   if (!SanitizerArguments.get())
     SanitizerArguments.reset(new SanitizerArgs(*this, Args));
index 3ab28d471bec7953a41effaf787a15e9dc1354cd..d96664cf0bef95383ccaf3aa6889ed68d0fd8fc3 100644 (file)
@@ -1869,7 +1869,7 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
   // arg after parsing the '-I' arg.
   bool TakeNextArg = false;
 
-  bool UseRelaxRelocations = ENABLE_X86_RELAX_RELOCATIONS;
+  bool UseRelaxRelocations = C.getDefaultToolChain().useRelaxRelocations();
   const char *MipsTargetFeature = nullptr;
   for (const Arg *A :
        Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) {
index 6d825fb81790f389abdba207a957e123f8f0c12b..6f438deca7ff13641dfe4144e12e256b57ec458c 100644 (file)
@@ -43,6 +43,7 @@ public:
   bool HasNativeLLVMSupport() const override { return true; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
   bool IsMathErrnoDefault() const override { return false; }
+  bool useRelaxRelocations() const override { return true; };
   RuntimeLibType GetDefaultRuntimeLibType() const override {
     return ToolChain::RLT_CompilerRT;
   }
index 3f5597c36efd247a9ece7a390b8f2916d50c2a3d..eb413b7509be786ee47becbb5e22b0b05caaaccb 100644 (file)
@@ -5,6 +5,7 @@
 // RUN:     --sysroot=%S/platform 2>&1 \
 // RUN:     | FileCheck -check-prefixes=CHECK,CHECK-AARCH64 %s
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
+// CHECK: "--mrelax-relocations"
 // CHECK: "-munwind-tables"
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"