Subject: bin/4599: backgammon fails to link on mips due to conflict with libtermcap?
To: None <gnats-bugs@gnats.netbsd.org>
From: Jonathan Stone <jonathan@DSG.Stanford.EDU>
List: netbsd-bugs
Date: 11/28/1997 18:10:45
>Number:         4599
>Category:       bin
>Synopsis:       backgammon fails to link on mips due to conflict with libtermcap?
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Nov 28 18:20:02 1997
>Last-Modified:
>Originator:     Jonathan Stone
>Organization:
	
>Release:        NetBSD-1.3_ALPHA supped at Nov 27
>Environment:
	
System: NetBSD Reno.DSG.Stanford.EDU 1.3_ALPHA NetBSD 1.3_ALPHA (GENERIC) #0: Sat Nov 22 16:32:51 PST 1997 jonathan@Reno.DSG.Stanford.EDU:/reno/compile/GENERIC pmax


>Description:

I think the nonstatic file-level variable "ospeed" in
	/usr/src/lib/libtermcap/tputs.c
is colliding with the nonstatic file-level variable "ospeed" in

	 /usr/src/games/backgammon/backgammon/main.c
	 /usr/src/games/backgammon/teachgammon/teach.c

and that namespace collision seems to be causing the linker to lose on
pmaxes.  Other games show changes in size between compile and link
that suggest problems there too.

On a pmax, the linker coredumps when linking backgammon and
teachgammon. THat happens with ld from both GNU binutils 2.8 and 2.8.1
coredumparound to test.  (There may be problems with 2.7 as well; I
don't have one around anymore to test. In fact the problem may go back
to sometime last year.)

The fact hat gnu LD coredumps shows there's _some_ kind of bug in gnu
ld: it should never dump core.  But there's good evidence the
backgammon source code is not entirely correct: that's the subject of
this PR.



>How-To-Repeat:

	On a pmax, do: (cd /usr/src/games/backgammon; make -k).
	Watch ld coredump.

>Fix:

Perhaps changing the libtermcap private variable `ospeed' to be
`static' or in the ANSI reserved namespace, to avoid the conflict?

Here's some analysis behind this:

Installing a prerelease test version of GNU ld, with better
diagnostics, and trying `(cd /usr/src/games/backgammon; make -k) emits
warnings which suggests the `extern' declarations in backgammon are
not correct.  The object size of extern objects `instr', `message',
and `ospeed' are changing, which shows that their declaration and
their definitions are in conflict. (the "type of symbol" changes are
relatively innocuous.)

here's a log of a relink with the  prerelease ld:


all ===> games/backgammon
all ===> games/backgammon/common_source
building standard common library
ranlib libcommon.a
all ===> games/backgammon/backgammon
cc   -o backgammon -nostdlib -L/reno/build/usr/lib /reno/build/usr/lib/crt0.o  extra.o main.o move.o text.o version.o -ltermcap -lcompat  -L/usr/src/games/backgammon/common_source/obj -lcommon -lgcc -lc -lgcc 
ld: Warning: size of symbol `instr' changed from 4 to 256 in text.o
ld: Warning: size of symbol `message' changed from 4 to 8 in version.o
ld: Warning: type of symbol `_gp_disp' changed from 1 to 3 in /reno/build/usr/lib/libtermcap.so
ld: Warning: size of symbol `ospeed' changed from 4 to 2 in /reno/build/usr/lib/libtermcap.so
ld: Warning: type of symbol `getout' changed from 1 to 2 in subs.o
all ===> games/backgammon/teachgammon
cc   -o teachgammon -nostdlib -L/reno/build/usr/lib /reno/build/usr/lib/crt0.o  data.o teach.o ttext1.o ttext2.o tutor.o -ltermcap -lcompat  -L/usr/src/games/backgammon/common_source/obj -lcommon -lgcc -lc -lgcc 
ld: Warning: type of symbol `_gp_disp' changed from 1 to 3 in /reno/build/usr/lib/libtermcap.so
ld: Warning: type of symbol `getout' changed from 1 to 2 in subs.o

