flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Linux > Custom object loader (ELF64). LEA vs MOV

Author
Thread Post new topic Reply to topic
system error



Joined: 01 Sep 2013
Posts: 667
Custom object loader (ELF64). LEA vs MOV
I am trying to write a custom object loader for ELF64 and should be able to execute the loaded object from memory they were loaded. It's working just fine until I ran into the old MOV vs LEA problem again;

Here's my pseudo program

Code:
format ELF64 executable 3
entry start

segment readable writeable
f db 'object.o',0               ;the object file to be loaded

segment readable executable
start:
        ;open the file
        ;get the object size
        ;create dynamic memory based on the size
        ;save/load the object to that memory. Pointer in RAX
        add rax,64      ;skip the header
        jmp rax



And here's the object file I'm loading

Code:
;compile to create object.o
format elf64

mov rdx,29      
lea rsi,[x]     ;address
;mov rsi,x      ;this won't work. Why?
mov edi,1       
mov eax,1       
syscall         ;print the string

xor edi,edi
mov rax,60
syscall         ;exit code

x db 'Hi, I am from the loaded file.'



See the commented line. That's the problem. I can't address the string by using MOV but it is working perfectly using LEA (the message got printed from the loaded object).

What's wrong here?
Post 31 Mar 2016, 07:35
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 667
Mom?
Post 31 Mar 2016, 07:57
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3439
Location: Bulgaria
"mov rsi, x" works here as well as "lea".
Post 31 Mar 2016, 08:00
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
system error



Joined: 01 Sep 2013
Posts: 667
John, it doesn't work on my machine. Maybe you missed the fact that it is a loaded object, and not a linked / executable file. Of course both work if it was in an executable / linked object. That means I can't properly execute a string code which is addressed using MOV, this way?
Post 31 Mar 2016, 08:15
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6605
Location: Kraków, Poland
LEA in this case uses RIP-relative addressing and therefore does not need relocation (unless it refers to an address in some other section), while the opcode of MOV contains an absolute address that has to be relocated. So the fact that LEA works in your case but MOV doesn't, means that your loader has not applied the relocations correctly.
Post 31 Mar 2016, 12:51
View user's profile Send private message Visit poster's website Reply with quote
system error



Joined: 01 Sep 2013
Posts: 667
Thanks Tomasz. Sounds like there's more to it than it seemed. I'll check that out.
Post 31 Mar 2016, 22:35
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.