Message ID | 20240622100307.9498-1-xry111@xry111.site |
---|---|
Headers |
Return-Path: <binutils-bounces+patchwork=sourceware.org@sourceware.org> 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 834B93828934 for <patchwork@sourceware.org>; Sat, 22 Jun 2024 10:04:19 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 11F5A385DDCC for <binutils@sourceware.org>; Sat, 22 Jun 2024 10:03:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11F5A385DDCC Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 11F5A385DDCC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.208.246.23 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719050622; cv=none; b=ogRK52GPmPdFSu3VNiUKtkonHMfpwHJDJhA9ncs/Dj2x5oFwRTSxRbIjsxOWfFQin8dsrQ6d+aKDTmPugRJAq2sEDG1bl2nL6tzE/uDqGrDrsIeWvkhG1C7dQSRPqp2m3U3ewibrJmzjYp2EqAa2OaVs01P8ELZQ7niu1+4OD9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719050622; c=relaxed/simple; bh=55EYb8wjSnxzL3QMcfjPBwhxeBevpjXCvB6kURXKifE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=pxXM0FlRT1FjqpDL+T5ts/9IjBdEoeP/nT0/+RWfuiJlc3yhfc5VgKVwDaaqr3k7Cjv4ubwvXnMeghVjGok9LPDhY2WQq6NSpZ01it/XrD/ae2Z1NKCnXVP5DOItQ0ZUvEbtBWbz8DkwH+TfadTPWv3XTRGbanMPCFmVjv5pqSU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1719050619; bh=55EYb8wjSnxzL3QMcfjPBwhxeBevpjXCvB6kURXKifE=; h=From:To:Cc:Subject:Date:From; b=ZcfsRxrG6x+YLkOVSw7tV3Z116ytow9E9t7e3KVA7neFFIvAq/b2dBaiNhGZSnHW8 jO3mVwPKTbFsW8YGiNWkzFuTFxsuXuizd/EyAGOB32Up1sRuHCCOT19WTDWBPhtLW/ pBqy+ob0T1fwxF1zcqgNr6g+23e/HD4zhV/oSYGk= Received: from stargazer.. (unknown [113.200.174.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 0025D670ED; Sat, 22 Jun 2024 06:03:36 -0400 (EDT) From: Xi Ruoyao <xry111@xry111.site> To: binutils@sourceware.org Cc: mengqinggang@loongson.cn, Zhensong Liu <liuzhensong@loongson.cn>, i.swmail@xen0n.name, maskray@google.com, Szabolcs Nagy <szabolcs.nagy@arm.com>, Xi Ruoyao <xry111@xry111.site> Subject: [PATCH 0/5] LoongArch: Add DT_RELR (packing relative relocs) support Date: Sat, 22 Jun 2024 18:03:02 +0800 Message-ID: <20240622100307.9498-1-xry111@xry111.site> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, LIKELY_SPAM_FROM, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org |
Series |
LoongArch: Add DT_RELR (packing relative relocs) support
|
|
Message
Xi Ruoyao
June 22, 2024, 10:03 a.m. UTC
This series adds DT_RELR support for LoongArch. The leading 3 patches pave the way for DT_RELR: The first patch rejects turning R_LARCH_32 as a runtime reloc in ELFCLASS64, specifically R_LARCH_32 won't be turned to an R_LARCH_RELATIVE in ELFCLASS64 silently. This avoids an OOB write at runtime, and also simplifies the logic of DT_RELR implementation. The second patch fixes a long-standing bug causing some relocs missing (overwritten by another reloc, or written out of the .rela.dyn section) when multiple STT_GNU_IFUNC symbol is defined locally with different visibilities and we are linking a shared object. Without DT_RELR in most cases an R_LARCH_RELATIVE against __dso_handle is overwritten by an R_LARCH_JUMP_SLOT and the issue is mostly latent. But with DT_RELR the R_LARCH_RELATIVE is packed, and other relocs start to be overwritten, causing Glibc test failures. Thus the bug must be fixed before implementing DT_RELR. The third patch makes STV_PROTECTED function (STT_FUNC and STT_GNU_IFUNC) symbols referenced locally when linking a shared library. The other ports don't do this only because they rely on copy relocation and -mdirect-extern-access to remove unnecessary GOT access, and with -mdirect-extern-access locally referencing STV_PROTECTED functions can break pointer equality. This is not a problem for us because we don't and won't support copy relocation, and a programmer shouldn't use -mdirect-extern-access unless they can make sure no dynamic link is performed. So we can just make STV_PROTECTED functions referenced locally. This makes the code slightly faster, and also simplifies the logic of DT_RELR implementation. The fourth patch implements DT_RELR. The algorithm is based on the AArch64 implementation by Szabolcs and simplified because we don't have as many features as AArch64 (for example we don't have -z dynamic-undefined-weak). The linker relaxation pass is adapted to fix up the relative relocations to be packed when deleting bytes from the section where the relative relocations are against. The fifth patch adds tests for DT_RELR. Most tests are also ported from AArch64. Several tests were added to check the addend (link-time address) is correctly written into the relocated section (doing so is not strictly needed for RELA, but strictly needed for RELR). Besides these tests, the DT_RELR implementation is also tested by: - Running ld bootstrap test with -z pack-relative-relocs. The test has passed. (The patch adding this test isn't included in this series because it's not a target specific change and better reviewed separately.) - Building Glibc (which enables -z pack-relative-relocs by default if available) with the patched linker and run its test suite. All relative relocs in libc.so are packed and the test result is all clean. - Building patched Linux kernel with DT_RELR enabled. All relative relocs in vmlinux is packed, the kernel booted fine and it has been running fine for 24 hours. Xi Ruoyao (5): LoongArch: Reject R_LARCH_32 from becoming a runtime reloc in ELFCLASS64 LoongArch: Fix bad reloc with mixed visibility ifunc symbols in shared libraries LoongArch: Make protected function symbols local for -shared LoongArch: Add DT_RELR support LoongArch: Add DT_RELR tests bfd/elfnn-loongarch.c | 654 +++++++++++++++++- binutils/testsuite/lib/binutils-common.exp | 1 + ld/emulparams/elf64loongarch.sh | 1 + ld/testsuite/ld-loongarch-elf/ifunc-reloc.d | 19 + ld/testsuite/ld-loongarch-elf/ifunc-reloc.s | 55 ++ .../ld-loongarch-elf/ld-loongarch-elf.exp | 13 + .../ld-loongarch-elf/protected-func.d | 6 + .../ld-loongarch-elf/protected-func.s | 17 + .../ld-loongarch-elf/r_larch_32_elf64.d | 4 + .../ld-loongarch-elf/r_larch_32_elf64.s | 3 + ld/testsuite/ld-loongarch-elf/relr-addend.d | 11 + ld/testsuite/ld-loongarch-elf/relr-addend.s | 17 + ld/testsuite/ld-loongarch-elf/relr-align.d | 22 + ld/testsuite/ld-loongarch-elf/relr-align.s | 106 +++ ld/testsuite/ld-loongarch-elf/relr-data-pie.d | 18 + .../ld-loongarch-elf/relr-data-shared.d | 18 + ld/testsuite/ld-loongarch-elf/relr-data.s | 71 ++ .../ld-loongarch-elf/relr-discard-pie.d | 8 + .../ld-loongarch-elf/relr-discard-shared.d | 11 + ld/testsuite/ld-loongarch-elf/relr-discard.ld | 13 + ld/testsuite/ld-loongarch-elf/relr-discard.s | 61 ++ ld/testsuite/ld-loongarch-elf/relr-got-pie.d | 15 + .../ld-loongarch-elf/relr-got-shared.d | 15 + ld/testsuite/ld-loongarch-elf/relr-got.s | 27 + ld/testsuite/ld-loongarch-elf/relr-relocs.ld | 24 + ld/testsuite/ld-loongarch-elf/relr-text-pie.d | 14 + .../ld-loongarch-elf/relr-text-shared.d | 14 + ld/testsuite/ld-loongarch-elf/relr-text.s | 10 + 28 files changed, 1215 insertions(+), 33 deletions(-) create mode 100644 ld/testsuite/ld-loongarch-elf/ifunc-reloc.d create mode 100644 ld/testsuite/ld-loongarch-elf/ifunc-reloc.s create mode 100644 ld/testsuite/ld-loongarch-elf/protected-func.d create mode 100644 ld/testsuite/ld-loongarch-elf/protected-func.s create mode 100644 ld/testsuite/ld-loongarch-elf/r_larch_32_elf64.d create mode 100644 ld/testsuite/ld-loongarch-elf/r_larch_32_elf64.s create mode 100644 ld/testsuite/ld-loongarch-elf/relr-addend.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-addend.s create mode 100644 ld/testsuite/ld-loongarch-elf/relr-align.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-align.s create mode 100644 ld/testsuite/ld-loongarch-elf/relr-data-pie.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-data-shared.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-data.s create mode 100644 ld/testsuite/ld-loongarch-elf/relr-discard-pie.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-discard-shared.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-discard.ld create mode 100644 ld/testsuite/ld-loongarch-elf/relr-discard.s create mode 100644 ld/testsuite/ld-loongarch-elf/relr-got-pie.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-got-shared.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-got.s create mode 100644 ld/testsuite/ld-loongarch-elf/relr-relocs.ld create mode 100644 ld/testsuite/ld-loongarch-elf/relr-text-pie.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-text-shared.d create mode 100644 ld/testsuite/ld-loongarch-elf/relr-text.s