Index
Home
About
Blog
Newsgroups: comp.risks
X-issue: 6.34
Date: Mon, 29 Feb 88 18:27:44 pst
From: Joe Dellinger <joe@hanauma.STANFORD.EDU>
Subject: Lousy Lazy UNIX Linkers
This started with a very strange bug: Some C graphics software of
mine would unexpectedly shift the plot origin now and then while plotting.
Eventually it was discovered the the problem occurred whenever FORTRAN
formatted I/O was used. Finally it turned out that both our graphics
software library and the system FORTRAN I/O runtime library use a global
variable called "pc". In the graphics routines it is a structure pointer,
in the fortran routines it is an integer.
Now, I had always thought that you can only actually declare a
global variable in one place... everywhere else it should be an external.
Otherwise how can you know something is amiss when you link together 2
different libraries that might happen to clash in their choice of global
variable names?
Silly me... it turns out that UNIX linkers indeed WILL allow you
to declare something in more than one place, and indeed will then happily
assign them to the same memory location, even if they are of completely
incompatible types. And if you don't happen to have the source code for one
of the libraries that gets linked in, such as the FORTRAN runtime library,
THERE REALLY IS NO WAY YOU CAN KNOW AHEAD OF TIME what variable names might
get overlayed in this way...
It makes me wonder how often this is happening and I DON'T catch
it, because the bugs it causes are not so "graphic". This seems to me to
be a very serious "RISK" of using the UNIX linker. Now I wonder if they
also used my favorite variable names, "ii", "jj", and "kk"...?
Index
Home
About
Blog