From patchwork Wed Jan 17 23:15:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 188970 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp10327dyb; Wed, 17 Jan 2024 15:16:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9OT8UzWs6BnAc+PirtGzcbrbHoFqKytHcPAASzoIdVSzgORxVrT5pjoEfkUwNjbG5dM7M X-Received: by 2002:a05:622a:9:b0:42a:b14:7f0 with SMTP id x9-20020a05622a000900b0042a0b1407f0mr2754436qtw.129.1705533378609; Wed, 17 Jan 2024 15:16:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705533378; cv=pass; d=google.com; s=arc-20160816; b=xWUxE1pwKOs28FGKvCvm27H2DNzQuruRRzPsuC44kG6PKQPSOSEF4sXQ7Bpac8JJWh /+KK6fb4nZtdxqYo2BbrAtHgBJJJ8rSHFFyqErwjV4H0NbEp/PL9vE5U663sDCfoUcTM RVB87LXD8xpfGVFy99PVi1eMW/gkN0gJRiP8MS7H+k8YrQCX/uUovTtSZTsjc5vYYX96 iOCEUzMUVnd0okQdZhwTLqtjS4RyNFgalMwBTmwjmJmkCjHfczHFuGZ+LTA8R6Rqwcrk +G6qIRP9ypQ0+crqXpWHCmugo7tAZSIgdYTPGzfFNgC4DSdvVknxBAOh1DG4hCgi2M56 GadA== 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:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=hp8kClrkg9pOCXS4V4wcEoj35RRZR9p2gSbDzfDd5gk=; fh=NLxAvL/bDfPg4AGOtxqvQlND8vazkZrNzKLY8+LAbBY=; b=a3ynjI/91s1ohwnrNB1UJMWn8fHLfPvKIVXp6ikbKY5CHl1EkIkchYLkRBqAlv9knP uROkSf7L5CPBVtLhbPQWJVBIaWjAyyWZ2BTQLTQzHnJT79iZJQtXoCTv1uVq3SHMUIM3 CgJY9b+ATtVjcSw4tO0OI2wf3NbAE4wU48KRl1KklaWKiounQEs6V8nrHPFDIS86AMTG 1FmkNVFeF/YB2bXUqSqQFXOUHvnzw2PnIhPKpD1hA4A5muoZMH8u5vV5V1OT/+74ykNC QwHO/oKyP3li69Dp0dxhXOb+GxiIlMfwjx2YslR8zGgkQaYI37C1gdJW2ovQ+Zl11UhJ oomw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZsBKHbZy; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id o11-20020a05622a044b00b00429c7fae4fasi12381424qtx.26.2024.01.17.15.16.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 15:16:18 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZsBKHbZy; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 444333858438 for ; Wed, 17 Jan 2024 23:16:18 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id B7BEF3858C62 for ; Wed, 17 Jan 2024 23:16:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B7BEF3858C62 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 B7BEF3858C62 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705533369; cv=none; b=vuXrzas3JKwpF4Q3yypZFuv8MJR6C7wPEkmhGf65U5WpZQgKflzWT1sSU5sFGl83/8lUc9Rt6xTze2iNSQqIDfwxTRKxuPpUibkZT+ON7Brv5mzhDU/WwKtRLzOpaCNg+1HxB1f4n+3JVn0h2vIp+Im/oz2cVjmbfF3QKyjJnc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705533369; c=relaxed/simple; bh=9hYHOP/4oOA8rqslwnOeWCf7/i0IJ8R3PXAiPYLJsO4=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=U3OPYVDsM218wJSR6Ki077T9dL0GvIWl5TFB757wTYgS7tlx97wR0szaVlvHAh1Z2SrkpJ5nRvC/SSsdnwsk1ejCWfPHOBavZajgyjzQzTRepWTLNPbRWjCBTdqynUjzkB6ERLWeVw5ToHOhD2IAJtkO3LLASI9HVeoViiVXbao= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6daf694b439so6411688b3a.1 for ; Wed, 17 Jan 2024 15:16:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705533363; x=1706138163; darn=sourceware.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=hp8kClrkg9pOCXS4V4wcEoj35RRZR9p2gSbDzfDd5gk=; b=ZsBKHbZyxM7+bWKjJzF2QnHNx4E/T0NLqBdZvYBhGRMg7l+j/HFwM9mIhp3ZjTJ8+y bv4OG/LQkdBbr/QObPt7zFh02CdqHVCFPzhb5fXrgrh+awoY9068zbhsAd36jlCJb/Xs xBJrZYMDJQoiLHGunV0fNNjPskQUQpKpCnupCM5RozWzN8jkVq4BWExa/MoW+QKIKFHb NDquvlkbxapdmrYuSnP3KFxzrF58O7AaXQDrxePEGIB9R7DJR4PbU3fhU6y0e3epkjbX mNQhh8qvK1Xj3DvUNoc8dW8NCIobaIxv+XmWkXBxMdmI3lA3JFFJC07rDQ+BQVtRYiuM i4ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705533363; x=1706138163; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hp8kClrkg9pOCXS4V4wcEoj35RRZR9p2gSbDzfDd5gk=; b=w+vOzm4j8wtpmMp4pQLwNL+3jUbd4qyyOVFUPS9gkznWynK4us5Ca/b7zITr3c2ZES 8dEai55vghuiRgEtcuAmrpjQYnn37IQhrYhjOTT6YwTNJuZVNJP7JvdECrOxG7Pppf/t 9TsE8+VBppsVOjbGTkicW3JYD5o6Zn5fZE34aSuEjdqDrcsRklUmno3MrUX6jB0bu4QM FaXQiUqaoDoCuliOTT544jGsV5InMOsziNpYg9Z3HbMsJAZquTQ05IwBotBLv80xfqfR s7UqtmaTnvokXmowv9lXug2fVhmq9oAOaa4YkIWtzvwmDjxONOn+FDaJexitSaoJ9IK5 ugcg== X-Gm-Message-State: AOJu0Yz1hucv44zDJg1AWN9bV6m8ViOMvj+l10wvruo2GIbxrl/dRyp4 u9D0MUfAZtbb2LjfwkUtyoFmK8lOtEY= X-Received: by 2002:aa7:9e4e:0:b0:6d9:aa4c:db9b with SMTP id z14-20020aa79e4e000000b006d9aa4cdb9bmr5779688pfq.10.1705533362817; Wed, 17 Jan 2024 15:16:02 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:e216:a5f7:2a14:6d20]) by smtp.gmail.com with ESMTPSA id fd30-20020a056a002e9e00b006d9c0dd1b26sm2049233pfb.15.2024.01.17.15.16.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 15:16:02 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id C81CA1140198; Thu, 18 Jan 2024 09:45:59 +1030 (ACDT) Date: Thu, 18 Jan 2024 09:45:59 +1030 From: Alan Modra To: binutils@sourceware.org Subject: PR30824 internal error with -z pack-relative-relocs Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3033.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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: 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: 1788381368462212901 X-GMAIL-MSGID: 1788381368462212901 This corrects a counting problem, where prior to relocate_section relr encoded relative relocs were allowed when it was known they were on even boundaries, but relocate_section can only put relative relocs (non-relr) on eight byte boundaries. Pushed to mainline and 2.42 branch. PR 30824 * elf64-ppc.c (RELR_ALIGN): Define, use throughout. (maybe_relr): New function, use throughout. diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index 3d1fdd3a7c9..e95f9fbe651 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -4749,6 +4749,24 @@ is_8byte_reloc (enum elf_ppc64_reloc_type r_type) || r_type == R_PPC64_PLTCALL); } +/* The RELR encoding doesn't allow odd addresses, so RELR_ALIGN must + be at least 1. R_PPC64_RELATIVE relocs require alignment of 2**3. + We use 3 here to avoid complexity in relocate_section, where for a + value of 1 we'd need to test for not just an output RELATIVE reloc + near the call to maybe_relr but also UADDR64 and some conditions on + the symbol. See PR30824. */ +#define RELR_ALIGN 3 + +static bool +maybe_relr (enum elf_ppc64_reloc_type r_type, + const Elf_Internal_Rela *rel, + const asection *sec) +{ + return ((r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC) + && (rel->r_offset & ((1 << RELR_ALIGN) - 1)) == 0 + && sec->alignment_power >= RELR_ALIGN); +} + /* Like bfd_reloc_offset_in_range but without a howto. Return true iff a field of SIZE bytes at OFFSET is within SEC limits. */ @@ -5401,9 +5419,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, p->count += 1; if (!must_be_dyn_reloc (info, r_type)) p->pc_count += 1; - if ((r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC) - && rel->r_offset % 2 == 0 - && sec->alignment_power != 0) + if (maybe_relr (r_type, rel, sec)) p->rel_count += 1; } else @@ -5438,9 +5454,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, p->ifunc = is_ifunc; } p->count += 1; - if ((r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC) - && rel->r_offset % 2 == 0 - && sec->alignment_power != 0) + if (maybe_relr (r_type, rel, sec)) p->rel_count += 1; } } @@ -7291,9 +7305,7 @@ dec_dynrel_count (const Elf_Internal_Rela *rel, { if (!must_be_dyn_reloc (info, r_type)) p->pc_count -= 1; - if ((r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC) - && rel->r_offset % 2 == 0 - && sec->alignment_power != 0) + if (maybe_relr (r_type, rel, sec)) p->rel_count -= 1; p->count -= 1; if (p->count == 0) @@ -7326,9 +7338,7 @@ dec_dynrel_count (const Elf_Internal_Rela *rel, { if (p->sec == sec && p->ifunc == is_ifunc) { - if ((r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC) - && rel->r_offset % 2 == 0 - && sec->alignment_power != 0) + if (maybe_relr (r_type, rel, sec)) p->rel_count -= 1; p->count -= 1; if (p->count == 0) @@ -13884,6 +13894,9 @@ ppc64_elf_size_stubs (struct bfd_link_info *info) switch (r_type) { default: + if (info->enable_dt_relr + && maybe_relr (r_type, irela, section)) + break; continue; case R_PPC64_REL24: @@ -13895,14 +13908,6 @@ ppc64_elf_size_stubs (struct bfd_link_info *info) if ((section->flags & SEC_CODE) != 0) break; continue; - - case R_PPC64_ADDR64: - case R_PPC64_TOC: - if (info->enable_dt_relr - && irela->r_offset % 2 == 0 - && section->alignment_power != 0) - break; - continue; } /* Now determine the call target, its name, value, @@ -15285,7 +15290,7 @@ ppc64_elf_build_stubs (struct bfd_link_info *info, while (i < htab->relr_count) { bfd_vma base = relr_addr[i]; - BFD_ASSERT (base % 2 == 0); + BFD_ASSERT ((base & ((1 << RELR_ALIGN) - 1)) == 0); bfd_put_64 (htab->elf.dynobj, base, loc); loc += 8; i++; @@ -17517,9 +17522,8 @@ ppc64_elf_relocate_section (bfd *output_bfd, if (!(info->enable_dt_relr && ELF64_R_TYPE (outrel.r_info) == R_PPC64_RELATIVE - && rel->r_offset % 2 == 0 - && input_section->alignment_power != 0 - && ELF64_R_TYPE (orig_rel.r_info) != R_PPC64_UADDR64)) + && maybe_relr (ELF64_R_TYPE (orig_rel.r_info), + rel, input_section))) { sreloc = elf_section_data (input_section)->sreloc; if (h != NULL