What's the purpose of a base address in an executable?

For example, in Microsoft Visual C++'s linker, you can set a base address, or use the default of 0x1000000. But with virtual memory, why would a base address be needed?

Why would you not just link it to 0x0 and put the initialization routine (mainCRTStartup on Windows) there which would make it so writing to NULL (0x0) would just overwrite the startup routine (a method that will never be called again). Plus, you could just set the code's pages to execute only on an x86 processor so writing will cause an exception.

  • 2
    For one, language implementations tend to use 0x0 to represent a NULL address because it makes comparisons to NULL easy. If the base address is 0x0, then this becomes a valid pointer and some other value has to be used as NULL. If you pick some other value to represent NULL, then you have to worry about addresses getting large enough to hit that value, which means that only 0x0 and 0xFFFFFFFF (for 32 bit) make sense to represent NULL. Jan 25, 2013 at 16:28
  • @StevenBurnap That's why OSX 64-bit uses 0x100000000 (32 bit max + 1) for base, but it doesn't answer my question really...
    – Cole Tobin
    Jan 25, 2013 at 17:43
  • Please try to keep votes relevant to the content of the question, and not the tools being used. Thank you.
    – maple_shaft
    Jan 25, 2013 at 19:04

2 Answers 2


Traditionally executables get mapped at their desired base address, if that's not in use yet. You can't map at 0, since the lowest part of the address space is reserved (leads to crashes on null pointer dereferencing, instead of accessing memory you didn't intend to acceess).

Since you only load a single .exe file into a process, they don't need to use a unique base address. So most .exe files keep the default value 0x400000. They often lack a relocation table, and thus must be loaded at that address.

For dlls things are a bit more complicated, since their target address can be in use already. In that case they'll get mapped at another address, and a relocation table is used to patch parts of its code that now need to point to other addresses. This fixup costs both CPU time and memory (executables are mapped as copy-on-write, and the fixup means your application gets a unique copy of the dll). So base addresses for dlls are typically chosen to avoid overlaps and thus relocation.

Nowadays things are different. RAM is much cheaper, so the cost of relocation isn't that important anymore. On the other hand security is very important now. So we use a process called ASLR where executables are mapped at unguessable addresses. This makes the base address the executable specifies rather meaningless.

Thus executables being able to choose their own base address is a performance optimization that was useful on slow computers with little RAM but isn't useful on modern systems anymore since MS decided to trade a bit of performance for increased security.


Base addresses are needed to compute the virtual addresses of objects in the file after it has been loaded into virtual memory. Remember that the linker may have to link many PE files, and each one may request to be loaded at 0x0- this means that the PE file will have to cope with being located in different places in virtual memory.

The base address is used to make the other addresses relative- so if you have a vtable, you load the address 0x1000FF00, say. Then, when the dynamic linker rebases the executable because there was already something there, it knows how to modify this address to point to the new location.

  • But you could just make it relative to the virtual page's 0x0
    – Cole Tobin
    Jan 25, 2013 at 18:26
  • But since every executable would not be able to achieve that address, you'd have to rebase every executable- expensive.
    – DeadMG
    Jan 25, 2013 at 19:01
  • why won't they be able to achieve the address? In referring to setting the linker to link to a base of 0x0 instead of the default. Why not use 0x0?
    – Cole Tobin
    Jan 25, 2013 at 22:54
  • Because every executable will attempt to map itself to the same address, and also, that would destroy every piece of code now compiled to use 0 as NULL. In fact, many operating systems now support ASLR, which effectively means the base address is random.
    – DeadMG
    Jan 26, 2013 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.