From patchwork Thu Mar 31 16:38:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 52540 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 C75D63857C50 for ; Thu, 31 Mar 2022 16:40:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C75D63857C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1648744849; bh=uOmWaRWobYu0EOjZ71fT7GvlyIJT4wmL3DokAM5gl2M=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=wcsLT0HJ/VOTnaKsL7a4x0YP5jAFs1f4TkdHt/+mTlw9Oy5jlBi9ibmDq0xDoWeuW ZbmaqPiT+31YePc1qF/2IGyIbYeQHpWWsLV26j89RosQpL30IHW2ptX3Cl4aegLck2 NUhzMsuvpzxDHdGTEqm7QqOLtjAz0HB18q8eSwq8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id B15873858D3C for ; Thu, 31 Mar 2022 16:39:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B15873858D3C Received: by mail-pg1-x52c.google.com with SMTP id s72so235764pgc.5 for ; Thu, 31 Mar 2022 09:39:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=uOmWaRWobYu0EOjZ71fT7GvlyIJT4wmL3DokAM5gl2M=; b=Mi6x1979wLnbTguD1xzZt47MNisDHnutDToM6O9xFPvgx+SHVL8xj6u5VRgxW0ahpf m2pmIx0VkariIjuX0C5cEVldCyNGBzXIPlcQ80Jb67xWB1IeGASQg+ecdQIXPVBcQShF /tW4jT66c6e/gM8yAzOTjBRLoqzAS3h7fL8OUsqVuXjEOJSxdlqeh4vAmQO17Rr5aUzK dIvnr2r/fjixBIGUfpow5EWdcPIeHagu3fUnXWzx4TCP2Z7WXsTiIbI8dRepv7EV/K5w cYCgfHSLx7LfroK01OwJvTxZSB/TPsBbxAcpskeUiAhIJwBUbdOebOEl4g6dxQOnlEiw Aeww== X-Gm-Message-State: AOAM530MAalhgaypDyrjlBvGYTECEgJmOm6Hbp7kVR8Mz7Ns4YkvpBJw X/wDT8pAIaqgAeMw83hl28A= X-Google-Smtp-Source: ABdhPJz0PCfmWpE/b649BB4sPBjmc+Cbd2Q3MNfb+Yz95uKcV8wiKXRjqLTxE/H7r1Ty5BaegxEVxQ== X-Received: by 2002:a63:4405:0:b0:382:173c:1b97 with SMTP id r5-20020a634405000000b00382173c1b97mr11280615pga.532.1648744741687; Thu, 31 Mar 2022 09:39:01 -0700 (PDT) Received: from gnu-tgl-3.localdomain (cpe-98-155-102-20.hawaii.res.rr.com. [98.155.102.20]) by smtp.gmail.com with ESMTPSA id f91-20020a17090a706400b001c7858a6879sm10241077pjk.12.2022.03.31.09.38.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 09:38:59 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 17475C0262; Thu, 31 Mar 2022 09:38:58 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v7 0/6] Support DT_RELR relative relocation format Date: Thu, 31 Mar 2022 09:38:52 -0700 Message-Id: <20220331163858.95516-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3021.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK autolearn=no 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: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Changes in v7: 1. Add GLIBC_ABI_DT_RELR support before adding DT_RELR support. 2. Update the DT_RELR NEWS entry. 3. Misc fixes. Changes in v6: 1. Move ELF_DYNAMIC_DO_RELR before ELF_DYNAMIC_DO_REL. Changes in v5: 1. Update NEWS entry with the linker option, -z pack-relative-relocs. 2. Remove elf/libc-abi-version.exp and use $(READELF) to check GLIBC_ABI_DT_RELR. Changes in v4: 1. Always enable GLIBC_ABI_DT_RELR check. 2. Use $(OBJDUMP) instead of $(NM) for GLIBC_ABI_DT_RELR check. Changes in v3: 1. Don't define SUPPORT_DT_RELR. 2. Enable DT_RELR in glibc shared libraries and position independent executables (PIE) automatically if linker supports -z pack-relative-relocs. Changes in v2: 1. Enable DT_RELR for all targets. 2. Issue an error if there is a DT_RELR entry without GLIBC_ABI_DT_RELR dependency nor GLIBC_PRIVATE definition. --- PIE and shared objects usually have many relative relocations. In 2017/2018, SHT_RELR/DT_RELR was proposed on https://groups.google.com/g/generic-abi/c/bX460iggiKg/m/GxjM0L-PBAAJ ("Proposal for a new section type SHT_RELR") and is a pre-standard. RELR usually takes 3% or smaller space than R_*_RELATIVE relocations. The virtual memory size of a mostly statically linked PIE is typically 5~10% smaller. Binutils 2.38 supports DT_RELR on x86 with the -z report-relative-reloc option. When DT_RELR is enabled, ld adds a GLIBC_ABI_DT_RELR symbol version dependency on libc.so to outputs. Issue an error if there is a DT_RELR entry without GLIBC_ABI_DT_RELR dependency nor GLIBC_PRIVATE definition. DT_RELR is enabled in glibc shared libraries and position independent executables (PIE) automatically if linker supports -z pack-relative-relocs. The DT_RELR usage in glibc can be disabled with --disable-default-dt-relr. Tested with binutils 2.38 on i686, x86-64 and x32. Fangrui Song (1): elf: Support DT_RELR relative relocation format [BZ #27924] H.J. Lu (5): elf: Define DT_RELR related macros and types Add GLIBC_ABI_DT_RELR for DT_RELR support elf: Properly handle zero DT_RELA/DT_REL values Add --disable-default-dt-relr NEWS: Mention DT_RELR support INSTALL | 6 ++++ Makeconfig | 19 ++++++++++++ Makerules | 2 ++ NEWS | 7 ++++- configure | 55 +++++++++++++++++++++++++++++++++++ configure.ac | 18 ++++++++++++ elf/Makefile | 43 ++++++++++++++++++++++++++-- elf/Versions | 5 ++++ elf/dl-version.c | 33 +++++++++++++++++++-- elf/dynamic-link.h | 40 +++++++++++++++++++++++++- elf/elf.h | 13 +++++++-- elf/get-dynamic-info.h | 25 ++++++++++++---- elf/tst-relr-pie.c | 1 + elf/tst-relr.c | 65 ++++++++++++++++++++++++++++++++++++++++++ include/link.h | 6 ++++ manual/install.texi | 5 ++++ scripts/abilist.awk | 2 ++ scripts/versions.awk | 7 ++++- 18 files changed, 337 insertions(+), 15 deletions(-) create mode 100644 elf/tst-relr-pie.c create mode 100644 elf/tst-relr.c