From patchwork Mon Jun 18 18:07:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 931125 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-93356-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mips.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="aj0b/wxJ"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 418fGT3RQFz9ryk for ; Tue, 19 Jun 2018 04:08:17 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version:content-type; q=dns; s=default; b=B072h IzJHvZklFr2ObbpDlLuDWUr6DCwo8Ti2xYDTAcW4VY2FO61rMs8wRGqJ29941rH8 GpXEhu/YpcXToB/DAwBBruY/7mr92MDfMLliZSEaxEzbnYTircu5w/LE7qnA0g2q h+tq8Zp6baImt5pjrE19nETfZ3LRJezz+qZK/E= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version:content-type; s=default; bh=bk4B8jLHmqS x5T/iA0SmHsCAwaE=; b=aj0b/wxJhEhNuhVvPYuvaO7UENErpTIFzozbZbrtZ1D KoFwUeu7Y1LUR7ulVzUg2is1ZMGP769CK6OMuDSKnktaIb03B9BFRgps3t/UoHjI +2Sq53kwV31K+yFIG5sfUnRBLDJyLmk7Z1thNGBQ1X+Sf28/VViXFzGbHFVnSbQQ = Received: (qmail 100260 invoked by alias); 18 Jun 2018 18:08:11 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 100244 invoked by uid 89); 18 Jun 2018 18:08:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_SHORT, KAM_STOCKGEN, SPF_PASS autolearn=ham version=3.3.2 spammy=dating, Got, 00000000 X-HELO: 9pmail.ess.barracuda.com Date: Mon, 18 Jun 2018 19:07:03 +0100 From: "Maciej W. Rozycki" To: CC: Alan Modra Subject: [PATCH 1/2] elf: Accept absolute (SHN_ABS) symbols whose value is zero [BZ #23307] In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 X-ClientProxiedBy: mipsdag02.mipstec.com (10.20.40.47) To mipsdag02.mipstec.com (10.20.40.47) X-BESS-ID: 1529345280-637138-14484-104370-1 X-BESS-VER: 2018.7-r1806151722 X-BESS-Apparent-Source-IP: 12.201.5.32 X-BESS-Envelope-From: Maciej.Rozycki@mips.com X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS59374 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-Orig-Rcpt: libc-alpha@sourceware.org,amodra@gmail.com X-BESS-BRTS-Status: 1 We have this condition in `check_match' (in elf/dl-lookup.c): if (__glibc_unlikely ((sym->st_value == 0 /* No value. */ && stt != STT_TLS) || ELF_MACHINE_SYM_NO_MATCH (sym) || (type_class & (sym->st_shndx == SHN_UNDEF)))) return NULL; which causes all !STT_TLS symbols whose value is zero to be silently ignored in lookup. This may make sense for regular symbols, however not for absolute (SHN_ABS) ones, where zero is like any value, there's no special meaning attached to it. Consequently legitimate programs fail, for example taking the `elf/tst-absolute-sym' test case, substituting 0 for 0x55aa in `elf/tst-absolute-sym-lib.lds' and then trying to run the resulting program we get this: $ .../elf/tst-absolute-sym .../elf/tst-absolute-sym: symbol lookup error: .../elf/tst-absolute-sym-lib.so: undefined symbol: absolute $ even though the symbol clearly is there: $ readelf --dyn-syms .../elf/tst-absolute-sym-lib.so | grep '\babsolute\b' 7: 00000000 0 NOTYPE GLOBAL DEFAULT ABS absolute $ The check for the zero value has been there since forever or commit d66e34cd4234/08162fa88891 ("Implemented runtime dynamic linker to support ELF shared libraries.") dating back to May 2nd 1995, and the problem triggers regardless of commit e7feec374c63 ("elf: Correct absolute (SHN_ABS) symbol run-time calculation [BZ #19818]") being present or not. Fix the issue then, by permitting `sym->st_value' to be 0 for SHN_ABS symbols in lookup. [BZ #23307] * elf/dl-lookup.c (check_match): Do not reject a symbol whose `st_value' is 0 if `st_shndx' is SHN_ABS. * elf/tst-absolute-zero.c: New file. * elf/tst-absolute-zero-lib.c: New file. * elf/tst-absolute-zero-lib.lds: New file. * elf/Makefile (tests): Add `tst-absolute-zero'. (modules-names): Add `tst-absolute-zero-lib'. (LDLIBS-tst-absolute-zero-lib.so): New variable. ($(objpfx)tst-absolute-zero-lib.so): New dependency. ($(objpfx)tst-absolute-zero: New dependency. --- Hi, This has been regression-tested successfully with the `mips-linux-gnu' target and the o32 ABI, big endianness. The new test case fails with an "undefined symbol" message where the fix included here to `check_match' has been removed whether commit e7feec374c63 ("elf: Correct absolute (SHN_ABS) symbol run-time calculation [BZ #19818]") is also present or not, and it passes with the fix applied. OK to apply? Maciej --- elf/Makefile | 8 ++++++-- elf/dl-lookup.c | 1 + elf/tst-absolute-zero-lib.c | 25 +++++++++++++++++++++++++ elf/tst-absolute-zero-lib.lds | 1 + elf/tst-absolute-zero.c | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 2 deletions(-) glibc-elf-shn-abs-zero.diff Index: glibc/elf/Makefile =================================================================== --- glibc.orig/elf/Makefile 2018-06-18 18:12:19.911942887 +0100 +++ glibc/elf/Makefile 2018-06-18 18:12:40.092259983 +0100 @@ -186,7 +186,7 @@ tests += restest1 preloadtest loadfail m tst-tlsalign tst-tlsalign-extern tst-nodelete-opened \ tst-nodelete2 tst-audit11 tst-audit12 tst-dlsym-error tst-noload \ tst-latepthread tst-tls-manydynamic tst-nodelete-dlclose \ - tst-debug1 tst-main1 tst-absolute-sym tst-big-note + tst-debug1 tst-main1 tst-absolute-sym tst-absolute-zero tst-big-note # reldep9 tests-internal += loadtest unload unload2 circleload1 \ neededtest neededtest2 neededtest3 neededtest4 \ @@ -273,7 +273,7 @@ modules-names = testobj1 testobj2 testob tst-latepthreadmod $(tst-tls-many-dynamic-modules) \ tst-nodelete-dlclose-dso tst-nodelete-dlclose-plugin \ tst-main1mod tst-libc_dlvsym-dso tst-absolute-sym-lib \ - tst-big-note-lib + tst-absolute-zero-lib tst-big-note-lib ifeq (yes,$(have-mtls-dialect-gnu2)) tests += tst-gnu2-tls1 @@ -1456,6 +1456,10 @@ LDLIBS-tst-absolute-sym-lib.so = tst-abs $(objpfx)tst-absolute-sym-lib.so: $(LDLIBS-tst-absolute-sym-lib.so) $(objpfx)tst-absolute-sym: $(objpfx)tst-absolute-sym-lib.so +LDLIBS-tst-absolute-zero-lib.so = tst-absolute-zero-lib.lds +$(objpfx)tst-absolute-zero-lib.so: $(LDLIBS-tst-absolute-zero-lib.so) +$(objpfx)tst-absolute-zero: $(objpfx)tst-absolute-zero-lib.so + # Both the main program and the DSO for tst-libc_dlvsym need to link # against libdl. $(objpfx)tst-libc_dlvsym: $(libdl) Index: glibc/elf/dl-lookup.c =================================================================== --- glibc.orig/elf/dl-lookup.c 2018-06-17 09:06:30.202407070 +0100 +++ glibc/elf/dl-lookup.c 2018-06-18 18:12:36.138114433 +0100 @@ -76,6 +76,7 @@ check_match (const char *const undef_nam unsigned int stt = ELFW(ST_TYPE) (sym->st_info); assert (ELF_RTYPE_CLASS_PLT == 1); if (__glibc_unlikely ((sym->st_value == 0 /* No value. */ + && sym->st_shndx != SHN_ABS && stt != STT_TLS) || ELF_MACHINE_SYM_NO_MATCH (sym) || (type_class & (sym->st_shndx == SHN_UNDEF)))) Index: glibc/elf/tst-absolute-zero-lib.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ glibc/elf/tst-absolute-zero-lib.c 2018-06-18 18:12:40.102324540 +0100 @@ -0,0 +1,25 @@ +/* BZ #xxxxx absolute zero symbol calculation shared module. + Copyright (C) 2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +extern char absolute; + +void * +get_absolute (void) +{ + return &absolute; +} Index: glibc/elf/tst-absolute-zero-lib.lds =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ glibc/elf/tst-absolute-zero-lib.lds 2018-06-18 18:12:40.129495568 +0100 @@ -0,0 +1 @@ +"absolute" = 0; Index: glibc/elf/tst-absolute-zero.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ glibc/elf/tst-absolute-zero.c 2018-06-18 18:12:40.147611912 +0100 @@ -0,0 +1,38 @@ +/* BZ #xxxxx absolute zero symbol calculation main executable. + Copyright (C) 2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +void *get_absolute (void); + +static int +do_test (void) +{ + void *ref = (void *) 0; + void *ptr; + + ptr = get_absolute (); + if (ptr != ref) + FAIL_EXIT1 ("Got %p, expected %p\n", ptr, ref); + + return 0; +} + +#include From patchwork Mon Jun 18 18:07:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 931126 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-93357-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mips.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="av/IosFX"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 418fGl4dfvz9ryk for ; Tue, 19 Jun 2018 04:08:31 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version:content-type; q=dns; s=default; b=NE13u YuMYvs58/hWeolzKZ7ukwTqbl2tF1JklXQDUcTvxVlqoZ4utq0UGixnGHX2I0jUl quQ6XATyPr2MgplT9E2cym96YB4tm+YX8CZiLVgNSwZFngR90Z3EPJ4Qgbb+gBDs P5W2H+NdQRtdjLJYOpYs3Aa8mM0PHcJKeDM/C4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version:content-type; s=default; bh=YW9lMvbMPg/ bzCpdplCfJ9EPTB4=; b=av/IosFXoz/kszFih1BDWfIhoeFItRnia14Qwogcxen dZUaPb1+vU9eOF8juzUZZXatj5TZ19bSM9svn1UNsjO1+glEgHkxAwaue9n9E8hs yg5U/lopJY7mZtYuu4eMFI31yVkYpsUMWxCQUGYo5yUfSgsEBiW4j75kaXayGhtc = Received: (qmail 101620 invoked by alias); 18 Jun 2018 18:08:25 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 101605 invoked by uid 89); 18 Jun 2018 18:08:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS autolearn=ham version=3.3.2 spammy=suffer, arguably X-HELO: 9pmail.ess.barracuda.com Date: Mon, 18 Jun 2018 19:07:50 +0100 From: "Maciej W. Rozycki" To: CC: Alan Modra Subject: [PATCH 2/2] libc-abis: Define ABSOLUTE ABI [BZ #19818][BZ #23307] In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 X-ClientProxiedBy: mipsdag02.mipstec.com (10.20.40.47) To mipsdag02.mipstec.com (10.20.40.47) X-BESS-ID: 1529345280-637138-14484-104370-2 X-BESS-VER: 2018.7-r1806151722 X-BESS-Apparent-Source-IP: 12.201.5.32 X-BESS-Envelope-From: Maciej.Rozycki@mips.com X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS59374 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-Orig-Rcpt: libc-alpha@sourceware.org,amodra@gmail.com X-BESS-BRTS-Status: 1 Define a new ABSOLUTE ABI for static linker's use with EI_ABIVERSION where correct absolute (SHN_ABS) symbol run-time load semantics is required. This way it can be ensured at static link time that a program or DSO will not suffer from previous semantics where absolute symbols were relocated by the base address, or symbols whose `st_value' is zero silently ignored leading to a confusing "undefined symbol" error message at load time, and instead "ELF file ABI version invalid" is printed with old dynamic loaders, making it clear that there is an ABI version incompatibility. [BZ #19818] [BZ #23307] * libc-abis (ABSOLUTE): New ABI. * sysdeps/unix/sysv/linux/mips/libc-abis (ABSOLUTE): New ABI. --- Hi, Arguably the "ELF file ABI version invalid" message could be improved too, e.g. I think "Unsupported ELF file ABI version" or even "Unsupported ELF file ABI version, please upgrade `ld.so'" would make it clearer what is going on. But that's a matter for a separate change. OK to apply? Maciej --- libc-abis | 2 ++ sysdeps/unix/sysv/linux/mips/libc-abis | 2 ++ 2 files changed, 4 insertions(+) glibc-abi-absolute.diff Index: glibc/libc-abis =================================================================== --- glibc.orig/libc-abis 2015-05-20 23:10:30.000000000 +0100 +++ glibc/libc-abis 2018-06-16 20:03:55.899525111 +0100 @@ -46,3 +46,5 @@ IFUNC powerpc64-*-linux* IFUNC powerpc-*-linux* IFUNC sparc64-*-linux* IFUNC sparc-*-linux* +# Absolute (SHN_ABS) symbols working correctly. +ABSOLUTE Index: glibc/sysdeps/unix/sysv/linux/mips/libc-abis =================================================================== --- glibc.orig/sysdeps/unix/sysv/linux/mips/libc-abis 2015-05-20 23:10:47.000000000 +0100 +++ glibc/sysdeps/unix/sysv/linux/mips/libc-abis 2018-06-16 20:04:29.888042455 +0100 @@ -14,3 +14,5 @@ UNIQUE # # MIPS O32 FP64 MIPS_O32_FP64 mips*-*-linux* +# Absolute (SHN_ABS) symbols working correctly. +ABSOLUTE