Skip to contentSkip to conversation

New: Bigendian binary is output even if it is configured to output little endian

Buildroot bugzilla at busybox.net 2 participants 6 messages Dec 18, 2011 – Feb 17, 2012

lore
Share & tools
lore
#0 lore raw

https://bugs.busybox.net/show_bug.cgi?id=4634

Summary: Bigendian binary is output even if it is configured to
output little endian
Product: buildroot
Version: 2011.11
Platform: PC
OS/Version: Linux
Status: NEW
Severity: major
Priority: P5
Component: Other
AssignedTo: unassigned at buildroot.uclibc.org
ReportedBy: matusita at k-micro.com
CC: buildroot at uclibc.org
Estimated Hours: 0.0

I set build options as below in "make menuconfig" to build root filesystem:
Target Architecture (mipsel)
Target Architecture Variant (mips 32r2)
Toolcain-Toolchain type (External toolchain) Toolcain-Toolchain (CodeSourcery MIPS 2011.03)

I expected that little enfian binary will be output because "mipsel" is selected. But it was big endian.
I confirmed it by objdump with "-f" option like below.

% mips-linux-gnu-objdump -f busybox
busybox: file format elf32-tradbigmips <-- Big endian !!!
architecture: mips:isa32r2, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x00403f00

So, I saw following file:
toolchain/toolchain-external/ext-tool.mk

And I understand that this script get libraries' location by calling (prefix)-gcc with following options:
-print-sysroot
-print-file-name=libc.a

But as for this toolchain(CodeSourcery MIPS 2011.03), it is need to set "-EL" option as well to get correct location of little endian libraries.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#1 lore raw
Quoted 37 lines · bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=4634

Summary: Bigendian binary is output even if it is configured to
output little endian
Product: buildroot
Version: 2011.11
Platform: PC
OS/Version: Linux
Status: NEW
Severity: major
Priority: P5
Component: Other
AssignedTo: unassigned at buildroot.uclibc.org
ReportedBy: matusita at k-micro.com
CC: buildroot at uclibc.org
Estimated Hours: 0.0

I set build options as below in "make menuconfig" to build root filesystem:
Target Architecture (mipsel)
Target Architecture Variant (mips 32r2)
Toolcain-Toolchain type (External toolchain) Toolcain-Toolchain (CodeSourcery MIPS 2011.03)

I expected that little enfian binary will be output because "mipsel" is selected. But it was big endian.
I confirmed it by objdump with "-f" option like below.

% mips-linux-gnu-objdump -f busybox
busybox: file format elf32-tradbigmips <-- Big endian !!!
architecture: mips:isa32r2, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x00403f00

So, I saw following file:
toolchain/toolchain-external/ext-tool.mk

Quoted 8 lines

And I understand that this script get libraries' location by calling (prefix)-gcc with following options:
-print-sysroot
-print-file-name=libc.a

But as for this toolchain(CodeSourcery MIPS 2011.03), it is need to set "-EL" option as well to get correct location of little endian libraries.

I think that the endian default is a gcc build-time option and some builders do select (or it defaults to) little endian.

But the CS toolchains do default to big endian.
Too be more general purpose, perhaps there should also be a "knob" to pass -mno-mips16 since the gcc default is to produce mixed 16/32 (or 16/64) bit code and the mips16e decoder is not a core requirement.

http://openplayer.org/resource/tutorials/57-cs-multi-library-tour.html

Mike

#2 lore raw
Quoted 50 lines · Michael S. Zick
Quoted 37 lines · bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=4634

Summary: Bigendian binary is output even if it is configured to
output little endian
Product: buildroot
Version: 2011.11
Platform: PC
OS/Version: Linux
Status: NEW
Severity: major
Priority: P5
Component: Other
AssignedTo: unassigned at buildroot.uclibc.org
ReportedBy: matusita at k-micro.com
CC: buildroot at uclibc.org
Estimated Hours: 0.0

I set build options as below in "make menuconfig" to build root filesystem:
Target Architecture (mipsel)
Target Architecture Variant (mips 32r2)
Toolcain-Toolchain type (External toolchain) Toolcain-Toolchain (CodeSourcery MIPS 2011.03)

I expected that little enfian binary will be output because "mipsel" is selected. But it was big endian.
I confirmed it by objdump with "-f" option like below.

% mips-linux-gnu-objdump -f busybox
busybox: file format elf32-tradbigmips <-- Big endian !!!
architecture: mips:isa32r2, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x00403f00

So, I saw following file:
toolchain/toolchain-external/ext-tool.mk

Quoted 8 lines

And I understand that this script get libraries' location by calling (prefix)-gcc with following options:
-print-sysroot
-print-file-name=libc.a

But as for this toolchain(CodeSourcery MIPS 2011.03), it is need to set "-EL" option as well to get correct location of little endian libraries.

I think that the endian default is a gcc build-time option and some builders do select (or it defaults to) little endian.

Quoted 7 lines

But the CS toolchains do default to big endian.
Too be more general purpose, perhaps there should also be a "knob" to pass -mno-mips16 since the gcc default is to produce mixed 16/32 (or 16/64) bit code and the mips16e decoder is not a core requirement.

http://openplayer.org/resource/tutorials/57-cs-multi-library-tour.html

PS:
Another point -

The MIPS recommendation for code generation is to use:
-Os (the BR default) when compiling 'pure' code and to use:
-O2 when compiling mixed code (gcc defaults to mixed code).

Mike

Quoted 7 lines

Mike
_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

#3 lore raw

