public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/99113] New: SHF_GNU_RETAIN doesn't work with Linux kernel
@ 2021-02-15 18:32 hjl.tools at gmail dot com
  2021-02-15 18:34 ` [Bug target/99113] " hjl.tools at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2021-02-15 18:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99113
           Summary: SHF_GNU_RETAIN doesn't work with Linux kernel
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hjl.tools at gmail dot com
                CC: jozef.l at somniumtech dot com
  Target Milestone: ---

when building Linux kernel, ld in ninutils 2.36 with GCC 11 generates
thousands of

ld: warning: orphan section `.data.event_initcall_finish' from `init/main.o'
bei
ng placed in section `.data.event_initcall_finish'
ld: warning: orphan section `.data.event_initcall_start' from `init/main.o'
bein
g placed in section `.data.event_initcall_start'
ld: warning: orphan section `.data.event_initcall_level' from `init/main.o'
bein
g placed in section `.data.event_initcall_level'

Since these sections are marked with SHF_GNU_RETAIN, they are placed in
separate sections.  They become orphan sections since they aren't expected
in the Linux kernel linker script. But orphan sections normally don't work
well with the Linux kernel linker script and the resulting kernel crashed.

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

* [Bug target/99113] SHF_GNU_RETAIN doesn't work with Linux kernel
  2021-02-15 18:32 [Bug target/99113] New: SHF_GNU_RETAIN doesn't work with Linux kernel hjl.tools at gmail dot com
@ 2021-02-15 18:34 ` hjl.tools at gmail dot com
  2021-02-15 18:54 ` slyfox at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2021-02-15 18:34 UTC (permalink / raw)
  To: gcc-bugs

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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-02-15
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> ---
Since the Linux kernel is compiled with -fno-function-sections
-fno-data-sections, we should use it to avoid putting SHF_GNU_RETAIN
sections in separate sections.

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

* [Bug target/99113] SHF_GNU_RETAIN doesn't work with Linux kernel
  2021-02-15 18:32 [Bug target/99113] New: SHF_GNU_RETAIN doesn't work with Linux kernel hjl.tools at gmail dot com
  2021-02-15 18:34 ` [Bug target/99113] " hjl.tools at gmail dot com
@ 2021-02-15 18:54 ` slyfox at gcc dot gnu.org
  2021-02-15 19:12 ` hjl.tools at gmail dot com
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: slyfox at gcc dot gnu.org @ 2021-02-15 18:54 UTC (permalink / raw)
  To: gcc-bugs

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

Sergei Trofimovich <slyfox at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |slyfox at gcc dot gnu.org

--- Comment #2 from Sergei Trofimovich <slyfox at gcc dot gnu.org> ---
I have a few notes:

1. GCC should put SHF_GNU_RETAIN section into a different section from .data
anyway, right?

I think that means linux kernel would need to adapt in any case to merge new
.data.${SHF_GNU_RETAIN_name} section into appropriate place in it's linker
script.

Proposal: rename a section in an easily distinguishable prefix, like:

    NEW:    .data.retain.event_initcall_finish
    OLD:    .data.event_initcall_finish

That would simplify tweaking linux ldscript. For -fno-function-sections case it
could be just.
    .data.retain

Do we still have time for such a rename? Is it safe?

2. Linux kernel does support -ffunction-sections  with
CONFIG_LD_DEAD_CODE_DATA_ELIMINATION. But it relies even more on naming
conventions:

  #ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
  #define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
  #define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..LPBX*
  #define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]*
  #define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]*
  #define BSS_MAIN .bss .bss.[0-9a-zA-Z_]*
  #define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]*
  #else
  #define TEXT_MAIN .text
  #define DATA_MAIN .data
  #define SDATA_MAIN .sdata
  #define RODATA_MAIN .rodata
  #define BSS_MAIN .bss
  #define SBSS_MAIN .sbss
  #endif

  A variant of [1.] would allow for easier section ganthering in the script.

3. I tried to add '.data.event*' (and similar) to linux ldscript and it was not
enough for me to built a kernel that does not crash. Which might hint at
binutils bug or linux loader bug (or at my bad attempt at adding sections).

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

* [Bug target/99113] SHF_GNU_RETAIN doesn't work with Linux kernel
  2021-02-15 18:32 [Bug target/99113] New: SHF_GNU_RETAIN doesn't work with Linux kernel hjl.tools at gmail dot com
  2021-02-15 18:34 ` [Bug target/99113] " hjl.tools at gmail dot com
  2021-02-15 18:54 ` slyfox at gcc dot gnu.org
@ 2021-02-15 19:12 ` hjl.tools at gmail dot com
  2021-02-15 19:31 ` slyfox at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2021-02-15 19:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Sergei Trofimovich from comment #2)
> 3. I tried to add '.data.event*' (and similar) to linux ldscript and it was
> not enough for me to built a kernel that does not crash. Which might hint at
> binutils bug or linux loader bug (or at my bad attempt at adding sections).

There are many different section names.

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

