Home Explore Blog CI



man-pages

33th chunk of `ld.man`
a0866a274135771633a798bb27496e5df18a69218bb72e020000000100000fa7
 use version scripts to filter symbol visibility in auto‐export mode:  any
           symbols marked local in the version script will not be exported.

       --warn-common
           Warn  when  a  common  symbol is combined with another common symbol or with a symbol definition.  Unix linkers allow this somewhat sloppy practice, but linkers on some other operating systems do not.  This option
           allows you to find potential problems from combining global symbols.  Unfortunately, some C libraries use this practice, so you may get some warnings about symbols in the libraries as well as in your programs.

           There are three kinds of global symbols, illustrated here by C examples:

           int i = 1;
               A definition, which goes in the initialized data section of the output file.

           extern int i;
               An undefined reference, which does not allocate space.  There must be either a definition or a common symbol for the variable somewhere.

           int i;
               A common symbol.  If there are only (one or more) common symbols for a variable, it goes in the uninitialized data area of the output file.  The linker merges multiple common symbols for the same variable into
               a single symbol.  If they are of different sizes, it picks the largest size.  The linker turns a common symbol into a declaration, if there is a definition of the same variable.

           The --warn-common option can produce five kinds of warnings.  Each warning consists of a pair of lines: the first describes the symbol just encountered, and the second describes  the  previous  symbol  encountered
           with the same name.  One or both of the two symbols will be a common symbol.

           1.  Turning a common symbol into a reference, because there is already a definition for the symbol.

                       <file>(<section>): warning: common of `<symbol>'
                          overridden by definition
                       <file>(<section>): warning: defined here

           2.  Turning a common symbol into a reference, because a later definition for the symbol is encountered.  This is the same as the previous case, except that the symbols are encountered in a different order.

                       <file>(<section>): warning: definition of `<symbol>'
                          overriding common
                       <file>(<section>): warning: common is here

           3.  Merging a common symbol with a previous same‐sized common symbol.

                       <file>(<section>): warning: multiple common
                          of `<symbol>'
                       <file>(<section>): warning: previous common is here

           4.  Merging a common symbol with a previous larger common symbol.

                       <file>(<section>): warning: common of `<symbol>'
                          overridden by larger common
                       <file>(<section>): warning: larger common is here

           5.  Merging a common symbol with a previous smaller common symbol.  This is the same as the previous case, except that the symbols are encountered in a different order.

                       <file>(<section>): warning: common of `<symbol>'
                          overriding smaller common
                       <file>(<section>): warning: smaller common is here

       --warn-constructors
           Warn if any global constructors are used.  This is only useful for a few object file formats.  For formats like COFF or ELF, the linker can not detect the use of global constructors.

       --warn-execstack
       --no-warn-execstack
           On ELF platforms this option controls how the linker generates warning messages when it creates an output file with an executable stack.  By default the linker will not warn if the -z execstack command line option
           has been used, but this behaviour can be overridden by the --warn-execstack option.

           On the other hand the

Title: LD (GNU Linker) Options: Symbol Visibility, Common Symbols, and Global Constructors
Summary
This section details linker options for managing symbol visibility, warnings related to common symbols (--warn-common), and warnings about the use of global constructors (--warn-constructors). It explains how version scripts can filter symbol visibility, the potential problems of combining common symbols, and provides C examples illustrating different types of global symbols (definition, undefined reference, common symbol). It also describes the different warning scenarios produced by --warn-common and discusses the --warn-execstack option for controlling warnings related to executable stacks on ELF platforms.