From patchwork Thu Jun 23 15:47:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 55335 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 D3FF3385043E for ; Thu, 23 Jun 2022 15:48:29 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id C2D163853571 for ; Thu, 23 Jun 2022 15:47:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C2D163853571 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pj1-x1036.google.com with SMTP id a11-20020a17090acb8b00b001eca0041455so3664483pju.1 for ; Thu, 23 Jun 2022 08:47:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JJQ7x4DIIe2HTGspXbW8C3stUWA2A9mJ6NLr/2ZppyM=; b=WqvyGeDY7uxb2XTjU9jSKu/SC0yepGpQ5culpsSXsE5hD1ERertrIplpAKS2NyJO6x k22AEH7+F/LPT6efbBfGs3y+P3Muq6AW7/KtqNvcg8r5Goa3IUF1bVWlq1Kit/Q494Z5 PPxl0atP9bEwMWKP8J37clQS62Gn0MmL0LAHfz2hibOsYQ+Ny2OToTg3768UBfTXOZyG 0Em/3w3g7NWzpKlIoSSZ1PQu6EsKVEv1SILqOnFu/ryJWR0guzKw/EFj1CSlocMf64/4 Zcb7bI01n40if3GKCvIb8q4orJ0Pecpsh6yMbaZFgiqxk6lJ7f78ag7Sh5LL0B+oatBH Zn5Q== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=JJQ7x4DIIe2HTGspXbW8C3stUWA2A9mJ6NLr/2ZppyM=; b=5TQoTwxqHkXfJKiHKknjHb5EWsaqNyXlbc7GNQTzFRHeknzhKYXySTOYSuCZdt/yWY sdbBMMO9yATposxij2y+G0RRVRjO3pP3j7+dt7jZAtHHEZIdNf7xcXYnQFBSAISqM0mq byBpI9MtuFnQnxvSLx+I1urc5MS0V6fk+U9bpOs5V6lmyXoIxJaZaVe+O8fNgTQbhfxN ueQok08wJX8D+nHSZCb6XaB/t6BL3qU/yNtcF7PXZtRtXbTR9Jn/34URrGTIMUz74PYC bwp/71YW+a32PPeWfGgAtk0E2LYoUf0+jQJWLkRsBSoCe7cjTWWjKcx3DgfZEyxjxwOd d4yA== X-Gm-Message-State: AJIora83oDJFo8Lc/6H72p4BVAplXMR03BhlNaC1/igLvhqXNhphLBgt N0y3EKQoPutRV3b/n9Ay5CjeRWGbRrRTfQ== X-Google-Smtp-Source: AGRyM1t0jyp4kb+vG2RBcQ2dVLjaUwL7QYNhQcaX6gGudhryc9v8TK0SkvdONWLXPl7fNuL+nZI6ew== X-Received: by 2002:a17:902:efc3:b0:16a:2a8d:3689 with SMTP id ja3-20020a170902efc300b0016a2a8d3689mr19254262plb.152.1655999238468; Thu, 23 Jun 2022 08:47:18 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id 20-20020a621614000000b0052551c1a413sm2453126pfw.204.2022.06.23.08.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jun 2022 08:47:18 -0700 (PDT) From: Kito Cheng To: libc-alpha@sourceware.org, kito.cheng@gmail.com, palmer@dabbelt.com, darius@bluespec.com Subject: [PATCH 1/2] riscv: Use elf_machine_rela_relative to handle R_RISCV_RELATIVE Date: Thu, 23 Jun 2022 23:47:04 +0800 Message-Id: <20220623154705.14416-2-kito.cheng@sifive.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220623154705.14416-1-kito.cheng@sifive.com> References: <20220623154705.14416-1-kito.cheng@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , Cc: Kito Cheng Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Minor clean-up, we need to change this part in following patch, clean this up to prevent we duplicated the change twice. Reviewed-by: Adhemerval Zanella Reviewed-by: Palmer Dabbelt Acked-by: Palmer Dabbelt --- sysdeps/riscv/dl-machine.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h index a60a452952..4bb858adaa 100644 --- a/sysdeps/riscv/dl-machine.h +++ b/sysdeps/riscv/dl-machine.h @@ -152,6 +152,14 @@ elf_machine_fixup_plt (struct link_map *map, lookup_t t, #ifdef RESOLVE_MAP +static inline void +__attribute__ ((always_inline)) +elf_machine_rela_relative (ElfW(Addr) l_addr, const ElfW(Rela) *reloc, + void *const reloc_addr) +{ + *(ElfW(Addr) *) reloc_addr = l_addr + reloc->r_addend; +} + /* Perform a relocation described by R_INFO at the location pointed to by RELOC_ADDR. SYM is the relocation symbol specified by R_INFO and MAP is the object containing the reloc. */ @@ -182,7 +190,7 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[], switch (r_type) { case R_RISCV_RELATIVE: - *addr_field = map->l_addr + reloc->r_addend; + elf_machine_rela_relative (map->l_addr, reloc, addr_field); break; case R_RISCV_JUMP_SLOT: case __WORDSIZE == 64 ? R_RISCV_64 : R_RISCV_32: @@ -258,14 +266,6 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[], } } -static inline void -__attribute__ ((always_inline)) -elf_machine_rela_relative (ElfW(Addr) l_addr, const ElfW(Rela) *reloc, - void *const reloc_addr) -{ - *(ElfW(Addr) *) reloc_addr = l_addr + reloc->r_addend; -} - static inline void __attribute__ ((always_inline)) elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[], From patchwork Thu Jun 23 15:47:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 55336 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 3E392385355E for ; Thu, 23 Jun 2022 15:48:51 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id 52DF0385085E for ; Thu, 23 Jun 2022 15:47:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 52DF0385085E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pl1-x633.google.com with SMTP id jh14so1082546plb.1 for ; Thu, 23 Jun 2022 08:47:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OU8TRtYlvv6w1+PH3eqp7rCKjNOrf2cXDnvlha/dXGs=; b=Lw3N1GhZKG7gGcLmDsNMp4DCjbRZmPQfSv3pojZ4+lbKR9Sm5xKLAJYIyJkgOwQeUp ZQdCYuePNw7W/i4EzRH7jd1PVj7cVDfHLlCcQHWJlysviogf2Z0E9Tp6HMrPiQCFqEyg wXR5ataNCvwE+kq8Ah7qcAFRMOaODwBvmkw+EoFs5iGFVL3DGh0LotNOt/t7dXfQX7wo ZPvWXVfiruJRUiHzRkAHL2nd8YQmXKSKjVIHWBI2PU873LVnepT+yPmYYF1SU5mzgrrr tttm5t7q1+/HkXBKiIJG8Wfp3s66AwDGevh8u7Ve6+/mcjYiFCf6CSZRu2lCYO35+oBx sG+g== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=OU8TRtYlvv6w1+PH3eqp7rCKjNOrf2cXDnvlha/dXGs=; b=6qSpisn9r4yd/8wXnqUa81IguldOidu+AyudeYid7E2Bo1M/KBYKDm7QijwIewTIvB vyawM81qKHnp3WBUN3D18ZC6Nq6fNXxj5xDcpXZJfUpTsGk0UYyzlM+S+82KaM0onhZ0 Uo1QwaFQ8RHFOgDX22zzdOKtuuVMP5W28fOoUqATbB8TrYZn+DVf57WT/SJKaJbmE23t B1LwUg8KZtV1O3uK8/h+DRNYwRuseEe2f6PA947zKOxVBi9QDowTGaDHDPz8eGUguDh8 EWWWi891ZHq343PlIwUgWUI4UYbYV6rBkX2nP0nfAHRX0FVJgMgHCCfRKWPWsVG1PFZA vBwQ== X-Gm-Message-State: AJIora96cXqLDg8Eb6VlYhgwbtz2KkY+02mi7PmzWSXKTFIqfjRH8LFe CPiN5JCGe8e6dFqFR0FuS5MaG55oKUOIvQ== X-Google-Smtp-Source: AGRyM1urEbf+jH7PPg+bQYLEH765iepirUfA0CHANhnvtm6LrqCskQDPcdvsY488c1yc8KKky2wIkQ== X-Received: by 2002:a17:902:aa4b:b0:164:11ad:af0f with SMTP id c11-20020a170902aa4b00b0016411adaf0fmr40061024plr.54.1655999241168; Thu, 23 Jun 2022 08:47:21 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id 20-20020a621614000000b0052551c1a413sm2453126pfw.204.2022.06.23.08.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jun 2022 08:47:20 -0700 (PDT) From: Kito Cheng To: libc-alpha@sourceware.org, kito.cheng@gmail.com, palmer@dabbelt.com, darius@bluespec.com Subject: [PATCH 2/2] riscv: Let compiler handle unaligned access when fixing R_RISCV_RELATIVE Date: Thu, 23 Jun 2022 23:47:05 +0800 Message-Id: <20220623154705.14416-3-kito.cheng@sifive.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220623154705.14416-1-kito.cheng@sifive.com> References: <20220623154705.14416-1-kito.cheng@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , Cc: Kito Cheng Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Explicitly say that might be unaligned, so that the compiler will generate appropriate code sequence for this relocation fix-up. Although RISC-V Linux will enable the unaligned memory access handler by default, that is quite expensive in general, letting the compiler solve this will be much cheaper - just break down that into several store byte instructions. ARM and MIPS has similar issue: ARM: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51456 MIPS: https://gcc.gnu.org/legacy-ml/gcc-help/2005-07/msg00325.html Acked-by: Palmer Dabbelt --- sysdeps/riscv/dl-machine.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h index 4bb858adaa..c83513e5b8 100644 --- a/sysdeps/riscv/dl-machine.h +++ b/sysdeps/riscv/dl-machine.h @@ -157,7 +157,14 @@ __attribute__ ((always_inline)) elf_machine_rela_relative (ElfW(Addr) l_addr, const ElfW(Rela) *reloc, void *const reloc_addr) { - *(ElfW(Addr) *) reloc_addr = l_addr + reloc->r_addend; + /* R_RISCV_RELATIVE might located in debug info section which might not + aligned to XLEN bytes. */ + struct unaligned + { + ElfW(Addr) x; + } __attribute__ ((packed, may_alias)); + /* Support relocations on unaligned offsets. */ + ((struct unaligned *) reloc_addr)->x = l_addr + reloc->r_addend; } /* Perform a relocation described by R_INFO at the location pointed to