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