From patchwork Fri Sep 3 09:13:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1524140 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=EUjC9Frp; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H1Bw26m7Jz9sRf for ; Fri, 3 Sep 2021 19:15:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC0263865C2A for ; Fri, 3 Sep 2021 09:15:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 55A613865C27 for ; Fri, 3 Sep 2021 09:14:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 55A613865C27 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x333.google.com with SMTP id x2-20020a1c7c02000000b002e6f1f69a1eso3289554wmc.5 for ; Fri, 03 Sep 2021 02:14:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=0nMqUic4GQ/kpu8TEhzx706GS+MiVjA5bTv2ez1nya8=; b=EUjC9FrpcG6hGqwgmdTR2j324IW5H5/vC7ZpGNKqdxzySIPHkbpa0U5q/C8tvv0rDx suCnKdR3KY3QAzIwL7P5urF5ENHtLkaSZZqUHWdLiuvQQW/Yg4jYBov5gDU/NRg5ea0U IJCynb+G1LkCxXwhYe2KcI3mAmkbPOM8xjevAep2ISmwDpatQKkdB/us27BPkGqys4Wt HsZTuGYQ3ISNVRKTec0zUbb8G7MFjKM2INWi/R37cGEzsZCL8eEdOOEFdDE0Jh1KAlpK SVnpn5qZt4cmViJziUrl04Il71af5EfRIcIlUJXhmZKj4mmMNavQ9wLKEFpJbv3KdOdw av+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=0nMqUic4GQ/kpu8TEhzx706GS+MiVjA5bTv2ez1nya8=; b=aKgqI9aYxFYFqYy0Y+n2J4BJQ8ntNH/LHkk2N/cz8CDuQYf5LhNivPL68AZ2hJu3Dw 3DuQdwTBve6gOqsdjt5kLwGleO4sEI0G/KdzMRZ41dXIduyptVmrGJ0tDVWH4PHtbfOF A0tG43TOKDyw9DoK1ADc9nIOAP3/EUiZw6HQK4PGzYRvIf6r0pqRVBH0r6vDKf9I0bWO OM87GlmuGiWzUHvXSzPGzcO5jeENvrpDjffJ0qXdr7y49aEazSeJSqxyK5BnvHj5zqkT MKj/4VgpHK9N/6X4E8ADhO1Wo421DfVYHmBVG4pzJZZgPyubH0YhiaWqijLqpdWD2PKy zlgg== X-Gm-Message-State: AOAM5330q4hNC/NJC619UzNR8rF5eRoRbJre3IKpTDTsIm7dZ9XPYlpP I2t5UgeGMitzgprTcZvnvhTcq5WEFzZqMeRK X-Google-Smtp-Source: ABdhPJy3B0BjELGmUiNHct827OWEtEpLgRhxlZRXuPgD6ezV0XVEaw/mB4doM6XQzuWChhnkbZI7qw== X-Received: by 2002:a1c:2313:: with SMTP id j19mr7428378wmj.189.1630660451239; Fri, 03 Sep 2021 02:14:11 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:41b:84f0:cf71:f5e0:b050:bede]) by smtp.gmail.com with ESMTPSA id d7sm4145578wrs.39.2021.09.03.02.14.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 02:14:10 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [i386] Fix PR C++/64697 Date: Fri, 03 Sep 2021 11:13:59 +0200 Message-ID: <2183660.iZASKD2KPV@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, this old PR is about a link failure on x86-64/Cygwin with thread-local storage variables: use.o:use.cxx:(.text$_ZTWN1N3ptdE[_ZTWN1N3ptdE]+0x15): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for N::ptd' collect2: error: ld returned 1 exit status At the time MinGW was not affected because the base address of executables was within the lower 4GB. This was changed in binutils 2.36 and the bug was then reported for MinGW to binutils's Bugzilla: https://sourceware.org/bugzilla/show_bug.cgi?id=26659 The BFD fix eliminates the link failure and working code is generated at -O0, but _not_ when optimization is enabled because the optimizer changes: movq .refptr._ZTH1s(%rip), %rax testq %rax, %rax je .L2 call _ZTH1s into: leaq _ZTH1s(%rip), %rax testq %rax, %rax je .L2 call _ZTH1s and the leaq now also gets the relocation overflow. So the fix is to teach legitimate_pic_address_disp_p to reject the transformation when the symbol is an external weak function, which yields: cmpq $0, .refptr._ZTH1s(%rip) je .L2 call _ZTH1s and the cmpq keeps a relocation that does not overflow. Tested on x86-64/Windows, OK for mainline, 11 and 10 branches? 2021-09-03 Eric Botcazou * config/i386/i386.c (legitimate_pic_address_disp_p): For PE-COFF, do not return true for external weak function symbols in the medium model. diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index bfefbd718bb..2f708a1cf1c 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -10664,24 +10664,19 @@ legitimate_pic_address_disp_p (rtx disp) if (is_imported_p (op0)) return true; - if (SYMBOL_REF_FAR_ADDR_P (op0) - || !SYMBOL_REF_LOCAL_P (op0)) + if (SYMBOL_REF_FAR_ADDR_P (op0) || !SYMBOL_REF_LOCAL_P (op0)) break; - /* Function-symbols need to be resolved only for - large-model. - For the small-model we don't need to resolve anything - here. */ + /* Non-external-weak function symbols need to be resolved only + for the large model. Non-external symbols don't need to be + resolved for large and medium models. For the small model, + we don't need to resolve anything here. */ if ((ix86_cmodel != CM_LARGE_PIC - && SYMBOL_REF_FUNCTION_P (op0)) + && SYMBOL_REF_FUNCTION_P (op0) + && !(SYMBOL_REF_EXTERNAL_P (op0) && SYMBOL_REF_WEAK (op0))) + || !SYMBOL_REF_EXTERNAL_P (op0) || ix86_cmodel == CM_SMALL_PIC) return true; - /* Non-external symbols don't need to be resolved for - large, and medium-model. */ - if ((ix86_cmodel == CM_LARGE_PIC - || ix86_cmodel == CM_MEDIUM_PIC) - && !SYMBOL_REF_EXTERNAL_P (op0)) - return true; } else if (!SYMBOL_REF_FAR_ADDR_P (op0) && (SYMBOL_REF_LOCAL_P (op0)