How to put 2 sections in 1 segment (Using ld scripts)
Asked Answered
K

1

10

I have the following linker script:

SECTIONS {

    .arora_exec_free_space 4399531 : 
    {
        *(.text)
        *(.rodata)
        *(.data.rel.ro.local)
    }
    .arora_data_free_space (ADDR(.arora_exec_free_space) + SIZEOF(.arora_exec_free_space)) : AT (7592352)
    {
        *(.data)
        *(.bss)
        *(.got)
    }
}

When I compile my program the two section (exec and data) are in different LOAD segments. I want to put the two sections (.arora_data_free_space and .arora_exec_free_space) into one LOAD segment. Is there any way to do it using linker scripts? How can I do it? Thanks.

Keenakeenan answered 28/6, 2012 at 14:40 Comment(0)
I
5

Sure - you just need to use PHDRS. The example at that link is pretty much exactly what you want to do, I think. Here is an (untested) example I made from your linker script:

PHDRS
{
   mysegment PT_LOAD;
}

SECTIONS 
{
    .arora_exec_free_space 4399531 : 
    {
        *(.text)
        *(.rodata)
        *(.data.rel.ro.local)
    } :mysegment

    .arora_data_free_space (ADDR(.arora_exec_free_space) + SIZEOF(.arora_exec_free_space)) : AT (7592352)
    {
        *(.data)
        *(.bss)
        *(.got)
    } :mysegment
}
Impasto answered 30/6, 2012 at 14:54 Comment(2)
When I'm using PHDRS the rest of the ELF segments are deleted. I'm looking for a way to put this sections into one segemnt and keep the rest of the elf without any change.Keenakeenan
Did you read the link? "The linker will create reasonable program headers by default. However, in some cases, you may need to specify the program headers more precisely. You may use the PHDRS command for this purpose. When the linker sees the PHDRS command in the linker script, it will not create any program headers other than the ones specified." If you want to leave the others the way they are, you just need to include them in your PHDRS.Impasto

© 2022 - 2024 — McMap. All rights reserved.