From owner-svn-src-head@freebsd.org Sat Dec 16 14:26:12 2017 Return-Path: Delivered-To: svn-src-head@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 66E72E83CE3; Sat, 16 Dec 2017 14:26:12 +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 3EFD365AC8; Sat, 16 Dec 2017 14:26:12 +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 vBGEQBYA023872; Sat, 16 Dec 2017 14:26:11 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vBGEQBBt023871; Sat, 16 Dec 2017 14:26:11 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201712161426.vBGEQBBt023871@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Sat, 16 Dec 2017 14:26:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r326897 - 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: 326897 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: Sat, 16 Dec 2017 14:26:12 -0000 Author: emaste Date: Sat Dec 16 14:26:11 2017 New Revision: 326897 URL: https://svnweb.freebsd.org/changeset/base/326897 Log: lld: Slightly simplify code and add comment. Cherry-pick lld r315658 by Rui Ueyama: This is not a mechanical transformation. Even though I believe this patch is correct, I'm not 100% sure if lld with this patch behaves exactly the same way as before on all edge cases. At least all tests still pass. I'm submitting this patch because it took almost a day to understand this function, and I don't want to lose it. This fixes jemalloc assertion failures observed at startup with i386 binaries and an lld-linked libc.so. Reviewed by: dim Obtained from: LLVM r315658 MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D13503 Modified: head/contrib/llvm/tools/lld/ELF/Relocations.cpp Modified: head/contrib/llvm/tools/lld/ELF/Relocations.cpp ============================================================================== --- head/contrib/llvm/tools/lld/ELF/Relocations.cpp Sat Dec 16 12:23:59 2017 (r326896) +++ head/contrib/llvm/tools/lld/ELF/Relocations.cpp Sat Dec 16 14:26:11 2017 (r326897) @@ -790,13 +790,31 @@ static void addGotEntry(SymbolBody &Sym, bool Preempti DynType = Target->GotRel; } - bool Constant = !Preemptible && (!Config->Pic || isAbsolute(Sym)); - if (!Constant) + // If a GOT slot value can be calculated at link-time, which is now, + // we can just fill that out. + // + // (We don't actually write a value to a GOT slot right now, but we + // add a static relocation to a Relocations vector so that + // InputSection::relocate will do the work for us. We may be able + // to just write a value now, but it is a TODO.) + bool IsLinkTimeConstant = !Preemptible && (!Config->Pic || isAbsolute(Sym)); + if (IsLinkTimeConstant) { + InX::Got->Relocations.push_back({Expr, DynType, Off, 0, &Sym}); + } else { + // Otherwise, we emit a dynamic relocation to .rel[a].dyn so that + // the GOT slot will be fixed at load-time. In::RelaDyn->addReloc( {DynType, InX::Got, Off, !Preemptible, &Sym, 0}); - if (Constant || (!Config->IsRela && !Preemptible)) - InX::Got->Relocations.push_back({Expr, DynType, Off, 0, &Sym}); + // REL type relocations don't have addend fields unlike RELAs, and + // their addends are stored to the section to which they are applied. + // So, store addends if we need to. + // + // This is ugly -- the difference between REL and RELA should be + // handled in a better way. It's a TODO. + if (!Config->IsRela) + InX::Got->Relocations.push_back({R_ABS, Target->GotRel, Off, 0, &Sym}); + } } // The reason we have to do this early scan is as follows