From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by sourceware.org (Postfix) with ESMTPS id 2F4C038582BD for ; Tue, 28 Jun 2022 03:30:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2F4C038582BD Received: by mail-pg1-x52e.google.com with SMTP id v126so6759557pgv.11 for ; Mon, 27 Jun 2022 20:30:54 -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=4/6J5+67OVRuptE2m+lG3aay3aiKmOiOEjjnYxuuL7c=; b=j5NAtnj7hNuwLIM0kdow6nWaelwkWKLp0YfbxHwQG9oq0yMVtdwMma9gIZkb2l0Px8 uAd617NWnPOKEQ4mZkx3WvFBYBp0UKimNJ24TYHAO+7pJvk6vU/r2rPjB9FjXs7oSRKu FN2x0JaRtGlQYGqCVve5zLwQy/th7hFZeJSnD3c9xYXqGT5BstKCY1jn25uSIPn+yAS6 sAe9iQMCEPRpSs8sBhuVefKNj5Z3lRlOSLI/8Lm1HWQmHPLjv1zFsNQxdubw+WM0xtwk C5swzdiH9bdm04CgeVwZ80JPs/IHVA/7BPhX79tGbyyuHfNLNq9VyvTAa36qJQrfT+2V 1LtA== X-Gm-Message-State: AJIora8WHCNUFjvFbnsXGCs/6cm9fmNxc0OSfxvoV5WFlsIJ3kYT1maJ JhPVk7hZWxqy9XbT8R23uDaZ6pgZNE8= X-Google-Smtp-Source: AGRyM1uyyRYUUxKqbkj+tSphj1IHykmeivf1qPXoX2Jtdb7n1NJE8BTIJ9P0fF5SESjvhQKxKBIgyg== X-Received: by 2002:a05:6a00:1a91:b0:525:b9ea:feac with SMTP id e17-20020a056a001a9100b00525b9eafeacmr1266430pfv.13.1656387052912; Mon, 27 Jun 2022 20:30:52 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:ff85:b5f6:bac4:e58f]) by smtp.gmail.com with ESMTPSA id q14-20020a63d60e000000b0040cf5cd74cdsm7725850pgg.19.2022.06.27.20.30.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 20:30:52 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id C52441140138; Tue, 28 Jun 2022 13:00:49 +0930 (ACST) Date: Tue, 28 Jun 2022 13:00:49 +0930 From: Alan Modra To: binutils@sourceware.org Subject: PowerPC64: plt_stub_pad 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: Tue, 28 Jun 2022 03:30:55 -0000 Another tidy. * elf64-ppc.c (plt_stub_pad): Simplify parameters and untangle from plt_stub_size. (ppc_size_one_stub): Call plt_stub_size before plt_stub_pad to provide size. Recalculate size if it might change. diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index 9491a0f9e66..202c941515d 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -11183,29 +11183,22 @@ plt_stub_size (struct ppc_link_hash_table *htab, boundaries if we align, then return the padding needed to do so. */ static inline unsigned int -plt_stub_pad (struct ppc_link_hash_table *htab, - struct ppc_stub_hash_entry *stub_entry, +plt_stub_pad (int plt_stub_align, bfd_vma stub_off, - bfd_vma plt_off, - unsigned int odd) + unsigned int stub_size) { - int stub_align; - unsigned stub_size; + unsigned int stub_align; - if (htab->params->plt_stub_align >= 0) + if (plt_stub_align >= 0) + stub_align = 1u << plt_stub_align; + else { - stub_align = 1 << htab->params->plt_stub_align; - if ((stub_off & (stub_align - 1)) != 0) - return stub_align - (stub_off & (stub_align - 1)); - return 0; + stub_align = 1u << -plt_stub_align; + if (((stub_off + stub_size - 1) & -stub_align) - (stub_off & -stub_align) + <= ((stub_size - 1) & -stub_align)) + return 0; } - - stub_align = 1 << -htab->params->plt_stub_align; - stub_size = plt_stub_size (htab, stub_entry, plt_off, odd); - if (((stub_off + stub_size - 1) & -stub_align) - (stub_off & -stub_align) - > ((stub_size - 1) & -stub_align)) - return stub_align - (stub_off & (stub_align - 1)); - return 0; + return stub_align - 1 - ((stub_off - 1) & (stub_align - 1)); } /* Build a toc using .plt call stub. */ @@ -12245,7 +12238,7 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) struct ppc_link_hash_table *htab; asection *plt; bfd_vma targ, off, r2off; - unsigned int size, extra, lr_used, delta, odd; + unsigned int size, pad, extra, lr_used, delta, odd; bfd_vma stub_offset; /* Massage our args to the form they really have. */ @@ -12504,13 +12497,14 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) odd = off & 4; off = targ - off; - if (htab->params->plt_stub_align != 0) + size = plt_stub_size (htab, stub_entry, off, odd); + pad = plt_stub_pad (htab->params->plt_stub_align, stub_offset, size); + if (pad != 0) { - unsigned pad = plt_stub_pad (htab, stub_entry, stub_offset, off, odd); - stub_offset += pad; off -= pad; odd ^= pad & 4; + size = plt_stub_size (htab, stub_entry, off, odd); } if (info->emitrelocations) @@ -12524,8 +12518,6 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) stub_entry->group->stub_sec->flags |= SEC_RELOC; } - size = plt_stub_size (htab, stub_entry, off, odd); - if (stub_entry->type.sub != ppc_stub_notoc) { /* After the bcl, lr has been modified so we need to emit @@ -12578,12 +12570,9 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) + htab->sec_info[stub_entry->group->link_sec->id].toc_off); off = targ - off; - if (htab->params->plt_stub_align != 0) - { - unsigned pad = plt_stub_pad (htab, stub_entry, stub_offset, off, 0); - - stub_offset += pad; - } + size = plt_stub_size (htab, stub_entry, off, 0); + pad = plt_stub_pad (htab->params->plt_stub_align, stub_offset, size); + stub_offset += pad; if (info->emitrelocations) { @@ -12596,8 +12585,6 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) stub_entry->group->stub_sec->flags |= SEC_RELOC; } - size = plt_stub_size (htab, stub_entry, off, 0); - if (stub_entry->h != NULL && is_tls_get_addr (&stub_entry->h->elf, htab) && htab->params->tls_get_addr_opt -- Alan Modra Australia Development Lab, IBM