Bug 1255946 - add little endian powerpc targets
Summary: add little endian powerpc targets
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: cross-gcc
Version: 23
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: David Howells
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On: 1255947
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-08-22 07:12 UTC by Dan Horák
Modified: 2015-12-19 18:26 UTC (History)
6 users (show)

Fixed In Version: cross-gcc-5.2.1-4.fc23
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-12-19 18:26:29 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Dan Horák 2015-08-22 07:12:04 UTC
Per discussion on #fedora-ppc it seems the current cross-{binutils,gcc} lack the little endian powerpc targets, please add them.

<benh> hey
<benh> somebody knows if the ppc64 cross compile in x86 fedora can do LE ?
<benh> powerpc64-linux-gnu-ld: unrecognised emulation mode: elf64lppc
<benh> Supported emulations: elf64ppc elf32ppc elf32ppclinux elf32ppcsim
<sharkcz> benh: hi, yes, the cross binutils/gcc spec files have no mention about LE as target, can you please open a bug to add it?
<benh> sharkcz: it works if I just use -m elf64ppc and -EL
<benh> sharkcz: so not sure it's actually a problem, but it's certainly a difference vs. what's in ubuntu
<sharkcz> the native LE ld lists ld: supported emulations: elf64lppc elf32lppc elf32lppclinux elf32lppcsim elf32_spu elf32ppclinux elf32ppc elf32ppcsim elf64ppc - so I think we should add LE as a target to the cross-tools too
<sharkcz> does it understand ELFv2 in the current state?
<benh> sharkcz: it seems to, my stuff works once built
<benh> sharkcz: but yeah it looks like it should still probably be fixed

Comment 1 Chris Smart 2015-09-01 11:50:25 UTC
I'm running Fedora 22 x86_64 and trying to build upstream kernel 4.2 (commit 64291f7db5bd8150a74ad2036f1037e6a0428df2) using pseries_defconfig with CONFIG_CPU_LITTLE_ENDIAN=y set (BE kernel builds fine).


I have the following packages installed:

 binutils-powerpc64-linux-gnu-2.25.1-1.fc22.x86_64
 cross-binutils-common-2.25.1-1.fc22.noarch
 cross-gcc-common-5.2.1-2.fc22.noarch
 gcc-c++-powerpc64-linux-gnu-5.2.1-2.fc22.x86_64
 gcc-powerpc64-linux-gnu-5.2.1-2.fc22.x86_64

I am building with the following command:
 ARCH=powerpc CROSS_COMPILE=powerpc64-linux-gnu- make V=1


I get the following failure:

 powerpc64-linux-gnu-gcc -mlittle-endian -mno-strict-align -m64 -Wp,-MD,arch/powerpc/kernel/vdso64/.vdso64.so.dbg.d  -nostdinc -isystem /usr/lib/gcc/powerpc64-linux-gnu/5.2.1/include -I./arch/powerpc/include -Iarch/powerpc/include/generated/uapi -Iarch/powerpc/include/generated  -Iinclude -I./arch/powerpc/include/uapi -Iarch/powerpc/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -Iarch/powerpc -DHAVE_AS_ATHIGH=1 -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -msoft-float -pipe -Iarch/powerpc -mtraceback=no -mabi=elfv2 -mcmodel=medium -mno-pointers-to-nested-functions -mcpu=power7 -mno-altivec -mno-vsx -mno-spe -mspe=no -funit-at-a-time -fno-dwarf2-cfi-asm -mno-string -Wa,-maltivec -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fno-stack-protector -Wno-unused-but-set-variable -fomit-frame-pointer -fno-var-tracking-assignments -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -DCC_HAVE_ASM_GOTO -Werror -shared -fno-common -fno-builtin -nostdlib -Wl,-soname=linux-vdso64.so.1 -Wl,--hash-style=sysv    -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(vdso64.so)"  -D"KBUILD_MODNAME=KBUILD_STR(vdso64.so)" -Wl,-T arch/powerpc/kernel/vdso64/vdso64.lds arch/powerpc/kernel/vdso64/sigtramp.o arch/powerpc/kernel/vdso64/gettimeofday.o arch/powerpc/kernel/vdso64/datapage.o arch/powerpc/kernel/vdso64/cacheflush.o arch/powerpc/kernel/vdso64/note.o arch/powerpc/kernel/vdso64/getcpu.o -o arch/powerpc/kernel/vdso64/vdso64.so.dbg
