Fatal Resolutions

Symbol conflicts that cannot be resolved result in a fatal error condition and an appropriate error message. This message indicates the symbol name together with the names of the files that provided the symbols. No output file is generated. Although the fatal condition is sufficient to terminate the link-edit, all input file processing is first completed. In this manner, all fatal resolution errors can be identified.

The most common fatal error condition exists when two relocatable objects both define non-weak symbols of the same name.

$ cat foo.c
int bar = 1;
$ cat bar.c
int bar()
{
        return (0);
}
$ ld -r -o temp.o foo.c bar.c
ld: fatal: symbol 'bar' is multiply-defined:
    (file foo.o and file bar.o);

foo.c and bar.c have conflicting definitions for the symbol bar. Because the link-editor cannot determine which should dominate, the link-edit usually terminates with an error message.

Multiple symbol definitions should not occur. In some simple coding scenarios, multiple symbol definition errors can be suppressed using the link-editor's -z muldefs option. This option allows the first definition of a multiply defined symbol to be propagated to the output file, while any other definitions of the multiply defined symbol are discarded. If all references to a multiply defined item use the global symbol name of that item, then all references are resolved to the first instance of the multiply defined symbol.

However, specialized compiler options, or high levels of compiler optimization, can circumvent the use of the -z muldefs option. Under these conditions, the compilers may substitute a global symbol reference to a local section symbol reference. This can result in the individual items of a multiply defined item continuing to be referenced, rather than all references being directed to a single global symbol. This inconsistency can result in multiple items having different values, which can cause unexpected program behavior. For greater flexibility, multiple symbol definitions should be avoided.