3

While it could be clear in the context of a resulting binary or ELF file what is a section, many places in documentation (independently of the compiler used) refers them as to Input or Output sections.

What are the differences between these?

urnenfeld
  • 1,030
  • 9
  • 25

1 Answers1

3

The linker consumes object files (and possibly shared libraries) and outputs an executable or shared library. The input object files are composed of named sections - .text, .data, .rodata, .bss, etc. So is the output file.

It is a principal part of the linker's job to combine all the input sections of the same name, from all of the input object files, into a single output section of that name in the output file. E.g. all of the .text sections of the input object files contribute to the .text section of the output file.

Some input sections may discarded from the output file if the linker determines they are redundant.

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
  • In general terms, would the sections delimited in the source code(#pragma like) be input sections, and the sections referenced in the final linker-file be output sections? – urnenfeld Mar 27 '18 at 10:33
  • 1
    @urnenfeld In Standard C or C++ there are no syntactic means to define sections. Section definition normally is entirely the compiler's business. A compiler may have non-standard extensions that let you assign an object to a named section. For GCC see the documentation of `__attribute__ ((section ("")))` in [Common Variable Attributes](https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes) and [Common Function Attributes](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html) Such extensions are for specialized purposes. – Mike Kinghan Mar 27 '18 at 10:48
  • 1
    @urnenfeld Any sections that *are* defined with source-language extensions will become sections of the object files the compiler generates and will become *input* sections to the linker. – Mike Kinghan Mar 27 '18 at 10:51