/usr/bin/powerpc64-linux-gnu-ld: arch/powerpc/kernel/vdso64/sigtramp.o: file class ELFCLASS64 incompatible with ELFCLASS32
/usr/bin/powerpc64-linux-gnu-ld: final link failed: File in wrong format
collect2: error: ld returned 1 exit status
arch/powerpc/kernel/vdso64/Makefile:26: recipe for target 'arch/powerpc/kernel/vdso64/vdso64.so.dbg' failed
make[2]: *** [arch/powerpc/kernel/vdso64/vdso64.so.dbg] Error 1
scripts/Makefile.build:403: recipe for target 'arch/powerpc/kernel/vdso64' failed
make[1]: *** [arch/powerpc/kernel/vdso64] Error 2
Makefile:949: recipe for target 'arch/powerpc/kernel' failed
make: *** [arch/powerpc/kernel] Error 2


All of those files are 64bit LE:

arch/powerpc/kernel/vdso64/cacheflush.o:   ELF 64-bit LSB relocatable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), not stripped
arch/powerpc/kernel/vdso64/datapage.o:     ELF 64-bit LSB relocatable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), not stripped
arch/powerpc/kernel/vdso64/getcpu.o:       ELF 64-bit LSB relocatable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), not stripped
arch/powerpc/kernel/vdso64/gettimeofday.o: ELF 64-bit LSB relocatable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), not stripped
arch/powerpc/kernel/vdso64/note.o:         ELF 64-bit LSB relocatable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), not stripped
arch/powerpc/kernel/vdso64/sigtramp.o:     ELF 64-bit LSB relocatable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), not stripped

If I build with make -k the rest of the kernel builds, it's just this linker step that seems to fail.


strace shows collect2 being run with --oformat elf32-powerpcle

24904 execve("/usr/libexec/gcc/powerpc64-linux-gnu/5.2.1/collect2", ["/usr/libexec/gcc/powerpc64-linux"..., "-plugin", "/usr/libexec/gcc/powerpc64-linux"..., "-plugin-opt=/usr/libexec/gcc/pow"..., "-plugin-opt=-fresolution=/tmp/cc"..., "--sysroot=/usr/powerpc64-linux-g"..., "--build-id", "--no-add-needed", "--eh-frame-hdr", "--hash-style=gnu", "-shared", "--oformat", "elf32-powerpcle", "-m", "elf64lppc", "-o", ...], [/* 66 vars */] <unfinished ...>


$ gcc -###
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/5.1.1/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --disable-libgcj --with-default-libstdcxx-abi=c++98 --with-isl --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC) 


$ rpm -q --whatprovides $(which powerpc64-linux-gnu-gcc)
gcc-powerpc64-linux-gnu-5.2.1-2.fc22.x86_64

Comment 2 David Howells 2015-09-01 19:45:44 UTC
This will produce the error for me:

powerpc64-linux-gnu-gcc \
    --param=allow-store-data-races=0 \
    -Wl,--hash-style=sysv    \
    -Wl,-T arch/powerpc/kernel/vdso64/vdso64.lds \
    -Wl,-soname=linux-vdso64.so.1 \
    -m64 \
    -mabi=elfv2 \
    -mcmodel=medium \
    -mcpu=power7 \
    -mlittle-endian \
    -nostdlib \
    -shared \
    arch/powerpc/kernel/vdso64/sigtramp.o \
    arch/powerpc/kernel/vdso64/gettimeofday.o \
    arch/powerpc/kernel/vdso64/datapage.o \
    arch/powerpc/kernel/vdso64/cacheflush.o \
    arch/powerpc/kernel/vdso64/note.o \
    arch/powerpc/kernel/vdso64/getcpu.o \
    -o arch/powerpc/kernel/vdso64/vdso64.so.dbg

Or this, if you want to go direct to collect2:

/usr/libexec/gcc/powerpc64-linux-gnu/5.2.1/collect2 \
    -plugin /usr/libexec/gcc/powerpc64-linux-gnu/5.2.1/liblto_plugin.so \
    -plugin-opt=/usr/libexec/gcc/powerpc64-linux-gnu/5.2.1/lto-wrapper \
    -plugin-opt=-fresolution=/tmp/ccN6D4rT.res \
    --sysroot=/usr/powerpc64-linux-gnu/sys-root \
    --build-id \
    --no-add-needed \
    --eh-frame-hdr \
    --hash-style=gnu \
    -shared \
    --oformat elf32-powerpcle \
    -m elf64lppc \
    -o arch/powerpc/kernel/vdso64/vdso64.so.dbg \
    -L/usr/lib/gcc/powerpc64-linux-gnu/5.2.1/le \
    -L/usr/lib/gcc/powerpc64-linux-gnu/5.2.1 \
    --hash-style=sysv \
    -T arch/powerpc/kernel/vdso64/vdso64.lds \
    -soname=linux-vdso64.so.1 \
    arch/powerpc/kernel/vdso64/sigtramp.o \
    arch/powerpc/kernel/vdso64/gettimeofday.o \
    arch/powerpc/kernel/vdso64/datapage.o \
    arch/powerpc/kernel/vdso64/cacheflush.o \
    arch/powerpc/kernel/vdso64/note.o \
    arch/powerpc/kernel/vdso64/getcpu.o

Changing the 32 to a 64 in the "--oformat elf32-powerpcle" above seems to allow collect2 to work.

Comment 3 David Howells 2015-09-01 20:02:03 UTC
I wonder if this bit in the powerpc64 compiler build specs file is the problem:

*link_target:
%{mlittle|mlittle-endian: --oformat elf32-powerpcle;mbig|mbig-endian:;mcall-i960-old: --oformat elf32-powerpcle;:}

Comment 4 David Howells 2015-09-01 20:07:17 UTC
This can also be seen by doing:

    powerpc64-linux-gnu-gcc -dumpspecs | less

and searching for oformat

Comment 5 David Howells 2015-09-01 20:23:42 UTC
Looking in gcc/config/rs6000/sysv4.h (which is used by a --target=powerpc64-linux-gnu build) I see:

/* Override the default target of the linker.  */
#define	LINK_TARGET_SPEC \
  ENDIAN_SELECT("", " --oformat elf32-powerpcle", "")

which might be the problem.

Comment 6 David Howells 2015-09-01 21:03:26 UTC
It seems that a compiler built for powerpc64 with powerpc64le as a secondary target doesn't work.  It seems to be necessary to make powerpc64le the primary target.

Comment 7 David Howells 2015-09-01 21:28:18 UTC
The compiler is configured as:

CC=gcc \
CXX=g++ \
CFLAGS='-O2 -g -Wall -Wformat-security -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -mtune=generic' \
CXXFLAGS=' -O2 -g -Wformat-security -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -mtune=generic ' \
CFLAGS_FOR_TARGET='-g -O2 -Wall -fexceptions' \
AR_FOR_TARGET=/usr/bin/powerpc64-linux-gnu-ar \
AS_FOR_TARGET=/usr/bin/powerpc64-linux-gnu-as \
DLLTOOL_FOR_TARGET=/usr/bin/powerpc64-linux-gnu-dlltool \
LD_FOR_TARGET=/usr/bin/powerpc64-linux-gnu-ld \
NM_FOR_TARGET=/usr/bin/powerpc64-linux-gnu-nm \
OBJDUMP_FOR_TARGET=/usr/bin/powerpc64-linux-gnu-objdump \
RANLIB_FOR_TARGET=/usr/bin/powerpc64-linux-gnu-ranlib \
READELF_FOR_TARGET=/usr/bin/powerpc64-linux-gnu-readelf \
STRIP_FOR_TARGET=/usr/bin/powerpc64-linux-gnu-strip \
WINDRES_FOR_TARGET=/usr/bin/powerpc64-linux-gnu-windres \
WINDMC_FOR_TARGET=/usr/bin/powerpc64-linux-gnu-windmc \
LDFLAGS='-Wl,-z,relro ' \
../gcc-5.2.1-20150716/configure --bindir=/usr/bin --build=x86_64-redhat-linux-gnu --datadir=/usr/share --disable-decimal-float --disable-dependency-tracking --disable-gold --disable-libgcj --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libunwind-exceptions --disable-nls --disable-plugin --disable-shared --disable-silent-rules --disable-sjlj-exceptions --disable-threads --with-ld=/usr/bin/powerpc64-linux-gnu-ld --enable-__cxa_atexit --enable-checking=release --enable-gnu-indirect-function --enable-gnu-unique-object --enable-initfini-array --enable-languages=c,c++ --enable-linker-build-id --enable-nls --enable-obsolete --enable-plugin --enable-targets=all --exec-prefix=/usr --host=x86_64-redhat-linux-gnu --includedir=/usr/include --infodir=/usr/share/info --libexecdir=/usr/libexec --localstatedir=/var --mandir=/usr/share/man --prefix=/usr --program-prefix=powerpc64-linux-gnu- --sbindir=/usr/sbin --sharedstatedir=/var/lib --sysconfdir=/etc --target=powerpc64-linux-gnu --with-bugurl=http://bugzilla.redhat.com/bugzilla/ --with-isl --with-linker-hash-style=gnu --with-newlib --with-sysroot=/usr/powerpc64-linux-gnu/sys-root --with-system-libunwind --with-system-zlib --without-headers --with-cpu-32=power7 --with-tune-32=power8 --with-cpu-64=power7 --with-tune-64=power8 --enable-secureplt --with-long-double-128

