public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/95095] New: Feature request: support -fno-unique-section-names
@ 2020-05-12 21:57 i at maskray dot me
  2020-05-24 22:08 ` [Bug target/95095] " i at maskray dot me
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: i at maskray dot me @ 2020-05-12 21:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95095

            Bug ID: 95095
           Summary: Feature request: support -fno-unique-section-names
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: i at maskray dot me
  Target Milestone: ---

-ffunction-sections produces sections .text.foo , .text.bar , etc, which can
take significant amount of string table space.

In clang, -fno-unique-section-names emits multiple ".text" sections which can
share the section name. Multiple sections with the same name require the new
GNU as feature https://sourceware.org/bugzilla/show_bug.cgi?id=25380 (binutils
2.35).

For .text.exit.* .text.unlikely.* .text.hot.* .text.startup.* , the preferred
sections are .text.exit. .text.unlikely. .text.hot. .text.startup. The trailing
dots can avoid a linker problem described in https://reviews.llvm.org/D79600

--------- pasted below for your convenience

GNU ld's internal linker script uses
(https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=add44f8d5c5c05e08b11e033127a744d61c26aee)

.text           :
{
  *(.text.unlikely .text.*_unlikely .text.unlikely.*)
  *(.text.exit .text.exit.*)
  *(.text.startup .text.startup.*)
  *(.text.hot .text.hot.*)
  *(SORT(.text.sorted.*))
  *(.text .stub .text.* .gnu.linkonce.t.*)
  /* .gnu.warning sections are handled specially by elf.em.  */
  *(.gnu.warning)
}
Because *(.text.exit .text.exit.*) is ordered before *(.text .text.*), in a
-ffunction-sections build, the C library function exit will be placed before
other functions.
gold's -z keep-text-section-prefix has the same problem.

In lld, -z keep-text-section-prefix recognizes
.text.{exit,hot,startup,unlikely,unknown}.*, but not
.text.{exit,hot,startup,unlikely,unknown}, to avoid the strange placement
problem.

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

* [Bug target/95095] Feature request: support -fno-unique-section-names
  2020-05-12 21:57 [Bug target/95095] New: Feature request: support -fno-unique-section-names i at maskray dot me
@ 2020-05-24 22:08 ` i at maskray dot me
  2021-01-16 20:49 ` segher at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: i at maskray dot me @ 2020-05-24 22:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95095

--- Comment #1 from Fangrui Song <i at maskray dot me> ---
I just learned that `int main() {}` compiles to .text.startup in -O2 or -Os

It seems that .text.startup. may be better to not accidentally move a C
function named `startup` (`startup.` is not a valid C identifier)

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

* [Bug target/95095] Feature request: support -fno-unique-section-names
  2020-05-12 21:57 [Bug target/95095] New: Feature request: support -fno-unique-section-names i at maskray dot me
  2020-05-24 22:08 ` [Bug target/95095] " i at maskray dot me
@ 2021-01-16 20:49 ` segher at gcc dot gnu.org
  2021-01-16 21:00 ` i at maskray dot me
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: segher at gcc dot gnu.org @ 2021-01-16 20:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95095

--- Comment #2 from Segher Boessenkool <segher at gcc dot gnu.org> ---
Can't we use ".text%name" for -ffunction-sections, like we did originally,
in 1996?  See cf4403481dd6.  This does not conflict with other section
names, and does not have all the problems you get from doing anything that
is not a simple prefix.

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

* [Bug target/95095] Feature request: support -fno-unique-section-names
  2020-05-12 21:57 [Bug target/95095] New: Feature request: support -fno-unique-section-names i at maskray dot me
  2020-05-24 22:08 ` [Bug target/95095] " i at maskray dot me
  2021-01-16 20:49 ` segher at gcc dot gnu.org
@ 2021-01-16 21:00 ` i at maskray dot me
  2021-01-22  0:57 ` segher at kernel dot crashing.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: i at maskray dot me @ 2021-01-16 21:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95095

