public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* putting __glibcxx_assert_fail into debug.cc bloats binary size by introducing all the dead code with debug.cc
@ 2021-11-18  3:16 unlvsur unlvsur
  2021-11-18  9:09 ` Jonathan Wakely
  0 siblings, 1 reply; 6+ messages in thread
From: unlvsur unlvsur @ 2021-11-18  3:16 UTC (permalink / raw)
  To: unlvsur unlvsur via Libstdc++

Can we put it into a separate translation unit with only __glibcxx_assert_fail? Linker does not remove dead functions.

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: putting __glibcxx_assert_fail into debug.cc bloats binary size by introducing all the dead code with debug.cc
  2021-11-18  3:16 putting __glibcxx_assert_fail into debug.cc bloats binary size by introducing all the dead code with debug.cc unlvsur unlvsur
@ 2021-11-18  9:09 ` Jonathan Wakely
  2021-11-18  9:12   ` unlvsur unlvsur
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Wakely @ 2021-11-18  9:09 UTC (permalink / raw)
  To: unlvsur unlvsur; +Cc: unlvsur unlvsur via Libstdc++

On Thu, 18 Nov 2021, 03:16 unlvsur unlvsur via Libstdc++, <
libstdc++@gcc.gnu.org> wrote:

> Can we put it into a separate translation unit with only
> __glibcxx_assert_fail? Linker does not remove dead functions.
>

Why does -ffunction-sections not help?



>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: putting __glibcxx_assert_fail into debug.cc bloats binary size by introducing all the dead code with debug.cc
  2021-11-18  9:09 ` Jonathan Wakely
@ 2021-11-18  9:12   ` unlvsur unlvsur
  2021-11-18  9:14     ` unlvsur unlvsur
  2021-11-18  9:44     ` Jonathan Wakely
  0 siblings, 2 replies; 6+ messages in thread
From: unlvsur unlvsur @ 2021-11-18  9:12 UTC (permalink / raw)
  To: Jonathan Wakely, unlvsur unlvsur via Libstdc++

There are all sorts of reasons why it does not work.

sec18-quach.pdf (usenix.org)<https://www.usenix.org/system/files/conference/usenixsecurity18/sec18-quach.pdf>

In the security paper Debloating Software through Piece-Wise Compilation and Loading

Unused Functions. Static analysis during compilation can efficiently remove dead code at a basic block level,
however, entire unused functions are not eliminated. Consider the following program:

int f() { return 1; }
int main() { return 0; }

Both gcc and clang retain the function f in
the above code even under optimization level
-O3. Removal of unused functions require additional non-standard often-unused compiler (-fdata-sections -ffunction-sections -Os) and linker (-Wl,--gc-sections) optimization flags.
Even so, unused functions in dynamically loaded libraries can not be eliminated during compile time.

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows

From: Jonathan Wakely<mailto:jwakely.gcc@gmail.com>
Sent: Thursday, November 18, 2021 04:09
To: unlvsur unlvsur<mailto:unlvsur@live.com>
Cc: unlvsur unlvsur via Libstdc++<mailto:libstdc++@gcc.gnu.org>
Subject: Re: putting __glibcxx_assert_fail into debug.cc bloats binary size by introducing all the dead code with debug.cc


On Thu, 18 Nov 2021, 03:16 unlvsur unlvsur via Libstdc++, <libstdc++@gcc.gnu.org<mailto:libstdc%2B%2B@gcc.gnu.org>> wrote:
Can we put it into a separate translation unit with only __glibcxx_assert_fail? Linker does not remove dead functions.

Why does -ffunction-sections not help?





^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: putting __glibcxx_assert_fail into debug.cc bloats binary size by introducing all the dead code with debug.cc
  2021-11-18  9:12   ` unlvsur unlvsur
@ 2021-11-18  9:14     ` unlvsur unlvsur
  2021-11-18  9:44     ` Jonathan Wakely
  1 sibling, 0 replies; 6+ messages in thread
From: unlvsur unlvsur @ 2021-11-18  9:14 UTC (permalink / raw)
  To: Jonathan Wakely, unlvsur unlvsur via Libstdc++

That is exactly why newlib or musl puts every function into separate translation unit to prevent dead code.

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows

From: unlvsur unlvsur<mailto:unlvsur@live.com>
Sent: Thursday, November 18, 2021 04:12
To: Jonathan Wakely<mailto:jwakely.gcc@gmail.com>; unlvsur unlvsur via Libstdc++<mailto:libstdc++@gcc.gnu.org>
Subject: RE: putting __glibcxx_assert_fail into debug.cc bloats binary size by introducing all the dead code with debug.cc

