flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [fasm2] macro for making ELF64 x86-64 Linux executables

Author
Thread Post new topic Reply to topic
cbytensky



Joined: 20 Dec 2025
Posts: 1
cbytensky 20 Dec 2025, 15:37
I wrote a set of macros for producing ELF64 x86-64 Linux executable binaries.
https://github.com/cbytensky/fasm2-elf64
Examples. HelloWorld using syscalls:
Code:
include "elf64.inc"
        sys         write, 1, <"hello, world", 10>, @$
        sys         exit, 0    

Produces 148-byte ELF64.
HelloWorld using libc:
Code:
include "elf64.inc"
needed "libc.so.6"
        dyncallz    puts, "hello, world"
        dyncall     _exit, 0    

Produces 464-byte ELF64.

Implemented:

  • Dynamic linking (PT_INTERP/PT_DYNAMIC segments), no external linker required. Enabled automatically if "needed" and "dyncall" used.
  • Automatic symbols importing (like "puts" or "_exit" from "libc.so.6" in example).
  • Named Linux syscalls ("write", "exit").
  • SysV ABI call macros "sys", "dyncall", "dyncallz" (which is like "dyncall" but appends zero byte to all string arguments).
  • "@" contains the address of the last string argument.
  • "@$" contains the size in bytes of the last string argument (in example it is 13, the length of <"hello, world", 10>).
  • "movopt" macro for size/speed-optimized data transfer using mov/xor/push-pop.
  • "@optspeed" and "@optsize" macros that switches optimization strategy of "movopt" macro.
  • 1 file, 335 lines.

Non-features/limitations:

  • Poor tool compatibility (like readelf/objdump/gdb). Optimized for minimal size.
  • No section header table.
  • No FP support for SysV ABI calls.
Post 20 Dec 2025, 15:37
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.