I'd like to merge multiple .o files into a single .o while also merging some of the sections.
If I execute
ld -r first.o second.o -o result.o
then it properly merges the object files but I also need to merge the various .text sections. This section merging functionality is available by the default linker script in ld when you are linking a shared object but I did not manage to force the usage of a custom linker script while using -r. ld seems to ignore any script I've tried. I've tried to modify the default linker script and replaced the .text section block with this
.text :
{
*(.text.unlikely .text.*_unlikely)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf32.em. */
*(.gnu.warning)
} =0x90909090
How can I merge the object files while also merge the .text sections using ld?