There are all sorts of reasons why it does not work.

sec18-quach.pdf (usenix.org)<https://www.usenix.org/system/files/conference/usenixsecurity18/sec18-quach.pdf>

In the security paper Debloating Software through Piece-Wise Compilation and Loading

Unused Functions. Static analysis during compilation can efficiently remove dead code at a basic block level,
however, entire unused functions are not eliminated. Consider the following program:

int f() { return 1; }
int main() { return 0; }

Both gcc and clang retain the function f in
the above code even under optimization level
-O3. Removal of unused functions require additional non-standard often-unused compiler (-fdata-sections -ffunction-sections -Os) and linker (-Wl,--gc-sections) optimization flags.
Even so, unused functions in dynamically loaded libraries can not be eliminated during compile time.

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows

From: Jonathan Wakely<mailto:jwakely.gcc@gmail.com>
Sent: Thursday, November 18, 2021 04:09
To: unlvsur unlvsur<mailto:unlvsur@live.com>
Cc: unlvsur unlvsur via Libstdc++<mailto:libstdc++@gcc.gnu.org>
Subject: Re: putting __glibcxx_assert_fail into debug.cc bloats binary size by introducing all the dead code with debug.cc


On Thu, 18 Nov 2021, 03:16 unlvsur unlvsur via Libstdc++, <libstdc++@gcc.gnu.org<mailto:libstdc%2B%2B@gcc.gnu.org>> wrote:
Can we put it into a separate translation unit with only __glibcxx_assert_fail? Linker does not remove dead functions.

Why does -ffunction-sections not help?






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: putting __glibcxx_assert_fail into debug.cc bloats binary size by introducing all the dead code with debug.cc
  2021-11-18  9:12   ` unlvsur unlvsur
  2021-11-18  9:14     ` unlvsur unlvsur
@ 2021-11-18  9:44     ` Jonathan Wakely
  2021-11-18  9:51       ` Jonathan Wakely
  1 sibling, 1 reply; 6+ messages in thread
From: Jonathan Wakely @ 2021-11-18  9:44 UTC (permalink / raw)
  To: unlvsur unlvsur; +Cc: unlvsur unlvsur via Libstdc++

On Thu, 18 Nov 2021 at 09:12, unlvsur unlvsur wrote:
> -O3. Removal of unused functions require additional non-standard often-unused compiler (-fdata-sections -ffunction-sections -Os) and linker (-Wl,--gc-sections) optimization flags.

I asked why one of those flags doesn't help, and all you've done is
quote something that says you need to use those flags. You realise
that's not an answer, right?

Libstdc++ is built with -fdata-sections -ffunction-sections -O2 and
linked with -Wl,--gc-sections

So why doesn't it help?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: putting __glibcxx_assert_fail into debug.cc bloats binary size by introducing all the dead code with debug.cc
  2021-11-18  9:44     ` Jonathan Wakely
@ 2021-11-18  9:51       ` Jonathan Wakely
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Wakely @ 2021-11-18  9:51 UTC (permalink / raw)
  To: unlvsur unlvsur; +Cc: unlvsur unlvsur via Libstdc++

On Thu, 18 Nov 2021 at 09:44, Jonathan Wakely wrote:
>
> On Thu, 18 Nov 2021 at 09:12, unlvsur unlvsur wrote:
> > -O3. Removal of unused functions require additional non-standard often-unused compiler (-fdata-sections -ffunction-sections -Os) and linker (-Wl,--gc-sections) optimization flags.
>
> I asked why one of those flags doesn't help, and all you've done is
> quote something that says you need to use those flags. You realise
> that's not an answer, right?
>
> Libstdc++ is built with -fdata-sections -ffunction-sections -O2 and
> linked with -Wl,--gc-sections
>
> So why doesn't it help?

I guess the problem is that users need to link their own code with
-Wl,--gc-sections to get the benefit. But then if you care about the
size of the result, you should be doing that.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-11-18  9:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-18  3:16 putting __glibcxx_assert_fail into debug.cc bloats binary size by introducing all the dead code with debug.cc unlvsur unlvsur
2021-11-18  9:09 ` Jonathan Wakely
2021-11-18  9:12   ` unlvsur unlvsur
2021-11-18  9:14     ` unlvsur unlvsur
2021-11-18  9:44     ` Jonathan Wakely
2021-11-18  9:51       ` 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).