This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
LD script: global symbols and multiple defintions
- From: Ted Carter <tcarter at broadcom dot com>
- To: binutils at sourceware dot org
- Date: Thu, 18 Dec 2014 00:59:34 +0000 (UTC)
- Subject: LD script: global symbols and multiple defintions
- Authentication-results: sourceware.org; auth=none
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.