如何解决来自gcc交叉编译器的ARM7目标错误

时间:2015-07-13 05:34:36

标签: gcc assembly arm gnu samsung-mobile

我正在尝试使用gcc验证成功编译样本hello世界,这是我所理解的armv7目标。它是Snapdragon msm8974。我收到以下错误:

hello_world.s: Assembler messages:
hello_world.s:1: Error: unknown pseudo-op: `.syntax'
hello_world.s:3: Error: junk at end of line, first unrecognized character is `@'
hello_world.s:6: Error: junk at end of line, first unrecognized character is `@'
hello_world.s:7: Error: junk at end of line, first unrecognized character is `@'
hello_world.s:8: Error: invalid char '{' beginning operand 1 `{ip'
hello_world.s:10: Error: junk at end of line, first unrecognized character is `@'
hello_world.s:11: Error: no such instruction: `ldr r0,=message'
hello_world.s:12: Error: no such instruction: `bl printf'
hello_world.s:14: Error: junk at end of line, first unrecognized character is `@'
hello_world.s:15: Error: expecting operand after ','; got nothing
hello_world.s:17: Error: junk at end of line, first unrecognized character is `@'
hello_world.s:18: Error: junk at end of line, first unrecognized character is `@'
hello_world.s:19: Error: invalid char '{' beginning operand 1 `{ip'
hello_world.s:21: Error: junk at end of line, first unrecognized character is `@'
hello_world.s:22: Error: junk at end of line, first unrecognized character is `@'
hello_world.s:23: Error: junk at end of line, first unrecognized character is `@'

以下是代码:

    .syntax unified  

    @ --------------------------------  
.global main  
main:  
    @ Stack the return address (lr) in addition to a dummy register (ip) to  
    @ keep the stack 8-byte aligned.  
    push    {ip, lr}  

    @ Load the argument and perform the call. This is like 'printf("...")' in C.  
    ldr     r0, =message  
    bl      printf  

    @ Exit from 'main'. This is like 'return 0' in C.  
    mov     r0, #0    @ Return 0.  

    @ Pop the dummy ip to reverse our alignment fix, and pop the original lr  
    @ value directly into pc — the Program Counter — to return.  
    pop     {ip, pc}  

    @ --------------------------------  
    @ Data for the printf calls. The GNU assembler's ".asciz" directive  
    @ automatically adds a NULL character termination.  
message:  
    .asciz "Hello, world.\n" 

我做错了什么?这是我的gcc版本:

gcc (Ubuntu 4.9.2-10ubuntu13) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@Michael - 这是更详细的.. 这是我的工作文件夹中的gcc -v,它由Samsung Source和AOSP组成:

sansari@ubuntu:~/WORKING_DIRECTORY$ gcc -v 
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.9.2-10ubuntu13' --with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.9 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.9.2 (Ubuntu 4.9.2-10ubuntu13) 

我正在使用交叉编译器;这是我工作文件夹中Makefile的行:

CROSS_COMPILE   ?= /arm-eabi-4.7/bin/arm-eabi-

我基本上将汇编代码放在/ external目录中。我创建了另一个文件夹并只放置汇编代码并创建了一个Makefile,如下所示:

sansari@ubuntu:~/WORKING_DIRECTORY/external/shahin$ ls
hello_world.s  Makefile  template.s
sansari@ubuntu:~/WORKING_DIRECTORY/external/shahin$ more Makefile 
hello_world: hello_world.s
    gcc hello_world.s  -o hello_world 

当我从同一个目录运行make时,不是工作目录,而是它的父目录,但是...... / external / shahin,我得到你看到的错误。

@leppie-谢谢。让我试一试。我还怀疑我需要指定其他标志?这是Kconfig的一行:

0628Samsung:KBUILD_AFLAGS = -D__ASSEMBLY__ -mabi=aapcs-linux -mno-thumb-interwork -funwind-tables  -D__LINUX_ARM_ARCH__=7 -mcpu=cortex-a15  -include asm/unified.h -msoft-float -gdwarf-2

我可以这样做:

make -D__ASSEMBLY__ -mabi=aapcs-linux -mno-thumb-interwork -funwind-tables  -D__LINUX_ARM_ARCH__=7 -mcpu=cortex-a15  -include asm/unified.h -msoft-float -gdwarf-2

或者我需要将这些添加到/ external / shahin目录中的makefile吗?我认为两者都有效。我只是想让你验证它是否有错误。

@Notlikethat - 谢谢我是a.out的自豪的拥有者:-)

sansari@ubuntu:~/WORKING_DIRECTORY/external/shahin$ ls
a.out  hello_world.S  Makefile  temp  template.s

确定。我把a.out放在sdcard上,并将其权限更改为777,但我无法运行它。然后我将它移动到/ system / lib文件夹,无法运行它。我认为这应该运行,因为我使用了相同的交叉编译器,在我的手机上构建了运行图像。我的意思是我成功地使用我要添加到此处的代码来刷新手机。我使用相同的交叉编译器。谁能提出别的建议?我在这做错了什么?我将完全构建另一个图像并闪存手机,看看我是否可以运行此示例程序。我还需要先付一些努力吗?

@dwelch - 为了清楚起见,你在我收到a.out之前写了你的最后一条评论吗?我想我现在正在使用正确的工具链。感谢。

0 个答案:

没有答案