Judging by the question you reference and the tag of Linux, I am going to assume that you are using GNU ld
.
The short answer for GNU ld
is yes, sections can be placed at specific addresses.
The longer answer is that you will need to create a custom linker script to do that, which can be specified the -T for ld
. If you are using gcc
as a wrapper around ld
, you will need pass it the linker via the gcc
-Wl,
option.
The linker script will have to include something like the following:
SECTIONS {
.text 0x08049000 :
{
foo.o (.text)
bar.o (.text)
}
}
Something to watch out for though is that -T option replaces the default linker script that ld uses. You may want to modify the default linker script to do what you want. The default linker script can be dumped by passing the --verbose
option to ld
without any other options.
More info about linker scripts is available in the LD Manual.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…