0
votes

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.

1
Could you please give the purpose of your program?Mark Garcia
It's kind of QEMU, which loads guest application then run it. I want to make space for the guest application (i.e., space below 4G). In other words, I need move QEMU image above 4G.chenwj
I think you should just minimize your program's memory usage as much as possible. You can also provide 64 bit versions of your program to have more virtual memory available for the guest apps.Mark Garcia
I guess I found one, ''gcc -Wl,-Ttext-segment=0x200000''.chenwj
Well, good luck in your program!Mark Garcia

1 Answers

0
votes

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.