From owner-svn-src-projects@freebsd.org Tue Jul 4 17:32:52 2017 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 65AA5D96915 for ; Tue, 4 Jul 2017 17:32:52 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3458181D0A; Tue, 4 Jul 2017 17:32:52 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v64HWpgX023627; Tue, 4 Jul 2017 17:32:51 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v64HWp0u023626; Tue, 4 Jul 2017 17:32:51 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201707041732.v64HWp0u023626@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Tue, 4 Jul 2017 17:32:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r320649 - projects/clang500-import/contrib/llvm/tools/lld/ELF X-SVN-Group: projects X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: projects/clang500-import/contrib/llvm/tools/lld/ELF X-SVN-Commit-Revision: 320649 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Jul 2017 17:32:52 -0000 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(Cmd)) + return OSCmd->Sec == OS; + return false; + }); + Cmds.erase(I, Cmds.end()); + } } }