flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > Linker

Author
Thread Post new topic Reply to topic
drobole



Joined: 03 Nov 2010
Posts: 67
Location: Norway
drobole
Has anyone considered writing a linker with the same attitude as fasm? eg. Small, fast, stand-alone with a friendly license.
I would love to do it myself if I had the know how.
The only linker I have found that could potentially do the job is Gnu's ld, as it is the only linker supporting most of the file formats and platforms that fasm does. Anyone know any other linkers than ld that would suit fasm btw?

Since I'm new to fasm I have another couple of questions;
In what circumstances is fasm able to do the linking itself, and in what circumstances do you have to use an external linker?

So far, I have noticed that the dll example (flibcdll.asm) can be compiled and run without a linker step, while the other examples (those using static linkage) seems to need it
Post 09 Nov 2010, 13:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17714
Location: In your JS exploiting you and your system
revolution
drobole wrote:
In what circumstances is fasm able to do the linking itself, and in what circumstances do you have to use an external linker?
See here:

http://flatassembler.net/docs.php?article=manual#2.4
Post 09 Nov 2010, 13:24
View user's profile Send private message Visit poster's website Reply with quote
drobole



Joined: 03 Nov 2010
Posts: 67
Location: Norway
drobole
Thanks for the link

I managed to convert my testbed to an executable by adding executable to the format directive, out commenting the sections and adding a entry point

Code:
format ELF executable

;public main as 'main'
entry _main

;section '.text' executable

_main:

        mov edi, hello
        call print

        mov ebx, 0
        call exit

print:
        mov ebx, edi
        xor ecx, ecx
        xor al, al
        not ecx
        cld
        repne scasb
        not ecx
        dec ecx

        mov edx, ecx
        mov ecx, ebx
        mov eax, 4
        mov ebx, 1
        int 0x80
        ret

exit:
        mov eax, 1
        int 0x80
        ret

;section '.data' writable

        hello db "Hello, world",10,0
    


Is this good code or should I be using the segment directive or something like that?
Post 09 Nov 2010, 14:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17714
Location: In your JS exploiting you and your system
revolution
If you want to protect against potential buffer overflows and such like then you should probably use the sections with appropriate attributes. But otherwise it mostly doesn't matter if you mix code and data, the CPU can handle it.
Post 09 Nov 2010, 14:50
View user's profile Send private message Visit poster's website Reply with quote
drobole



Joined: 03 Nov 2010
Posts: 67
Location: Norway
drobole
revolution wrote:
If you want to protect against potential buffer overflows and such like then you should probably use the sections with appropriate attributes. But otherwise it mostly doesn't matter if you mix code and data, the CPU can handle it.


I see. Thanks again
Post 09 Nov 2010, 14:52
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17714
Location: In your JS exploiting you and your system
revolution
BTW: Don't forget the bss section.

http://board.flatassembler.net/topic.php?t=3689
Post 09 Nov 2010, 14:58
View user's profile Send private message Visit poster's website Reply with quote
drobole



Joined: 03 Nov 2010
Posts: 67
Location: Norway
drobole
revolution wrote:
BTW: Don't forget the bss section.

http://board.flatassembler.net/topic.php?t=3689


This stuff is a bit over my head still but if I get it right, earlier versions of the linux kernel would choke on any not writable .bss sections?
Post 09 Nov 2010, 15:19
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


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.