From owner-svn-src-all@freebsd.org Mon Jan 29 13:55:51 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EBF0EEC8986; Mon, 29 Jan 2018 13:55:50 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9E04A74707; Mon, 29 Jan 2018 13:55:50 +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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 98D8BF7F; Mon, 29 Jan 2018 13:55:50 +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 w0TDtou2067821; Mon, 29 Jan 2018 13:55:50 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w0TDtoRB067819; Mon, 29 Jan 2018 13:55:50 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201801291355.w0TDtoRB067819@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Mon, 29 Jan 2018 13:55:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r328548 - head/contrib/llvm/tools/lld/ELF X-SVN-Group: head X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: head/contrib/llvm/tools/lld/ELF X-SVN-Commit-Revision: 328548 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Jan 2018 13:55:51 -0000 Author: emaste Date: Mon Jan 29 13:55:50 2018 New Revision: 328548 URL: https://svnweb.freebsd.org/changeset/base/328548 Log: lld: Put the header in the first PT_LOAD even if that PT_LOAD has a LMAExpr The root problem is that we were creating a PT_LOAD just for the header. That was technically valid, but inconvenient: we should not be making the ELF discontinuous. The solution is to allow a section with LMAExpr to be added to a PT_LOAD if that PT_LOAD doesn't already have a LMAExpr. LLVM PR: 36017 Obtained from: LLVM r323625 by Rafael Espindola Modified: head/contrib/llvm/tools/lld/ELF/Writer.cpp head/contrib/llvm/tools/lld/ELF/Writer.h Modified: head/contrib/llvm/tools/lld/ELF/Writer.cpp ============================================================================== --- head/contrib/llvm/tools/lld/ELF/Writer.cpp Mon Jan 29 13:54:51 2018 (r328547) +++ head/contrib/llvm/tools/lld/ELF/Writer.cpp Mon Jan 29 13:55:50 2018 (r328548) @@ -822,6 +822,8 @@ void PhdrEntry::add(OutputSection *Sec) { p_align = std::max(p_align, Sec->Alignment); if (p_type == PT_LOAD) Sec->PtLoad = this; + if (Sec->LMAExpr) + ASectionHasLMA = true; } // The beginning and the ending of .rel[a].plt section are marked @@ -1626,8 +1628,9 @@ template std::vector Writer< // different flags or is loaded at a discontiguous address using AT linker // script command. uint64_t NewFlags = computeFlags(Sec->getPhdrFlags()); - if (Sec->LMAExpr || Sec->MemRegion != Load->FirstSec->MemRegion || - Flags != NewFlags) { + if ((Sec->LMAExpr && Load->ASectionHasLMA) || + Sec->MemRegion != Load->FirstSec->MemRegion || Flags != NewFlags) { + Load = AddHdr(PT_LOAD, NewFlags); Flags = NewFlags; } Modified: head/contrib/llvm/tools/lld/ELF/Writer.h ============================================================================== --- head/contrib/llvm/tools/lld/ELF/Writer.h Mon Jan 29 13:54:51 2018 (r328547) +++ head/contrib/llvm/tools/lld/ELF/Writer.h Mon Jan 29 13:55:50 2018 (r328548) @@ -44,6 +44,11 @@ struct PhdrEntry { OutputSection *FirstSec = nullptr; OutputSection *LastSec = nullptr; bool HasLMA = false; + + // True if any of the sections in this program header as a LMA specified via + // linker script: AT(addr). + bool ASectionHasLMA = false; + uint64_t LMAOffset = 0; };