public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug bootstrap/107728] New: with -O0, libgcc in the first stage compiler has reference to libc functions
@ 2022-11-16 21:43 thomas.petazzoni@free-electrons.com
  2022-11-16 21:54 ` [Bug bootstrap/107728] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: thomas.petazzoni@free-electrons.com @ 2022-11-16 21:43 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107728
           Summary: with -O0, libgcc in the first stage compiler has
                    reference to libc functions
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: bootstrap
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thomas.petazzoni@free-electrons.com
  Target Milestone: ---

We've started doing builds with -O0 in Buildroot, and we get build failures in
glibc that look like this:


/home/autobuild/autobuild/instance-11/output-1/host/lib/gcc/sh4eb-buildroot-linux-gnu/11.3.0/../../../../sh4eb-buildroot-linux-gnu/bin/ld:
/home/autobuild/autobuild/instance-11/output-1/build/glibc-2.36-66-ga1dc0be03c9dd850b864bd7a9c03cf8e396eb7ca/build/elf/librtld.os:
in function `__register_frame':
/home/autobuild/autobuild/instance-11/output-1/build/host-gcc-initial-11.3.0/build/sh4eb-buildroot-linux-gnu/libgcc/../../../libgcc/unwind-dw2-fde.c:138:
undefined reference to `malloc'
/home/autobuild/autobuild/instance-11/output-1/host/lib/gcc/sh4eb-buildroot-linux-gnu/11.3.0/../../../../sh4eb-buildroot-linux-gnu/bin/ld:
/home/autobuild/autobuild/instance-11/output-1/build/glibc-2.36-66-ga1dc0be03c9dd850b864bd7a9c03cf8e396eb7ca/build/elf/librtld.os:
in function `__register_frame_table':
/home/autobuild/autobuild/instance-11/output-1/build/host-gcc-initial-11.3.0/build/sh4eb-buildroot-linux-gnu/libgcc/../../../libgcc/unwind-dw2-fde.c:186:
undefined reference to `malloc'
/home/autobuild/autobuild/instance-11/output-1/host/lib/gcc/sh4eb-buildroot-linux-gnu/11.3.0/../../../../sh4eb-buildroot-linux-gnu/bin/ld:
/home/autobuild/autobuild/instance-11/output-1/build/glibc-2.36-66-ga1dc0be03c9dd850b864bd7a9c03cf8e396eb7ca/build/elf/librtld.os:
in function `__deregister_frame_info_bases':
/home/autobuild/autobuild/instance-11/output-1/build/host-gcc-initial-11.3.0/build/sh4eb-buildroot-linux-gnu/libgcc/../../../libgcc/unwind-dw2-fde.c:246:
undefined reference to `free'
/home/autobuild/autobuild/instance-11/output-1/host/lib/gcc/sh4eb-buildroot-linux-gnu/11.3.0/../../../../sh4eb-buildroot-linux-gnu/bin/ld:
/home/autobuild/autobuild/instance-11/output-1/build/glibc-2.36-66-ga1dc0be03c9dd850b864bd7a9c03cf8e396eb7ca/build/elf/librtld.os:
in function `__deregister_frame':
/home/autobuild/autobuild/instance-11/output-1/build/host-gcc-initial-11.3.0/build/sh4eb-buildroot-linux-gnu/libgcc/../../../libgcc/unwind-dw2-fde.c:260:
undefined reference to `free'
/home/autobuild/autobuild/instance-11/output-1/host/lib/gcc/sh4eb-buildroot-linux-gnu/11.3.0/../../../../sh4eb-buildroot-linux-gnu/bin/ld:
/home/autobuild/autobuild/instance-11/output-1/build/glibc-2.36-66-ga1dc0be03c9dd850b864bd7a9c03cf8e396eb7ca/build/elf/librtld.os:
in function `start_fde_sort':
/home/autobuild/autobuild/instance-11/output-1/build/host-gcc-initial-11.3.0/build/sh4eb-buildroot-linux-gnu/libgcc/../../../libgcc/unwind-dw2-fde.c:449:
undefined reference to `malloc'
/home/autobuild/autobuild/instance-11/output-1/host/lib/gcc/sh4eb-buildroot-linux-gnu/11.3.0/../../../../sh4eb-buildroot-linux-gnu/bin/ld:
/home/autobuild/autobuild/instance-11/output-1/build/host-gcc-initial-11.3.0/build/sh4eb-buildroot-linux-gnu/libgcc/../../../libgcc/unwind-dw2-fde.c:449:
undefined reference to `malloc'
/home/autobuild/autobuild/instance-11/output-1/host/lib/gcc/sh4eb-buildroot-linux-gnu/11.3.0/../../../../sh4eb-buildroot-linux-gnu/bin/ld:
/home/autobuild/autobuild/instance-11/output-1/build/glibc-2.36-66-ga1dc0be03c9dd850b864bd7a9c03cf8e396eb7ca/build/elf/librtld.os:
in function `end_fde_sort':
/home/autobuild/autobuild/instance-11/output-1/build/host-gcc-initial-11.3.0/build/sh4eb-buildroot-linux-gnu/libgcc/../../../libgcc/unwind-dw2-fde.c:629:
undefined reference to `free'
/home/autobuild/autobuild/instance-11/output-1/host/lib/gcc/sh4eb-buildroot-linux-gnu/11.3.0/../../../../sh4eb-buildroot-linux-gnu/bin/ld:
/home/autobuild/autobuild/instance-11/output-1/build/glibc-2.36-66-ga1dc0be03c9dd850b864bd7a9c03cf8e396eb7ca/build/elf/librtld.os:
in function `abort':
(.text+0x2345c): undefined reference to `__pthread_mutex_lock'
/home/autobuild/autobuild/instance-11/output-1/host/lib/gcc/sh4eb-buildroot-linux-gnu/11.3.0/../../../../sh4eb-buildroot-linux-gnu/bin/ld:
(.text+0x23464): undefined reference to `__pthread_mutex_unlock'
/home/autobuild/autobuild/instance-11/output-1/host/lib/gcc/sh4eb-buildroot-linux-gnu/11.3.0/../../../../sh4eb-buildroot-linux-gnu/bin/ld:
(.text+0x2346c): undefined reference to `__pthread_mutex_lock'
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:1339:
/home/autobuild/autobuild/instance-11/output-1/build/glibc-2.36-66-ga1dc0be03c9dd850b864bd7a9c03cf8e396eb7ca/build/elf/ld.so]
Error 1

