]> granicus.if.org Git - llvm/commitdiff
[gold-plugin] Disable section ordering for relocatable links
authorBill Wendling <isanbard@gmail.com>
Thu, 12 Jul 2018 20:35:58 +0000 (20:35 +0000)
committerBill Wendling <isanbard@gmail.com>
Thu, 12 Jul 2018 20:35:58 +0000 (20:35 +0000)
Not all programs want section ordering when compiled with LTO.
In particular, the Linux kernel is very sensitive when it comes to linking, and
doesn't boot when each function is placed in its own sections.

Reviewed By: pcc

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

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

test/tools/gold/X86/relocatable.ll
tools/gold/gold-plugin.cpp

index a7cd8f4ac0ba90b313dd3eab9059f39995122d57..cc4d020a78c2b7e29c02ffbd9b9b7aafaf170eb2 100644 (file)
@@ -10,7 +10,7 @@
 ; CHECK-NEXT:   Binding: Global
 ; CHECK-NEXT:   Type: Function
 ; CHECK-NEXT:   Other: 0
-; CHECK-NEXT:   Section: .text.foo
+; CHECK-NEXT:   Section: .text
 ; CHECK-NEXT: }
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
index 25ba80d2666621ae3da398ea8db4b814c8b96cbd..6c55ebcddc43a6dffd18dcb3e2b6c5c87322acfb 100644 (file)
@@ -115,6 +115,7 @@ static ld_plugin_add_input_file add_input_file = nullptr;
 static ld_plugin_set_extra_library_path set_extra_library_path = nullptr;
 static ld_plugin_get_view get_view = nullptr;
 static bool IsExecutable = false;
+static bool SplitSections = true;
 static Optional<Reloc::Model> RelocationModel = None;
 static std::string output_name = "";
 static std::list<claimed_file> Modules;
@@ -324,6 +325,7 @@ ld_plugin_status onload(ld_plugin_tv *tv) {
       switch (tv->tv_u.tv_val) {
       case LDPO_REL: // .o
         IsExecutable = false;
+        SplitSections = false;
         break;
       case LDPO_DYN: // .so
         IsExecutable = false;
@@ -834,9 +836,9 @@ static std::unique_ptr<LTO> createLTO(IndexWriteCallback OnIndexWrite,
   // FIXME: Check the gold version or add a new option to enable them.
   Conf.Options.RelaxELFRelocations = false;
 
-  // Enable function/data sections by default.
-  Conf.Options.FunctionSections = true;
-  Conf.Options.DataSections = true;
+  // Toggle function/data sections.
+  Conf.Options.FunctionSections = SplitSections;
+  Conf.Options.DataSections = SplitSections;
 
   Conf.MAttrs = MAttrs;
   Conf.RelocModel = RelocationModel;