RoMa
RoMa

Reputation: 859

How can i make the gnu linker create an output section similar to .bss?

In an embedded environment i want to convey information about a special part of memory (start address and length) from the build process to the program loader. My idea is to let linker create an output section similar to .bss, i.e. that section should not occupy space in the elf file and should have flags like the .bss section. I came to this idea since i am already using a customized linker script.

When processing the elf file, my costumized loader could recognize this section by a magic name and use the sections size and VMA as the description for the special part of memory.

When i say it should be similar to .bss, i mean the output of objdump -h should be similar to this:

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
...
  7 .bss          00000204  10204c9c  10204c9c  00005c40  2**2
                  ALLOC
...

I guess it is important that here only the flag ALLOC is present, but not LOAD or CONTENTS.

Can this be achieved with some instructions in the linker script? If so, what are those instructions?

Upvotes: 2

Views: 893

Answers (1)

RoMa
RoMa

Reputation: 859

Browsing through similar questions here at stackoverflow and the ld documentation showed that the solution is quite simple:

.special_start = 0x20000000;
.special_size  = 0x10000000;
.special .special_start (NOLOAD) :
{
    . = . + .special_size;
}

gives this ouput from objdump -h:

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
...
  6 .sbss         0000005c  10204c40  10204c40  00005c40  2**2
                  ALLOC, SMALL_DATA
  7 .bss          00000204  10204c9c  10204c9c  00005c40  2**2
                  ALLOC
  8 .special      10000000  20000000  20000000  00006000  2**0
                  ALLOC
...

Upvotes: 1

Related Questions