See
http://autobuild.buildroot.net/results/7df/7df2d0648dd666dd07845614b34f59d6afba96c1/build-end.log
for a more complete build log.

The reason is that a number of functions in libgcc/unwind-dw2-fde.c call into C
library functions. With an optimization level of -O1 at least, these functions
get compiled out, and there is no problem. But at -O0, the code of those
functions is kept, causing the above build failure.

To reproduce:

$ git clone https://gitlab.com/buildroot.org/buildroot.git
$ cd buildroot
$ cat > .config <<EOF
BR2_sh=y
BR2_sh4eb=y
BR2_KERNEL_HEADERS_4_14=y
BR2_GCC_VERSION_12_X=y
BR2_TOOLCHAIN_BUILDROOT_CXX=y
# BR2_STRIP_strip is not set
BR2_OPTIMIZE_0=y
EOF
$ make olddefconfig
$ make

(and wait)

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

* [Bug bootstrap/107728] with -O0, libgcc in the first stage compiler has reference to libc functions
  2022-11-16 21:43 [Bug bootstrap/107728] New: with -O0, libgcc in the first stage compiler has reference to libc functions thomas.petazzoni@free-electrons.com
@ 2022-11-16 21:54 ` pinskia at gcc dot gnu.org
  2022-11-16 22:09 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-16 21:54 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |MOVED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is not a GCC issue as __register_frame_table is declared as extern.
This is almost definitely a glibc issue really.
But I doubt glibc can be compiled at -O0 because of these issues.

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

* [Bug bootstrap/107728] with -O0, libgcc in the first stage compiler has reference to libc functions
  2022-11-16 21:43 [Bug bootstrap/107728] New: with -O0, libgcc in the first stage compiler has reference to libc functions thomas.petazzoni@free-electrons.com
  2022-11-16 21:54 ` [Bug bootstrap/107728] " pinskia at gcc dot gnu.org
@ 2022-11-16 22:09 ` pinskia at gcc dot gnu.org
  2022-11-16 22:51 ` thomas.petazzoni@free-electrons.com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-16 22:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Move over, the functions are not optimized out at -O2 but rather they don't get
pulled in glibc building because another function is referenced.

Either libgcc should be built with -fdata-sections -ffunction-sections or glibc
builds needs to be fixed such that it does not reference the function in the
unwinder at -O0.  You need to look at the linker map to figure why the object
file is being pulled into glibc at -O0 and not at -O2.
But it is still a bug in glibc's ld.so really.

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

* [Bug bootstrap/107728] with -O0, libgcc in the first stage compiler has reference to libc functions
  2022-11-16 21:43 [Bug bootstrap/107728] New: with -O0, libgcc in the first stage compiler has reference to libc functions thomas.petazzoni@free-electrons.com
  2022-11-16 21:54 ` [Bug bootstrap/107728] " pinskia at gcc dot gnu.org
  2022-11-16 22:09 ` pinskia at gcc dot gnu.org
