* Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers?
@ 2021-05-15 2:25 unlvsur unlvsur
2021-05-15 8:23 ` Jonathan Wakely
0 siblings, 1 reply; 8+ messages in thread
From: unlvsur unlvsur @ 2021-05-15 2:25 UTC (permalink / raw)
To: unlvsur unlvsur via Libstdc++
The issue is that this will silently introduce dependency to stdio. On MinGW-w64 for example, any snprintf function call will bloat binary size for 70kb, that is even we shared linking with both msvcrt and libstdc++.
I frequently see a random bloat because of that.
By the way, it also hurts optimizations since compilers cannot merge them together.
Better just throw an exception with “vector<T> out of bounds” instead of formatting subscriptor.
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers?
2021-05-15 2:25 Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers? unlvsur unlvsur
@ 2021-05-15 8:23 ` Jonathan Wakely
2021-05-20 19:20 ` Jonathan Wakely
0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Wakely @ 2021-05-15 8:23 UTC (permalink / raw)
To: unlvsur unlvsur; +Cc: unlvsur unlvsur via Libstdc++
On Sat, 15 May 2021, 04:12 unlvsur unlvsur via Libstdc++, <
libstdc++@gcc.gnu.org> wrote:
> The issue is that this will silently introduce dependency to stdio. On
> MinGW-w64 for example, any snprintf function call will bloat binary size
> for 70kb, that is even we shared linking with both msvcrt and libstdc++.
>
> I frequently see a random bloat because of that.
>
> By the way, it also hurts optimizations since compilers cannot merge them
> together.
>
> Better just throw an exception with “vector<T> out of bounds” instead of
> formatting subscriptor.
>
I can make that depend on the _GLIBCXX_VERBOSE macro.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers?
2021-05-15 8:23 ` Jonathan Wakely
@ 2021-05-20 19:20 ` Jonathan Wakely
[not found] ` <DM6PR05MB4697628C7E6769B8FCDA1D6ED62A9@DM6PR05MB4697.namprd05.prod.outlook.com>
0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Wakely @ 2021-05-20 19:20 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: unlvsur unlvsur, unlvsur unlvsur via Libstdc++
On 15/05/21 09:23 +0100, Jonathan Wakely via Libstdc++ wrote:
>On Sat, 15 May 2021, 04:12 unlvsur unlvsur via Libstdc++, <
>libstdc++@gcc.gnu.org> wrote:
>
>> The issue is that this will silently introduce dependency to stdio. On
>> MinGW-w64 for example, any snprintf function call will bloat binary size
>> for 70kb, that is even we shared linking with both msvcrt and libstdc++.
>>
>> I frequently see a random bloat because of that.
>>
>> By the way, it also hurts optimizations since compilers cannot merge them
>> together.
>>
>> Better just throw an exception with “vector<T> out of bounds” instead of
>> formatting subscriptor.
>>
>
>
>I can make that depend on the _GLIBCXX_VERBOSE macro.
Where is the dependency on stdio coming from though? Formatting the
exception string doesn't use stdio.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers?
[not found] ` <DM6PR05MB4697628C7E6769B8FCDA1D6ED62A9@DM6PR05MB4697.namprd05.prod.outlook.com>
@ 2021-05-20 19:35 ` Jonathan Wakely
2021-05-20 19:47 ` unlvsur unlvsur
0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Wakely @ 2021-05-20 19:35 UTC (permalink / raw)
To: unlvsur unlvsur; +Cc: unlvsur unlvsur via Libstdc++
On 20/05/21 19:27 +0000, unlvsur unlvsur wrote:
>Well. It comes from snprintf. You cannot use any stdio functionalities.
>
>For example
>https://github.com/gcc-mirror/gcc/blob/4f4a2f199baf46d35492edadc16f30f32920c4df/libstdc%2B%2B-v3/include/bits/stl_vector.h#L1070
But that doesn't use snprintf.
>
>https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/libstdc%2B%2B-v3/include/experimental/string_view#L274
And that doesn't use snprintf either.
Have you actually seen a dependency on stdio from these functions, or
are you just assuming?
>We need something which is a silent EH thrown, this format string thrown stuff will always introduce dependencies silently.
>
>This also hurts optimizations
>
>[cid:image002.png@01D74D8C.9AD99570]
>
>
>Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
>From: Jonathan Wakely<mailto:jwakely@redhat.com>
>Sent: Thursday, May 20, 2021 15:21
>To: Jonathan Wakely<mailto:jwakely.gcc@gmail.com>
>Cc: unlvsur unlvsur<mailto:unlvsur@live.com>; unlvsur unlvsur via Libstdc++<mailto:libstdc++@gcc.gnu.org>
>Subject: Re: Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers?
>
>On 15/05/21 09:23 +0100, Jonathan Wakely via Libstdc++ wrote:
>>On Sat, 15 May 2021, 04:12 unlvsur unlvsur via Libstdc++, <
>>libstdc++@gcc.gnu.org> wrote:
>>
>>> The issue is that this will silently introduce dependency to stdio. On
>>> MinGW-w64 for example, any snprintf function call will bloat binary size
>>> for 70kb, that is even we shared linking with both msvcrt and libstdc++.
>>>
>>> I frequently see a random bloat because of that.
>>>
>>> By the way, it also hurts optimizations since compilers cannot merge them
>>> together.
>>>
>>> Better just throw an exception with “vector<T> out of bounds” instead of
>>> formatting subscriptor.
>>>
>>
>>
>>I can make that depend on the _GLIBCXX_VERBOSE macro.
>
>Where is the dependency on stdio coming from though? Formatting the
>exception string doesn't use stdio.
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers?
2021-05-20 19:35 ` Jonathan Wakely
@ 2021-05-20 19:47 ` unlvsur unlvsur
2021-05-20 19:50 ` unlvsur unlvsur
2021-05-20 19:52 ` Jonathan Wakely
0 siblings, 2 replies; 8+ messages in thread
From: unlvsur unlvsur @ 2021-05-20 19:47 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: unlvsur unlvsur via Libstdc++
// I have disabled libstdcxx verbose
#include<fast_io.h>
int main(int argc,char** argv)
{
std::string_view str(*argv);
puts(str.substr(4).data());
}
g++ -o b b.cc -Ofast -std=c++20 -s -flto -march=native -I../fast_io/include -static-libstdc++
binary size 86kb
#include<fast_io.h>
int main(int argc,char** argv)
{
std::string_view str(*argv);
if(str.size()<4)
__builtin_trap();
puts(std::string_view(str.data()+4,str.size()).data());
}
g++ -o c c.cc -Ofast -std=c++20 -s -flto -march=native -I../fast_io/include -static-libstdc++
binary size 15kb
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
From: Jonathan Wakely<mailto:jwakely@redhat.com>
Sent: Thursday, May 20, 2021 15:35
To: unlvsur unlvsur<mailto:unlvsur@live.com>
Cc: unlvsur unlvsur via Libstdc++<mailto:libstdc++@gcc.gnu.org>
Subject: Re: Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers?
On 20/05/21 19:27 +0000, unlvsur unlvsur wrote:
>Well. It comes from snprintf. You cannot use any stdio functionalities.
>
>For example
>https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgcc-mirror%2Fgcc%2Fblob%2F4f4a2f199baf46d35492edadc16f30f32920c4df%2Flibstdc%252B%252B-v3%2Finclude%2Fbits%2Fstl_vector.h%23L1070&data=04%7C01%7C%7C5e592cf75b1a4524c05408d91bc66216%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637571361118589300%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=5OZqIYtKRzXDWOcATMsIrBBYjCJOupkxk0of7SagS%2FQ%3D&reserved=0
But that doesn't use snprintf.
>
>https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgcc-mirror%2Fgcc%2Fblob%2F16e2427f50c208dfe07d07f18009969502c25dc8%2Flibstdc%252B%252B-v3%2Finclude%2Fexperimental%2Fstring_view%23L274&data=04%7C01%7C%7C5e592cf75b1a4524c05408d91bc66216%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637571361118589300%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=iukICKyYF0pB1qJv16vCcZpXrbpBhzK%2FPteRZAEZx3U%3D&reserved=0
And that doesn't use snprintf either.
Have you actually seen a dependency on stdio from these functions, or
are you just assuming?
>We need something which is a silent EH thrown, this format string thrown stuff will always introduce dependencies silently.
>
>This also hurts optimizations
>
>[cid:image002.png@01D74D8C.9AD99570]
>
>
>Sent from Mail<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgo.microsoft.com%2Ffwlink%2F%3FLinkId%3D550986&data=04%7C01%7C%7C5e592cf75b1a4524c05408d91bc66216%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637571361118589300%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=e5r3X770y%2Bm4nLrY37xW%2FUv3Bg7aa0bpsQEMoLnMstA%3D&reserved=0> for Windows 10
>
>From: Jonathan Wakely<mailto:jwakely@redhat.com>
>Sent: Thursday, May 20, 2021 15:21
>To: Jonathan Wakely<mailto:jwakely.gcc@gmail.com>
>Cc: unlvsur unlvsur<mailto:unlvsur@live.com>; unlvsur unlvsur via Libstdc++<mailto:libstdc++@gcc.gnu.org>
>Subject: Re: Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers?
>
>On 15/05/21 09:23 +0100, Jonathan Wakely via Libstdc++ wrote:
>>On Sat, 15 May 2021, 04:12 unlvsur unlvsur via Libstdc++, <
>>libstdc++@gcc.gnu.org> wrote:
>>
>>> The issue is that this will silently introduce dependency to stdio. On
>>> MinGW-w64 for example, any snprintf function call will bloat binary size
>>> for 70kb, that is even we shared linking with both msvcrt and libstdc++.
>>>
>>> I frequently see a random bloat because of that.
>>>
>>> By the way, it also hurts optimizations since compilers cannot merge them
>>> together.
>>>
>>> Better just throw an exception with “vector<T> out of bounds” instead of
>>> formatting subscriptor.
>>>
>>
>>
>>I can make that depend on the _GLIBCXX_VERBOSE macro.
>
>Where is the dependency on stdio coming from though? Formatting the
>exception string doesn't use stdio.
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers?
2021-05-20 19:47 ` unlvsur unlvsur
@ 2021-05-20 19:50 ` unlvsur unlvsur
2021-05-20 20:00 ` Jonathan Wakely
2021-05-20 19:52 ` Jonathan Wakely
1 sibling, 1 reply; 8+ messages in thread
From: unlvsur unlvsur @ 2021-05-20 19:50 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: unlvsur unlvsur via Libstdc++
#include<fast_io.h>
int main(int argc,char** argv)
{
std::string_view str(*argv);
if(str.size()<4)
__builtin_trap();
print(std::string_view(str.data()+4,str.size()));
}
g++ -o c c.cc -Ofast -std=c++20 -s -flto -march=native -I../fast_io/include -static-libstdc++
26kb (10kb of EH in libsupc++)
#include<fast_io.h>
int main(int argc,char** argv)
{
std::string_view str(*argv);
print(str.substr(4));
}
g++ -o c c.cc -Ofast -std=c++20 -s -flto -march=native -I../fast_io/include -static-libstdc++
87kb (10kb of EH in libsupc++)
-fno-exceptions is useless here.
I think the reason is because it introduces the translation unit of logic errors in libstdc++. That contains 60 kb of binary.
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
From: unlvsur unlvsur<mailto:unlvsur@live.com>
Sent: Thursday, May 20, 2021 15:47
To: Jonathan Wakely<mailto:jwakely@redhat.com>
Cc: unlvsur unlvsur via Libstdc++<mailto:libstdc++@gcc.gnu.org>
Subject: RE: Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers?
// I have disabled libstdcxx verbose
#include<fast_io.h>
int main(int argc,char** argv)
{
std::string_view str(*argv);
puts(str.substr(4).data());
}
g++ -o b b.cc -Ofast -std=c++20 -s -flto -march=native -I../fast_io/include -static-libstdc++
binary size 86kb
#include<fast_io.h>
int main(int argc,char** argv)
{
std::string_view str(*argv);
if(str.size()<4)
__builtin_trap();
puts(std::string_view(str.data()+4,str.size()).data());
}
g++ -o c c.cc -Ofast -std=c++20 -s -flto -march=native -I../fast_io/include -static-libstdc++
binary size 15kb
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
From: Jonathan Wakely<mailto:jwakely@redhat.com>
Sent: Thursday, May 20, 2021 15:35
To: unlvsur unlvsur<mailto:unlvsur@live.com>
Cc: unlvsur unlvsur via Libstdc++<mailto:libstdc++@gcc.gnu.org>
Subject: Re: Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers?
On 20/05/21 19:27 +0000, unlvsur unlvsur wrote:
>Well. It comes from snprintf. You cannot use any stdio functionalities.
>
>For example
>https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgcc-mirror%2Fgcc%2Fblob%2F4f4a2f199baf46d35492edadc16f30f32920c4df%2Flibstdc%252B%252B-v3%2Finclude%2Fbits%2Fstl_vector.h%23L1070&data=04%7C01%7C%7C5e592cf75b1a4524c05408d91bc66216%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637571361118589300%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=5OZqIYtKRzXDWOcATMsIrBBYjCJOupkxk0of7SagS%2FQ%3D&reserved=0
But that doesn't use snprintf.
>
>https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgcc-mirror%2Fgcc%2Fblob%2F16e2427f50c208dfe07d07f18009969502c25dc8%2Flibstdc%252B%252B-v3%2Finclude%2Fexperimental%2Fstring_view%23L274&data=04%7C01%7C%7C5e592cf75b1a4524c05408d91bc66216%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637571361118589300%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=iukICKyYF0pB1qJv16vCcZpXrbpBhzK%2FPteRZAEZx3U%3D&reserved=0
And that doesn't use snprintf either.
Have you actually seen a dependency on stdio from these functions, or
are you just assuming?
>We need something which is a silent EH thrown, this format string thrown stuff will always introduce dependencies silently.
>
>This also hurts optimizations
>
>[cid:image002.png@01D74D8C.9AD99570]
>
>
>Sent from Mail<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgo.microsoft.com%2Ffwlink%2F%3FLinkId%3D550986&data=04%7C01%7C%7C5e592cf75b1a4524c05408d91bc66216%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637571361118589300%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=e5r3X770y%2Bm4nLrY37xW%2FUv3Bg7aa0bpsQEMoLnMstA%3D&reserved=0> for Windows 10
>
>From: Jonathan Wakely<mailto:jwakely@redhat.com>
>Sent: Thursday, May 20, 2021 15:21
>To: Jonathan Wakely<mailto:jwakely.gcc@gmail.com>
>Cc: unlvsur unlvsur<mailto:unlvsur@live.com>; unlvsur unlvsur via Libstdc++<mailto:libstdc++@gcc.gnu.org>
>Subject: Re: Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers?
>
>On 15/05/21 09:23 +0100, Jonathan Wakely via Libstdc++ wrote:
>>On Sat, 15 May 2021, 04:12 unlvsur unlvsur via Libstdc++, <
>>libstdc++@gcc.gnu.org> wrote:
>>
>>> The issue is that this will silently introduce dependency to stdio. On
>>> MinGW-w64 for example, any snprintf function call will bloat binary size
>>> for 70kb, that is even we shared linking with both msvcrt and libstdc++.
>>>
>>> I frequently see a random bloat because of that.
>>>
>>> By the way, it also hurts optimizations since compilers cannot merge them
>>> together.
>>>
>>> Better just throw an exception with “vector<T> out of bounds” instead of
>>> formatting subscriptor.
>>>
>>
>>
>>I can make that depend on the _GLIBCXX_VERBOSE macro.
>
>Where is the dependency on stdio coming from though? Formatting the
>exception string doesn't use stdio.
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers?
2021-05-20 19:47 ` unlvsur unlvsur
2021-05-20 19:50 ` unlvsur unlvsur
@ 2021-05-20 19:52 ` Jonathan Wakely
1 sibling, 0 replies; 8+ messages in thread
From: Jonathan Wakely @ 2021-05-20 19:52 UTC (permalink / raw)
To: unlvsur unlvsur; +Cc: unlvsur unlvsur via Libstdc++
On 20/05/21 19:47 +0000, unlvsur unlvsur wrote:
>// I have disabled libstdcxx verbose
>
>#include<fast_io.h>
>
>int main(int argc,char** argv)
>{
> std::string_view str(*argv);
> puts(str.substr(4).data());
>}
>
>g++ -o b b.cc -Ofast -std=c++20 -s -flto -march=native -I../fast_io/include -static-libstdc++
>
>binary size 86kb
>
>
>#include<fast_io.h>
>
>int main(int argc,char** argv)
>{
> std::string_view str(*argv);
> if(str.size()<4)
> __builtin_trap();
> puts(std::string_view(str.data()+4,str.size()).data());
>}
>
>g++ -o c c.cc -Ofast -std=c++20 -s -flto -march=native -I../fast_io/include -static-libstdc++
>
>binary size 15kb
OK, but it still doesn't use stdio.
__throw_out_of_range_fmt is defined in src/c++11/functexcept.cc which
uses __snprintf_lite defined in src/c++11/snprintf_lite.cc which
doesn't use stdio.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers?
2021-05-20 19:50 ` unlvsur unlvsur
@ 2021-05-20 20:00 ` Jonathan Wakely
0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Wakely @ 2021-05-20 20:00 UTC (permalink / raw)
To: unlvsur unlvsur; +Cc: unlvsur unlvsur via Libstdc++
On 20/05/21 19:50 +0000, unlvsur unlvsur wrote:
>#include<fast_io.h>
>
>int main(int argc,char** argv)
>{
> std::string_view str(*argv);
> if(str.size()<4)
> __builtin_trap();
> print(std::string_view(str.data()+4,str.size()));
>}
>
>g++ -o c c.cc -Ofast -std=c++20 -s -flto -march=native -I../fast_io/include -static-libstdc++
>26kb (10kb of EH in libsupc++)
>
>#include<fast_io.h>
>
>int main(int argc,char** argv)
>{
> std::string_view str(*argv);
> print(str.substr(4));
>}
>
>g++ -o c c.cc -Ofast -std=c++20 -s -flto -march=native -I../fast_io/include -static-libstdc++
>87kb (10kb of EH in libsupc++)
>
>-fno-exceptions is useless here.
>
>I think the reason is because it introduces the translation unit of logic errors in libstdc++. That contains 60 kb of binary.
To really get rid of exceptions you need to build libstdc++ itself
with -fno-exceptions.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-05-20 20:00 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-15 2:25 Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers? unlvsur unlvsur
2021-05-15 8:23 ` Jonathan Wakely
2021-05-20 19:20 ` Jonathan Wakely
[not found] ` <DM6PR05MB4697628C7E6769B8FCDA1D6ED62A9@DM6PR05MB4697.namprd05.prod.outlook.com>
2021-05-20 19:35 ` Jonathan Wakely
2021-05-20 19:47 ` unlvsur unlvsur
2021-05-20 19:50 ` unlvsur unlvsur
2021-05-20 20:00 ` Jonathan Wakely
2021-05-20 19:52 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).