[comp.sys.next] Redefining a symbol in /lib/libsys_s.a

byron@archone.tamu.edu (Byron Rakitzis) (06/27/91)

If I redefine a symbol in a program I write, say malloc(), then the
NeXT loader will refuse to load my object file with /lib/libsys_s.a.

For example:

$ cat > a.c
malloc(){return 0;}
main(){return malloc();}
$ cc a.c
/bin/ld: multiple definitions of symbol _malloc
a.o definition of _malloc in section (__TEXT,__text)
/lib/libsys_s.a(malloc.o) definition of absolute _malloc (value 0x50028fa)

Does anyone know a way to work around this problem (besides the obvious
renaming of malloc() in a.c...)?

Please send me mail and I will summarize to the net.


--
Byron Rakitzis
byron@archone.tamu.edu

sef@kithrup.COM (Sean Eric Fagan) (06/27/91)

In article <17859@helios.TAMU.EDU> byron@archone.tamu.edu (Byron Rakitzis) writes:
>malloc(){return 0;}
>main(){return malloc();}
>$ cc a.c
>/bin/ld: multiple definitions of symbol _malloc
>a.o definition of _malloc in section (__TEXT,__text)
>/lib/libsys_s.a(malloc.o) definition of absolute _malloc (value 0x50028fa)

Almost certainly because malloc.o has a definition for malloc, free, and
probably realloc as well; other code that gets pulled in uses free,
therefore that module gets pulled in.  However, malloc is already defined in
both a.o and malloc.o (which was pulled in because of free).  Therefore,
multiply-redefined error.

The solution is to not to replace system routines unless you know what
you're doing.

-- 
Sean Eric Fagan  | "What *does* that 33 do?  I have no idea."
sef@kithrup.COM  |           -- Chris Torek
-----------------+              (torek@ee.lbl.gov)
This article may not be distributed under any copyright without my consent.