flat assembler
Message board for the users of flat assembler.

Index > Linux > [fasm2] Problem with 'format ELF64'

Author
Thread Post new topic Reply to topic
Jessé



Joined: 03 May 2025
Posts: 71
Location: Brazil
Jessé 05 Jan 2026, 00:22
Hello there, noob question!

Today, I'm getting myself out of comfort zone, and trying to use fasm2 in a more "standard" (i.e., assembly) way, and try to make an externally linked program work. But I have the following problem:

Test code:
Code:
format ELF64 

extrn printf
extrn exit
extrn stdout
public _start

section '.text' executable

        align 4
        _start:          
                        endbr64
                        mov         rdi, [plt.stdout]
                        lea         rsi, [msg0]
                        xor         al, al
                        call        plt.printf
                        
                        sub         rsp, 8
                        xor         eax, eax
                        jmp         plt.exit
                        
section '.data' writeable

        msg0:           db 'This is a fasm2 program, compiled in'
                        db ' a traditional way!',10,0
    


It compiles successfully, and correctly generates the .o file:
Quote:

flat assembler version g.l04h
4 passes, 0.1 seconds, 872 bytes.


But when I link it by using 'ld' command, I get the following:
Quote:

LANG=EN_us ld -o asmextern -pie -lc --dynamic-linker=/lib64/ld-linux-x86-64.so.2
ld: warning: cannot find entry symbol _start; not setting start address


The final executable is broken, and apparently devoid of any section filled in.

My goal is to make PIE executables, and also start doing some shared libraries using fasm2.

Can one help figure out what is wrong?

_________________
jesse6
Post 05 Jan 2026, 00:22
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20814
Location: In your JS exploiting you and your system
revolution 05 Jan 2026, 01:53
I've had success with linking in the past by using
Code:
ld ... -e start ...    
Code:
public  start

start:
;...    
This creates the _start label in the .so file. The linker adds the leading "_" automatically.
Post 05 Jan 2026, 01:53
View user's profile Send private message Visit poster's website Reply with quote
Jessé



Joined: 03 May 2025
Posts: 71
Location: Brazil
Jessé 05 Jan 2026, 04:00
Oooh, shame on me!
Sorry guys to annoy you with my lack of competence, it seems that my attention has blown away a fuse today!

Clearly my own 'ld' command line is missing the 'asmextern.o' file as the source object.

The correct is:
Quote:

ld -o asmextern asmextern.o -pie -lc --dynamic-linker=/lib/ld-linux-x86-64.so.2

With optional '-e _start' also working normally.

Change it here and it worked.

Consider solved.

Thanks anyways, revolution.
Post 05 Jan 2026, 04:00
View user's profile Send private message Visit poster's website Reply with quote
Jessé



Joined: 03 May 2025
Posts: 71
Location: Brazil
Jessé 05 Jan 2026, 04:09
And here, I let the correct working code, because the above one also has errors (if anyone wanna test it):

Code:
format ELF64 

extrn fprintf
extrn exit
extrn stdout
public _start

section '.text' executable

        align 4
        _start:          
                        endbr64
                        mov         rdi, [got.stdout]
                        mov         rdi, [rdi]
                        lea         rsi, [msg0]
                        xor         al, al
                        call        plt.fprintf
                        
                        sub         rsp, 8
                        xor         edi, edi
                        jmp         plt.exit
                        
section '.data' writeable

        msg0:           db 'This is a fasm2 program, compiled in'
                        db ' a traditional way!',10,0


    
Post 05 Jan 2026, 04:09
View user's profile Send private message Visit poster's website 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.