Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Jul 2017 17:32:51 +0000 (UTC)
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r320649 - projects/clang500-import/contrib/llvm/tools/lld/ELF
Message-ID:  <201707041732.v64HWp0u023626@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: emaste
Date: Tue Jul  4 17:32:51 2017
New Revision: 320649
URL: https://svnweb.freebsd.org/changeset/base/320649

Log:
  lld: [ELF] Remove unused synthetic sections from script commands
  
  Script commands are processed before unused synthetic sections are
  removed. Therefore, if a linker script matches one of these sections
  it'll get emitted as an empty output section because the logic for
  removing unused synthetic sections ignores script commands which
  could have already matched and captured one of these sections. This
  patch fixes that by also removing the unused synthetic sections from
  the script commands.
  
  Discussed with:	dim
  Obtained from:	LLVM r307037
  Sponsored by:	The FreeBSD Foundation

Modified:
  projects/clang500-import/contrib/llvm/tools/lld/ELF/Writer.cpp

Modified: projects/clang500-import/contrib/llvm/tools/lld/ELF/Writer.cpp
==============================================================================
--- projects/clang500-import/contrib/llvm/tools/lld/ELF/Writer.cpp	Tue Jul  4 17:15:23 2017	(r320648)
+++ projects/clang500-import/contrib/llvm/tools/lld/ELF/Writer.cpp	Tue Jul  4 17:32:51 2017	(r320649)
@@ -1149,8 +1149,17 @@ static void removeUnusedSyntheticSections(std::vector<
     SS->Live = false;
     // If there are no other sections in the output section, remove it from the
     // output.
-    if (OS->Sections.empty())
+    if (OS->Sections.empty()) {
       V.erase(std::find(V.begin(), V.end(), OS));
+      // Also remove script commands matching the output section.
+      auto &Cmds = Script->Opt.Commands;
+      auto I = std::remove_if(Cmds.begin(), Cmds.end(), [&](BaseCommand *Cmd) {
+        if (auto *OSCmd = dyn_cast<OutputSectionCommand>(Cmd))
+          return OSCmd->Sec == OS;
+        return false;
+      });
+      Cmds.erase(I, Cmds.end());
+    }
   }
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201707041732.v64HWp0u023626>