gcc - How to resolve crt0.o linking issue in cross compiling? -


how add ctr0.o ?

i error:

yagarto-4.7.2/bin/arm-none-eabi-ld: cannot find crt0.o: no such file or directory collect2: error: ld returned 1 exit status` 

while compiling simple program here:

/* -- first.s */ /* comment */ .global main /* 'main' our entry point , must global */ .func main   /* 'main' function */  main:          /* main */     mov r0, #2 /* put 2 inside register r0 */     bx lr      /* return main */ 

i have seen these 2 threads , didn't full , straight forward answer:

  1. http://www.raspberrypi.org/phpbb3/viewtopic.php?t=50046
  2. what rationale behind removing crt0.o gcc4.7.x?

i have these files, difference between crt0 , crtn can't use it?

./yagarto-4.7.2/lib/gcc/arm-none-eabi/4.7.2/crtbegin.o ./yagarto-4.7.2/lib/gcc/arm-none-eabi/4.7.2/crtend.o ./yagarto-4.7.2/lib/gcc/arm-none-eabi/4.7.2/crti.o ./yagarto-4.7.2/lib/gcc/arm-none-eabi/4.7.2/crtn.o ./yagarto-4.7.2/lib/gcc/arm-none-eabi/4.7.2/thumb/crtbegin.o ./yagarto-4.7.2/lib/gcc/arm-none-eabi/4.7.2/thumb/crtend.o ./yagarto-4.7.2/lib/gcc/arm-none-eabi/4.7.2/thumb/crti.o ./yagarto-4.7.2/lib/gcc/arm-none-eabi/4.7.2/thumb/crtn.o ./yagarto-4.7.2/lib/gcc/arm-none-eabi/4.7.2/thumb/v6m/crtbegin.o ./yagarto-4.7.2/lib/gcc/arm-none-eabi/4.7.2/thumb/v6m/crtend.o ./yagarto-4.7.2/lib/gcc/arm-none-eabi/4.7.2/thumb/v6m/crti.o ./yagarto-4.7.2/lib/gcc/arm-none-eabi/4.7.2/thumb/v6m/crtn.o ./yagarto-4.7.2/lib/gcc/arm-none-eabi/4.7.2/thumb/v7m/crtbegin.o ./yagarto-4.7.2/lib/gcc/arm-none-eabi/4.7.2/thumb/v7m/crtend.o ./yagarto-4.7.2/lib/gcc/arm-none-eabi/4.7.2/thumb/v7m/crti.o ./yagarto-4.7.2/lib/gcc/arm-none-eabi/4.7.2/thumb/v7m/crtn.o 

the solution gives workaround doesn't work either:

arm-none-eabi-gcc -o first assembler_tutorial/chapter01/first.o -nostartfiles ./yagarto-4.7.2/bin/arm-none-eabi-ld: warning: cannot find entry symbol _start; defaulting 0000000000008000 

vectors.s

.globl _start _start:     mov sp,#0x8000     bl main hang: b hang 

main.s

.globl main main:     mov r0,#2     bx lr 

memmap (linker script)

memory {     ram : origin = 0x8000, length = 0x10000 } sections {     .text : { *(.text*) } > ram     .bss : { *(.bss*) } > ram } 

commands

arm-none-eabi-as vectors.s -o vectors.o arm-none-eabi-as main.s -o main.o arm-none-eabi-ld vectors.o main.o -t memmap -o main.elf arm-none-eabi-objdump -d main.elf > main.list arm-none-eabi-objcopy main.elf -o binary main.bin 

result

main.elf:     file format elf32-littlearm   disassembly of section .text:  00008000 <_start>:     8000:   e3a0d902    mov sp, #32768  ; 0x8000     8004:   eb000000    bl  800c <main>  00008008 <hang>:     8008:   eafffffe    b   8008 <hang>  0000800c <main>:     800c:   e3a00002    mov r0, #2     8010:   e12fff1e    bx  lr 

if want use c instead of asm main then

main.c

int main ( void ) {     return(2); } 

commands

arm-none-eabi-as vectors.s -o vectors.o arm-none-eabi-gcc -wall -werror -o2 -nostdlib -nostartfiles -ffreestanding -c main.c -o main.o arm-none-eabi-ld vectors.o main.o -t memmap -o main.elf arm-none-eabi-objdump -d main.elf > main.list arm-none-eabi-objcopy main.elf -o binary main.bin 

result

main.elf:     file format elf32-littlearm   disassembly of section .text:  00008000 <_start>:     8000:   e3a0d902    mov sp, #32768  ; 0x8000     8004:   eb000000    bl  800c <main>  00008008 <hang>:     8008:   eafffffe    b   8008 <hang>  0000800c <main>:     800c:   e3a00002    mov r0, #2     8010:   e12fff1e    bx  lr 

i prefer use function name other main because compilers add baggage when see function name.

vectors.s

.globl _start _start:     mov sp,#0x8000     bl notmain hang: b hang 

main.c

int notmain ( void ) {     return(2); } 

result

main.elf:     file format elf32-littlearm   disassembly of section .text:  00008000 <_start>:     8000:   e3a0d902    mov sp, #32768  ; 0x8000     8004:   eb000000    bl  800c <notmain>  00008008 <hang>:     8008:   eafffffe    b   8008 <hang>  0000800c <notmain>:     800c:   e3a00002    mov r0, #2     8010:   e12fff1e    bx  lr 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -