7

Until recently I thought that section names generally have to start with a dot .. However, When studying the sample linker file of my bare-metal-C-IDE, I noticed that there seems to be one exception: The section COMMON.

.text :
{
    KEEP(*(.isr_vector))
    *(.text*)

    KEEP(*(.init))
    KEEP(*(.fini))

    /* .ctors */
    *crtbegin.o(.ctors)
    *crtbegin?.o(.ctors)
    *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
    *(SORT(.ctors.*))
    *(.ctors)

    /* .dtors */
    *crtbegin.o(.dtors)
    *crtbegin?.o(.dtors)
    *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
    *(SORT(.dtors.*))
    *(.dtors)

    *(.rodata*)

    KEEP(*(.eh_frame*))
} > ROM

.bss (NOLOAD):
{
    *(.bss*)
    *(COMMON)
} > RAM

This led me to the conclusion that beginning the section names with . seems to merely be a convention rather than a requirement.

So, my questions are:

  • What is the reason for starting section names with a dot? I suppose there there was a (perhaps historical?) reason for this convention to be established.
  • Why was an exception made for COMMON?
  • Why do usually output sections have the same name as input sections? It was rather confusing for me that there is actually a non-.bss sections included in my .bss output section. Same goes with the .text section. There are plenty of non-.text sections included in my .text output section. Why isn't it common just to give them their own output section? Wouldn't that be much more logical?

Are there any real reasons behind this, or is it just the way it is?

Multisync
  • 767
  • 6
  • 25
  • 2
    `COMMON` are from Fortran and its [COMMON blocks](http://www.obliquity.com/computer/fortran/common.html). As for why it's mixed with the `.bss` segment, it probably have to be zero-initialized so it's better to have one big block that will be zeroed and multiple blocks. As for the non-text parts in the `.text` segment, it's because the `.text` segment is usually read-only so it makes sense in a way to put other read.only data there. Also, a lot of the things put in the `.text` segment is actually code. – Some programmer dude Jan 16 '15 at 19:30
  • 12
    [This ELF specification](http://refspecs.linuxbase.org/elf/elf.pdf) from 1995 says: `Section names with a dot (.) prefix are reserved for the system, although applications may use these sections if their existing meanings are satisfactory. Applications may use names without the prefix to avoid conflicts with system sections.` – cremno Jan 16 '15 at 20:09
  • 1
    @cremno Yours is a perfectly valid answer, can you add it as an answer too, so it gets better preservation semantics? – Sedat Kapanoglu Aug 09 '21 at 03:30

0 Answers0