newlib-2.18: Problem with 'free' in __call_atexit.c
Jeff Kuskin
jk500500@yahoo.com
Mon Oct 25 19:32:00 GMT 2010
Hi,
I'm trying to upgrade from version of newlib-1.16 to 1.18. The problem described below does not occur with newlib-1.16.
I'm using binutils-2.20.1 and GCC 4.5.1.
When I try to compile this program:
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *f = fopen("qqq", "r");
return (f == 0);
}
I get this error at link time:
[...]/lib/libc.a(lib_a-__call_atexit.o):
In function `__call_exitprocs':
[...]/newlib/libc/stdlib/__call_atexit.c:97: undefined reference to `free'
collect2: ld returned 1 exit status
However, if I add a 'free(f);' statement into the main() code (which is of course a bug, but ignore that), the link error goes away. It's as if the weak reference to 'free' in __call_atexit.c is not being bound to free() by the linker unless there is also a non-weak reference to free() present.
Any suggestions?
More information about the Newlib
mailing list