--- Comment #3 from Fangrui Song <i at maskray dot me> ---
(In reply to Segher Boessenkool from comment #2)
> Can't we use ".text%name" for -ffunction-sections, like we did originally,
> in 1996?  See cf4403481dd6.  This does not conflict with other section
> names, and does not have all the problems you get from doing anything that
> is not a simple prefix.

A function named 'foo' compiles to '.text%foo'? It might have been better to
avoid conflicts with '.text.startup' '.text.hot' etc but now such a change
would just inconvenience users (think of various Linux kernel linker script
fragments).

.text%name does not address -fno-unique-section-names.

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

* [Bug target/95095] Feature request: support -fno-unique-section-names
  2020-05-12 21:57 [Bug target/95095] New: Feature request: support -fno-unique-section-names i at maskray dot me
                   ` (2 preceding siblings ...)
  2021-01-16 21:00 ` i at maskray dot me
@ 2021-01-22  0:57 ` segher at kernel dot crashing.org
  2021-01-22  1:38 ` i at maskray dot me
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: segher at kernel dot crashing.org @ 2021-01-22  0:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95095

--- Comment #4 from Segher Boessenkool <segher at kernel dot crashing.org> ---
On Sat, Jan 16, 2021 at 09:00:56PM +0000, i at maskray dot me wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95095
> 
> --- Comment #3 from Fangrui Song <i at maskray dot me> ---
> (In reply to Segher Boessenkool from comment #2)
> > Can't we use ".text%name" for -ffunction-sections, like we did originally,
> > in 1996?  See cf4403481dd6.  This does not conflict with other section
> > names, and does not have all the problems you get from doing anything that
> > is not a simple prefix.
> 
> A function named 'foo' compiles to '.text%foo'? It might have been better to
> avoid conflicts with '.text.startup' '.text.hot' etc but now such a change
> would just inconvenience users (think of various Linux kernel linker script
> fragments).

The conflicts that show up from time to time *also* inconvenience users,
and that is an ongoing inconvenience.

> .text%name does not address -fno-unique-section-names.

And neither does ".text.name.".

Something like this is a prerequisite of such an option.

Also, please use a different name, one that does not start with "no-"?
It isn't about unique names at all anyway, it is about having multiple
sections with the same name (that then can get separately GCed, because
of new linker features).


Segher

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

* [Bug target/95095] Feature request: support -fno-unique-section-names
  2020-05-12 21:57 [Bug target/95095] New: Feature request: support -fno-unique-section-names i at maskray dot me
                   ` (3 preceding siblings ...)
  2021-01-22  0:57 ` segher at kernel dot crashing.org
@ 2021-01-22  1:38 ` i at maskray dot me
  2021-01-25 16:30 ` segher at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: i at maskray dot me @ 2021-01-22  1:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95095

--- Comment #5 from Fangrui Song <i at maskray dot me> ---
Linux kernel

include/asm-generic/vmlinux.lds.h currently has
#define TEXT_TEXT                                                       \
                ALIGN_FUNCTION();                                       \
                *(.text.hot .text.hot.*)                                \
                *(TEXT_MAIN .text.fixup)                                \
                *(.text.unlikely .text.unlikely.*)                      \
                *(.text.unknown .text.unknown.*)                        \
                NOINSTR_TEXT                                            \
                *(.text..refcount)                                      \
                *(.ref.text)                                            \
        MEM_KEEP(init.text*)                                            \
        MEM_KEEP(exit.text*)                                            \

If you change .text.* to .text%* , this script will need a change, along with
other projects which use or adapt GNU ld's built-in linker script

  .text           :
  {
    *(.text.unlikely .text.*_unlikely .text.unlikely.*)
    *(.text.exit .text.exit.*)
    *(.text.startup .text.startup.*)
    *(.text.hot .text.hot.*)
    *(SORT(.text.sorted.*))
    *(.text .stub .text.* .gnu.linkonce.t.*)
    /* .gnu.warning sections are handled specially by elf.em.  */
    *(.gnu.warning)
  }

By default, -fno-unique-section-names produces '.text' instead of '.text.foo'
in the normal -ffunction-sections case.

For PGO, -fno-unique-section-names produces '.text.hot.' instead of
'.text.hot.foo' in the normal -ffunction-sections case.

'.text.hot.' is an attempt to distinguish PGO caused 'hot' from a regular
functions named 'hot'.

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

* [Bug target/95095] Feature request: support -fno-unique-section-names
  2020-05-12 21:57 [Bug target/95095] New: Feature request: support -fno-unique-section-names i at maskray dot me
                   ` (4 preceding siblings ...)
  2021-01-22  1:38 ` i at maskray dot me
@ 2021-01-25 16:30 ` segher at gcc dot gnu.org
  2021-01-25 17:58 ` i at maskray dot me
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: segher at gcc dot gnu.org @ 2021-01-25 16:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95095

--- Comment #6 from Segher Boessenkool <segher at gcc dot gnu.org> ---
I was under the impression this unique section thing needed the trailing
dot thing.  This probably is not true.

I still think the old "%" thing is much superior to the trailing dot thing,
but that then is orthogonal to the "unique section" thing, so let's ignore
it now :-)

It still remains that this flag needs a name that says what it *does*, as I
mentioned at the end of Comment 4.

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

* [Bug target/95095] Feature request: support -fno-unique-section-names
  2020-05-12 21:57 [Bug target/95095] New: Feature request: support -fno-unique-section-names i at maskray dot me
                   ` (5 preceding siblings ...)
  2021-01-25 16:30 ` segher at gcc dot gnu.org
@ 2021-01-25 17:58 ` i at maskray dot me
  2021-01-25 19:04 ` segher at gcc dot gnu.org
  2021-01-25 20:11 ` i at maskray dot me
  8 siblings, 0 replies; 10+ messages in thread
From: i at maskray dot me @ 2021-01-25 17:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95095

--- Comment #7 from Fangrui Song <i at maskray dot me> ---
(In reply to Segher Boessenkool from comment #6)
> I was under the impression this unique section thing needed the trailing
> dot thing.  This probably is not true.
> 
> I still think the old "%" thing is much superior to the trailing dot thing,
> but that then is orthogonal to the "unique section" thing, so let's ignore
> it now :-)
> 
> It still remains that this flag needs a name that says what it *does*, as I
> mentioned at the end of Comment 4.

-ffunction-sections -fno-unique-section-names =>

.text.%
.text.startup.%
.text.hot.%
.text.cold.%
...

?

I agree that it is superior. If GCC wants to support this scheme, that looks
fine to me. It is likely that I can migrate Clang to this scheme as well.

I think

.text%
.text.startup%
.text.hot%
.text.cold%
...

is slightly worse.

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

* [Bug target/95095] Feature request: support -fno-unique-section-names
  2020-05-12 21:57 [Bug target/95095] New: Feature request: support -fno-unique-section-names i at maskray dot me
                   ` (6 preceding siblings ...)
  2021-01-25 17:58 ` i at maskray dot me
@ 2021-01-25 19:04 ` segher at gcc dot gnu.org
  2021-01-25 20:11 ` i at maskray dot me
  8 siblings, 0 replies; 10+ messages in thread
From: segher at gcc dot gnu.org @ 2021-01-25 19:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95095

--- Comment #8 from Segher Boessenkool <segher at gcc dot gnu.org> ---
I say nothing like that.  I say that
  .text.hot.
is nasty (is easily mistaken for .text.hot).

I also say that and that named-per-function sections are better as
  .text%name
than as
  .text.name
(just as they were long ago), because this doesn't conflict with things like
  .text.hot
(and there is a very long history of such conflicts giving real-world
problems).

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

* [Bug target/95095] Feature request: support -fno-unique-section-names
  2020-05-12 21:57 [Bug target/95095] New: Feature request: support -fno-unique-section-names i at maskray dot me
                   ` (7 preceding siblings ...)
  2021-01-25 19:04 ` segher at gcc dot gnu.org
@ 2021-01-25 20:11 ` i at maskray dot me
  8 siblings, 0 replies; 10+ messages in thread
From: i at maskray dot me @ 2021-01-25 20:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95095

--- Comment #9 from Fangrui Song <i at maskray dot me> ---
(In reply to Segher Boessenkool from comment #8)
> I say nothing like that.  I say that
>   .text.hot.
> is nasty (is easily mistaken for .text.hot).
> 
> I also say that and that named-per-function sections are better as
>   .text%name
> than as
>   .text.name
> (just as they were long ago), because this doesn't conflict with things like
>   .text.hot
> (and there is a very long history of such conflicts giving real-world
> problems).

.text%name and .text.hot%name will break existing output section descriptions
for .text

My scheme .text.% .text.hot.% is backward compatible.

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

end of thread, other threads:[~2021-01-25 20:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-12 21:57 [Bug target/95095] New: Feature request: support -fno-unique-section-names i at maskray dot me
2020-05-24 22:08 ` [Bug target/95095] " i at maskray dot me
2021-01-16 20:49 ` segher at gcc dot gnu.org
2021-01-16 21:00 ` i at maskray dot me
2021-01-22  0:57 ` segher at kernel dot crashing.org
2021-01-22  1:38 ` i at maskray dot me
2021-01-25 16:30 ` segher at gcc dot gnu.org
2021-01-25 17:58 ` i at maskray dot me
2021-01-25 19:04 ` segher at gcc dot gnu.org
2021-01-25 20:11 ` i at maskray dot me

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).