I would like to compile a program so that when it's loaded into memory, all its sections are above 4G space (I am on a x86_64 machine). I try to specify .text, .data, and .bss section, but it seems it's not enough. Is there a convenient way to do what I am trying to do? Thanks.
Note: http://sourceware.org/ml/binutils/2012-08/msg00480.html solve my problem.
This thread explains how to move a 64 bit binary above 4G virtual space. In short, you need to add -fPIE -pie
options to tell compiler and linker you want the executable can be loaded at arbitrary virtual address. -pie
will ask linker to link your object file against libraries which can be loaded upon 4G virtual addess. Default libraries usually are compiled in -mcmodel=small
mode which cannot be loaded above 2G virtual space, see 3.17.15 Intel 386 and AMD x86-64 Options for more details.