From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id E08423858D32 for ; Mon, 8 May 2023 04:34:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E08423858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-517c840f181so1954968a12.3 for ; Sun, 07 May 2023 21:34:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683520481; x=1686112481; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=7lmm/NbtoU81uIE1ZwyREvOlXNlNvxQxsxTW064fVrA=; b=gdvokEmTe4zJ/Nll25BqpOY9+fYWI89TAiO2+U+xVFsS9lKjCmn4AuQrrU5HH7TeCM SFFrsHUHmdgPghqkcZygtvm4cwJ0JQCeg60/is+bouEo+6LfGmwkTraZapU8K5jvsZ7X Jm5SEzjks4NNwBUVwBzPIHCOZvzUuh0zpAGJXliUFy2TVzZ96aIWq5O9wuFaO1DMyQex lpm+2TfnKia/YNjSiBpN6Z0CSvLMzhfdK8/ZGB1XPFCYo0TyELCd9Jtg9Q0pA2CFb0xU Mwc9xuFxe3c/OpSc+C/5l0RAvhhdzJ3cl3ucVq9kHc8CYZ/41eV6KIqRb0/vr0w8DnTg SOkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683520481; x=1686112481; 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=7lmm/NbtoU81uIE1ZwyREvOlXNlNvxQxsxTW064fVrA=; b=Hh4yPlb1X8furS3/m26B/qyEtYAVti/UvJSobW7UxHm8pfzIr94UiJbzYM31xe2X4R YDpx3H0p+8FDvLpSQusLl8bXX+3VTGWMOgUsNmxflEFi9muxDiX4NzP5aEsLSvEZ8DDT cOdejlr0T7YmYt8rqhG6dR7U699ImKlo4LGj2QNgiQEzUUX883ndOa6QgHmJBliFn/4f GJ29PRiV5kmfgrigRqPwaJTC9LDMduFaPEXDhMO/Und4teJj0m7gCWJOxJXyp7Wa9E4k j0h5RY7FV4jGvoA3EMyZRODgZbgnn9SCTZRvPgEXcYxdLtfRabct7ecl8JHqVnUrGJv9 HOkA== X-Gm-Message-State: AC+VfDy4f62da4XRB8VCJPMu/avdvO9yQg+GFDo+M415SQRGx3oP0MH0 vjccpFwGEqksx12p6eCoJYQnjO3wEEw= X-Google-Smtp-Source: ACHHUZ6t0z2nQk9BavkKuaLLX93poKpipsjWzogpTP6TmJfbn9bSIzEpB5yKR2k8rS+z11ic39VLBQ== X-Received: by 2002:a17:902:ecc3:b0:1ab:528:5f85 with SMTP id a3-20020a170902ecc300b001ab05285f85mr12052551plh.59.1683520481289; Sun, 07 May 2023 21:34:41 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:ec82:e5a:ce92:9a7c]) by smtp.gmail.com with ESMTPSA id d3-20020a170902b70300b001a52cfc73acsm6006323pls.129.2023.05.07.21.34.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 May 2023 21:34:40 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id F421F1140019; Mon, 8 May 2023 14:04:37 +0930 (ACST) Date: Mon, 8 May 2023 14:04:37 +0930 From: Alan Modra To: binutils@sourceware.org Subject: PR30343, LTO ignores linker reference to _pei386_runtime_relocator Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3034.4 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 List-Id: Make a reference to _pei386_runtime_relocator before LTO recompilation. This is done regardless of whether such a reference will be used, because it can't be known whether it is needed before LTO. I also found it necessary to enable long section names for the bfd created in make_runtime_pseudo_reloc, because otherwise when writing it out to the bfd-in-memory we get the section written as .rdata_r which when read back in leads to a linker warning ".rdata_r: section below image base" and likely runtime misbehaviour. PR 30343 * emultempl/pe.em (make_runtime_ref): New function. (gld${EMULATION_NAME}_before_plugin_all_symbols_read): New function. (LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ): Define. * emultempl/pep.em: Similarly to pe.em. * pe-dll.c (make_runtime_pseudo_reloc): Set long section names. diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em index 1f2a5f310be..4fe0cf203fb 100644 --- a/ld/emultempl/pe.em +++ b/ld/emultempl/pe.em @@ -1255,6 +1255,28 @@ make_import_fixup (arelent *rel, asection *s, char *name, const char *symname) pe_create_import_fixup (rel, s, _addend, name, symname); } +static void +make_runtime_ref (void) +{ + const char *rr = U ("_pei386_runtime_relocator"); + struct bfd_link_hash_entry *h + = bfd_wrapped_link_hash_lookup (link_info.output_bfd, &link_info, + rr, true, false, true); + if (!h) + einfo (_("%F%P: bfd_link_hash_lookup failed: %E\n")); + else + { + if (h->type == bfd_link_hash_new) + { + h->type = bfd_link_hash_undefined; + h->u.undef.abfd = NULL; + if (h->u.undef.next == NULL && h != link_info.hash->undefs_tail) + bfd_link_add_undef (link_info.hash, h); + } + h->non_ir_ref_regular = true; + } +} + static bool pr_sym (struct bfd_hash_entry *h, void *inf ATTRIBUTE_UNUSED) { @@ -1459,6 +1481,16 @@ setup_build_id (bfd *ibfd) return false; } +static void +gld${EMULATION_NAME}_before_plugin_all_symbols_read (void) +{ +#ifdef DLL_SUPPORT + if (link_info.lto_plugin_active + && link_info.pei386_auto_import) + make_runtime_ref (); +#endif +} + static void gld${EMULATION_NAME}_after_open (void) { @@ -2488,6 +2520,7 @@ EOF fi LDEMUL_AFTER_PARSE=gld${EMULATION_NAME}_after_parse +LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ=gld${EMULATION_NAME}_before_plugin_all_symbols_read LDEMUL_AFTER_OPEN=gld${EMULATION_NAME}_after_open LDEMUL_BEFORE_ALLOCATION=gld${EMULATION_NAME}_before_allocation LDEMUL_FINISH=gld${EMULATION_NAME}_finish diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em index ca4acaea148..5770df8ed0a 100644 --- a/ld/emultempl/pep.em +++ b/ld/emultempl/pep.em @@ -1256,6 +1256,28 @@ make_import_fixup (arelent *rel, asection *s, char *name, const char *symname) pep_create_import_fixup (rel, s, _addend, name, symname); } +static void +make_runtime_ref (void) +{ + const char *rr = U ("_pei386_runtime_relocator"); + struct bfd_link_hash_entry *h + = bfd_wrapped_link_hash_lookup (link_info.output_bfd, &link_info, + rr, true, false, true); + if (!h) + einfo (_("%F%P: bfd_link_hash_lookup failed: %E\n")); + else + { + if (h->type == bfd_link_hash_new) + { + h->type = bfd_link_hash_undefined; + h->u.undef.abfd = NULL; + if (h->u.undef.next == NULL && h != link_info.hash->undefs_tail) + bfd_link_add_undef (link_info.hash, h); + } + h->non_ir_ref_regular = true; + } +} + static bool pr_sym (struct bfd_hash_entry *h, void *inf ATTRIBUTE_UNUSED) { @@ -1461,6 +1483,16 @@ setup_build_id (bfd *ibfd) return false; } +static void +gld${EMULATION_NAME}_before_plugin_all_symbols_read (void) +{ +#ifdef DLL_SUPPORT + if (link_info.lto_plugin_active + && link_info.pei386_auto_import) /* -1=warn or 1=enable */ + make_runtime_ref (); +#endif +} + static void gld${EMULATION_NAME}_after_open (void) { @@ -2323,6 +2355,7 @@ EOF fi LDEMUL_AFTER_PARSE=gld${EMULATION_NAME}_after_parse +LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ=gld${EMULATION_NAME}_before_plugin_all_symbols_read LDEMUL_AFTER_OPEN=gld${EMULATION_NAME}_after_open LDEMUL_BEFORE_ALLOCATION=gld${EMULATION_NAME}_before_allocation LDEMUL_FINISH=gld${EMULATION_NAME}_finish diff --git a/ld/pe-dll.c b/ld/pe-dll.c index ab13e3bb94a..8d74dba6af0 100644 --- a/ld/pe-dll.c +++ b/ld/pe-dll.c @@ -2720,6 +2720,7 @@ make_runtime_pseudo_reloc (const char *name ATTRIBUTE_UNUSED, rt_rel = quick_section (abfd, ".rdata_runtime_pseudo_reloc", SEC_HAS_CONTENTS, 2); + bfd_coff_set_long_section_names (abfd, true); quick_symbol (abfd, "", fixup_name, "", UNDSEC, BSF_GLOBAL, 0); -- Alan Modra Australia Development Lab, IBM