From patchwork Sat Aug 7 05:58:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 44604 X-Patchwork-Delegate: szabolcs.nagy@arm.com 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 07CD13836037 for ; Sat, 7 Aug 2021 05:59:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 07CD13836037 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1628315959; bh=6fMHXoxVMNFYF2Vbdx//L7db6GXUn2bDDG2J7IPGN54=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ZcSoH3+CCtLk10k4Eks6hzskM++fiC9+8EfuoOMR8opMN9d0cgScAp8FKMiHJs94H RE8nsS67nD6Ryo+UCoy7qRVb7ku7hTAf4sXFPqoD2nNwcBvOud2+EAW43svc4CVYnr ZpUN+u0Q8wWNxnSTI/2SpSeFsyixAeMD1syXFtLI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by sourceware.org (Postfix) with ESMTPS id 694C83839837 for ; Sat, 7 Aug 2021 05:58:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 694C83839837 Received: by mail-yb1-xb4a.google.com with SMTP id 203-20020a250bd40000b02905933fff7091so4169572ybl.16 for ; Fri, 06 Aug 2021 22:58:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=6fMHXoxVMNFYF2Vbdx//L7db6GXUn2bDDG2J7IPGN54=; b=VnB2dC2WaXv7K/vBzRTKHw0nm2yXrvP3V0RHUo2aE2LbyaXeMoiBuIEI7WywA9DvyA Tz5SM63kWZCRHo837XTehGnGv8TZnAns/zgGjizXz3rEdMawkliYh5G5SP6FgYI8NSSM FLyQfZXOVSj5Vdd1ucfZdkepGYsWJKHVj5kOdTILj0EXZr1Z4IFLeE3+zF21IZ5alEQn IwD66OSIUpelHCdiBKQvQDTzH8IlBoVetkOCVk4iwh75nDH/mcDxS35Bj7j8Wj5U7P5n 9cHpW5CgYYC/Q3ikHPENYSihAUrg3W8pxid6EePdfFzMh6Hue+ahnijOJ583Qo+Nwz9q MjEw== X-Gm-Message-State: AOAM533iEHsHjI4GmAmRgNFx3Psf8i+mGs0t9t0BYGxWaCfzluqZf8Im XdO12SmEiUT4H+msmU+VKRHXNma/dVUMhnXtVFt9hqG6MK0BmpvZiRzZkBje8s3AzmRfzmtG9ZN 7HYPSAua5yXFeo1LIjVau2oyupKUr/haeIR10QAHLALH7KTAdFhTxNB8QwRbxx+tODNuO X-Google-Smtp-Source: ABdhPJyjIxmrvTm/xwVHOKebnGfCxuz/Xb0kjSWaaPtKPo+M1voFWJuepdBZbJlGdLJI+zLxsRK2DXETk/Sr X-Received: from maskray1.svl.corp.google.com ([2620:15c:2ce:200:6d69:ec51:238e:4db2]) (user=maskray job=sendgmr) by 2002:a25:d68c:: with SMTP id n134mr18816103ybg.67.1628315935171; Fri, 06 Aug 2021 22:58:55 -0700 (PDT) Date: Fri, 6 Aug 2021 22:58:44 -0700 Message-Id: <20210807055844.1855107-1-maskray@google.com> Mime-Version: 1.0 Subject: [PATCH] elf: Unconditionally use __ehdr_start To: libc-alpha@sourceware.org X-Spam-Status: No, score=-19.7 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Fangrui Song via Libc-alpha From: Fangrui Song Reply-To: Fangrui Song Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" We can consider __ehdr_start (from binutils 2.23 onwards) unconditionally supported, since configure.ac requires binutils>=2.25. The configure.ac check is related to an ia64 bug fixed by binutils 2.24. See https://sourceware.org/pipermail/libc-alpha/2014-August/053503.html Tested on x86_64-linux-gnu. Tested build-many-glibcs.py with aarch64-linux-gnu and s390x-linux-gnu. Reviewed-by: Szabolcs Nagy --- config.h.in | 3 --- configure | 52 ---------------------------------------------------- configure.ac | 34 ---------------------------------- elf/rtld.c | 13 ++++--------- 4 files changed, 4 insertions(+), 98 deletions(-) diff --git a/config.h.in b/config.h.in index 8b45a3a61d..0d92504f65 100644 --- a/config.h.in +++ b/config.h.in @@ -198,9 +198,6 @@ /* Define if CC supports attribute retain. */ #undef HAVE_GNU_RETAIN -/* Define if the linker defines __ehdr_start. */ -#undef HAVE_EHDR_START - /* Define to 1 if the assembler needs intermediate aliases to define multiple symbol versions for one symbol. */ #define SYMVER_NEEDS_ALIAS 0 diff --git a/configure b/configure index 9619c10991..7272fbf6ea 100755 --- a/configure +++ b/configure @@ -6636,58 +6636,6 @@ if test $libc_cv_predef_fortify_source = yes; then fi -# Some linkers on some architectures support __ehdr_start but with -# bugs. Make sure usage of it does not create relocations in the -# output (as the linker should resolve them all for us). -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the linker provides working __ehdr_start" >&5 -$as_echo_n "checking whether the linker provides working __ehdr_start... " >&6; } -if ${libc_cv_ehdr_start+:} false; then : - $as_echo_n "(cached) " >&6 -else - -old_CFLAGS="$CFLAGS" -old_LDFLAGS="$LDFLAGS" -old_LIBS="$LIBS" -CFLAGS="$CFLAGS -fPIC" -LDFLAGS="$LDFLAGS -nostdlib -nostartfiles -shared $no_ssp" -LIBS= -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -typedef struct { - char foo; - long val; -} Ehdr; -extern const Ehdr __ehdr_start __attribute__ ((visibility ("hidden"))); -long ehdr (void) { return __ehdr_start.val; } - -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - if $READELF -r conftest | grep -F __ehdr_start >/dev/null; then - libc_cv_ehdr_start=broken - else - libc_cv_ehdr_start=yes - fi -else - libc_cv_ehdr_start=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -CFLAGS="$old_CFLAGS" -LDFLAGS="$old_LDFLAGS" -LIBS="$old_LIBS" - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_ehdr_start" >&5 -$as_echo "$libc_cv_ehdr_start" >&6; } -if test "$libc_cv_ehdr_start" = yes; then - $as_echo "#define HAVE_EHDR_START 1" >>confdefs.h - -elif test "$libc_cv_ehdr_start" = broken; then - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: linker is broken -- you should upgrade" >&5 -$as_echo "$as_me: WARNING: linker is broken -- you should upgrade" >&2;} -fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the assembler requires one version per symbol" >&5 $as_echo_n "checking whether the assembler requires one version per symbol... " >&6; } if ${libc_cv_symver_needs_alias+:} false; then : diff --git a/configure.ac b/configure.ac index 34ecbba540..af47cd51e6 100644 --- a/configure.ac +++ b/configure.ac @@ -1662,40 +1662,6 @@ if test $libc_cv_predef_fortify_source = yes; then fi AC_SUBST(CPPUNDEFS) -# Some linkers on some architectures support __ehdr_start but with -# bugs. Make sure usage of it does not create relocations in the -# output (as the linker should resolve them all for us). -AC_CACHE_CHECK([whether the linker provides working __ehdr_start], - libc_cv_ehdr_start, [ -old_CFLAGS="$CFLAGS" -old_LDFLAGS="$LDFLAGS" -old_LIBS="$LIBS" -CFLAGS="$CFLAGS -fPIC" -LDFLAGS="$LDFLAGS -nostdlib -nostartfiles -shared $no_ssp" -LIBS= -AC_LINK_IFELSE([AC_LANG_SOURCE([ -typedef struct { - char foo; - long val; -} Ehdr; -extern const Ehdr __ehdr_start __attribute__ ((visibility ("hidden"))); -long ehdr (void) { return __ehdr_start.val; } -])], - [if $READELF -r conftest | grep -F __ehdr_start >/dev/null; then - libc_cv_ehdr_start=broken - else - libc_cv_ehdr_start=yes - fi], [libc_cv_ehdr_start=no]) -CFLAGS="$old_CFLAGS" -LDFLAGS="$old_LDFLAGS" -LIBS="$old_LIBS" -]) -if test "$libc_cv_ehdr_start" = yes; then - AC_DEFINE([HAVE_EHDR_START]) -elif test "$libc_cv_ehdr_start" = broken; then - AC_MSG_WARN([linker is broken -- you should upgrade]) -fi - dnl Starting with binutils 2.35, GAS can attach multiple symbol versions dnl to one symbol (PR 23840). AC_CACHE_CHECK(whether the assembler requires one version per symbol, diff --git a/elf/rtld.c b/elf/rtld.c index d733359eaf..878e6480f4 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -1684,21 +1684,16 @@ dl_main (const ElfW(Phdr) *phdr, if (GLRO(dl_use_load_bias) == (ElfW(Addr)) -2) GLRO(dl_use_load_bias) = main_map->l_addr == 0 ? -1 : 0; - /* Set up the program header information for the dynamic linker - itself. It is needed in the dl_iterate_phdr callbacks. */ - const ElfW(Ehdr) *rtld_ehdr; - /* Starting from binutils-2.23, the linker will define the magic symbol __ehdr_start to point to our own ELF header if it is visible in a segment that also includes the phdrs. If that's not available, we use the old method that assumes the beginning of the file is part of the lowest-addressed PT_LOAD segment. */ -#ifdef HAVE_EHDR_START extern const ElfW(Ehdr) __ehdr_start __attribute__ ((visibility ("hidden"))); - rtld_ehdr = &__ehdr_start; -#else - rtld_ehdr = (void *) GL(dl_rtld_map).l_map_start; -#endif + + /* Set up the program header information for the dynamic linker + itself. It is needed in the dl_iterate_phdr callbacks. */ + const ElfW(Ehdr) *rtld_ehdr = &__ehdr_start; assert (rtld_ehdr->e_ehsize == sizeof *rtld_ehdr); assert (rtld_ehdr->e_phentsize == sizeof (ElfW(Phdr)));