How to cross-compile ARM on Mac OS X (error: invalid listing parameter "r" - cross-compilation error)

I am trying to create a gcc cross compiler on Mac OS X, target arm-elf-eabi.

This is what I have done so far:

Install gcc and configure the environment

I tried not to use clang / llvm on Mac, so I used gcc-4.8 from brew.

brew tap homebrew/versions 
brew install gcc48
brew install binutils

In front of the building, I set environment variables:

export CC=/usr/local/bin/gcc-4.8
export CXX=/usr/local/bin/g++-4.8
export CPP=/usr/local/bin/cpp-4.8
export LD=/usr/local/bin/gcc-4.8
export PREFIX=/opt/cross
export TARGET=arm-elf-eabi

build binutils

Loading the binutils source, then creating the assembly directory and the ability to build binutils without problems:

mkdir build-binutils
cd build-binutils
../binutils-2.24/configure --target=$TARGET --prefix=$PREFIX --with-sysroot --enable-64-bit-bfd --disable-shared --disable-werror --disable-nls
make configure-host
make LDFLAGS="-all-static"
sudo make install

gcc building

Download gcc 4.8 source and start the build process

mkdir build-gcc
cd build-gcc
../gcc-4.8.3/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c,c++ --without-headers --disable-shared --enable-multilib --with-sysroot --disable-werror
make configure-host
make all-gcc << ERROR
make all-target-libgcc

However, I got an invalid listing optionr`` error in the build.

/usr/local/bin/g++-4.8 -c   -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE  -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -DGENERATOR_FILE -I. -Ibuild -I../../gcc-4.8.3/gcc -I../../gcc-4.8.3/gcc/build -I../../gcc-4.8.3/gcc/../include  -I../../gcc-4.8.3/gcc/../libcpp/include  \
        -o build/genconstants.o ../../gcc-4.8.3/gcc/genconstants.c
Assembler messages:
Fatal error: invalid listing option `r'
make[2]: *** [build/genconstants.o] Error 1
make[1]: *** [all-gcc] Error 2

Alternative construction process

I tried using the default compiler from Mac with the following configuration:

./contrib/download_prerequisites
CFLAGS="-arch i386 -arch x86_64 -Wno-error=deprecated-declarations -Wno-error=unused-variable -Wno-error=unused-function" ../gcc-4.8.3/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c --without-headers --disable-shared --enable-multilib

make all-gcc, make all-target-libgcc, gcc- clang/llvm.

, as Apple - , gcc ( clang/llvm ).

? ?

+4
4

build-gcc/gcc as script, /usr/bin/as. as as_temp , . AS=/usr/bin/as, , .

, /opt/cross/arm-elf-eabi/sys-root/usr/include, .

, - Mac OS X.

0

- Mac OS X qemu, , .

- https://github.com/jsnyder/arm-eabi-toolchain

mkdir /opt/arm # and make it writable
PREFIX=/opt/arm PROCS=8 CC=clang make install-cross
PREFIX=/opt/arm PROCS=8 CC=clang make cross-gdb

, .

.text
entry: b start
arr:    .byte 1, 2, 3, 4, 5, 6
eoa:
.align
start:  
    ldr r0, =eoa
    ldr r1, =arr
    mov r3, #0
loop:
    ldrb r2, [r1], #1
    add r3, r2, r3
    cmp r1, r0
    bne loop
stop:   b stop

script

dd if=/dev/zero of=flash.bin bs=4096 count=4096
arm-none-eabi-as --gstabs+ -o add.o add.S
arm-none-eabi-ld -Ttext=0x0 -o add.elf add.o
arm-none-eabi-objcopy -O binary add.elf add.bin
dd if=add.bin of=flash.bin bs=4096 conv=notrunc

Execute

qemu

qemu-system-arm -M connex -pflash flash.bin -gdb tcp::1234 -S

arm-none-eabi-gdb add.elf

target remote :1234

n .

(gdb) target remote :1234
Remote debugging using :1234
entry () at add.S:2
2   entry: b start
(gdb) n
7       ldr r0, =eoa
(gdb) n
8       ldr r1, =arr
(gdb) n
9       mov r3, #0
(gdb) n
11      ldrb r2, [r1], #1
(gdb) n
12      add r3, r2, r3
(gdb) n
13      cmp r1, r0
(gdb) n
14      bne loop
(gdb) n
11      ldrb r2, [r1], #1
(gdb) n
12      add r3, r2, r3

+1

homebrew, brew cask :

brew cask install gcc-arm-embedded
+1

-, - Linaro, . , , , . , .c :

${PREFIX}gcc -Wall -Wextra -Os -ffreestanding -mcpu=cortex-a8 -march=armv7-a -mfpu=neon -marm -c filename.c 

Prefix , .

0

All Articles