If I use the --pic-executable flag then everything works fine. The loader resolves everything at execution time so there are no wrong addresses.

But, what if I wanted a pure statically linked ELF64 executable with all addresses known at link time? I am probably missing a flag for the linker or smth.

Does anyone know?



@mcoll I'm interested but this is waaaay out of my comfort zone: had to read about ELF segments to even understand what you're talking about...

So, I may have an idea, but I have literally no idea what I'm talking about.

Does gdb has a magic flag that let you trace the segfault? If so, you may be able trace both what's wrong and what libc is doing.

I'm interested in a writeup about that problem when you'll figure it out.

@mcoll @ninjatrappeur Copy/paste borked that makefile, btw, the tabs will need fixed. Just noticed that. Sorry.

@SuperFloppies @ninjatrappeur

Sorry was not home, the code is public on my GitHub but it's not updated with the tests Ive done. Will update when I get home

@SuperFloppies @ninjatrappeur

Updated code in the repo, the makefile builds three versions, pic & libc should work fine. static one should segfault before even arriving at _start. At least that's what happens on my machine.

You'll need fasm to assemble the files.

@mcoll @ninjatrappeur A static binary should not declare an ELF interpreter, it lacks dynlink segments. The PIC executable option gives you a shared library with an entrypoint, averting the crash.

@mcoll @ninjatrappeur So, you appear to be crashing before _start because _start is called by the interpreter, which crashes because it is being loaded to interpret a non dynamic ELF.

@ninjatrappeur @SuperFloppies

ah, just remove those rules, not using asm_io.asm at all

@ninjatrappeur @mcoll No need to even run through assembly process... just remove the "--dynamic-linker=/usr/lib/" from all statically linked programs, and the _start entrypoint will be the first thing run when the ELF image setup is complete.

The example I posted earlier (in C w/ inline asm) will build a simple program that simply returns to the (Linux) OS. However, when you build that ELF and compare it (with readelf -Wa) to crashing one, the diff will be ELF interpreter.

Inicia la sessió per participar a la conversa, xarxa social pels catalans d'arreu.

Servidor social en català per a la comunitat de llengua i cultura catalana d'arreu d'internet.