Linkers, Loaders & Executables
How does a linker treat a weak symbol?
- AA weak symbol always takes priority over other definitions
- BIf an ordinary (strong) definition with the same name exists, it is used; otherwise the weak definition is used
- CFiles containing weak symbols cannot be linked
Show answer and explanation
Answer: B. If an ordinary (strong) definition with the same name exists, it is used; otherwise the weak definition is used
A weak symbol is a fallback definition: "use this if there is no other". Embedded software often supplies default interrupt handlers as weak symbols so that a user-written function with the same name replaces them. Two strong definitions collide with a multiple-definition error, but overlapping with a weak definition is not an error.
- A. On the contrary, it loses to a strong definition.
- B. Correct. It provides a default definition that can be overridden.
- C. They link normally.