Subject: bin/586: ld doesn't notice multiply defined symbols
To: None <gnats-admin@sun-lamp.cs.berkeley.edu>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: netbsd-bugs
Date: 11/23/1994 11:50:03
>Number:         586
>Category:       bin
>Synopsis:       ld doesn't notice multiply defined symbols
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    gnats-admin (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Nov 23 11:50:02 1994
>Originator:     der Mouse
>Organization:
>Release:        NetBSD/sparc 1.0
>Environment:
	Sparc IPC, everything built from 1.0 release sources
>Description:
	ld does not notice multiply-defined symbols, under some
	circumstances.
>How-To-Repeat:
	Script started on Wed Nov 23 14:09:12 1994
	[Callisto] 1> std
	[Callisto] 2> cat w.c
	#include <stdio.h>
	extern int foo(void);
	extern int foo1(void);
	extern int foo2(void);
	void main(void);
	void main(void)
	{
	 printf("%d %d %d\n",foo1(),foo2(),foo());
	}
	[Callisto] 3> cat x.c
	int foo(void) { return(1); }
	int foo1(void) { return(1); }
	[Callisto] 4> cat y.c
	int foo(void) { return(2); }
	int foo2(void) { return(2); }
	[Callisto] 5> cc -c w.c
	[Callisto] 6> cc -c x.c
	[Callisto] 7> cc -c y.c
	[Callisto] 8> cc -o w w.o x.o y.o
	[Callisto] 9> w
	1 2 1
	[Callisto] 10> cc -static -o w w.o x.o y.o
	[Callisto] 11> w
	1 2 1
	[Callisto] 12> cc -static -o w w.o y.o x.o
	[Callisto] 13> w
	1 2 2
	[Callisto] 14> exit
	[Callisto] 15> exit
	
	Script done on Wed Nov 23 14:10:20 1994
>Fix:
	A quick skim of the ld source seems to imply this is because
	both version of foo() are at the same offset in their
	respective text segments.  Interchanging foo() and foo1() in
	x.c produces the expected errors.

	I suspect the "sp->value != p->n_value" on line 1804 of
	gnu/usr.bin/ld/ld.c (1.0 sources) should be removed entirely,
	or possibly only for non-N_COMM symbols.  I am not confident
	enough to attempt this myself now.

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu
>Audit-Trail:
>Unformatted: