Search code examples
gcclinkerloaderlinker-scripts

Creating multiple segment for section using linker script


Could anyone please point me out what is the limitation to the alignment value which makes the creation of multiple segment for a section.

With The test case mentioned below:

#include <stdio.h>
#define SIZE (1 << 11)

int Buffer[SIZE]  __attribute__ ((aligned (SIZE * sizeof(int)))) ;

int main (int argc, char * argv[])
{
printf("Test\n");
return 0;
}

And here if i change the macro as:

#define SIZE (1 << 11) to #define SIZE (1 << 12)

Without the above changes we see only two loadable segment while with the above changes we observed three loadable segment. As the alignment of BSS changes from 8K to 16K for GCC 4.8.1 which creates three loadable segments.

So can anyone please tell me what changes need to be done in linker script to make creation of only one loadable segment for data.


Solution

  • GNU Linker script is build based on:

    1. Under directory ~/binutils-2013.11/ld/emulparams/, there are different architecture specifics shell script based on different ELF type and platform like for i386/Vxworks

    elf_i386_vxworks.sh

    1. While still the rest of generic contains in the script came from the ld/elf sources.

    While about segment creation then please look into procedure **bfd_boolean _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)** under source "bfd/elf.c"