LD script: global symbols and multiple defintions

Ted Carter tcarter@broadcom.com
Thu Dec 18 01:05:00 GMT 2014


I was expecting that a global symbol defined in a linker script (e.g. foo =
0x3000) would produce a multiple definition error if a non-weak symbol is
already defined in an object file on the link line, but this didn't happen.
 Instead, references will always resolve to the global definition without
throwing a diag if it's defined elsewhere.  My expectation is based on
verbage in https://sourceware.org/binutils/docs-2.24/ld/PROVIDE.html#PROVIDE.

Is the reference to PROVIDE still accurate, or am I misunderstanding how
global symbols are used in this context?  Could someone edify me?

$ ld -v
GNU ld (GNU Binutils) 2.24

/* main.ld */
foo = 0x3000;
SECTIONS {
 .text : { *(.text) }
 .data : { *(.data) }
 .bss : { *(.bss) }
}

/* main.c */
extern void foo(void);
int main() { foo(); return 0;}

/* foo.c */
void foo(void) { }

$ gcc \
-nostartfiles \
-Wl,--undefined=main \
-Wl,--gc-sections \
-T main.ld \
main.o foo.o \
-o main

$ nm -g main
00003000 A foo
00000000 T main

Regards, Ted.



More information about the Binutils mailing list