From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id 6FCF2385841A for ; Tue, 30 Aug 2022 17:20:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6FCF2385841A Received: by mail-ed1-x532.google.com with SMTP id b44so15092644edf.9 for ; Tue, 30 Aug 2022 10:20:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=0nqR2MjoLGezOiuD5TYcAxOXaufJaGv9b+zX80bDPaU=; b=0Nh1mlhdGtys3ihmHcacvRpnNTHztJKh1pouhUeF+E9tEI6V1lcCL9NNwbJ2tj1sNR HZ7zOiiamkhPVp5poUf6fcFifj/YoD5eHGSjiti8kGcyLKkAvwxnCR1qUNPPrpyJQeK0 w2gJRvDyG8Nr4esXE38x+ydJx0isIvT1Ug3/irTSjirrzrZMjkwW5W3FQsH8wEPhfX0B klslBvlDwmF3x/I+mDJsEOv6O8WtfripRo9QXzDiGsvnIr0AKyBR+HnqwcS3gwCLbE3R FMJPd4GTwS60zxU8bXMygxahol0VaK5uh2xZWINYUUrcXkIkeNr9aq6Wl1u3yUIgNudw 2w1A== X-Gm-Message-State: ACgBeo13cF5MUJarI4EU24c4439ctB6H5X2KziQ7dRkv7qVEL5GS3BDx BKaCENCNdjPTFe6RuqgeWRf9t4yjVLFgJ8uHMDM= X-Google-Smtp-Source: AA6agR7lao+0xvbpfBcKrfK8a+pRCC3N863NtQyDKWWtBxhAqfDDXgoBqPuZijVmEMoCRl5RMfaTOtifjc9I+NdBuIY= X-Received: by 2002:aa7:d995:0:b0:447:ea61:d7d8 with SMTP id u21-20020aa7d995000000b00447ea61d7d8mr16317746eds.118.1661880057243; Tue, 30 Aug 2022 10:20:57 -0700 (PDT) MIME-Version: 1.0 References: <4161b707473552ce74c41c8867c2cc6d77ff4e05.camel@gmail.com> <0951c3b4584404fab95dd7d92af8b6f301b758c7.camel@gmail.com> In-Reply-To: <0951c3b4584404fab95dd7d92af8b6f301b758c7.camel@gmail.com> From: Jonathan Wakely Date: Tue, 30 Aug 2022 18:20:43 +0100 Message-ID: Subject: Re: Relation between gcc version and libstdc++ version To: =?UTF-8?Q?Anton_W=C3=B6llert?= Cc: "gcc@gcc.gnu.org" X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, KAM_SHORT, 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Aug 2022 17:21:01 -0000 On Tue, 30 Aug 2022, 17:53 Anton W=C3=B6llert, wrote= : > Hi Jonathan, > > thank you for your reply! > > On Tue, 2022-08-30 at 17:09 +0100, Jonathan Wakely wrote: > > > > > > On Tue, 30 Aug 2022, 15:48 Anton W=C3=B6llert via Gcc, > > wrote: > > > If this libstdc++ is > > > newer than the one one the target, I get undefined references > > > (because > > > there are some newer implementation details and things like that). > > > > Then you're not telling the executable how find the new libstdc++. > > > > > https://gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.how_to_set_paths > > > > > > I tried to do that. If I let the toolchain use it's own libstdc++.so, > then I get at runtime unresolved symbols due to the version mismatch > (these GLIBCXX errors). This is clear. > Which is the problem described in the above FAQ. And you should solve it that way. Apparently you haven't done what it says to do, because you wouldn't get errors if you had done it. See also the page in the manual that the FAQ links to. > If I force the toolchain to link against the older target libstdc++, > then I get undefined symbols at compile time, because it is still using > it's own shipped headers for the newer libstdc++, which have > implementation details that use newer "functions/symbols" that are not > available in the old libstdc++. > Yes, that won't work. > If I furthermore remove the shipped headers and force it to include the > c++ headers from the older libstdc++, then everything works out. > > But this whole "patching" seems very hacky. > > > > Is > > > it possible to tell G++/GCC to use the libstdc++.so from the target > > > and > > > also to use the C++ headers (like iostream) from the target? > > > > It's possible, but unsupported and probably won't work. > > So it seems to be indeed possible, but not intended. > > > > > > If not, is there any reason this is hard-coded? > > > > The libstdc++ headers are tightly coupled to the GCC version, so > > headers from a given GCC release might not even compile with a newer > > or older GCC. > > I would see an argument if you're trying to compile an newer libstdc++ > with an older gcc - but why not the other way around? Sometimes the old libstdc++ headers contain invalid C++ which the old GCC did not diagnose. A newer GCC will give errors when trying to include those old headers. This is uncommon, but has happened a few times. C++ in general > tries to be very good in backward compatibility. > This essentially means that you can't use newer compilers with more > features/bugfixes to compile software for older targets. > No it doesn't. Using new compilers on older machines works fine. You just need to do it right. Is there any obvious reason this is not supported? Clang, for example, > also seems to be able to compile/link against different libstdc++ > versions. I'm just wondering. Clang has various hacks to compile the invalid code in old libstdc++ headers. This is necessary for compatibility, because clang doesn't control which libstdc++ headers are present on a system where clang gets installed. It has to be prepared to cope with arbitrary libstdc++ versions. That's not an issue for GCC, because libstdc++ is part of GCC, so if you have a given version of GCC, then you have the matching libstdc++ headers and libraries, and you can use them. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id 6FCF2385841A for ; Tue, 30 Aug 2022 17:20:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6FCF2385841A 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-ed1-x532.google.com with SMTP id b44so15092644edf.9 for ; Tue, 30 Aug 2022 10:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=0nqR2MjoLGezOiuD5TYcAxOXaufJaGv9b+zX80bDPaU=; b=RIUiCcS6vfRGgBGg9Eue4Udd0MV+RRbAdOsErkJbgtnMgSvjaHYJ1SE6Gss3SkVJmK VVV1EW/OUwwxmAXFwjKVfwZFtEbHIFN9s7MoC0lHZUT3g19ZyGonn1DL0JbdDkWLGDQZ N7peYc+i5i2p9yCemZoGB9+3b2kBYjzWRZOfjVOLhvRyqmIZKP10imy+enHHeCrN7kae 9zWvr/6JJpGF0cwCKk3S9jU+h21+ByDZoznGTzoAWNtPf2kjb+d17FTqo+lkWSltkfhi 2PsVx1sVRw9s+V9iHwxA8F5UY+iJTSFjpmeMjSX1BJtzu1HbQ09kovDr925WFp9X7yUv 10OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=0nqR2MjoLGezOiuD5TYcAxOXaufJaGv9b+zX80bDPaU=; b=0Nh1mlhdGtys3ihmHcacvRpnNTHztJKh1pouhUeF+E9tEI6V1lcCL9NNwbJ2tj1sNR HZ7zOiiamkhPVp5poUf6fcFifj/YoD5eHGSjiti8kGcyLKkAvwxnCR1qUNPPrpyJQeK0 w2gJRvDyG8Nr4esXE38x+ydJx0isIvT1Ug3/irTSjirrzrZMjkwW5W3FQsH8wEPhfX0B klslBvlDwmF3x/I+mDJsEOv6O8WtfripRo9QXzDiGsvnIr0AKyBR+HnqwcS3gwCLbE3R FMJPd4GTwS60zxU8bXMygxahol0VaK5uh2xZWINYUUrcXkIkeNr9aq6Wl1u3yUIgNudw 2w1A== X-Gm-Message-State: ACgBeo13cF5MUJarI4EU24c4439ctB6H5X2KziQ7dRkv7qVEL5GS3BDx BKaCENCNdjPTFe6RuqgeWRf9t4yjVLFgJ8uHMDM= X-Google-Smtp-Source: AA6agR7lao+0xvbpfBcKrfK8a+pRCC3N863NtQyDKWWtBxhAqfDDXgoBqPuZijVmEMoCRl5RMfaTOtifjc9I+NdBuIY= X-Received: by 2002:aa7:d995:0:b0:447:ea61:d7d8 with SMTP id u21-20020aa7d995000000b00447ea61d7d8mr16317746eds.118.1661880057243; Tue, 30 Aug 2022 10:20:57 -0700 (PDT) MIME-Version: 1.0 References: <4161b707473552ce74c41c8867c2cc6d77ff4e05.camel@gmail.com> <0951c3b4584404fab95dd7d92af8b6f301b758c7.camel@gmail.com> In-Reply-To: <0951c3b4584404fab95dd7d92af8b6f301b758c7.camel@gmail.com> From: Jonathan Wakely Date: Tue, 30 Aug 2022 18:20:43 +0100 Message-ID: Subject: Re: Relation between gcc version and libstdc++ version To: =?UTF-8?Q?Anton_W=C3=B6llert?= Cc: "gcc@gcc.gnu.org" Content-Type: multipart/alternative; boundary="00000000000078ad4d05e7789a56" X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,KAM_SHORT,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: Message-ID: <20220830172043.isLrOFj_utJNEJO9gtJNk5r8GqIInmd9TMXazWJ_EBw@z> --00000000000078ad4d05e7789a56 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 30 Aug 2022, 17:53 Anton W=C3=B6llert, wrote: > Hi Jonathan, > > thank you for your reply! > > On Tue, 2022-08-30 at 17:09 +0100, Jonathan Wakely wrote: > > > > > > On Tue, 30 Aug 2022, 15:48 Anton W=C3=B6llert via Gcc, > > wrote: > > > If this libstdc++ is > > > newer than the one one the target, I get undefined references > > > (because > > > there are some newer implementation details and things like that). > > > > Then you're not telling the executable how find the new libstdc++. > > > > > https://gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.how_to_set_paths > > > > > > I tried to do that. If I let the toolchain use it's own libstdc++.so, > then I get at runtime unresolved symbols due to the version mismatch > (these GLIBCXX errors). This is clear. > Which is the problem described in the above FAQ. And you should solve it that way. Apparently you haven't done what it says to do, because you wouldn't get errors if you had done it. See also the page in the manual that the FAQ links to. > If I force the toolchain to link against the older target libstdc++, > then I get undefined symbols at compile time, because it is still using > it's own shipped headers for the newer libstdc++, which have > implementation details that use newer "functions/symbols" that are not > available in the old libstdc++. > Yes, that won't work. > If I furthermore remove the shipped headers and force it to include the > c++ headers from the older libstdc++, then everything works out. > > But this whole "patching" seems very hacky. > > > > Is > > > it possible to tell G++/GCC to use the libstdc++.so from the target > > > and > > > also to use the C++ headers (like iostream) from the target? > > > > It's possible, but unsupported and probably won't work. > > So it seems to be indeed possible, but not intended. > > > > > > If not, is there any reason this is hard-coded? > > > > The libstdc++ headers are tightly coupled to the GCC version, so > > headers from a given GCC release might not even compile with a newer > > or older GCC. > > I would see an argument if you're trying to compile an newer libstdc++ > with an older gcc - but why not the other way around? Sometimes the old libstdc++ headers contain invalid C++ which the old GCC did not diagnose. A newer GCC will give errors when trying to include those old headers. This is uncommon, but has happened a few times. C++ in general > tries to be very good in backward compatibility. > This essentially means that you can't use newer compilers with more > features/bugfixes to compile software for older targets. > No it doesn't. Using new compilers on older machines works fine. You just need to do it right. Is there any obvious reason this is not supported? Clang, for example, > also seems to be able to compile/link against different libstdc++ > versions. I'm just wondering. Clang has various hacks to compile the invalid code in old libstdc++ headers. This is necessary for compatibility, because clang doesn't control which libstdc++ headers are present on a system where clang gets installed. It has to be prepared to cope with arbitrary libstdc++ versions. That's not an issue for GCC, because libstdc++ is part of GCC, so if you have a given version of GCC, then you have the matching libstdc++ headers and libraries, and you can use them. --00000000000078ad4d05e7789a56--