This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
COMMON symbols get overridden by PROVIDE commands?
- From: Tony Beta Lambda <tonybetalambda at gmail dot com>
- To: binutils at sourceware dot org
- Date: Thu, 18 Dec 2014 16:31:27 +0800
- Subject: COMMON symbols get overridden by PROVIDE commands?
- Authentication-results: sourceware.org; auth=none
Hi,
The default linker script PROVIDEs the symbol end, but this replaces
the symbol defined in COMMON section and causes error. (ld version
2.24 on Linux 3.16.0 x86_64)
Example C code:
int end[100000];
int main(void) { end[99999] = 0; return 0; }
This should be completely valid, but when compiled with default options
$ gcc foo.c
(gcc version 4.9.1) and running ./a.out gives SEGV. Examination with
nm shows end gets replaced in the PROVIDE(end = .) command in the
default linker script,
and now end equals _end. If instead I let the symbol go into the
section .bss by compiling with
$ gcc foo.c -fno-common
The program then runs fine, and nm results are as expected.
I think there should at least be some sort of warnings when these
kinds of overriding occurs, otherwise mysterious errors might occur.
--
Tony Beta Lambda