1

i´m new to assembly and using yasm, with the ebe editor.

Now after the first steps i want to check the global/extern mechanism.

Therefore i made 2 modules:

actor.asm

    extern greeter 

    section .text  
    global main   

        main:             
        push    rbp  

        call    greeter wrt ..plt  

        pop rbp     
        mov rax,0       
        ret 

greeter.asm

    extern  printf 

    section .data
    msg: db "Hello world", 0 
    fmt: db "%s", 10, 0  

    section .text         
    global greeter
    type greeter function
    size greeter greeter.end -greeter

        greeter:                
        push    rbp    

        mov rdi,fmt
        mov rsi,msg
        mov rax,0       
        call    printf         

        pop rbp    
        mov rax,0       
        ret 
        .end:        

Both files are compiled and when i run the first, following error message appears:

/home/1/Öffentlich/EBE_Space/ext_glob_test/actor.o: In function main': /home/1/Öffentlich/EBE_Space/ext_glob_test/actor.asm:6: undefined reference togreeter'

What´s wrong? What´s necessary to make a global function linkable?

TIA

  • What do you mean by _"when i run the first"_? What exactly are you running? What does your link command look like? – Michael Apr 16 '15 at 11:54
  • Ok, sorry, Some I've forgotten here: 1.I used that ebe enviroment to compile and run the asm files, i guess it does not support shared library. 2.It should output the elf64 format (Linux is my OS). – user3727740 Apr 16 '15 at 12:48
  • After reading the YASM manual, I editited my code sample above by the ELF directives ´size´, ´type´ and ´wrt´. Now I want to run yasm using: **yasm -f elf64 -o actor.o any/actor.asm** and **yasm -f elf64 -o greeter.so any/greeter.asm** When I execute the actor.o file, I get a error-message. – user3727740 Apr 16 '15 at 13:04
  • And this is the error by making an executable: **gcc any/actor.o -o actor.exe** any/actor.o: In function `main': any/actor.asm:(.text+0x2): undefined reference to `greeter' – user3727740 Apr 16 '15 at 16:28
  • _"When I execute the actor.o file"_. You don't execute .o files, you link them to produce an executable. _"`gcc any/actor.o -o actor.exe `"_ You need to include all your .o files when linking, not just one of them. – Michael Apr 16 '15 at 18:08
  • OK solved: **gcc any/actor.o any/greeter.so -o actor.exe** – user3727740 Apr 17 '15 at 05:52

0 Answers0