The source for the compiler is the Fedora rawhide cross-gcc SRPM - which is (or was at the time) patched the same as the gcc SRPM from the same source.

The cross-binutils is 2.25.1 also from Fedora rawhide.

Comment 8 Alan Modra 2015-09-02 00:40:46 UTC
Comments #5 and #6 are spot on.  LINK_TARGET_SPEC ought to be empty.  I'm not sure why it was ever defined, perhaps for some ancient linker?  Any GNU ld in the last 10 years or so should work with just a -melf64ppc or variants.  The ld -m options select a particular ld emulation (ld/e*.c file) which provide compiled in scripts or selects files in ld/ldscripts/.  Each of these scripts has an OUTPUT_FORMAT statement, which does the same thing as --oformat.

Comment 9 Benjamin Herrenschmidt 2015-09-02 00:49:26 UTC
So should we fix sysv4.h upstream (and carry a patch in fedora until that percolates ?)

Comment 10 Alan Modra 2015-09-02 01:11:04 UTC
Both sysv4.h and sysv4le.h.

Comment 12 Chris Smart 2015-09-02 07:11:36 UTC
Thanks Alan.

I rebuilt gcc-powerpc64-linux-gnu-5.1.1-3.fc22 with Alan's patch (against binutils 2.25.1 from updates-testing) and can confirm that it allowed me to cross-compile the kernel successfully.

$ rpm -qa |egrep "binutils|powerpc" |sort
binutils-2.25-9.fc22.x86_64
binutils-powerpc64-linux-gnu-2.25.1-1.fc22.x86_64
binutils-x86_64-linux-gnu-2.25.1-1.fc22.x86_64
cross-binutils-common-2.25.1-1.fc22.noarch
gcc-c++-powerpc64-linux-gnu-5.1.1-3.fc22.1.x86_64
gcc-powerpc64-linux-gnu-5.1.1-3.fc22.1.x86_64

Comment 13 David Howells 2015-09-02 15:25:24 UTC
Thanks Alan, that works for me too.

Comment 14 Fedora Update System 2015-09-04 07:34:10 UTC
cross-gcc-5.2.1-3.fc23 has been pushed to the Fedora 23 testing repository. If problems still persist, please make note of it in this bug report.\nIf you want to test the update, you can install it with \n su -c 'yum --enablerepo=updates-testing update cross-gcc'. You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2015-14933

Comment 15 Benjamin Herrenschmidt 2015-09-15 00:40:56 UTC
The only problem is that it defaults to ABI v1 for LE which is wrong, it should do ABI v2. However I don't know how easy/hard it is to make gcc have a different default for BE and LE on a single compiler.

As-is, this exposes a bug in the kernel Makefiles missing -mabi=elfv2 for the
zImage boot wrapper. I'll send a fix.

Comment 16 Fedora Update System 2015-12-10 14:29:32 UTC
cross-gcc-5.2.1-4.fc23 has been submitted as an update to Fedora 23. https://bodhi.fedoraproject.org/updates/FEDORA-2015-800f81b3f6

Comment 17 Fedora Update System 2015-12-11 06:01:10 UTC
cross-gcc-5.2.1-4.fc23 has been pushed to the Fedora 23 testing repository. If problems still persist, please make note of it in this bug report.
If you want to test the update, you can install it with
$ su -c 'dnf --enablerepo=updates-testing update cross-gcc'
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2015-800f81b3f6

Comment 18 Fedora Update System 2015-12-19 18:26:15 UTC
cross-gcc-5.2.1-4.fc23 has been pushed to the Fedora 23 stable repository. If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.