From owner-svn-src-head@freebsd.org Wed Jan 22 02:06:35 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8520E229B90; Wed, 22 Jan 2020 02:06:35 +0000 (UTC) (envelope-from bdragon@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 482TKl2yNqz4MFl; Wed, 22 Jan 2020 02:06:35 +0000 (UTC) (envelope-from bdragon@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 60ABD1E25C; Wed, 22 Jan 2020 02:06:35 +0000 (UTC) (envelope-from bdragon@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 00M26ZPR080186; Wed, 22 Jan 2020 02:06:35 GMT (envelope-from bdragon@FreeBSD.org) Received: (from bdragon@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 00M26Zpa080185; Wed, 22 Jan 2020 02:06:35 GMT (envelope-from bdragon@FreeBSD.org) Message-Id: <202001220206.00M26Zpa080185@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bdragon set sender to bdragon@FreeBSD.org using -f From: Brandon Bergren Date: Wed, 22 Jan 2020 02:06:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356966 - head/lib/libc/gen X-SVN-Group: head X-SVN-Commit-Author: bdragon X-SVN-Commit-Paths: head/lib/libc/gen X-SVN-Commit-Revision: 356966 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.29 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: Wed, 22 Jan 2020 02:06:35 -0000 Author: bdragon Date: Wed Jan 22 02:06:34 2020 New Revision: 356966 URL: https://svnweb.freebsd.org/changeset/base/356966 Log: [PowerPC] libc backwards compatibility shim for auxv change As part of the FreeBSD powerpc* flag day (1300070), the auxv numbering was changed to match every other platform. See D20799 for more details on that change. While the kernel and rtld were adapted, libc was not, so old dynamic binaries broke for reasons other than the ABI change on powerpc64. Since it's possible to support nearly everything regarding old binaries by adding compatibility code to libc (as besides rtld, it is the main point where auxv is digested), we might as well provide compatibility code. The only unhandled case remaining should be "new format libraries that call elf_aux_info() which are dynamically linked to by old-format binaries", which should be quite rare. Reviewed by: jhibbits Sponsored by: Tag1 Consulting, Inc. Differential Revision: https://reviews.freebsd.org/D23096 Modified: head/lib/libc/gen/auxv.c Modified: head/lib/libc/gen/auxv.c ============================================================================== --- head/lib/libc/gen/auxv.c Wed Jan 22 01:31:02 2020 (r356965) +++ head/lib/libc/gen/auxv.c Wed Jan 22 02:06:34 2020 (r356966) @@ -73,6 +73,12 @@ static char *canary, *pagesizes, *execpath; static void *timekeep; static u_long hwcap, hwcap2; +#ifdef __powerpc__ +static int powerpc_new_auxv_format = 0; +static void _init_aux_powerpc_fixup(void); +int _powerpc_elf_aux_info(int, void *, int); +#endif + static void init_aux(void) { @@ -125,11 +131,107 @@ init_aux(void) case AT_TIMEKEEP: timekeep = aux->a_un.a_ptr; break; +#ifdef __powerpc__ + /* + * Since AT_STACKPROT is always set, and the common + * value 23 is mutually exclusive with the legacy powerpc + * value 21, the existence of AT_STACKPROT proves we are + * on the common format. + */ + case AT_STACKPROT: /* 23 */ + powerpc_new_auxv_format = 1; + break; +#endif } } +#ifdef __powerpc__ + if (!powerpc_new_auxv_format) + _init_aux_powerpc_fixup(); +#endif } +#ifdef __powerpc__ +static void +_init_aux_powerpc_fixup(void) +{ + Elf_Auxinfo *aux; + + /* + * Before 1300070, PowerPC platforms had nonstandard numbering for + * the aux vector. When running old binaries, the kernel will pass + * the vector using the old numbering. Reload affected variables. + */ + for (aux = __elf_aux_vector; aux->a_type != AT_NULL; aux++) { + switch (aux->a_type) { + case AT_OLD_CANARY: + canary = (char *)(aux->a_un.a_ptr); + break; + case AT_OLD_CANARYLEN: + canary_len = aux->a_un.a_val; + break; + case AT_OLD_EXECPATH: + execpath = (char *)(aux->a_un.a_ptr); + break; + case AT_OLD_PAGESIZES: + pagesizes = (char *)(aux->a_un.a_ptr); + break; + case AT_OLD_PAGESIZESLEN: + pagesizes_len = aux->a_un.a_val; + break; + case AT_OLD_OSRELDATE: + osreldate = aux->a_un.a_val; + break; + case AT_OLD_NCPUS: + ncpus = aux->a_un.a_val; + break; + } + } +} + +int +_powerpc_elf_aux_info(int aux, void *buf, int buflen) +{ + + /* + * If we are in the old auxv format, we need to translate the aux + * parameter of elf_aux_info() calls into the common auxv format. + * Internal libc calls always use the common format, and they + * directly call _elf_aux_info instead of using the weak symbol. + */ + if (!powerpc_new_auxv_format) { + switch (aux) { + case AT_OLD_EXECPATH: + aux = AT_EXECPATH; + break; + case AT_OLD_CANARY: + aux = AT_CANARY; + break; + case AT_OLD_CANARYLEN: + aux = AT_CANARYLEN; + break; + case AT_OLD_OSRELDATE: + aux = AT_OSRELDATE; + break; + case AT_OLD_NCPUS: + aux = AT_NCPUS; + break; + case AT_OLD_PAGESIZES: + aux = AT_PAGESIZES; + break; + case AT_OLD_PAGESIZESLEN: + aux = AT_PAGESIZESLEN; + break; + case AT_OLD_STACKPROT: + aux = AT_STACKPROT; + break; + } + } + return _elf_aux_info(aux, buf, buflen); +} +__weak_reference(_powerpc_elf_aux_info, elf_aux_info); +#else __weak_reference(_elf_aux_info, elf_aux_info); +#endif int _elf_aux_info(int aux, void *buf, int buflen)