From owner-svn-src-head@freebsd.org Mon Jan 29 13:52:43 2018 Return-Path: Delivered-To: svn-src-head@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 16D6EEC875A; Mon, 29 Jan 2018 13:52:43 +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 C12A37441D; Mon, 29 Jan 2018 13:52:42 +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 BC270F7D; Mon, 29 Jan 2018 13:52:42 +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 w0TDqg7q067596; Mon, 29 Jan 2018 13:52:42 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w0TDqgIu067593; Mon, 29 Jan 2018 13:52:42 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201801291352.w0TDqgIu067593@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:52:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r328546 - 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: 328546 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Jan 2018 13:52:43 -0000 Author: emaste Date: Mon Jan 29 13:52:42 2018 New Revision: 328546 URL: https://svnweb.freebsd.org/changeset/base/328546 Log: lld: Improve LMARegion handling. This fixes the crash reported at [LLVM] PR36083. The issue is that we were trying to put all the sections in the same PT_LOAD and crashing trying to write past the end of the file. This also adds accounting for used space in LMARegion, without it all 3 PT_LOADs would have the same physical address. Obtained from: LLVM r323449 by Rafael Espindola Modified: head/contrib/llvm/tools/lld/ELF/LinkerScript.cpp head/contrib/llvm/tools/lld/ELF/LinkerScript.h head/contrib/llvm/tools/lld/ELF/Writer.cpp Modified: head/contrib/llvm/tools/lld/ELF/LinkerScript.cpp ============================================================================== --- head/contrib/llvm/tools/lld/ELF/LinkerScript.cpp Mon Jan 29 13:51:13 2018 (r328545) +++ head/contrib/llvm/tools/lld/ELF/LinkerScript.cpp Mon Jan 29 13:52:42 2018 (r328546) @@ -589,6 +589,10 @@ void LinkerScript::output(InputSection *S) { // If there is a memory region associated with this input section, then // place the section in that region and update the region index. + if (Ctx->LMARegion) + Ctx->LMARegion->CurPos += Pos - Before; + // FIXME: should we also produce overflow errors for LMARegion? + if (Ctx->MemRegion) { uint64_t &CurOffset = Ctx->MemRegion->CurPos; CurOffset += Pos - Before; @@ -651,6 +655,7 @@ void LinkerScript::assignOffsets(OutputSection *Sec) { setDot(Sec->AddrExpr, Sec->Location, false); Ctx->MemRegion = Sec->MemRegion; + Ctx->LMARegion = Sec->LMARegion; if (Ctx->MemRegion) Dot = Ctx->MemRegion->CurPos; @@ -660,7 +665,7 @@ void LinkerScript::assignOffsets(OutputSection *Sec) { Ctx->LMAOffset = Sec->LMAExpr().getValue() - Dot; if (MemoryRegion *MR = Sec->LMARegion) - Ctx->LMAOffset = MR->Origin - Dot; + Ctx->LMAOffset = MR->CurPos - Dot; // If neither AT nor AT> is specified for an allocatable section, the linker // will set the LMA such that the difference between VMA and LMA for the @@ -690,6 +695,8 @@ void LinkerScript::assignOffsets(OutputSection *Sec) { Dot += Cmd->Size; if (Ctx->MemRegion) Ctx->MemRegion->CurPos += Cmd->Size; + if (Ctx->LMARegion) + Ctx->LMARegion->CurPos += Cmd->Size; Ctx->OutSec->Size = Dot - Ctx->OutSec->Addr; continue; } Modified: head/contrib/llvm/tools/lld/ELF/LinkerScript.h ============================================================================== --- head/contrib/llvm/tools/lld/ELF/LinkerScript.h Mon Jan 29 13:51:13 2018 (r328545) +++ head/contrib/llvm/tools/lld/ELF/LinkerScript.h Mon Jan 29 13:52:42 2018 (r328546) @@ -206,6 +206,7 @@ class LinkerScript final { uint64_t ThreadBssOffset = 0; OutputSection *OutSec = nullptr; MemoryRegion *MemRegion = nullptr; + MemoryRegion *LMARegion = nullptr; uint64_t LMAOffset = 0; }; Modified: head/contrib/llvm/tools/lld/ELF/Writer.cpp ============================================================================== --- head/contrib/llvm/tools/lld/ELF/Writer.cpp Mon Jan 29 13:51:13 2018 (r328545) +++ head/contrib/llvm/tools/lld/ELF/Writer.cpp Mon Jan 29 13:52:42 2018 (r328546) @@ -1626,7 +1626,8 @@ 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 || Flags != NewFlags) { + if (Sec->LMAExpr || Sec->MemRegion != Load->FirstSec->MemRegion || + Flags != NewFlags) { Load = AddHdr(PT_LOAD, NewFlags); Flags = NewFlags; }