[Buildroot] [Bug 4634] Bigendian binary is output even if it is configured to output little endian

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=4634

Thomas Petazzoni <[email protected]> changed:

What |Removed |Added
----------------------------------------------------------------------------

             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX

--- Comment #1 from Thomas Petazzoni <[email protected]> 2012-01-31 19:46:56 UTC --- Buildroot does not automatically add the needed CFLAGS and LDFLAGS to use the adequate multilib variant, because those CFLAGS and LDFLAGS are very toolchain-specific and architecture-specific. So it is the user's job to add explictly those flags.

I have posted a patch,
http://lists.busybox.net/pipermail/buildroot/2012-January/049556.html, which adds some help text on the different external toolchains about their respective multilib variants and how to select between them. Hopefully, this patch should be merged for 2012.02.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#4 lore raw

[Buildroot] [Bug 4634] Bigendian binary is output even if it is configured to output little endian

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=4634

--- Comment #2 from Aristotelis Iordanidis <[email protected]> 2012-02-17 09:37:52 UTC --- Created attachment 4040
--> https://bugs.busybox.net/attachment.cgi?id=4040
Patch to properly create symlinks when ARCH_SUBDIR is not a single directory.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#5 lore raw

[Buildroot] [Bug 4634] Bigendian binary is output even if it is configured to output little endian

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=4634

--- Comment #3 from Aristotelis Iordanidis <[email protected]> 2012-02-17 09:42:09 UTC --- (In reply to comment #1)

Quoted 10 lines

Buildroot does not automatically add the needed CFLAGS and LDFLAGS to use the adequate multilib variant, because those CFLAGS and LDFLAGS are very toolchain-specific and architecture-specific. So it is the user's job to add explictly those flags.

I have posted a patch,
http://lists.busybox.net/pipermail/buildroot/2012-January/049556.html, which adds some help text on the different external toolchains about their respective multilib variants and how to select between them. Hopefully, this patch should be merged for 2012.02.

(I'm sorry I posted a patch before the explanation)

I don't think this is enough (it didn't work for me).
The TOOLCHAIN_EXTERNAL_CFLAGS in toolchain/toolchain-external/ext-tool.mk does not take into account BR2_TARGET_OPTIMIZATION.
So, in the end it always copies the big-endian libc/ from multilib.

From toolchain/toolchain-external/ext-tool.mk:

# march/mtune/floating point mode needs to be passed to the external toolchain
# to select the right multilib variant
ifneq ($(CC_TARGET_TUNE_),)
TOOLCHAIN_EXTERNAL_CFLAGS += -mtune=$(CC_TARGET_TUNE_)
TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_TUNE='"$(CC_TARGET_TUNE_)"'
endif
ifneq ($(CC_TARGET_ARCH_),)
TOOLCHAIN_EXTERNAL_CFLAGS += -march=$(CC_TARGET_ARCH_)
TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_ARCH='"$(CC_TARGET_ARCH_)"'
endif
ifneq ($(CC_TARGET_CPU_),)
TOOLCHAIN_EXTERNAL_CFLAGS += -mcpu=$(CC_TARGET_CPU_)
TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_CPU='"$(CC_TARGET_CPU_)"'
endif
ifneq ($(CC_TARGET_ABI_),)
TOOLCHAIN_EXTERNAL_CFLAGS += -mabi=$(CC_TARGET_ABI_)
TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_ABI='"$(CC_TARGET_ABI_)"'
endif

ifeq ($(BR2_SOFT_FLOAT),y) TOOLCHAIN_EXTERNAL_CFLAGS += -msoft-float TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_SOFTFLOAT=1 endif

ifeq ($(BR2_VFP_FLOAT),y) TOOLCHAIN_EXTERNAL_CFLAGS += -mfpu=vfp TOOLCHAIN_EXTERNAL_WRAPPER_ARGS += -DBR_VFPFLOAT=1 endif

...

        $(Q)SYSROOT_DIR=`$(TOOLCHAIN_EXTERNAL_CC) -print-sysroot 2>/dev/null` ;

\

...

        ARCH_SUBDIR=`$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS)
-print-multi-directory` ; \
        ARCH_SYSROOT_DIR=$${SYSROOT_DIR}/$${ARCH_SUBDIR} ; \

...

        echo "Copy external toolchain sysroot to staging..." ; \
        $(call

copy_toolchain_sysroot,$${SYSROOT_DIR},$${ARCH_SYSROOT_DIR},$${ARCH_SUBDIR}) ; \

I have selected the following in menuconfig (I've also selected soft-float):

BR2_TARGET_OPTIMIZATION="-pipe -EL -march=m14kc -mmcu" BR2_TARGET_LDFLAGS="-EL"

I attempted to fix the problem by passing $(TARGET_LDFLAGS) in ARCH_SUBDIR:

        ARCH_SUBDIR=`$(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS)

$(TARGET_LDFLAGS) -print-multi-directory` ; \

After this change it seems that the little-endian version of libc is copied in buildroot's sysroot, but I still get errors about crt1.o and crti.o (ld can't find them).

This happens because in my case ARCH_SUBDIR=soft-float/el . copy_toolchain_sysroot doesn't handle the case where ARCH_SUBDIR is not a single directory:

ln: failed to create symbolic link `/home/iordanidis/src/buildroot/buildroot/output/host/usr/mipsel-unknown-linux-gnu/sysroot/soft-float/el':
No such file or directory

I corrected this by slightly modifying copy_toolchain_sysroot. After that, busybox was built correctly with -EL -soft-float.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.