From patchwork Mon May 8 04:34:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 90933 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1908141vqo; Sun, 7 May 2023 21:34:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6HAtPYtQTa8dMJgv5190EoQR3JIEBCiNmVJ+6jmvCGbBjUBi8dcc1PaDuY9PtbY/6rxe/a X-Received: by 2002:a17:907:a44:b0:966:530c:3c90 with SMTP id be4-20020a1709070a4400b00966530c3c90mr2147118ejc.13.1683520494684; Sun, 07 May 2023 21:34:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683520494; cv=none; d=google.com; s=arc-20160816; b=pPQwGYsNtTtkyL+yOzED0JRMCShV8ajTPXq/qK93w7Vttl8+qBB1L4pVBsMycr1ezW bHPjFXMtCe9eyOALwlUSU6atOcdpJWOSPqomnGRWJZo6LH/ROPfGSXSoMJ8MsD+wquBU u71TxJGQ7H9U7slPCcDWegMIQZSYi6PTK6NuEtwxCephdlwAXtP9NxoCeqpCPGdsvMFj 1rXW4AxBI71aHaVjK99aOqXiACseMcVXfeBTBvZsXRAmybe0j3iNl0lryePKzaOLkdw6 BPfysgPL9FrdQdrPuUyWzeT7uemTfoSpLxTghLT+EtY057Xwx7DEeGD61XQl3ZO6E9IY PtvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=7lmm/NbtoU81uIE1ZwyREvOlXNlNvxQxsxTW064fVrA=; b=WfXO596xxkxO8aKUfWUkpksiNVgtxXoxFwhNNK1dP1m43eChIm9sfFYUc8iduBpVDJ AQH6Yu6rNOb4HESahMrzLvcQzXr1668Ka/oXuKuRos3UNETIzAPEpqLflqpiBXivgOtY 6MG4uXvuPkcgsDQfozSSNmxAfPe9C1VL561HxMsXU5111pNJ25nb6bTk5nP7Rf2PZyWP hl71VrHejuB9wkeQC5FAz2rZ6o/d4KjbBC91x0KqzlD2xbI2kIbKd7xIz90Yo7VGklWD QX64hSii0ztbb2DVQ4IbWIISwW9idsuiLxkMFwLO7h4fdvbh/svgBK/FtatF4lpOySMF L9kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=drfmIJLH; 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=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id k24-20020a17090646d800b0094e7f8172besi160711ejs.875.2023.05.07.21.34.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 May 2023 21:34:54 -0700 (PDT) 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=@sourceware.org header.s=default header.b=drfmIJLH; 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=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92851385842C for ; Mon, 8 May 2023 04:34:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92851385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683520493; bh=7lmm/NbtoU81uIE1ZwyREvOlXNlNvxQxsxTW064fVrA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=drfmIJLHHyAqB21owT4g2uruVovADWanLnjqel7y37ftDSm4b2uzIFyeh8rRyAVe+ 44WJI7/ZxLsLBpqxlo8dT0DOH14TEgdewhEXm6I3/pC4r0Ift9Ugh0ZffqKz6N8UwG QBHjQnZeScTUZgBfj8HxptIXTWJATE4DpDxovQk4= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org 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 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-517c840f181so1954968a12.3 for ; Sun, 07 May 2023 21:34:44 -0700 (PDT) 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-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 To: binutils@sourceware.org Subject: PR30343, LTO ignores linker reference to _pei386_runtime_relocator Message-ID: MIME-Version: 1.0 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 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-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765299186234739515?= X-GMAIL-MSGID: =?utf-8?q?1765299186234739515?= 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);