From patchwork Thu Mar 10 20:03:24 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: 1604102 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=f4Z8NUMd; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KF0Ph4s8wz9sGD for ; Fri, 11 Mar 2022 07:03:52 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7BBB13858422 for ; Thu, 10 Mar 2022 20:03:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7BBB13858422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1646942630; bh=9lgUrp2MCRh2Y8Kb3CUUu39+IIUKY0uAoEKjgexUiRY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=f4Z8NUMdT1f0D2lPtQqE8pRn8s9pnVWc4+iEu4ruezt8DW2VTUNMDTyC67F2VaDWS P4deCw/ECahk0rG0hRpPdBwnRDyviGVA+SjXEy/12qxVJZdNT/DPlFiKTc4Ekn5uS5 +qdK1ke73XycN5FogOZ6OB/DMtahXkz3MM8xwt5g= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 1FDCE3858D39 for ; Thu, 10 Mar 2022 20:03:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1FDCE3858D39 Received: by mail-pl1-x62c.google.com with SMTP id 9so5838982pll.6 for ; Thu, 10 Mar 2022 12:03:32 -0800 (PST) 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=9lgUrp2MCRh2Y8Kb3CUUu39+IIUKY0uAoEKjgexUiRY=; b=fnz/JJIxMK9I0liygEovrbmEg3kCzwRks0OfTBLng3a4xQWwxLZTR5aWWJuEJ6+S3B nDCfLVqT7Uo3J2VysnT7xF+0g6BbRzlN/hXatwlEeyTdGlBkjcXFqOIG7UdP41iZxT/v 7ilDlMydqhIYwggShHUIPrLcSNxgw7MLHA1v4smJnfqkz8qUOueNqLuGcaWP3Jd26UF5 6gq/g8QE5GmVi9Oq3zPg+d/Kt2ivJ07sZAJ9ZPZC2nwSBdrYT2STP8Hn3ybaW0Sm7O2q XLnxL8lKjnBAOkT5JgEaiT48HAC+xow4vO2mgVjnSbIwkkGpxYKM94hX1o+tLq9fIJpR K1NA== X-Gm-Message-State: AOAM532Rv5iVhtRL6b+PiaxLQl8hESg7HZtOe9G+XTL8bL+a/LT+W1Qn 4F89Mw3/8Nl0cMPfCt2wgNE= X-Google-Smtp-Source: ABdhPJwZCiHQHXszOB/KJzyaawypfFy02xypUhzpIbHs5rjsKIzAgGaSxAMpSGTK+4zm0+r69/AEmA== X-Received: by 2002:a17:902:bb81:b0:151:f154:2091 with SMTP id m1-20020a170902bb8100b00151f1542091mr6622578pls.150.1646942610919; Thu, 10 Mar 2022 12:03:30 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.58.38.221]) by smtp.gmail.com with ESMTPSA id k12-20020a635a4c000000b0037852b86236sm6137610pgm.75.2022.03.10.12.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 12:03:30 -0800 (PST) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 7F6B0C034D; Thu, 10 Mar 2022 12:03:29 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v6 0/5] Support DT_RELR relative relocation format Date: Thu, 10 Mar 2022 12:03:24 -0800 Message-Id: <20220310200329.1935466-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3020.7 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" Cc: Joseph Myers Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" 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. Reviewed-by: Fangrui Song --- 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 (4): elf: Properly handle zero DT_RELA/DT_REL values Add GLIBC_ABI_DT_RELR for DT_RELR support Add --disable-default-dt-relr NEWS: Mention DT_RELR support INSTALL | 6 ++++ Makeconfig | 19 +++++++++++++ Makerules | 2 ++ NEWS | 3 +- configure | 60 +++++++++++++++++++++++++++++++++++++++ configure.ac | 23 +++++++++++++++ elf/Makefile | 30 ++++++++++++++++++-- elf/Versions | 5 ++++ elf/dl-version.c | 33 ++++++++++++++++++++-- elf/dynamic-link.h | 40 +++++++++++++++++++++++++- elf/elf.h | 13 +++++++-- elf/get-dynamic-info.h | 19 +++++++++++-- elf/tst-relr-pie.c | 1 + elf/tst-relr.c | 64 ++++++++++++++++++++++++++++++++++++++++++ include/link.h | 6 ++++ manual/install.texi | 5 ++++ scripts/abilist.awk | 2 ++ scripts/versions.awk | 7 ++++- 18 files changed, 325 insertions(+), 13 deletions(-) create mode 100644 elf/tst-relr-pie.c create mode 100644 elf/tst-relr.c