diff mbox series

[2/3] gnuchess: disable -O2 and -O3 for ARM cortex-M cpus

Message ID 20190110175955.31565-2-fontaine.fabrice@gmail.com
State Superseded
Headers show
Series [1/3] gnuchess: fix license | expand

Commit Message

Fabrice Fontaine Jan. 10, 2019, 5:59 p.m. UTC
When building with -O2 (or -O3), link fails on:

/home/rclinux/rc-buildroot-test/scripts/instance-0/output/host/bin/arm-linux-g++ -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -O2 -Wl,-elf2flt -static  -Wl,-elf2flt -static   -Wl,-elf2flt -static -o gnuchess main.o components.o  frontend/libfrontend.a adapter/libadapter.a engine/libengine.a -lreadline -lncurses
ERROR: reloc type R_ARM_THM_MOVW_ABS_NC unsupported in this context
ERROR: reloc type R_ARM_THM_MOVT_ABS unsupported in this context
ERROR: reloc type R_ARM_THM_MOVW_ABS_NC unsupported in this context
ERROR: reloc type R_ARM_THM_MOVT_ABS unsupported in this context
ERROR: reloc type R_ARM_THM_MOVW_ABS_NC unsupported in this context
ERROR: reloc type R_ARM_THM_MOVT_ABS unsupported in this context
ERROR: reloc type R_ARM_THM_MOVW_ABS_NC unsupported in this context

To fix this, replace -O2 or -O3 by -Os

Fixes:
 - http://autobuild.buildroot.org/results/7918757b255ed41609609d2083c2d8904ff3136e

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
---
 package/gnuchess/gnuchess.mk | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Thomas Petazzoni Jan. 10, 2019, 7:59 p.m. UTC | #1
Hello,

On Thu, 10 Jan 2019 18:59:54 +0100, Fabrice Fontaine wrote:
> When building with -O2 (or -O3), link fails on:
> 
> /home/rclinux/rc-buildroot-test/scripts/instance-0/output/host/bin/arm-linux-g++ -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -O2 -Wl,-elf2flt -static  -Wl,-elf2flt -static   -Wl,-elf2flt -static -o gnuchess main.o components.o  frontend/libfrontend.a adapter/libadapter.a engine/libengine.a -lreadline -lncurses
> ERROR: reloc type R_ARM_THM_MOVW_ABS_NC unsupported in this context
> ERROR: reloc type R_ARM_THM_MOVT_ABS unsupported in this context
> ERROR: reloc type R_ARM_THM_MOVW_ABS_NC unsupported in this context
> ERROR: reloc type R_ARM_THM_MOVT_ABS unsupported in this context
> ERROR: reloc type R_ARM_THM_MOVW_ABS_NC unsupported in this context
> ERROR: reloc type R_ARM_THM_MOVT_ABS unsupported in this context
> ERROR: reloc type R_ARM_THM_MOVW_ABS_NC unsupported in this context

Interesting. In commit
https://git.buildroot.net/buildroot/commit/?id=49f574237983ae2e69e4a4c43df7be98902a63be,
we are doing exactly the opposite: when -Os is used, we pass -O2.

Romain reported the issue at
https://sourceware.org/bugzilla/show_bug.cgi?id=20552, and as you can
see, we got a tremendous amount of feedback from the binutils
developers :-)

Thomas
Fabrice Fontaine Jan. 12, 2019, 5:53 p.m. UTC | #2
Dear Thomas,

Le jeu. 10 janv. 2019 à 20:59, Thomas Petazzoni
<thomas.petazzoni@bootlin.com> a écrit :
>
> Hello,
>
> On Thu, 10 Jan 2019 18:59:54 +0100, Fabrice Fontaine wrote:
> > When building with -O2 (or -O3), link fails on:
> >
> > /home/rclinux/rc-buildroot-test/scripts/instance-0/output/host/bin/arm-linux-g++ -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -O2 -Wl,-elf2flt -static  -Wl,-elf2flt -static   -Wl,-elf2flt -static -o gnuchess main.o components.o  frontend/libfrontend.a adapter/libadapter.a engine/libengine.a -lreadline -lncurses
> > ERROR: reloc type R_ARM_THM_MOVW_ABS_NC unsupported in this context
> > ERROR: reloc type R_ARM_THM_MOVT_ABS unsupported in this context
> > ERROR: reloc type R_ARM_THM_MOVW_ABS_NC unsupported in this context
> > ERROR: reloc type R_ARM_THM_MOVT_ABS unsupported in this context
> > ERROR: reloc type R_ARM_THM_MOVW_ABS_NC unsupported in this context
> > ERROR: reloc type R_ARM_THM_MOVT_ABS unsupported in this context
> > ERROR: reloc type R_ARM_THM_MOVW_ABS_NC unsupported in this context
>
> Interesting. In commit
> https://git.buildroot.net/buildroot/commit/?id=49f574237983ae2e69e4a4c43df7be98902a63be,
> we are doing exactly the opposite: when -Os is used, we pass -O2.
>
> Romain reported the issue at
> https://sourceware.org/bugzilla/show_bug.cgi?id=20552, and as you can
> see, we got a tremendous amount of feedback from the binutils
> developers :-)
After fixing sunxi-cedarx, I found a better solution for gnuchess,
passing -fPIC in addition to -O2 fix the build failure. I'll send a
v2.
>
> Thomas
> --
> Thomas Petazzoni, CTO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
Best Regards,

Fabrice
diff mbox series

Patch

diff --git a/package/gnuchess/gnuchess.mk b/package/gnuchess/gnuchess.mk
index 0abdab5ba5..b2fbcff864 100644
--- a/package/gnuchess/gnuchess.mk
+++ b/package/gnuchess/gnuchess.mk
@@ -13,4 +13,11 @@  GNUCHESS_DEPENDENCIES = host-flex flex
 GNUCHESS_DEPENDENCIES += $(if $(BR2_PACKAGE_READLINE),readline) \
 	$(TARGET_NLS_DEPENDENCIES)
 
+# Workaround a build issue with -O2 or -03 for ARM Cortex-M cpus
+ifeq ($(BR2_ARM_CPU_ARMV7M):$(BR2_OPTIMIZE_2)$(BR2_OPTIMIZE_3),y:y)
+GNUCHESS_CONF_ENV += \
+	CFLAGS="$(TARGET_CFLAGS) -Os" \
+	CXXFLAGS="$(TARGET_CXXFLAGS) -Os"
+endif
+
 $(eval $(autotools-package))