[英]How to make ARM cross compilation on Mac OS X (error: invalid listing option `r' - cross compiling error)
我正在嘗試在Mac OS X上構建一個gcc交叉編譯器,目標是arm-elf-eabi
。
這是我到目前為止所做的:
我嘗試不使用Mac的clang / llvm,所以我使用brew中的gcc-4.8。
brew tap homebrew/versions
brew install gcc48
brew install binutils
在構建之前,我設置了環境變量:
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
下載binutils源,然后創建一個構建目錄,並可以構建binutils而不會出現問題:
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 4.8源代碼,並運行構建過程
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
但是,我在構建中收到了invalid listing option
r'。錯誤。
/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
我嘗試使用Mac中的默認編譯器,具有以下配置:
./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
從蘋果蹊蹺的是GCC給出(因為沒有什么錯鐺/ LLVM)參數。
可能有什么問題? 如何解決這個問題?
這是我在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
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
啟動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
--gstabs+
是要使用的標志 在目錄中build-gcc/gcc
,存在一個as
腳本文件被調用,而不是/usr/bin/as
。 當我重命名as
as_temp
並重新運行時,一切正常。 環境變量AS=/usr/bin/as
似乎沒有解決這個問題。
我需要再創建一個/opt/cross/arm-elf-eabi/sys-root/usr/include
,以防止出現其他錯誤消息。
我還發現這個站點在Mac OS X上的交叉編譯中非常有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.