LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

What are the linker's symbol resolution rules for handling duplicate symbols?

Two strong symbols sharing a name = a link error; a strong symbol beats any weak/COMMON ones; multiple weak ones are resolved by arbitrarily picking one (a silent-bug risk).

Rule Scenario Result
Rule 1 Multiple strong symbols with same name Linker error
Rule 2 One strong + one or more COMMON symbols Strong symbol wins
Rule 3 Multiple COMMON symbols, no strong Pick arbitrarily (dangerous!)
Rule 4 Strong + weak symbols Weak symbols relocate to strong

Strong vs Weak:

  • Strong: Functions and initialized global variables
  • Weak: Uninitialized global variables (tentative definitions)

Why Rule 3 is dangerous:

// file1.c
// Weak (COMMON)
int x;
// file2.c
// Weak (COMMON)
int x;
// Linker picks one arbitrarily - silent bug!

Best practices:

  • Use -fno-common (default since GCC 10)
  • Always initialize global variables
  • Use static for file-private globals
  • Use extern to declare variables defined elsewhere

Go deeper:

From Quiz: REVE1 / Program Execution | Updated: Jul 14, 2026