In the ld linker manual section 3.4.5 version 2.37 , the manual says about the EXTERN Command : "force symbol to be entered in the output file as an undefined symbol. ...etc", I understand the symbol is always kept in the output file , But My question now : is it necessarily kept undefined even if its defined in any file , or just forced to be kept only keeping its state being defined or not defined ? that is confusing for me , Second issue after some research I could get that is used with interrupt tables to keep symbols about the service routines , but I don't get how that actually works with interrupts , so kindly I need some example to help me understand this also
Thanks
Primarily to ensure that certain symbols are included during linking, especially when:
They are only referenced indirectly (e.g., via function pointers, interrupt tables).
You rely on linker garbage collection and don’t want important symbols to be discarded.
Suppose your interrupt vector table is defined in C as:
void (* const interrupt_vector_table[])() __attribute__((section(".vectors"))) = {
Reset_Handler,
Timer_Handler,
UART_Handler
};
But these handlers may not be referenced directly anywhere in your code. The linker might discard them unless you do:
EXTERN(Reset_Handler Timer_Handler UART_Handler)
This tells the linker to treat those symbols as used so it keeps them during garbage collection and ensures the function addresses are properly placed in the vector table.