Skip to contentSkip to conversation

package/gcc: ensure __register_frame is optimized out for glibc

PATCH In review James Hilliard 5 participants 6 messages Oct 28, 2022 – Dec 6, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/gcc: ensure __register_frame is optimized out for glibc

On some architectures when building with -O0 the __register_frame symbol fails to get optimized out which can cause linking failures when building glibc.

To fix this set -O1 for GCC target libs when building with glibc and BR2_OPTIMIZE_0 on the problematic target architectures.

Fixes:
- http://autobuild.buildroot.net/results/89b/89b6c6924240b7cf82035a844f3573673e91b364
- http://autobuild.buildroot.net/results/46f/46f4ec99d2b23d354a4bb5e92123d64f0da6ed27
- http://autobuild.buildroot.net/results/839/839f929f700cf181ebdf34389c7806a96f55813e
- http://autobuild.buildroot.net/results/0e2/0e202bf53a683930f3cad6edef2a4dea629eaecb
- http://autobuild.buildroot.net/results/8a8/8a8c917f597fdcca744e696e19e9300b64004335
- http://autobuild.buildroot.net/results/c05/c058b27ed2834dfa633b63ec6c3639ab1e8bf412
- http://autobuild.buildroot.net/results/8ba/8ba8882a861cf7df359c23969c09b2be0725b2e5

---
 package/gcc/gcc.mk | 9 +++++++++
 1 file changed, 9 insertions(+)
package/gcc/gcc.mk +9 -0
index ec6f3b550a..a339f77970 100644
@@ -103,6 +103,15 @@ GCC_COMMON_TARGET_CFLAGS += -matomic
 GCC_COMMON_TARGET_CXXFLAGS += -matomic
 endif
 
+# Enable GCC target libs optimizations to optimize out __register_frame
+# when needed for some architectures when building with glibc.
+ifeq ($(BR2_TOOLCHAIN_USES_GLIBC)$(BR2_OPTIMIZE_0),yy)
+ifeq ($(BR2_microblazebe)$(BR2_microblazeel)$(BR2_mips)$(BR2_mipsel)$(BR2_nios2)$(BR2_or1k)$(BR2_sh),y)
+GCC_COMMON_TARGET_CFLAGS += -O1
+GCC_COMMON_TARGET_CXXFLAGS += -O1
+endif
+endif
+
 # Propagate options used for target software building to GCC target libs
 HOST_GCC_COMMON_CONF_ENV += CFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CFLAGS)"
 HOST_GCC_COMMON_CONF_ENV += CXXFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CXXFLAGS)"
Signature · 6 lines
2.34.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

James, All,

On 2022-10-28 16:38 -0600, James Hilliard spake thusly:

Quoted 27 lines

On some architectures when building with -O0 the __register_frame symbol fails to get optimized out which can cause linking failures when building glibc.

To fix this set -O1 for GCC target libs when building with glibc and BR2_OPTIMIZE_0 on the problematic target architectures.

Fixes:
- http://autobuild.buildroot.net/results/89b/89b6c6924240b7cf82035a844f3573673e91b364
- http://autobuild.buildroot.net/results/46f/46f4ec99d2b23d354a4bb5e92123d64f0da6ed27
- http://autobuild.buildroot.net/results/839/839f929f700cf181ebdf34389c7806a96f55813e
- http://autobuild.buildroot.net/results/0e2/0e202bf53a683930f3cad6edef2a4dea629eaecb
- http://autobuild.buildroot.net/results/8a8/8a8c917f597fdcca744e696e19e9300b64004335
- http://autobuild.buildroot.net/results/c05/c058b27ed2834dfa633b63ec6c3639ab1e8bf412
- http://autobuild.buildroot.net/results/8ba/8ba8882a861cf7df359c23969c09b2be0725b2e5

---
 package/gcc/gcc.mk | 9 +++++++++
 1 file changed, 9 insertions(+)
package/gcc/gcc.mk +0 -0
index ec6f3b550a..a339f77970 100644
@@ -103,6 +103,15 @@ GCC_COMMON_TARGET_CFLAGS += -matomic
 GCC_COMMON_TARGET_CXXFLAGS += -matomic

package/gcc/gcc.mk GCC_COMMON_TARGET_CFLAGS += -matomic · line 113

Quoted 10 lines
package/gcc/gcc.mk +8 -0
 endif
 
+# Enable GCC target libs optimizations to optimize out __register_frame
+# when needed for some architectures when building with glibc.
+ifeq ($(BR2_TOOLCHAIN_USES_GLIBC)$(BR2_OPTIMIZE_0),yy)
+ifeq ($(BR2_microblazebe)$(BR2_microblazeel)$(BR2_mips)$(BR2_mipsel)$(BR2_nios2)$(BR2_or1k)$(BR2_sh),y)
+GCC_COMMON_TARGET_CFLAGS += -O1
+GCC_COMMON_TARGET_CXXFLAGS += -O1
+endif
+endif

