Linkers part 17

Warning Symbols

The GNU linker supports a weird extension to ELF used to issue warnings when symbols are referenced at link time. This was originally implemented for a.out using a special symbol type. For ELF, I implemented it using a special section name.

If you create a section named .gnu.warning.SYMBOL, then if and when the linker sees an undefined reference to SYMBOL, it will issue a warning. The warning is triggered by seeing an undefined symbol with the right name in an object file. Unlike the warning about an undefined symbol, it is not triggered by seeing a relocation entry. The text of the warning is simply the contents of the .gnu.warning.SYMBOL section.

The GNU C library uses this feature to warn about references to symbols like gets which are required by standards but are generally considered to be unsafe. This is done by creating a section named .gnu.warning.gets in the same object file which defines gets.

The GNU linker also supports another type of warning, triggered by sections named .gnu.warning (without the symbol name). If an object file with a section of that name is included in the link, the linker will issue a warning. Again, the text of the warning is simply the contents of the .gnu.warning section. I don’t know if anybody actually uses this feature.

Short entry today, more tomorrow.

1 Comment »

  1. d said,

    September 23, 2007 @ 6:28 am

    Here’s some more warnings that could be useful:
    - warn if a symbol is only referred to in the object file where it is
    defined (that way it can be changed into a static)
    - warn if the type of a def and of a use are different… not sure how
    feasible this is, as the linker normally does not have the information
    needed and the type compatibility rules are hairy. Maybe it could
    use the debug information…
    Just my 2 cents…

RSS feed for comments on this post · TrackBack URI

Leave a Comment

You must be logged in to post a comment.