* Linker Script: Put object files at specific addresses into ELF file
@ 2020-11-04 15:06 Khronis Official
0 siblings, 0 replies; only message in thread
From: Khronis Official @ 2020-11-04 15:06 UTC (permalink / raw)
To: gcc-help
Hello,
I have two files `one.c` and `two.c` which respectively contains `f_one`
and `f_two` functions. After compilation, I obtain two object files `one.o`
and `two.o`. I would like to place each object file (function) at
particular addresses (absolute) in the resulting binary.
For now, I succeeded in placing the two object files with a relative offset
in the final ELF by specifying the addresses in the `.text` section with a
linker script.
Linker script used to compile `one.c` (`objects_one.lds`):
[...]
.text 0 :
{
. = 0x10000;
*(.text .stub)
/* .gnu.warning sections are handled specially by elf32.em. */
*(.gnu.warning)
}
[...]
Linker script used to compile `two.c` (`objects_two.lds`):
[...]
.text 0 :
{
. = 0x40000;
*(.text .stub)
/* .gnu.warning sections are handled specially by elf32.em. */
*(.gnu.warning)
}
[...]
After analysing the final binary with objdump, I got:
[...]
0000000000010000 <f_one>:
0000000000050014 <f_two>: // relative to f_one (0x40000 + 0x10000 +
size of `f_one`)
[...]
My issue is that the function `f_two` starts at address `0x50014` (which is
a relative position from the first function and thus from the first object
file) and not at address `0x40000`.
I would like to have the following with objdump:
[...]
0000000000010000 <f_one>:
0000000000040000 <f_two>: // absolute address
[...]
Is it possible to do it with GCC?
Note: for the last linking, I do not specify a linker script.
Best Regard,
K.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-11-04 15:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-04 15:06 Linker Script: Put object files at specific addresses into ELF file Khronis Official
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).