Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

linux

ld

segments

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.

like image 543
Jah Avatar asked Jun 28 '12 14:06

Jah


1 Answers

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
}
like image 51
Carl Norum Avatar answered Oct 14 '22 09:10

Carl Norum