all ===> games/banner
cc   -o banner -nostdlib -L/reno/build/usr/lib /reno/build/usr/lib/crt0.o  banner.o  -lgcc -lc -lgcc 
ld: Warning: type of symbol `_gp_disp' changed from 1 to 3 in /reno/build/usr/lib/libc.so

all ===> games/battlestar
cc   -o battlestar -nostdlib -L/reno/build/usr/lib /reno/build/usr/lib/crt0.o  battlestar.o com1.o com2.o com3.o com4.o com5.o com6.o com7.o init.o cypher.o getcom.o parse.o room.o save.o fly.o misc.o globals.o dayfile.o nightfile.o dayobjs.o nightobjs.o words.o -lcurses -ltermlib -lgcc -lc -lgcc 
ld: Warning: size of symbol `dayfile' changed from 48 to 13248 in dayfile.o
ld: Warning: size of symbol `nightfile' changed from 48 to 13248 in nightfile.o
ld: Warning: size of symbol `dayobjs' changed from 4 to 388 in dayobjs.o
ld: Warning: size of symbol `nightobjs' changed from 4 to 236 in nightobjs.o
ld: Warning: size of symbol `wlist' changed from 16 to 2640 in words.o
ld: Warning: type of symbol `_gp_disp' changed from 1 to 3 in /reno/build/usr/lib/libcurses.so

all ===> games/sail
cc   -o sail -nostdlib -L/reno/build/usr/lib /reno/build/usr/lib/crt0.o  main.o pl_main.o pl_1.o pl_2.o pl_3.o pl_4.o pl_5.o pl_6.o pl_7.o dr_main.o dr_1.o dr_2.o dr_3.o dr_4.o dr_5.o lo_main.o assorted.o game.o globals.o misc.o parties.o sync.o version.o -lcurses -ltermlib -lgcc -lc -lgcc 
ld: Warning: type of symbol `choke' changed from 1 to 2 in pl_1.o
ld: Warning: type of symbol `child' changed from 1 to 2 in pl_1.o
ld: Warning: size of symbol `dtab' changed from 4 to 32 in dr_2.o
ld: Warning: size of symbol `scene' changed from 208 to 6656 in globals.o
ld: Warning: size of symbol `specs' changed from 36 to 3024 in globals.o
ld: Warning: size of symbol `rangeofshot' changed from 1 to 5 in globals.o
ld: Warning: size of symbol `countryname' changed from 4 to 32 in globals.o
ld: Warning: size of symbol `classname' changed from 4 to 28 in globals.o
ld: Warning: size of symbol `directionname' changed from 4 to 36 in globals.o
ld: Warning: size of symbol `qualname' changed from 4 to 24 in globals.o
ld: Warning: size of symbol `loadname' changed from 1 to 6 in globals.o
ld: Warning: size of symbol `dr' changed from 1 to 9 in globals.o
ld: Warning: size of symbol `dc' changed from 1 to 9 in globals.o
ld: Warning: size of symbol `version' changed from 1 to 50 in version.o
ld: Warning: type of symbol `_gp_disp' changed from 1 to 3 in /reno/build/usr/lib/libcurses.so
all ===> games/snake
all ===> games/snake/snake
cc   -o snake -nostdlib -L/reno/build/usr/lib /reno/build/usr/lib/crt0.o  snake.o move.o -lm -ltermcap -lcompat -lgcc -lc -lgcc 
ld: Warning: type of symbol `_gp_disp' changed from 1 to 3 in /reno/build/usr/lib/libm.so
ld: Warning: size of symbol `ospeed' changed from 4 to 2 in /reno/build/usr/lib/libtermcap.so
all ===> games/snake/snscore
cc   -o snscore -nostdlib -L/reno/build/usr/lib /reno/build/usr/lib/crt0.o  snscore.o  -lgcc -lc -lgcc 
ld: Warning: type of symbol `_gp_disp' changed from 1 to 3 in /reno/build/usr/lib/libc.so
all ===> games/tetris
cc   -o tetris -nostdlib -L/reno/build/usr/lib /reno/build/usr/lib/crt0.o  input.o screen.o shapes.o scores.o tetris.o -ltermcap -lgcc -lc -lgcc 
ld: Warning: type of symbol `_gp_disp' changed from 1 to 3 in /reno/build/usr/lib/libtermcap.so
ld: Warning: size of symbol `ospeed' changed from 4 to 2 in /reno/build/usr/lib/libtermcap.so


I haven't yet checked what's going on with battlestar, sail, or
tetris.  The size changes are very suggestive of other mismatched
declarations.

Any such declarations are likely to break on RISC machines which use a
small register-relative `constant pool' of small or constant objects
that can be addressed cheaply via a register dedicated to point at
that `pool' (mips, alpha, powerpc with AIX ABI_compliant toolchain?)
If I find real evidence of problems in any of these I'll send a
separate PR.
>Audit-Trail:
>Unformatted: