From patchwork Tue Mar 16 10:11:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 42584 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5C61E385482C; Tue, 16 Mar 2021 10:11:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C61E385482C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1615889503; bh=3C+LnhxWo9XayqfpkFpBHbZeYgR49dt+boIMclQbD80=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=X09Ul0P5jVV/9sKVRQDVuqdQkp6wNhwlabZX+oP8cd8A3rKlrnpo/TRpom5p4clnE j/zZyXDqIl/2LBrrAJL046j88Xti7yi4cEnM5+b03jY7U68drN6lrNFdg4gNR6yCl1 gvo6pMiwG+KQvrNh2ykTo3sNoylCAmYfmtgfdw3w= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 104163858004 for ; Tue, 16 Mar 2021 10:11:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 104163858004 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-597-LHkfuaGkOPyUkQRHZV7RKw-1; Tue, 16 Mar 2021 06:11:39 -0400 X-MC-Unique: LHkfuaGkOPyUkQRHZV7RKw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 23524107ACCD for ; Tue, 16 Mar 2021 10:11:38 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-112-163.ams2.redhat.com [10.36.112.163]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7BD359CA0 for ; Tue, 16 Mar 2021 10:11:37 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH COMMITTED 2.33] elf: ld.so --help calls _dl_init_paths without a main map [BZ #27577] Date: Tue, 16 Mar 2021 11:11:45 +0100 Message-ID: <877dm7qufy.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" In this case, use the link map of the dynamic loader itself as a replacement. This is more than just a hack: if we ever support DT_RUNPATH/DT_RPATH for the dynamic loader, reporting it for ld.so --help (without further command line arguments) would be the right thing to do. Fixes commit 332421312576bd7095e70589154af99b124dd2d1 ("elf: Always set l in _dl_init_paths (bug 23462)"). (cherry picked from commit 4e6db99c665d3b82a70a3e218860ef087b1555b4) --- NEWS | 1 + elf/Makefile | 18 ++++++++++++++++-- elf/dl-load.c | 8 +++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index abc4206f58..55eed26d15 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,7 @@ The following bugs are resolved with this release: [23462] Static binary with dynamic string tokens ($LIB, $PLATFORM, $ORIGIN) crashes + [27577] elf/ld.so --help doesn't work Version 2.33 diff --git a/elf/Makefile b/elf/Makefile index 63da0ed64f..4b92f8b305 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -245,7 +245,7 @@ tests += $(tests-execstack-$(have-z-execstack)) ifeq ($(run-built-tests),yes) tests-special += $(objpfx)tst-leaks1-mem.out \ $(objpfx)tst-leaks1-static-mem.out $(objpfx)noload-mem.out \ - $(objpfx)tst-ldconfig-X.out + $(objpfx)tst-ldconfig-X.out $(objpfx)tst-rtld-help.out endif tlsmod17a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 tlsmod18a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 @@ -433,7 +433,8 @@ endif ifeq (yes,$(build-shared)) ifeq ($(run-built-tests),yes) tests-special += $(objpfx)tst-pathopt.out $(objpfx)tst-rtld-load-self.out \ - $(objpfx)tst-rtld-preload.out $(objpfx)argv0test.out + $(objpfx)tst-rtld-preload.out $(objpfx)argv0test.out \ + $(objpfx)tst-rtld-help.out endif tests-special += $(objpfx)check-textrel.out $(objpfx)check-execstack.out \ $(objpfx)check-wx-segment.out \ @@ -1908,3 +1909,16 @@ $(objpfx)list-tunables.out: tst-rtld-list-tunables.sh $(objpfx)ld.so $(evaluate-test) tst-dst-static-ENV = LD_LIBRARY_PATH='$$ORIGIN' + +$(objpfx)tst-rtld-help.out: $(objpfx)ld.so + $(test-wrapper) $(rtld-prefix) --help > $@; \ + status=$$?; \ + echo "info: ld.so exit status: $$status" >> $@; \ + if ! grep -q 'Legacy HWCAP subdirectories under library search path directories' $@; then \ + echo "error: missing subdirectory pattern" >> $@; \ + if test $$status -eq 0; then \ + status=1; \ + fi; \ + fi; \ + (exit $$status); \ + $(evaluate-test) diff --git a/elf/dl-load.c b/elf/dl-load.c index 376a2e64d6..2f760503c5 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -758,8 +758,14 @@ _dl_init_paths (const char *llp, const char *source, max_dirnamelen = SYSTEM_DIRS_MAX_LEN; *aelem = NULL; - /* This points to the map of the main object. */ + /* This points to the map of the main object. If there is no main + object (e.g., under --help, use the dynamic loader itself as a + stand-in. */ l = GL(dl_ns)[LM_ID_BASE]._ns_loaded; +#ifdef SHARED + if (l == NULL) + l = &GL (dl_rtld_map); +#endif assert (l->l_type != lt_loaded); if (l->l_info[DT_RUNPATH])