From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by sourceware.org (Postfix) with ESMTPS id A19FB3835747 for ; Wed, 22 Jun 2022 03:08:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A19FB3835747 Received: by mail-pj1-x1033.google.com with SMTP id w24so6447437pjg.5 for ; Tue, 21 Jun 2022 20:08:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition; bh=oFAhi0Mz8fYVtDyeZyMS3GSl0S8XttJQjZahL3ASBkI=; b=XO8t5BTGncZ3yho90DRUk14VS2DsOFL+O5BYXujHJUKMKdcCFM8BnwRYcHV1u9mX6o 4J1pExY103VOWq5/Z84DzLDLx5D4cRsKBuUb3Eey31h41lXjFo9h7Ll+0N24JgtS6D9x oMn9xwX0YWMKR1m4hHfdSOJmHL6Y8gng3CD5G3hCg+doYHb9G13mMYEth7bslxeTAvD1 6+3KqPD0euIr7XlNmEoBQdNp8R4J5c3fIzGn7HDdPGBgc1ycDxltgZsPmT80CCbmXTh7 rlgRncddVfZJl+GrE5vFTgzKjUOcjohYkFpaquNDmPWe7dtxJPXqjwPyEsizvk+ZGO9u oY2g== X-Gm-Message-State: AJIora/xydyYDSO5h6+K7OQlNbuK+F5IkI8S6rfWgFfxKwGvF968+aYv XJ9/pF+MRL7gUUBHzyhAls07VzThpuU= X-Google-Smtp-Source: AGRyM1vA0ssuEe5VkfIO+nEhWH/uZBhCORSUvsrdxn12oLFfN3PWtqsLT2h2+MPsgp0J0fVd/x5yDA== X-Received: by 2002:a17:90b:180b:b0:1e3:2871:6be3 with SMTP id lw11-20020a17090b180b00b001e328716be3mr1276287pjb.85.1655867308431; Tue, 21 Jun 2022 20:08:28 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:bfc:958c:75d7:8c8]) by smtp.gmail.com with ESMTPSA id az9-20020a170902a58900b00167838b82e0sm11358725plb.205.2022.06.21.20.08.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 20:08:27 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 3245A1140976; Wed, 22 Jun 2022 12:38:25 +0930 (ACST) Date: Wed, 22 Jun 2022 12:38:25 +0930 From: Alan Modra To: binutils@sourceware.org Subject: PowerPC64: stub debug dump Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3036.3 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.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Jun 2022 03:08:31 -0000 powerpc64le-linux-ld is failing the assertion in ppc_build_one_stub, again apparently, which means a stub will overwrite the tail of a previous stub. The difficulty with debugging these issues is that it's not a problem with the stub that triggers the assertion, but the previous stub in that section. This patch keeps track of the last stub and adds a debug dump. Hopefully that will help. * elf64-ppc.c (enum _ppc64_sec_type): Add sec_stub. (struct _ppc64_elf_section_data): Add u.last_ent. (dump_previous_stub): New function. (ppc_build_one_stub): Keep track of previous stub, and dump it when finding an overlapping stub. diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index 6e2016c150d..c69b07435a1 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -1996,7 +1996,8 @@ static const struct bfd_elf_special_section ppc64_elf_special_sections[] = enum _ppc64_sec_type { sec_normal = 0, sec_opd = 1, - sec_toc = 2 + sec_toc = 2, + sec_stub = 3 }; struct _ppc64_elf_section_data @@ -2026,6 +2027,9 @@ struct _ppc64_elf_section_data /* And the relocation addend. */ bfd_vma *add; } toc; + + /* Stub debugging. */ + struct ppc_stub_hash_entry *last_ent; } u; enum _ppc64_sec_type sec_type:2; @@ -11636,6 +11640,47 @@ get_r2off (struct bfd_link_info *info, return r2off; } +/* Debug dump. */ + +static void +dump_previous_stub (struct ppc_stub_hash_entry *stub_entry) +{ + asection *stub_sec = stub_entry->group->stub_sec; + struct _ppc64_elf_section_data *esd = ppc64_elf_section_data (stub_sec); + if (esd->sec_type == sec_stub) + { + fprintf (stderr, "Previous stub: type = "); + switch (esd->u.last_ent->type.main) + { + case ppc_stub_none: fprintf (stderr, "none"); break; + case ppc_stub_long_branch: fprintf (stderr, "long_branch"); break; + case ppc_stub_plt_branch: fprintf (stderr, "plt_branch"); break; + case ppc_stub_plt_call: fprintf (stderr, "plt_call"); break; + case ppc_stub_global_entry: fprintf (stderr, "global_entry"); break; + case ppc_stub_save_res: fprintf (stderr, "save_res"); break; + default: fprintf (stderr, "???"); break; + } + switch (esd->u.last_ent->type.sub) + { + case ppc_stub_toc: fprintf (stderr, ":toc"); break; + case ppc_stub_notoc: fprintf (stderr, ":notoc"); break; + case ppc_stub_p9notoc: fprintf (stderr, ":p9notoc"); break; + default: fprintf (stderr, ":???"); break; + } + if (esd->u.last_ent->type.r2save) + fprintf (stderr, ":r2save"); + fprintf (stderr, "\nname = %s", esd->u.last_ent->root.string); + fprintf (stderr, "\noffset = %#lx:", esd->u.last_ent->stub_offset); + for (size_t i = esd->u.last_ent->stub_offset; + i < stub_entry->stub_offset; i += 4) + { + uint32_t *p = (uint32_t *) (stub_sec->contents + i); + fprintf (stderr, " %08x", *p); + } + fprintf (stderr, "\n"); + } +} + static bool ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) { @@ -11680,7 +11725,11 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) if (htab == NULL) return false; - BFD_ASSERT (stub_entry->stub_offset >= stub_entry->group->stub_sec->size); + if (stub_entry->stub_offset < stub_entry->group->stub_sec->size) + { + BFD_ASSERT (0); + dump_previous_stub (stub_entry); + } loc = stub_entry->group->stub_sec->contents + stub_entry->stub_offset; htab->stub_count[stub_entry->type.main - 1] += 1; @@ -12122,6 +12171,12 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) } stub_entry->group->stub_sec->size = stub_entry->stub_offset + (p - loc); + struct _ppc64_elf_section_data *esd + = ppc64_elf_section_data (stub_entry->group->stub_sec); + if (esd->sec_type == sec_normal) + esd->sec_type = sec_stub; + if (esd->sec_type == sec_stub) + esd->u.last_ent = stub_entry; if (htab->params->emit_stub_syms) { -- Alan Modra Australia Development Lab, IBM