Specifying an "Address Space layout" for a binary

First of all, I don't simply want to "turn off" Address Space Layout Randomization (ASLR). I already know how to know that. My issue is a bit more complicated.

Without going into unnecessary details and reasons for the weird request, I would like a binary to be loaded at addresses that I control. Not just the same address every time I run it like no-ASLR, but rather, an address of my choice which may change between runs. I can only think of two ways to do this:

  1. Explicitly let the kernel know that I want the binary loaded at some specific address. I have been googling for a while and I am not sure if this is even possible. But on the hopes that I am wrong, is there a way to do this?
  2. Compile the application from the beginning with specific addresses, which I wouldn't mind doing between runs. For example, take the following simple asm program (I know it will segfault, doesn't matter for now), is there a way to specify an absolute address for the .text section or the _start label? Either through the assembler itself as or the linker ld?
.section .text
.global _start

_start:
    jmp 0x0

Is one of those two ways possible? Any other possible solutions to this problem? My OS is Linux, and I use GCC as my compiler.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum