From patchwork Fri Feb 16 12:27:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 202106 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp474975dyb; Fri, 16 Feb 2024 04:28:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWW4BnSJ6FKipWdBrxC8D2hOX2+/Gdf+dsHCz9zKXBiFIPWAaTgdVtVvO5xzIOs6DVth/4NmutpyUwPJ5arav4PrWkQSw== X-Google-Smtp-Source: AGHT+IHjaTB8qUceCwXAYTFg6aaxrq7i65aQEM4phUlai93qOyFezyJPXhM5hQMXV0vWQpO0olFl X-Received: by 2002:a05:6830:1e28:b0:6e2:f0a9:1af5 with SMTP id t8-20020a0568301e2800b006e2f0a91af5mr4560324otr.23.1708086487645; Fri, 16 Feb 2024 04:28:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708086487; cv=pass; d=google.com; s=arc-20160816; b=zSm6oCOw5j2QIq6F4ZXXu6Vwiy+VXJ7hWx5ConwKAjZrjSBTlgKw+X0Dpb+wd67KlT BzyyQu1ucwHDUpPIIQgFsOocLd4IStiFDiddPP9FxnEPWU7ZFTt+MvEOKSz31qoxthXG P7CtZYtJiNYaRkumuBZyAfMDjTnXnZ7kIq16aNlyXzs9WxPjh2i8iXiGYod4jopyk46H esbuCP1M4GFE3hSyh7Um1hdtN6d3ISLGPfq/Kb/ts4j76khiGQsgOMQMjcvBno1wqiAX Y+VEWAgzOleV0Ese/4Itq4lZ70DIywDi68JeWJU6Xl67UnjJLtzpurWWEcDC/bXWVpts kPpQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=BBNBYAzi+eAf8xGvdlpTI17/11Y45GmAHHsLN2zNd/0=; fh=wepmanwWN1UO6TiiyWdkfcKdPxw0TShZkyL+IQB2vWU=; b=vONxWXnnptTVFucMRik3Sa93CyvMX0xiTQJ6YBumPkyvXJeQ6TLlNybtYRDlVO41qK Skw/LNXKMTZDbxHDe4iUdEKpecGngSVcPFILM7Eq5dxCgckLNAh0EKlUZQejcWm/rVIo 99m/eItkj6Qd1j7aTtE6EL9ApDLmRszX/OL42riSYTyzTd0FAy3cSa2o8/5uaeZR4ZjD 39rodESWvPVNfAWNKJqwJB7iiFcAWDD8Rio//5jbm4QXk73erE+ZXN3BIQBUZxGB7ikR Yv1Q9ySiPIjqNZZHDt3ux7TvtkiGStD99f0N1GwsTi0lsUoKBtvlKFjCvNhepE94am9E nCqA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MuNGqKS+; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id x18-20020ac87312000000b0042c184e12cfsi3663839qto.291.2024.02.16.04.28.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 04:28:07 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MuNGqKS+; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4F6F038582B9 for ; Fri, 16 Feb 2024 12:28:07 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 6A4F938582B7 for ; Fri, 16 Feb 2024 12:27:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A4F938582B7 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6A4F938582B7 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708086478; cv=none; b=dSzoEXAMCqLPvlILJ+CW2Ktzd3XB/+9iBsIaiBshr86EjdTLV4kNQAjVg9+/Y3bnMqZU5DjyrRlMtmCUQqdOdVPeC1tOar9N7p5pX1bRsZjtVKkRfvzbsFUEFXbOgIwy9j6+QcWsBive/gk9KJQhTiMuWH9l7PC7LHpfeYi0BZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708086478; c=relaxed/simple; bh=ZMnky9yNCytNsznnINki9j71OqYhC2TQGy4Pe1N50UA=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=ZiVkF1VfQS05UlgFj/pHQjozcGFFIOEzmA9S73rwlEhpoWpibKiavToRCWqB9QCkm0aCfl3FcHMYAWTFraEqiPjwgh9wQSTy0RQPRqB0WQ0gtEfa5pedtnnnD6UFn8zpyPXoaEVJmPxt4FPZkJ0Vaa6OavNg+7qx/mVB/KnwAXc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1d94b222a3aso18786045ad.2 for ; Fri, 16 Feb 2024 04:27:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708086475; x=1708691275; darn=sourceware.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=BBNBYAzi+eAf8xGvdlpTI17/11Y45GmAHHsLN2zNd/0=; b=MuNGqKS+G3WMTKYkOm0ab094ux3jTQ3IdKEsgoLoSbuq70MYmPISHxsqHY+RaLgO5Z qSjM/v7dRd2qheWTra0FyYePkqEet4ULzLVD49pupyqC9WHbV92COUu777NYnhGROWVV /pYkZCmdmV2VmfeyRncgbTfqfH/VO1GPajSqdSanbU5LjUzQzpLAFkHVfzWX2MSBWL0N tlgl279n30BVJntHRNaEjtiA575cs9a8VKvNKudqjOEjN8dfG1QaQAy9LETQz9GY75gF YSCp4B1TnXbhWTA1ULbV/56LYhSpBiaWITDQoAnEDmySl16UoN95LgZIPnBaCvCA8JSF ARmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708086475; x=1708691275; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BBNBYAzi+eAf8xGvdlpTI17/11Y45GmAHHsLN2zNd/0=; b=NrMYAdwdaIbiYm6AfjuepUMkSUEaD3VmOUBvXfuc7qM7Uv3rVV9OK5hPYJp4cfo8zK 4XlXsotLMmUCy9Vv7W7FRwUVADb1HafaveeHfPkOs9dlfnssNu/BcjmQMrAEoedhvs/j u9qwgKqa0r5j5DZFzOLa1vzbmjO8ds8SiFezcYX/6lYHG8NV1B8bOvHI6MIQPBhvmIlC ToLvud64etjBSIvvXnIp2WTSzTBKG0mxjh6MAMl/C3vcTI4UqIlaNPO75pmMqNugMkZT XAorYV5z7E6I4YT18wj90skHQtMAnIdDjFV1I7Nlv2HzduEXOYlBB0vMcGVGsmjDs2fO UZNQ== X-Gm-Message-State: AOJu0YxSYvH5RZ0x5519ilVJ22PL3lHNwVR+6bu6BgK/uMBH96ULbjwc bNMvxcRocFlhdD6OAWaWNAvDFCm0SjRtEQjR9KTnNWKZcLh4yLBY X-Received: by 2002:a17:902:c3c5:b0:1db:ab9c:d321 with SMTP id j5-20020a170902c3c500b001dbab9cd321mr923625plj.67.1708086474784; Fri, 16 Feb 2024 04:27:54 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:40d0:4922:dff1:9d41]) by smtp.gmail.com with ESMTPSA id 21-20020a170902ee5500b001db579a1124sm2899175plo.33.2024.02.16.04.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 04:27:54 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id B06F9114033C; Fri, 16 Feb 2024 22:57:51 +1030 (ACDT) Date: Fri, 16 Feb 2024 22:57:51 +1030 From: Alan Modra To: binutils@sourceware.org Cc: Sandra Loosemore , Andrew Jenner Subject: PR27597, nios: assertion fail in nios2_elf32_install_imm16 Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3033.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791058497280933537 X-GMAIL-MSGID: 1791058497280933537 The assertion in nios2_elf32_install_imm16 triggers when the PLT is twice the maximum allowable size for a branch from PLTn to reach .PLTresolve, and on no other call to nios2_elf32_install_imm16. That makes the assertion completely useless. We can handle a PIC PLT exceeding 0x8000 in size by bouncing branches that won't reach through previous branches. PR 27597 * elf32-nios2.c (nios2_elf32_install_imm16): Delete BFD_ASSERT. (nios2_build_one_stub): Don't bother masking value passed to nios2_elf32_install_imm16. (nios2_elf32_finish_dynamic_symbol): Likewise. Handle overflow of PLTn branch to .PLTresolve by bouncing through prior branches. diff --git a/bfd/elf32-nios2.c b/bfd/elf32-nios2.c index bebf4239958..7f61e2f8507 100644 --- a/bfd/elf32-nios2.c +++ b/bfd/elf32-nios2.c @@ -1878,8 +1878,6 @@ nios2_elf32_install_imm16 (asection *sec, bfd_vma offset, bfd_vma value) { bfd_vma word = bfd_get_32 (sec->owner, sec->contents + offset); - BFD_ASSERT (value <= 0xffff || ((bfd_signed_vma) value) >= -0xffff); - bfd_put_32 (sec->owner, word | ((value & 0xffff) << 6), sec->contents + offset); } @@ -2518,7 +2516,7 @@ nios2_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg ATTRIBUTE_U nios2_elf32_install_imm16 (stub_sec, hsh->stub_offset, hiadj (sym_value)); nios2_elf32_install_imm16 (stub_sec, hsh->stub_offset + 4, - (sym_value & 0xffff)); + sym_value); stub_sec->size += 12; break; default: @@ -4986,16 +4984,28 @@ nios2_elf32_finish_dynamic_symbol (bfd *output_bfd, /* Emit the PLT entry. */ if (bfd_link_pic (info)) { + bfd_vma br_offset; + nios2_elf32_install_data (splt, nios2_so_plt_entry, h->plt.offset, 3); plt_index = (h->plt.offset - 24) / 12; got_offset = (plt_index + 3) * 4; nios2_elf32_install_imm16 (splt, h->plt.offset, - hiadj(plt_index * 4)); + hiadj (plt_index * 4)); nios2_elf32_install_imm16 (splt, h->plt.offset + 4, - (plt_index * 4) & 0xffff); - nios2_elf32_install_imm16 (splt, h->plt.offset + 8, - 0xfff4 - h->plt.offset); + plt_index * 4); + br_offset = -(h->plt.offset + 12); + /* If this plt entry is too far away from the start of .plt + for the "br" to reach .PLTresolve, bounce through one or + more of the previous "br" instructions. */ + if (br_offset < (bfd_vma) -32768) + { + br_offset += 32768 / 12 * 12 - 4; + while (br_offset < (bfd_vma) -32768) + br_offset += 32768 / 12 * 12; + } + nios2_elf32_install_imm16 (splt, h->plt.offset + 8, br_offset); + got_address = (sgotplt->output_section->vma + sgotplt->output_offset + got_offset); @@ -5014,9 +5024,8 @@ nios2_elf32_finish_dynamic_symbol (bfd *output_bfd, nios2_elf32_install_data (splt, nios2_plt_entry, h->plt.offset, 3); got_address = (sgotplt->output_section->vma + sgotplt->output_offset + got_offset); - nios2_elf32_install_imm16 (splt, h->plt.offset, hiadj(got_address)); - nios2_elf32_install_imm16 (splt, h->plt.offset + 4, - got_address & 0xffff); + nios2_elf32_install_imm16 (splt, h->plt.offset, hiadj (got_address)); + nios2_elf32_install_imm16 (splt, h->plt.offset + 4, got_address); /* Fill in the entry in the global offset table. */ bfd_put_32 (output_bfd, @@ -5217,8 +5226,8 @@ nios2_elf32_finish_dynamic_sections (bfd *output_bfd, BFD_ASSERT ((got_pcrel & 0xf) == 0); nios2_elf32_install_data (splt, nios2_so_plt0_entry, 0, 6); nios2_elf32_install_imm16 (splt, 4, hiadj (got_pcrel)); - nios2_elf32_install_imm16 (splt, 12, got_pcrel & 0xffff); - nios2_elf32_install_imm16 (splt, 16, (got_pcrel + 4) & 0xffff); + nios2_elf32_install_imm16 (splt, 12, got_pcrel); + nios2_elf32_install_imm16 (splt, 16, got_pcrel + 4); } else { @@ -5240,14 +5249,13 @@ nios2_elf32_finish_dynamic_sections (bfd *output_bfd, nios2_elf32_install_data (splt, nios2_plt0_entry, res_size, 7); nios2_elf32_install_imm16 (splt, res_size, hiadj (res_start)); - nios2_elf32_install_imm16 (splt, res_size + 4, - res_start & 0xffff); + nios2_elf32_install_imm16 (splt, res_size + 4, res_start); nios2_elf32_install_imm16 (splt, res_size + 12, hiadj (got_address)); nios2_elf32_install_imm16 (splt, res_size + 16, - (got_address + 4) & 0xffff); + got_address + 4); nios2_elf32_install_imm16 (splt, res_size + 20, - (got_address + 8) & 0xffff); + got_address + 8); } } }