* [Bug target/99113] SHF_GNU_RETAIN doesn't work with Linux kernel
  2021-02-15 18:32 [Bug target/99113] New: SHF_GNU_RETAIN doesn't work with Linux kernel hjl.tools at gmail dot com
                   ` (2 preceding siblings ...)
  2021-02-15 19:12 ` hjl.tools at gmail dot com
@ 2021-02-15 19:31 ` slyfox at gcc dot gnu.org
  2021-02-15 20:33 ` hjl.tools at gmail dot com
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: slyfox at gcc dot gnu.org @ 2021-02-15 19:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Sergei Trofimovich <slyfox at gcc dot gnu.org> ---
(In reply to H.J. Lu from comment #3)
> (In reply to Sergei Trofimovich from comment #2)
> > 3. I tried to add '.data.event*' (and similar) to linux ldscript and it was
> > not enough for me to built a kernel that does not crash. Which might hint at
> > binutils bug or linux loader bug (or at my bad attempt at adding sections).
> 
> There are many different section names.

Yeah, that makes sense. My attempt was:

--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -102,7 +102,7 @@
 #define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]*
 #else
 #define TEXT_MAIN .text
-#define DATA_MAIN .data
+#define DATA_MAIN .data .data.event* .data.__syscall_meta__*
 #define SDATA_MAIN .sdata
 #define RODATA_MAIN .rodata
 #define BSS_MAIN .bss

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

* [Bug target/99113] SHF_GNU_RETAIN doesn't work with Linux kernel
  2021-02-15 18:32 [Bug target/99113] New: SHF_GNU_RETAIN doesn't work with Linux kernel hjl.tools at gmail dot com
                   ` (3 preceding siblings ...)
  2021-02-15 19:31 ` slyfox at gcc dot gnu.org
@ 2021-02-15 20:33 ` hjl.tools at gmail dot com
  2021-02-15 20:34 ` hjl.tools at gmail dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2021-02-15 20:33 UTC (permalink / raw)
  To: gcc-bugs

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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |hjl.tools at gmail dot com

--- Comment #5 from H.J. Lu <hjl.tools at gmail dot com> ---
Created attachment 50189
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50189&action=edit
A patch

I am testing this.

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

* [Bug target/99113] SHF_GNU_RETAIN doesn't work with Linux kernel
  2021-02-15 18:32 [Bug target/99113] New: SHF_GNU_RETAIN doesn't work with Linux kernel hjl.tools at gmail dot com
                   ` (4 preceding siblings ...)
  2021-02-15 20:33 ` hjl.tools at gmail dot com
@ 2021-02-15 20:34 ` hjl.tools at gmail dot com
  2021-02-15 22:36 ` hjl.tools at gmail dot com
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2021-02-15 20:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> ---
Created attachment 50190
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50190&action=edit
A kernel patch to pass -fno-gnu-retain

This patch makes kernel to boot.

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

* [Bug target/99113] SHF_GNU_RETAIN doesn't work with Linux kernel
  2021-02-15 18:32 [Bug target/99113] New: SHF_GNU_RETAIN doesn't work with Linux kernel hjl.tools at gmail dot com
                   ` (5 preceding siblings ...)
  2021-02-15 20:34 ` hjl.tools at gmail dot com
@ 2021-02-15 22:36 ` hjl.tools at gmail dot com
  2021-02-16  7:28 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2021-02-15 22:36 UTC (permalink / raw)
  To: gcc-bugs

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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
   Target Milestone|---                         |11.0

--- Comment #7 from H.J. Lu <hjl.tools at gmail dot com> ---
A patch is posted at

https://gcc.gnu.org/pipermail/gcc-patches/2021-February/565337.html

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

* [Bug target/99113] SHF_GNU_RETAIN doesn't work with Linux kernel
  2021-02-15 18:32 [Bug target/99113] New: SHF_GNU_RETAIN doesn't work with Linux kernel hjl.tools at gmail dot com
                   ` (6 preceding siblings ...)
  2021-02-15 22:36 ` hjl.tools at gmail dot com
@ 2021-02-16  7:28 ` rguenth at gcc dot gnu.org
  2021-02-18 21:27 ` cvs-commit at gcc dot gnu.org
  2021-02-18 21:29 ` hjl.tools at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-02-16  7:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
Well, certainly expected as you changed the semantics of 'used' ...

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

* [Bug target/99113] SHF_GNU_RETAIN doesn't work with Linux kernel
  2021-02-15 18:32 [Bug target/99113] New: SHF_GNU_RETAIN doesn't work with Linux kernel hjl.tools at gmail dot com
                   ` (7 preceding siblings ...)
  2021-02-16  7:28 ` rguenth at gcc dot gnu.org
@ 2021-02-18 21:27 ` cvs-commit at gcc dot gnu.org
  2021-02-18 21:29 ` hjl.tools at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-02-18 21:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by H.J. Lu <hjl@gcc.gnu.org>:

https://gcc.gnu.org/g:6347f4a0904fce17eedf5c071be6f3c118680290

commit r11-7284-g6347f4a0904fce17eedf5c071be6f3c118680290
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Feb 15 11:31:12 2021 -0800

    Add retain attribute to place symbols in SHF_GNU_RETAIN section

    When building Linux kernel, ld in bninutils 2.36 with GCC 11 generates
    thousands of

    ld: warning: orphan section `.data.event_initcall_finish' from
`init/main.o' being placed in section `.data.event_initcall_finish'
    ld: warning: orphan section `.data.event_initcall_start' from `init/main.o'
being placed in section `.data.event_initcall_start'
    ld: warning: orphan section `.data.event_initcall_level' from `init/main.o'
being placed in section `.data.event_initcall_level'

    Since these sections are marked with SHF_GNU_RETAIN, they are placed in
    separate sections.  They become orphan sections since they aren't expected
    in the Linux kernel linker script. But orphan sections normally don't work
    well with the Linux kernel linker script and the resulting kernel crashed.

    Add the "retain" attribute to place symbols in separate SHF_GNU_RETAIN
    sections.  Issue a warning if the configured assembler/linker doesn't
    support SHF_GNU_RETAIN.

    gcc/

            PR target/99113
            * varasm.c (get_section): Replace SUPPORTS_SHF_GNU_RETAIN with
            looking up the retain attribute.
            (resolve_unique_section): Likewise.
            (get_variable_section): Likewise.
            (switch_to_section): Likewise.  Warn when a symbol without the
            retain attribute and a symbol with the retain attribute are
            placed in the section with the same name, instead of the used
            attribute.
            * doc/extend.texi: Document the "retain" attribute.

    gcc/c-family/

            PR target/99113
            * c-attribs.c (c_common_attribute_table): Add the "retain"
            attribute.
            (handle_retain_attribute): New function.

    gcc/testsuite/

            PR target/99113
            * c-c++-common/attr-retain-1.c: New test.
            * c-c++-common/attr-retain-2.c: Likewise.
            * c-c++-common/attr-retain-3.c: Likewise.
            * c-c++-common/attr-retain-4.c: Likewise.
            * c-c++-common/attr-retain-5.c: Likewise.
            * c-c++-common/attr-retain-6.c: Likewise.
            * c-c++-common/attr-retain-7.c: Likewise.
            * c-c++-common/attr-retain-8.c: Likewise.
            * c-c++-common/attr-retain-9.c: Likewise.
            * c-c++-common/pr99113.c: Likewise.
            * gcc.c-torture/compile/attr-retain-1.c: Likewise.
            * gcc.c-torture/compile/attr-retain-2.c: Likewise.
            * c-c++-common/attr-used.c: Don't expect SHF_GNU_RETAIN section.
            * c-c++-common/attr-used-2.c: Likewise.
            * c-c++-common/attr-used-3.c: Likewise.
            * c-c++-common/attr-used-4.c: Likewise.
            * c-c++-common/attr-used-9.c: Likewise.
            * gcc.c-torture/compile/attr-used-retain-1.c: Likewise.
            * gcc.c-torture/compile/attr-used-retain-2.c: Likewise.
            * c-c++-common/attr-used-5.c: Don't expect warning for the used
            attribute nor SHF_GNU_RETAIN section.
            * c-c++-common/attr-used-6.c: Likewise.
            * c-c++-common/attr-used-7.c: Likewise.
            * c-c++-common/attr-used-8.c: Likewise.

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

* [Bug target/99113] SHF_GNU_RETAIN doesn't work with Linux kernel
  2021-02-15 18:32 [Bug target/99113] New: SHF_GNU_RETAIN doesn't work with Linux kernel hjl.tools at gmail dot com
                   ` (8 preceding siblings ...)
  2021-02-18 21:27 ` cvs-commit at gcc dot gnu.org
@ 2021-02-18 21:29 ` hjl.tools at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2021-02-18 21:29 UTC (permalink / raw)
  To: gcc-bugs

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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #10 from H.J. Lu <hjl.tools at gmail dot com> ---
Fixed.

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

end of thread, other threads:[~2021-02-18 21:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-15 18:32 [Bug target/99113] New: SHF_GNU_RETAIN doesn't work with Linux kernel hjl.tools at gmail dot com
2021-02-15 18:34 ` [Bug target/99113] " hjl.tools at gmail dot com
2021-02-15 18:54 ` slyfox at gcc dot gnu.org
2021-02-15 19:12 ` hjl.tools at gmail dot com
2021-02-15 19:31 ` slyfox at gcc dot gnu.org
2021-02-15 20:33 ` hjl.tools at gmail dot com
2021-02-15 20:34 ` hjl.tools at gmail dot com
2021-02-15 22:36 ` hjl.tools at gmail dot com
2021-02-16  7:28 ` rguenth at gcc dot gnu.org
2021-02-18 21:27 ` cvs-commit at gcc dot gnu.org
2021-02-18 21:29 ` hjl.tools at gmail dot com

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