From owner-svn-src-stable-11@freebsd.org Thu Jan 26 03:05:28 2017 Return-Path: Delivered-To: svn-src-stable-11@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 9F6EFCC2CFE; Thu, 26 Jan 2017 03:05:28 +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 548CADB7; Thu, 26 Jan 2017 03:05:28 +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 v0Q35Rdu056151; Thu, 26 Jan 2017 03:05:27 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v0Q35RkZ056149; Thu, 26 Jan 2017 03:05:27 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201701260305.v0Q35RkZ056149@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Thu, 26 Jan 2017 03:05:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r312789 - stable/11/libexec/rtld-elf/amd64 X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Jan 2017 03:05:28 -0000 Author: emaste Date: Thu Jan 26 03:05:27 2017 New Revision: 312789 URL: https://svnweb.freebsd.org/changeset/base/312789 Log: MFC r312288: rtld: do not rely on a populated GOT on amd64 On rela architectures GNU BFD ld and gold store the relocation addend in GOT entries (in addition to the relocation's r_addend field). rtld previously relied on this to access its own _DYNAMIC symbol in order to apply its own relocations. However, recording addends in the GOT is not specified by the ABI, and some versions of LLVM's LLD linker leave the GOT uninitialized on rela architectures. BFD ld does not populate the GOT on sparc64, and sparc64 rtld has a machine-dependent rtld_dynamic_addr() function that returns the _DYNAMIC address. Use the same approach on amd64, obtaining the %rip- relative _DYNAMIC address following a suggestion from Rafael EspĂ­ndola. Architectures other than amd64 should be addressed in future work. Modified: stable/11/libexec/rtld-elf/amd64/rtld_machdep.h stable/11/libexec/rtld-elf/amd64/rtld_start.S Directory Properties: stable/11/ (props changed) Modified: stable/11/libexec/rtld-elf/amd64/rtld_machdep.h ============================================================================== --- stable/11/libexec/rtld-elf/amd64/rtld_machdep.h Thu Jan 26 02:22:23 2017 (r312788) +++ stable/11/libexec/rtld-elf/amd64/rtld_machdep.h Thu Jan 26 03:05:27 2017 (r312789) @@ -35,8 +35,8 @@ struct Struct_Obj_Entry; /* Return the address of the .dynamic section in the dynamic linker. */ -#define rtld_dynamic(obj) \ - ((const Elf_Dyn *)((obj)->relocbase + (Elf_Addr)&_DYNAMIC)) +Elf_Dyn *rtld_dynamic_addr(void); +#define rtld_dynamic(obj) rtld_dynamic_addr() /* Fixup the jump slot at "where" to transfer control to "target". */ static inline Elf_Addr Modified: stable/11/libexec/rtld-elf/amd64/rtld_start.S ============================================================================== --- stable/11/libexec/rtld-elf/amd64/rtld_start.S Thu Jan 26 02:22:23 2017 (r312788) +++ stable/11/libexec/rtld-elf/amd64/rtld_start.S Thu Jan 26 03:05:27 2017 (r312789) @@ -156,4 +156,16 @@ _rtld_bind_start: .cfi_endproc .size _rtld_bind_start, . - _rtld_bind_start + .align 4 + .globl rtld_dynamic_addr + .type rtld_dynamic_addr,@function +rtld_dynamic_addr: + .cfi_startproc + .weak _DYNAMIC + .hidden _DYNAMIC + lea _DYNAMIC(%rip),%rax + ret + .cfi_endproc + .size rtld_dynamic_addr, . - rtld_dynamic_addr + .section .note.GNU-stack,"",%progbits