Problems with Elf and Global variables

Problems with Elf and Global variables

Post by John Michael Flo » Tue, 29 Aug 1995 04:00:00



I am having problems with the Elf linking system, binutils (V2.5.2l.17).

The problem is that the source file has a variable 'wait' defined as an
global char variable.  But the linker treats it as an external
function.  The definition in the .o file is correct.  It is after the
linking that it the definition has been redefined to an external
undefined value (which is then satified from the libraries).

Example nm from the object file

...
         U printf
         U signal
         U sleep
         U strcmp
         U strlen
00000000 D trace
00000001 C wait                           <---------------
...

sample nm from the executable! built from the object file
...
080159b8 d type.78
08017400 b value.74
08017410 b valuepairsets
         U wait                           <---------------
080161d0 B widgetClassRec
080172d0 b widget_name
...

However, a simple test file will not go through to completion - though
the error may point to the problem area, there is an assert error though the
exec is produced. But I have had other cases where there was NOT an
apparent link error but the same effect was noticed.

If the wait variable is made local eg declared static then all is OK.  

/*---------------------------------------------*/
char wait;

main()
{

        wait = 1;
        printf("Test %d\n",wait);

Quote:}

/*---------------------------------------------*/

Compile to object OK
Compile to executable fail with

bfd assertion fail /opt/release/pub/bin/binutils/bfd/elf32-i386.c:624

The linker is confusing the global variable with the library entry.  I
think that this should not happen. I would have thought that yes this is
a problem if the variable was declared as an external variable, but it is
defined in this example.

It appears to be a problem with the dynamic linker.

Any comments please.

Regards
John Floyd

--
-------------------------------------------------------------------------------

  Estuary Management - Department of Land and Water Conservation
  New South Wales. Australia.