From owner-svn-src-all@freebsd.org Mon Mar 19 14:29:00 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 55FC1F50C0B; Mon, 19 Mar 2018 14:29:00 +0000 (UTC) (envelope-from marius@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 060D571CE0; Mon, 19 Mar 2018 14:29:00 +0000 (UTC) (envelope-from marius@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 00F927C16; Mon, 19 Mar 2018 14:29:00 +0000 (UTC) (envelope-from marius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w2JESxO1027619; Mon, 19 Mar 2018 14:28:59 GMT (envelope-from marius@FreeBSD.org) Received: (from marius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w2JESwYm027606; Mon, 19 Mar 2018 14:28:58 GMT (envelope-from marius@FreeBSD.org) Message-Id: <201803191428.w2JESwYm027606@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: marius set sender to marius@FreeBSD.org using -f From: Marius Strobl Date: Mon, 19 Mar 2018 14:28:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r331206 - in stable/10: lib/libc/sparc64/sys libexec/rtld-elf libexec/rtld-elf/amd64 libexec/rtld-elf/arm libexec/rtld-elf/i386 libexec/rtld-elf/ia64 libexec/rtld-elf/mips libexec/rtld-... X-SVN-Group: stable-10 X-SVN-Commit-Author: marius X-SVN-Commit-Paths: in stable/10: lib/libc/sparc64/sys libexec/rtld-elf libexec/rtld-elf/amd64 libexec/rtld-elf/arm libexec/rtld-elf/i386 libexec/rtld-elf/ia64 libexec/rtld-elf/mips libexec/rtld-elf/powerpc libexec/rtld-... X-SVN-Commit-Revision: 331206 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, 19 Mar 2018 14:29:00 -0000 Author: marius Date: Mon Mar 19 14:28:58 2018 New Revision: 331206 URL: https://svnweb.freebsd.org/changeset/base/331206 Log: MFC: r328834 o Let rtld(1) set up psABI user trap handlers prior to executing the objects' init functions instead of doing the setup via a constructor in libc as the init functions may already depend on these handlers to be in place. This gets us rid of: - the undefined order in which libc constructors as __guard_setup() and jemalloc_constructor() are executed WRT __sparc_utrap_setup(), - the requirement to link libc last so __sparc_utrap_setup() gets called prior to constructors in other libraries (see r122883). For static binaries, crt1.o still sets up the user trap handlers. o Move misplaced prototypes for MD functions in to the MD prototype section of rtld.h. o Sprinkle nitems(). Modified: stable/10/lib/libc/sparc64/sys/__sparc_utrap_setup.c stable/10/libexec/rtld-elf/amd64/reloc.c stable/10/libexec/rtld-elf/arm/reloc.c stable/10/libexec/rtld-elf/i386/reloc.c stable/10/libexec/rtld-elf/ia64/reloc.c stable/10/libexec/rtld-elf/mips/reloc.c stable/10/libexec/rtld-elf/powerpc/reloc.c stable/10/libexec/rtld-elf/powerpc64/reloc.c stable/10/libexec/rtld-elf/rtld.c stable/10/libexec/rtld-elf/rtld.h stable/10/libexec/rtld-elf/sparc64/reloc.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/sparc64/sys/__sparc_utrap_setup.c ============================================================================== --- stable/10/lib/libc/sparc64/sys/__sparc_utrap_setup.c Mon Mar 19 14:28:20 2018 (r331205) +++ stable/10/lib/libc/sparc64/sys/__sparc_utrap_setup.c Mon Mar 19 14:28:58 2018 (r331206) @@ -27,13 +27,11 @@ #include __FBSDID("$FreeBSD$"); -#include +#include #include #include -#include - #include "__sparc_utrap_private.h" static const struct sparc_utrap_args ua[] = { @@ -45,10 +43,10 @@ static const struct sparc_utrap_args ua[] = { }; static const struct sparc_utrap_install_args uia[] = { - { sizeof (ua) / sizeof (*ua), ua } + { nitems(ua), ua } }; -void __sparc_utrap_setup(void) __attribute__((constructor)); +void __sparc_utrap_setup(void); void __sparc_utrap_setup(void) Modified: stable/10/libexec/rtld-elf/amd64/reloc.c ============================================================================== --- stable/10/libexec/rtld-elf/amd64/reloc.c Mon Mar 19 14:28:20 2018 (r331205) +++ stable/10/libexec/rtld-elf/amd64/reloc.c Mon Mar 19 14:28:58 2018 (r331206) @@ -471,6 +471,12 @@ ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)] } void +pre_init(void) +{ + +} + +void allocate_initial_tls(Obj_Entry *objs) { /* Modified: stable/10/libexec/rtld-elf/arm/reloc.c ============================================================================== --- stable/10/libexec/rtld-elf/arm/reloc.c Mon Mar 19 14:28:20 2018 (r331205) +++ stable/10/libexec/rtld-elf/arm/reloc.c Mon Mar 19 14:28:58 2018 (r331206) @@ -437,6 +437,13 @@ reloc_jmpslot(Elf_Addr *where, Elf_Addr target, const void ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)] __unused) { + +} + +void +pre_init(void) +{ + } void Modified: stable/10/libexec/rtld-elf/i386/reloc.c ============================================================================== --- stable/10/libexec/rtld-elf/i386/reloc.c Mon Mar 19 14:28:20 2018 (r331205) +++ stable/10/libexec/rtld-elf/i386/reloc.c Mon Mar 19 14:28:58 2018 (r331206) @@ -457,6 +457,12 @@ ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)] } void +pre_init(void) +{ + +} + +void allocate_initial_tls(Obj_Entry *objs) { void* tls; Modified: stable/10/libexec/rtld-elf/ia64/reloc.c ============================================================================== --- stable/10/libexec/rtld-elf/ia64/reloc.c Mon Mar 19 14:28:20 2018 (r331205) +++ stable/10/libexec/rtld-elf/ia64/reloc.c Mon Mar 19 14:28:58 2018 (r331206) @@ -606,6 +606,13 @@ call_init_pointer(const Obj_Entry *obj, Elf_Addr targe void ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)] __unused) { + +} + +void +pre_init(void) +{ + } /* Initialize the special PLT entries. */ Modified: stable/10/libexec/rtld-elf/mips/reloc.c ============================================================================== --- stable/10/libexec/rtld-elf/mips/reloc.c Mon Mar 19 14:28:20 2018 (r331205) +++ stable/10/libexec/rtld-elf/mips/reloc.c Mon Mar 19 14:28:58 2018 (r331206) @@ -620,6 +620,13 @@ reloc_jmpslot(Elf_Addr *where, Elf_Addr target, const void ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)] __unused) { + +} + +void +pre_init(void) +{ + } void Modified: stable/10/libexec/rtld-elf/powerpc/reloc.c ============================================================================== --- stable/10/libexec/rtld-elf/powerpc/reloc.c Mon Mar 19 14:28:20 2018 (r331205) +++ stable/10/libexec/rtld-elf/powerpc/reloc.c Mon Mar 19 14:28:58 2018 (r331206) @@ -622,6 +622,13 @@ init_pltgot(Obj_Entry *obj) void ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)] __unused) { + +} + +void +pre_init(void) +{ + } void Modified: stable/10/libexec/rtld-elf/powerpc64/reloc.c ============================================================================== --- stable/10/libexec/rtld-elf/powerpc64/reloc.c Mon Mar 19 14:28:20 2018 (r331205) +++ stable/10/libexec/rtld-elf/powerpc64/reloc.c Mon Mar 19 14:28:58 2018 (r331206) @@ -490,6 +490,13 @@ init_pltgot(Obj_Entry *obj) void ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)] __unused) { + +} + +void +pre_init(void) +{ + } void Modified: stable/10/libexec/rtld-elf/rtld.c ============================================================================== --- stable/10/libexec/rtld-elf/rtld.c Mon Mar 19 14:28:20 2018 (r331205) +++ stable/10/libexec/rtld-elf/rtld.c Mon Mar 19 14:28:58 2018 (r331206) @@ -659,6 +659,12 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr obj_main->fini_array = (Elf_Addr)NULL; } + /* + * Execute MD initializers required before we call the objects' + * init functions. + */ + pre_init(); + wlock_acquire(rtld_bind_lock, &lockstate); if (obj_main->crt_no_init) preinit_main(); Modified: stable/10/libexec/rtld-elf/rtld.h ============================================================================== --- stable/10/libexec/rtld-elf/rtld.h Mon Mar 19 14:28:20 2018 (r331205) +++ stable/10/libexec/rtld-elf/rtld.h Mon Mar 19 14:28:58 2018 (r331206) @@ -380,8 +380,6 @@ void dump_Elf_Rela(Obj_Entry *, const Elf_Rela *, u_lo unsigned long elf_hash(const char *); const Elf_Sym *find_symdef(unsigned long, const Obj_Entry *, const Obj_Entry **, int, SymCache *, struct Struct_RtldLockState *); -void ifunc_init(Elf_Auxinfo *); -void init_pltgot(Obj_Entry *); void lockdflt_init(void); void digest_notes(Obj_Entry *, Elf_Addr, Elf_Addr); Obj_Entry *globallist_curr(const Obj_Entry *obj); @@ -411,6 +409,9 @@ int reloc_plt(Obj_Entry *); int reloc_jmpslots(Obj_Entry *, int flags, struct Struct_RtldLockState *); int reloc_iresolve(Obj_Entry *, struct Struct_RtldLockState *); int reloc_gnu_ifunc(Obj_Entry *, int flags, struct Struct_RtldLockState *); +void ifunc_init(Elf_Auxinfo *); +void pre_init(void); +void init_pltgot(Obj_Entry *); void allocate_initial_tls(Obj_Entry *); #endif /* } */ Modified: stable/10/libexec/rtld-elf/sparc64/reloc.c ============================================================================== --- stable/10/libexec/rtld-elf/sparc64/reloc.c Mon Mar 19 14:28:20 2018 (r331205) +++ stable/10/libexec/rtld-elf/sparc64/reloc.c Mon Mar 19 14:28:58 2018 (r331206) @@ -365,8 +365,7 @@ reloc_nonplt_object(Obj_Entry *obj, const Elf_Rela *re * Note: R_SPARC_TLS_TPOFF64 must be the numerically largest * relocation type. */ - if (type >= sizeof(reloc_target_bitmask) / - sizeof(*reloc_target_bitmask)) { + if (type >= nitems(reloc_target_bitmask)) { _rtld_error("%s: Unsupported relocation type %d in non-PLT " "object\n", obj->path, type); return (-1); @@ -789,8 +788,18 @@ reloc_jmpslot(Elf_Addr *wherep, Elf_Addr target, const void ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)] __unused) { + } +extern void __sparc_utrap_setup(void); + +void +pre_init(void) +{ + + __sparc_utrap_setup(); +} + /* * Install rtld function call into this PLT slot. */ @@ -819,6 +828,7 @@ init_pltgot(Obj_Entry *obj) static void install_plt(Elf_Word *pltgot, Elf_Addr proc) { + pltgot[0] = SAVE; flush(pltgot, 0); pltgot[1] = SETHI_l0 | HIVAL(proc, 42);