cross-compiling for arm with clang
Warner Losh
imp at bsdimp.com
Fri Jun 17 19:20:19 UTC 2011
On Jun 17, 2011, at 12:38 PM, Damjan Marion wrote:
>
> On Jun 17, 2011, at 7:29 PM, Warner Losh wrote:
>
>> Shouldn't you be modifying the CFLAGS and CXXFLAGS instead of CC and CXX?
>>
>> Warner
>
>
> Right, must be some "smart" reason why I used CC and CXX, but now I don't remember why.
Redefining CC usually leads to tears, since it blurs the host compiler and the cross compiler.
> Now, I'm back on my original problem, clang invokes /usr/bin/as which is i386 AS instead of ARM version in obj tree.
That's a bogus assumption on the part of clang. At the very least, it should be adding the magic gas flags to use the correct triple for the platform. But if you did that, your next complaint would be that we only build as for the native architecture and not anything else.
> How this works on other platforms (i.e. cross-compiling for amd64)?
How it normally works is that we build a compiler that invokes the right as, ld, etc for the architecture in question. Clang is clearly broken here in assuming that as can cope with anything other than native assembler :) We normally either build gcc that knows where to find these files. In the buildworld case, this is communicate with weird paths and shell variables. With the whole 'xdev' series of targets (which are instructive to look at), we build into a specific location /usr/freebsd-xdev-arm/bin, etc).
It works by accident for i386 on amd64, I think. as treats the more or less as the same.
Warner
>
>
>
> make CC=clang CXX=clang++ TARGET=arm TARGET_CPUTYPE=cortex-a9 -DNO_CLEAN _libraries
>
> --------------------------------------------------------------
>>>> stage 4.2: building libraries
> --------------------------------------------------------------
> cd /usr/src-svn; MAKEOBJDIRPREFIX=/zfs/data2/src/obj/arm.arm MACHINE_ARCH=arm MACHINE=arm CPUTYPE=cortex-a9 GROFF_BIN_PATH=/zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/legacy/usr/bin GROFF_FONT_PATH=/zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/legacy/usr/share/groff_font GROFF_TMAC_PATH=/zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/legacy/usr/share/tmac CFLAGS="-O2 -pipe -v -ccc-host-triple arm-unknown-freebsd" CXXFLAGS="-O2 -pipe -ccc-host-triple arm-elf-freebsd" _SHLIBDIRPREFIX=/zfs/data2/src/obj/arm.arm/usr/src-svn/tmp VERSION="FreeBSD 9.0-CURRENT i386 900036" INSTALL="sh /usr/src-svn/tools/install.sh" PATH=/zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/legacy/usr/sbin:/zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/legacy/usr/bin:/zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/legacy/usr/games:/zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/usr/sbin:/zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/usr/bin:/zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/usr/games:/sbin:/bin:/usr/sbin:/usr/bin make -f Makefile.inc1 DESTDIR=/zfs/data2/src/obj/arm.arm/usr/src-svn/tmp -DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT -DWITHOUT_MAN -DWITHOUT_PROFILE libraries
> cd /usr/src-svn; make -f Makefile.inc1 _prereq_libs; make -f Makefile.inc1 _startup_libs; make -f Makefile.inc1 _prebuild_libs; make -f Makefile.inc1 _generic_libs;
> ===> gnu/lib/libssp/libssp_nonshared (obj,depend,all,install)
> sh /usr/src-svn/tools/install.sh -C -o root -g wheel -m 444 libssp_nonshared.a /zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/usr/lib
> ===> gnu/lib/libgcc (obj,depend,all,install)
> sh /usr/src-svn/tools/install.sh -C -o root -g wheel -m 444 libgcc_eh.a /zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/usr/lib
> ===> lib/libcompiler_rt (obj,depend,all,install)
> sh /usr/src-svn/tools/install.sh -C -o root -g wheel -m 444 libcompiler_rt.a /zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/usr/lib
> /zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/usr/lib/libgcc.a -> libcompiler_rt.a
> ===> gnu/lib/csu (obj,depend,all,install)
> sh /usr/src-svn/tools/install.sh -o root -g wheel -m 444 crtbegin.o /zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/usr/lib/crtbegin.o
> sh /usr/src-svn/tools/install.sh -o root -g wheel -m 444 crtend.o /zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/usr/lib/crtend.o
> sh /usr/src-svn/tools/install.sh -o root -g wheel -m 444 crtbeginT.o /zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/usr/lib/crtbeginT.o
> sh /usr/src-svn/tools/install.sh -o root -g wheel -m 444 crtbegin.So /zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/usr/lib/crtbeginS.o
> sh /usr/src-svn/tools/install.sh -o root -g wheel -m 444 crtend.So /zfs/data2/src/obj/arm.arm/usr/src-svn/tmp/usr/lib/crtendS.o
> ===> lib/csu/arm (obj,depend,all,install)
> clang -O2 -pipe -v -ccc-host-triple arm-unknown-freebsd -mcpu=cortex-a9 -I/usr/src-svn/lib/csu/arm/../common -I/usr/src-svn/lib/csu/arm/../../libc/include -std=gnu99 -Wsystem-headers -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wunused-parameter -Wcast-align -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -Wold-style-definition -Wno-pointer-sign -c -o crt1.o crt1.s
> FreeBSD clang version 3.0 (trunk 130700) 20110502
> Target: arm-unknown-freebsd
> Thread model: posix
> clang: warning: argument unused during compilation: '-O2'
> clang: warning: argument unused during compilation: '-mcpu=cortex-a9'
> clang: warning: argument unused during compilation: '-I /usr/src-svn/lib/csu/arm/../common'
> clang: warning: argument unused during compilation: '-I /usr/src-svn/lib/csu/arm/../../libc/include'
> clang: warning: argument unused during compilation: '-std=gnu99'
> clang: warning: argument unused during compilation: '-Wsystem-headers'
> clang: warning: argument unused during compilation: '-Wall'
> clang: warning: argument unused during compilation: '-Wno-format-y2k'
> clang: warning: argument unused during compilation: '-W'
> clang: warning: argument unused during compilation: '-Wno-unused-parameter'
> clang: warning: argument unused during compilation: '-Wstrict-prototypes'
> clang: warning: argument unused during compilation: '-Wmissing-prototypes'
> clang: warning: argument unused during compilation: '-Wpointer-arith'
> clang: warning: argument unused during compilation: '-Wreturn-type'
> clang: warning: argument unused during compilation: '-Wcast-qual'
> clang: warning: argument unused during compilation: '-Wwrite-strings'
> clang: warning: argument unused during compilation: '-Wswitch'
> clang: warning: argument unused during compilation: '-Wshadow'
> clang: warning: argument unused during compilation: '-Wunused-parameter'
> clang: warning: argument unused during compilation: '-Wcast-align'
> clang: warning: argument unused during compilation: '-Wchar-subscripts'
> clang: warning: argument unused during compilation: '-Winline'
> clang: warning: argument unused during compilation: '-Wnested-externs'
> clang: warning: argument unused during compilation: '-Wredundant-decls'
> clang: warning: argument unused during compilation: '-Wold-style-definition'
> clang: warning: argument unused during compilation: '-Wno-pointer-sign'
> "/usr/bin/as" -o crt1.o crt1.s
> crt1.s: Assembler messages:
> crt1.s:11: Error: too many memory references for `mov'
> crt1.s:12: Error: too many memory references for `mov'
> crt1.s:13: Error: too many memory references for `mov'
> crt1.s:15: Error: no such instruction: `ldr r0,[sp,'
> crt1.s:16: Error: too many memory references for `add'
> crt1.s:17: Error: too many memory references for `add'
> crt1.s:18: Error: too many memory references for `add'
> crt1.s:20: Error: no such instruction: `bic sp,sp,'
> crt1.s:21: Error: too many memory references for `sub'
> crt1.s:22: Error: invalid char '[' beginning operand 2 `[sp'
> crt1.s:23: Error: invalid char '[' beginning operand 2 `[sp'
> crt1.s:25: Error: no such instruction: `b __start'
> clang: error: assembler command failed with exit code 1 (use -v to see invocation)
> *** Error code 1
>
> Stop in /usr/src-svn/lib/csu/arm.
> *** Error code 1
>
> Stop in /usr/src-svn.
> *** Error code 1
>
> Stop in /usr/src-svn.
> *** Error code 1
>
> Stop in /usr/src-svn.
> *** Error code 1
>
> Stop in /usr/src-svn.
>
>
>
>
More information about the freebsd-toolchain
mailing list