'How to put 2 sections in 1 segment (Using ld scripts)

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.



Solution 1:[1]

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
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AJM