This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

LD script: global symbols and multiple defintions


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]