@ 2022-11-16 22:51 ` thomas.petazzoni@free-electrons.com
  2022-11-24 16:49 ` arnout at mind dot be
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: thomas.petazzoni@free-electrons.com @ 2022-11-16 22:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Thomas Petazzoni <thomas.petazzoni@free-electrons.com> ---
Thanks for the super quick feedback. Could you clarify "Move over, the
functions are not optimized out at -O2 but rather they don't get pulled in
glibc building because another function is referenced." ?

For the record, we are able to work around this issue by passing -O1 in
CFLAGS_FOR_TARGET/CXXFLAGS_FOR_TARGET when building the first stage gcc.

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

* [Bug bootstrap/107728] with -O0, libgcc in the first stage compiler has reference to libc functions
  2022-11-16 21:43 [Bug bootstrap/107728] New: with -O0, libgcc in the first stage compiler has reference to libc functions thomas.petazzoni@free-electrons.com
                   ` (2 preceding siblings ...)
  2022-11-16 22:51 ` thomas.petazzoni@free-electrons.com
@ 2022-11-24 16:49 ` arnout at mind dot be
  2022-11-24 17:29 ` arnout at mind dot be
  2022-11-24 17:31 ` [Bug libgcc/107728] _umoddi3.o has reference to the unwinder at -O0 pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: arnout at mind dot be @ 2022-11-24 16:49 UTC (permalink / raw)
  To: gcc-bugs

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

Arnout Vandecappelle <arnout at mind dot be> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |arnout at mind dot be

--- Comment #4 from Arnout Vandecappelle <arnout at mind dot be> ---
This bug was already reported before at glibc:
https://sourceware.org/bugzilla/show_bug.cgi?id=29621

There it was concluded that it is due to gcc stage1 being built with
CFLAGS_FOR_TARGET="-O0". This is not something that is tested in glibc's
testing infrastructure.

It's not clear to me whether the issue needs to be solved in GCC or in glibc.

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

* [Bug bootstrap/107728] with -O0, libgcc in the first stage compiler has reference to libc functions
  2022-11-16 21:43 [Bug bootstrap/107728] New: with -O0, libgcc in the first stage compiler has reference to libc functions thomas.petazzoni@free-electrons.com
                   ` (3 preceding siblings ...)
  2022-11-24 16:49 ` arnout at mind dot be
@ 2022-11-24 17:29 ` arnout at mind dot be
  2022-11-24 17:31 ` [Bug libgcc/107728] _umoddi3.o has reference to the unwinder at -O0 pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: arnout at mind dot be @ 2022-11-24 17:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Arnout Vandecappelle <arnout at mind dot be> ---
Based on

> glibc builds needs to be fixed such that it does not reference the function in the unwinder at -O0

I've traced through the map file why this symbol is pulled in:

/.../libgcc.a(unwind-dw2.o)
                              /.../libgcc.a(_umoddi3.o) (_Unwind_Resume)
/.../libgcc.a(unwind-dw2-fde-dip.o)
                              /.../libgcc.a(unwind-dw2.o) (_Unwind_Find_FDE)

In other words, _umoddi3.o is the one that pulls in the unwinder.

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

* [Bug libgcc/107728] _umoddi3.o has reference to the unwinder at -O0
  2022-11-16 21:43 [Bug bootstrap/107728] New: with -O0, libgcc in the first stage compiler has reference to libc functions thomas.petazzoni@free-electrons.com
                   ` (4 preceding siblings ...)
  2022-11-24 17:29 ` arnout at mind dot be
@ 2022-11-24 17:31 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-24 17:31 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|bootstrap                   |libgcc
             Status|RESOLVED                    |UNCONFIRMED
            Summary|with -O0, libgcc in the     |_umoddi3.o has reference to
                   |first stage compiler has    |the unwinder at -O0
                   |reference to libc functions |
           Keywords|                            |build
             Target|                            |sh4eb-buildroot-linux-gnu
         Resolution|MOVED                       |---

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
There still might not much to be done really.
But let's see ...

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

end of thread, other threads:[~2022-11-24 17:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-16 21:43 [Bug bootstrap/107728] New: with -O0, libgcc in the first stage compiler has reference to libc functions thomas.petazzoni@free-electrons.com
2022-11-16 21:54 ` [Bug bootstrap/107728] " pinskia at gcc dot gnu.org
2022-11-16 22:09 ` pinskia at gcc dot gnu.org
2022-11-16 22:51 ` thomas.petazzoni@free-electrons.com
2022-11-24 16:49 ` arnout at mind dot be
2022-11-24 17:29 ` arnout at mind dot be
2022-11-24 17:31 ` [Bug libgcc/107728] _umoddi3.o has reference to the unwinder at -O0 pinskia at gcc dot gnu.org

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