1

I am trying to validate successful compilation of a sample hello world using gcc for what I understand to be armv7 target. It is Snapdragon msm8974. I get the following errors:

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 `@'

Here is the code:

    .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" 

What am I doing wrong? Here is my gcc version:

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 - Here is more detail.. Here is gcc -v from my working folder, which is composed of Samsung Source and 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) 

I am using a cross compiler; here is the line from my Makefile in my working folder:

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

I basically put the assembly code in the /external directory. I created another folder and put just the assembly code and created a Makefile as follows:

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 

When I run make from this same directory, not the working directory which is it's parent, but .../external/shahin, I get the errors you see.

@leppie - Thanks. Let me try that. I also suspect I need to specify other flags? Here is a line from 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

Can I just do:

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

Or do I need to add these to my makefile in /external/shahin directory? I think both works. I just want you to verify it for errors please.

@Notlikethat - Thanks I am the proud owner of a a.out:-)

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

Ok. I put the a.out on the sdcard, and changed its permissions to 777 but I could not run it. I then moved it to /system/lib folder and could not run it. I thought this should run given that I used the same cross compiler that built the running image on my phone. What I mean is I successfully flashed the phone with the code that I am trying to add to here. And I used the same cross compiler. Can anyone suggest anything else? What am I doing wrong here? I am going to build another image entirely and flash the phone just to see if I can run this sample program. Is there anything else with less effort I need to look into first?

@dwelch - Just to be clear, did you write your last comment before I got the a.out? I think I am now using the right toolchain. Thanks.

user3326293
  • 817
  • 1
  • 14
  • 37
  • 1
    Are you sure that's a GCC targetting ARM processors? What do you get if you run gcc with the `-v` switch? – Michael Jul 13 '15 at 07:06
  • Dunno if related, but assembly files need a capital `S` for the extension. – leppie Jul 13 '15 at 07:45
  • 2
    @leppie not quite - by default, `.s` files go straight to the assembler, `.S` files get run through the C proprocessor first. As for the question, well, if you invoke `gcc` in your makefile, you get `gcc`, what else would you expect? If you you look at makefiles used for cross-compiling, you'll see the command they invoke is typically `$(CROSS_COMPILE)$(CC)` - nothing is magic enough to change hard-coded commands for you. – Notlikethat Jul 13 '15 at 09:12
  • 1
    I woulud say it is pretty clear you are not using an arm toolchain but some other architecture. – old_timer Jul 13 '15 at 13:26

0 Answers0