flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Relocatable executables |
Author |
|
Octavio 05 Aug 2006, 13:45
Object file formats like elf relocatable contains the information required
for loading the code at any adress. The Os read the file ,make relocations and jmps to the code, thats all. |
|||
05 Aug 2006, 13:45 |
|
Artlav 05 Aug 2006, 14:16
Well, ive already tryed to do it with ELF.
The problem is that Code: format ELF executable entry start section readable executable use32 start: jmp begin ;############################################################################### begin: mov esi,msg mov eax,111 int 32 ret msg db "Hello world! (Aprom PE/AE)",0 and the same without mov Code: format ELF executable entry start section readable executable use32 start: jmp begin ;############################################################################### begin: ;mov esi,msg nop nop nop nop nop mov eax,111 int 32 ret msg db "Hello world! (Aprom PE/AE)",0 produces exactly the same ELF file, with only diffirence in place of the mov opcode. Maybe iam missing something about ELF? |
|||
05 Aug 2006, 14:16 |
|
Dex4u 05 Aug 2006, 19:56
You use a simple relocte able bin file like this:
Code: org 0use32jmp start;maybe a simple header herestart:mov eax,[MyVar1 + ebx] ; you need to do thismov [MyVar2 + ebx],edx; same with thismov esi,MyStringadd esi,ebx ; you need to do thiscall print ; this is ok like thisjmp LetsGo ;this is ok like this; some more code here, maybeLetsGo: retprint:;print code hereret;DataMyString: db 'hello world!',13,0MyVar1 rd 1MyVar2 rd 1 This can be loaded any where in memory, you just need to load ebx with the load address at load time and keep ebx untouched. There is a better way, "0x4e71" came up with for Dex4u OS. |
|||
05 Aug 2006, 19:56 |
|
Tomasz Grysztar 05 Aug 2006, 20:30
"format ELF executable" is not an object, is an executable - and it doesn't contains relocations.
Use pure "format ELF" to get relocatable object. I had once also written (for a Maverick's request) a tool COFF2REL that was converting fasm-produced COFF object into simple flat binary with an auxiliary file containing addresses of relocations. I don't know where is it now, though. |
|||
05 Aug 2006, 20:30 |
|
Artlav 05 Aug 2006, 20:33
Heh, that's the kind of code i was testing the OS with, only using
call bg bg: pop ebx in the beginning. After exausting the ELF manual i got into EXE PE one. It appears that PE format supports full relocations, fasm can generate it, and it's exe output is quite plain, so no big deal to make exe->aex1 converter. So, the problem is closed, atlease for now. Anyway, please clarify "There is a better way, "0x4e71" came up with for Dex4u OS.". |
|||
05 Aug 2006, 20:33 |
|
Artlav 05 Aug 2006, 20:40
Like that?
Code: format ELF use32 start: jmp begin ;############################################################################### begin: mov esi,msg mov eax,111 int 32 ret msg db "Hello world! (Aprom PE/AE)",0 That produces an object file... Or do you mean something like linking programs at load-time? |
|||
05 Aug 2006, 20:40 |
|
Dex4u 05 Aug 2006, 22:59
Artlav wrote:
You can get info and test prog here: http://jas2o.forthworks.com/dexforum/index.php?topic=108.30 note: its based on the PE file format. |
|||
05 Aug 2006, 22:59 |
|
f0dder 06 Aug 2006, 07:58
I think ELF executables generally aren't relocatable, but that ELF shared libraries generated with GCC/LD use "-fPIC", which produces position-independent code. I dunno if the ELF format supports relocations.
In my own kernel, I use PE executables... they support relocations, and I can use the nice Visual C++ compiler which has decent optimizations. |
|||
06 Aug 2006, 07:58 |
|
Tomasz Grysztar 06 Aug 2006, 11:13
For executables you're right (look here for some information on PIC), but the linkable objects always need to be relocatable, and so are the ELF ones.
Artlav: Yes, this is the right way to produce linkable (and thus relocatable) object file. Even the "use32" is actually redundant here. You can also try "format COFF" if that format would be easier for you to handle. I'll post here if I find my old COFF2REL tool somewhere. Unfortunately the Maverick who perhaps was the only one who had a copy seems to be no longer available (if anyone knows what happened to him, please let me know, BTW). |
|||
06 Aug 2006, 11:13 |
|
f0dder 06 Aug 2006, 18:07
I could try firing off an email to Maverick... I think he got tired of boards and had real life to attend to as well.
Tomasz Grysztar wrote:
Doh yes, of course, I wasn't thinking clearly - I wonder if the ELF *loader* supports relocations, though? Ie, if a shared library could be non-PIC and have relocs applied instead... I used to think wasting a register for GOT instead of using relocs was a bad idea, but this means somewhat smaller executables. Also, in the case of a DLL that can't be loaded to it's preferred base address, thus needing relocations, those code pages will be dirty and nonshareable - that won't happen with -fPIC code on ELF systems. |
|||
06 Aug 2006, 18:07 |
|
Tomasz Grysztar 06 Aug 2006, 18:11
I tried e-mailing him a few times in recent years, but each time it was returned saying the quota on his inbox was exceeded.
|
|||
06 Aug 2006, 18:11 |
|
Tomasz Grysztar 06 Aug 2006, 20:14
Thanks f0dder, with your help Maverick and I got in touch again. He just sent me a copy of COFF2REL and I'm attaching it here before he's able to post himself.
I think you may find this tool useful. It should be also easy to adapt it to output some your own relocatable format.
|
|||||||||||
06 Aug 2006, 20:14 |
|
Artlav 07 Aug 2006, 04:55
Thank you all for help.
Ive currently stopped on PE to aex1 converter as the simpliest solution, but COFF2REL may be of use too. If anyone is interested, ive attached current version of Aprom PE.
|
|||||||||||
07 Aug 2006, 04:55 |
|
Maverick 07 Aug 2006, 06:54
Hello
_________________ Greets, Fabio |
|||
07 Aug 2006, 06:54 |
|
pelaillo 07 Aug 2006, 19:38
Maverick, nice to "see" you again.
I hope you are going to keep in touch helping us here |
|||
07 Aug 2006, 19:38 |
|
Maverick 08 Aug 2006, 06:03
¡Hola pelaillo, mi viejo amigo! I'll keep an eye open, that's for sure, but free time is the most limited resource in the universe right now. ;P ¡Hasta la vista! -- FabI/O |
|||
08 Aug 2006, 06:03 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.