This is the mail archive of the mailing list for the gas2 project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

global vars and symbol visibility for mips32/elf

I have this problem and I don't know who exactly (binutils or gcc) is
causing the problem.  Hopefully with the homework I have done my
debugging information will allow someone to see what and where the
problem is.

I have support for Linux/MIPS written for gcc/binutils.  It uses the
generic elf32-mips support in binutils.  I am also using GNU libc to
link against.  Here is the delimma:

When running c-torture I get a failure for execute/960218-1.c which
looks like:

int glob;

g (x)
  glob = x;
  return 0;

f (x)
  int a = ~x;
  while (a)
    a = g (a);

main ()
  f (3);
  if (glob != -4)
    abort ();
  exit (0);

The problem is caused by the symbol 'glob'.  GNU libc also has a
symbol glob.  The assembly output by gcc for the glob variable in the
960218-1.c test case looks like:

        .comm   glob,4,4

And that is it.  When assembled by gas into an object file it's symbol
entry looks like.

00000004 C glob

Now when it is linked, the problem occurs, the linker decides to
override this symbol with the symbol for 'glob' in GNU libc, so in the
final executable image glob is undefined and will be resolved at
dynamic link time.  This of course causes the test to erroneously
write into the elf pltgot stub instructions when assigning values to
the variable 'glob' in the test program.

More data points.  The symbol table entry for 'glob' in my shared GNU
libc looks like:

600462f0 A glob

I played around with the native assembler/linker under IRIX6.2 using
gcc and here is what I found them to be doing when compiling this

gcc for the IRIX6.2 target outputs the glob symbol information in the
same way as my MIPS/Linux gcc does:

        .comm   glob,4

The IRIX6.2 assembler also created the symbol in the same way within
the object file:

00000004 C glob

The IRIX6.2 linker however places this symbol in the MIPS_ACOMMON
section of the resulting executable and does not override using the
libc symbol of the same name (the shared IRIX libc does in fact have a
symbol named 'glob' just like my MIPS/Linux GNU libc does).

[37]    | 268505200|       4|OBJT |GLOB |DEFAULT  |MIPS_ACOMMON|glob

The IRIX6.2 compiler outputs the 'glob' symbol differently in the
resulting assembly.

        .globl  glob
        .lcomm  glob 4

Does anyone know who is at fault here (gcc, binutils, or my GNU libc
for some reason) and how this problem can be resolved?

This is all using the latest snapshots of gas and gcc btw.

'Ooohh.. "FreeBSD is faster over loopback, when compared to
Linux over the wire". Film at 11.' -Linus