From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by sourceware.org (Postfix) with ESMTPS id BDCE43858C5E for ; Tue, 30 Jan 2024 23:39:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BDCE43858C5E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BDCE43858C5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4860:4864:20::30 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706657946; cv=none; b=bxqUST6O1YhXvYoSm0SfPKRHC77QH8tAtBYVCL3+nLV8HiBZrMJy4yv7czehC9ZqbLXo+vZ1U3AZ/Au/KoMIWOfaXz49SLWOGJYESRpKjGU81BLDAwqLE+qRPni97jo1+gbJ/EoBt/bpiZPkkDhziKru4BxnLOCV/DkHpfX4dfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706657946; c=relaxed/simple; bh=buTTSAHIXzDZie3bzK8AApGuF0m5XEXmzoATGlQi/7g=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=s7dYKjPGcfV8+4iLIjPkLyGlitFmowbxhNm4nLWz8aJYLwcvfRcgXVD09kUMrzuadAcRAUN4ujuJNDNa7E/sIXc9TiwOEgU80CCUoowrVDiCDv1aoQWc4kWlpMsjq9kWPoeAHlh+TvnTbyUHF0Vz7Vsn/tjDYOUi76Ac5G1fH3k= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-21499c9650cso1876383fac.1 for ; Tue, 30 Jan 2024 15:39:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706657942; x=1707262742; darn=sourceware.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=4YYArXRCKBRbcwhy3FFx0//tH4QwEAHC7kuWygdjR/k=; b=D0wKeAXt9h+c5Pfmtp0qQBGqKi6rNx/AzdvChEVGz6Q4m0zpVxzmSCFsMP1CIx0P9Z juN/bNRCxFs1xP7TbMsngg219vpsGodRj/1hQcOVB5fSLkHMXs3pvYesmP8Vc5+l71TQ 7iIBCOf7AMWtGgNkonQaXcXaoFCVUQ0nWHGxH8RfAKae6+yp5XnO8RH4qYh2XQSVElDH P4ZClWiFHjWqvty3XqOxl6SaZBqg7FHkIc/F94eZuqSCgKmKYDZj7LEBCos2gJq1zOPX I1HtXW/2SDQpNcqfCQzndaVupdDCFBQxySLGy1To5zXxxKW+PVxbL5YwWHXxKn6D1NUw p0Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706657942; x=1707262742; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4YYArXRCKBRbcwhy3FFx0//tH4QwEAHC7kuWygdjR/k=; b=nrR+2ONG4PfOCH/+LiQmxcZQ3bR/axctwr1UcaHFQgIqUUX/goF/+j2AthLrO7oMqY tO5hC/OYW+GwdaQZKh5KbWVPBZRVqSp/BLCzflsxh0hGKDHuZ2Z36YK0bo9/Mq/F2ZOq /YXeDN4bUU11+ELZ3nGUzxwnjECiqol41pqwzZoQYaDVkXF5edHgDaBfhGbDiBjCw7Iz vsMr3bCaYV21z0PB/22OTCj3scUgeHb5ivceVoNXHf5RS8ykqA6/0wuqmBd9JJQhj6Qs EujmON/AujSSsdOG9XzGgNshkNv30kOe7IG1RGsg9DMPYUKd8sNTSdwGoxbJ8EeP8b/u Tzhw== X-Gm-Message-State: AOJu0YwgFSDU6E4GTjSs41hwBh7eQmeGMaddio3Q5/b7hBYUBRnJ5d5X OWPbCF1eBvxZ+xY4/x91xGM44vJ+HvG1y8B618O2yiw1G4YE72i3Sw7wCt5e4WMSV656b81kh5/ GKl5JjyyTEeqlCJA0FOCFkonrQipDLfkHA/WxDQ== X-Google-Smtp-Source: AGHT+IEcQPXybd1Ua+oZ14WlLVel6Qx28R/QjT0z1k+rqZ/vGCsyDuwhjTuQKVbgMutD+CrPqYYzkrHgF51aQ39dJks= X-Received: by 2002:a05:6870:32d2:b0:214:85d0:b912 with SMTP id r18-20020a05687032d200b0021485d0b912mr198546oac.14.1706657941836; Tue, 30 Jan 2024 15:39:01 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Nelson Chu Date: Wed, 31 Jan 2024 07:38:50 +0800 Message-ID: Subject: Re: [PATCH] bfd: check for truncation with R_RISCV_32 relocations To: Joseph Faulls Cc: "binutils@sourceware.org" , "palmer@rivosinc.com" Content-Type: multipart/alternative; boundary="000000000000606ad4061032442e" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,HTML_MESSAGE,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 List-Id: --000000000000606ad4061032442e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable It's been a long time so I forgot the details, if we add this overflow checks for ADD/SUB/SET relocations, then the regression will fail since we may generate 32-bit debug information for the rv64 toolchain in gcc, and that's why we always silent the truncated error. Not sure if that also fails for now, we need to make sure of that at first. Nelson On Wed, Jan 31, 2024 at 2:21=E2=80=AFAM Joseph Faulls wrote: > Relevant bug report: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31= 318 > > > > With high addresses, these relocations can be truncated. In these cases, > > throw an error instead of silently truncating. > > > > bfd/ > > * elfnn-riscv.c (perform_relocation): Check for overflow. > > > > ld/ > > * ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated. > > * ld/testsuite/ld-riscv-elf/data-reloc-rv64-abs32-truncation.d: > > New test case. > > --- > > bfd/elfnn-riscv.c | 3 +++ > > ld/testsuite/ld-riscv-elf/data-reloc-rv64-abs32-truncation.d | 4 ++++ > > ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp | 1 + > > 3 files changed, 8 insertions(+) > > create mode 100644 > ld/testsuite/ld-riscv-elf/data-reloc-rv64-abs32-truncation.d > > > > diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c > > index 8b27e3b8d6a..975b40e5f53 100644 > > --- a/bfd/elfnn-riscv.c > > +++ b/bfd/elfnn-riscv.c > > @@ -1865,6 +1865,9 @@ perform_relocation (const reloc_howto_type *howto, > > } > > > > case R_RISCV_32: > > + if (value & ~howto->dst_mask) > > + return bfd_reloc_overflow; > > + break; > > case R_RISCV_64: > > case R_RISCV_ADD8: > > case R_RISCV_ADD16: > > diff --git a/ld/testsuite/ld-riscv-elf/data-reloc-rv64-abs32-truncation.d > b/ld/testsuite/ld-riscv-elf/data-reloc-rv64-abs32-truncation.d > > new file mode 100644 > > index 00000000000..925d1cdb662 > > --- /dev/null > > +++ b/ld/testsuite/ld-riscv-elf/data-reloc-rv64-abs32-truncation.d > > @@ -0,0 +1,4 @@ > > +#source: data-reloc.s > > +#as: -march=3Drv64i -mabi=3Dlp64 -defsym __abs__=3D1 > > +#ld: -m[riscv_choose_lp64_emul] -Ttext 0x8000 --defsym _start=3D0x0 > --defsym abs=3D0xc00000100 --defsym abs_local=3D0x200 > > +#error: .*relocation truncated to fit: R_RISCV_32 > > diff --git a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp > b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp > > index 7e1281d826b..5a4d8728366 100644 > > --- a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp > > +++ b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp > > @@ -175,6 +175,7 @@ if [istarget "riscv*-*-*"] { > > run_dump_test "uleb128" > > run_dump_test "pr31179" > > run_dump_test "pr31179-r" > > + run_dump_test "data-reloc-rv64-abs32-truncation" > > run_ld_link_tests [list \ > > [list "Weak reference 32" "-T weakref.ld > -m[riscv_choose_ilp32_emul]" "" \ > > "-march=3Drv32i -mabi=3Dilp32" {weakref32.s} \ > > -- > > 2 > --000000000000606ad4061032442e--