Should this not be limitied to the intial compiler only? Otherwise, why would we need it for the final compiler?

Regards,
Yann E. MORIN.

Quoted 10 lines
package/gcc/gcc.mk +0 -0
 # Propagate options used for target software building to GCC target libs
 HOST_GCC_COMMON_CONF_ENV += CFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CFLAGS)"
 HOST_GCC_COMMON_CONF_ENV += CXXFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CXXFLAGS)"
Signature · 6 lines
2.34.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw
Quoted 2 lines · On Sun, 30 Oct 2022 09:30:33 +0100 "Yann E. MORIN" <[email protected]>…

Should this not be limitied to the intial compiler only? Otherwise, why would we need it for the final compiler?

I confirm limiting the work-around to gcc-initial works.

However, I have reported the bug to gcc upstream, and they say the issue is in glibc:

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

To be honest, even after reading multiple times the feedback from the gcc folks, I'm not entirely sure that I really understand their explanation nor how to move forward with investigating the issue.

Best regards,

Thomas

Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#3 lore raw
Quoted 6 lines · Thomas Petazzoni via buildroot
Quoted 2 lines · On Sun, 30 Oct 2022 09:30:33 +0100 "Yann E. MORIN" <[email protected]>…

Should this not be limitied to the intial compiler only? Otherwise, why would we need it for the final compiler?

Quoted 6 lines

I confirm limiting the work-around to gcc-initial works.

However, I have reported the bug to gcc upstream, and they say the issue is in glibc:

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

James previously already reported the problem to glibc:

https://sourceware.org/bugzilla/show_bug.cgi?id=29621

I picked up the thread in both issues, I was able to narrow the problem down a
little more, but in the end the conclusion seems to be "We can't support that on the glibc side at present."

So I applied this patch to master, after making two major changes:

- move it to host-gcc-initial only;
- instead of putting the full condition in the .mk file, make a Config.in symbol BR2_TOOLCHAIN_HAS_GCC_BUG_107728.

... And now I notice I forgot to put the changes I made in the commit message.
But it's pushed already.

Anyway, applied to master, thanks!

Regards,
Arnout

Quoted 8 lines

To be honest, even after reading multiple times the feedback from the gcc folks, I'm not entirely sure that I really understand their explanation nor how to move forward with investigating the issue.

Best regards,

Thomas

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#4 lore raw
Quoted 10 lines · On Fri, 25 Nov 2022 15:06:21 +0100 Arnout Vandecappelle <[email protected]> wrote:

James previously already reported the problem to glibc:

https://sourceware.org/bugzilla/show_bug.cgi?id=29621

I picked up the thread in both issues, I was able to narrow the problem down a
little more, but in the end the conclusion seems to be "We can't support that on the glibc side at present."

So I applied this patch to master, after making two major changes:

Quoted 8 lines

- move it to host-gcc-initial only;
- instead of putting the full condition in the .mk file, make a Config.in symbol BR2_TOOLCHAIN_HAS_GCC_BUG_107728.

... And now I notice I forgot to put the changes I made in the commit message.
But it's pushed already.

Anyway, applied to master, thanks!

Thanks for following up on this. I reviewed the change you pushed, and it looks like the best trade-off. Thanks again!

Thomas

Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#5 lore raw
In reply to Arnout Vandecappelle
Quoted 23 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Arnout" == Arnout Vandecappelle <[email protected]> writes:

Quoted 9 lines · Thomas Petazzoni via buildroot
Quoted 2 lines · On Sun, 30 Oct 2022 09:30:33 +0100 "Yann E. MORIN" <[email protected]>…

Should this not be limitied to the intial compiler only? Otherwise, why would we need it for the final compiler?

I confirm limiting the work-around to gcc-initial works. However, I have reported the bug to gcc upstream, and they say the issue is in glibc:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107728

James previously already reported the problem to glibc:

https://sourceware.org/bugzilla/show_bug.cgi?id=29621

I picked up the thread in both issues, I was able to narrow the problem down a little more, but in the end the conclusion seems to be
"We can't support that on the glibc side at present."

So I applied this patch to master, after making two major changes:

Quoted 8 lines

- move it to host-gcc-initial only;
- instead of putting the full condition in the .mk file, make a Config.in symbol BR2_TOOLCHAIN_HAS_GCC_BUG_107728.

... And now I notice I forgot to put the changes I made in the commit message. But it's pushed already.

Anyway, applied to master, thanks!

Committed to 2022.08.x and 2022.02.x, thanks.

Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot