Difference between input and output sections in a

2019-07-11 03:49发布

问题:

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?

回答1:

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.