*BSD News Article 46180


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!simtel!daffy!uwvax!uchinews!vixen.cso.uiuc.edu!howland.reston.ans.net!xlink.net!zib-berlin.de!news.tu-chemnitz.de!irz401!uriah.heep!bonnie.heep!not-for-mail
From: j@bonnie.heep.sax.de (J Wunsch)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: When did this become linux.advocacy
Date: 29 Jun 1995 11:20:25 +0200
Organization: Private U**x site, Dresden.
Lines: 92
Message-ID: <3str8p$akq@bonnie.tcd-dresden.de>
References: <marcus.114.00E9749F@ccelab.iastate.edu> <3shime$l2i@news.nynexst.com> <DAt15p.F5p@citylink.dinoex.sub.org> <3ss3fh$ig7@agate.berkeley.edu>
Reply-To: joerg_wunsch@uriah.heep.sax.de
NNTP-Posting-Host: 192.109.108.139
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

While i cannot comment on the other problems, allow me a note on
this:

Nick Kralevich <nickkral@octans.EECS.Berkeley.EDU> wrote:

>>3. cc/ld is no longer able to handle certain global variable names. The
>>   programs will be built without error-message, but will crash with
>>   segfault, when the global variable is written the first time. [...]

>I would claim that you didn't find anything because #3 isn't a common
>problem.  I've never had any problem compiling programs that use
>global variables.  If this is a bug, then it is a bug with GNU gcc,
>and I suggest you report it to them.  

It's a common misconception of several C cc/ld systems (not only gcc)
that the linker doesn't complain about multiply defined symbols in the
sections text and bss.  Hence some module might try to reference a
variable ``foo'', while another module is going to define ``foo'' to
be a function.  The result is great confusion.  Below an example:

j@bonnie 141% uname -sr
FreeBSD 1.1.5.1(RELEASE)
j@bonnie 142% cat foo.c 
#include <stdio.h>

void foo(void)
{
        printf("This is foo\n");
}

void bar(void)
{
        foo();
}
j@bonnie 143% cat bar.c
#include <stdio.h>

extern void bar(void);

int foo;

int main(void)
{
        foo++;
        bar();
        printf("This is another foo: %d\n", foo);

        return 0;
}
j@bonnie 144% cc -o foo foo.c bar.c
j@bonnie 145% ./foo
Bus error (core dumped)

j@mara 62% uname -sr
dgux 5.4R3.00
j@mara 63% cc -o foo foo.c bar.c
foo.c:
bar.c:
ld: bar.o: warning: symbol: `foo` has different size in file foo.o
ld: bar.o: warning: incompatible types for symbol: `foo` also in file foo.o
j@mara 64% ./foo
Segmentation fault (core dumped)
j@mara 65% setenv TARGET_BINARY_INTERFACE m88kdguxcoff
j@mara 66% cc -o foo foo.c bar.c
foo.c:
bar.c:
j@mara 67% ./foo
Bus error (core dumped)

j@pluto 60% uname -sr
IRIX 5.2
j@pluto 61% cc -o foo foo.c bar.c
foo.c:
bar.c:
ld:
Warning: bar.o: foo: multiply defined
        previous (used) definition from 'foo.o';
        new (ignored) definition from 'bar.o'
j@pluto 62% ./foo
Segmentation fault (core dumped)

As you can see, DG/UX in the default (ELF) environment and Irix got it
(almost) right in issuing a warning (while it's actually an error).
DG/UX in the COFF environment fails as FreeBSD does.  I guess Linux
would behave as FreeBSD here, since both are essentially using the
same compiler/loader.  (Perhaps Linux would do the Right Thing in ELF,
too?)
-- 
cheers, J"org                      private:   joerg_wunsch@uriah.heep.sax.de
                                   http://www.sax.de/~joerg/

Never trust an operating system you don't have sources for. ;-)