ld.so-1.7.11 RTLD_GLOBAL working?

ld.so-1.7.11 RTLD_GLOBAL working?

Post by Neal Beck » Wed, 06 Dec 1995 04:00:00



I'm glad to see ld.so-1.7.11 says that RTLD_GLOBAL is supported!  But
does it work?  This simple test program seems to show it doesn't.  We
load a.so, which defines 'a'.  Then we load b.so, and it fails, saying
'a' is undefined.

#!/bin/sh
# This is a shell archive (produced by GNU shar 4.0).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#

# Source directory was `/home/neal/dyn5'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#     14 -rw-r--r-- a.h
#     16 -rw-r--r-- b.h
#    436 -rw-r--r-- Main.cc
#     18 -rw-r--r-- a.cc
#     45 -rw-r--r-- b.cc
#    153 -rw-r--r-- Makefile
#
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo 'WARNING: not restoring timestamps'
fi
rm -f 1231235999 $$.touch
#
# ============= a.h ==============
if test -f 'a.h' && test X"$1" != X"-c"; then
  echo 'x - skipping a.h (File already exists)'
else
  echo 'x - extracting a.h (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'a.h' &&
extern int a;
SHAR_EOF
  $shar_touch -am 0928230695 'a.h' &&
  chmod 0644 'a.h' ||
  echo 'restore of a.h failed'
  shar_count="`wc -c < 'a.h'`"
  test 14 -eq "$shar_count" ||
    echo "a.h: original size 14, current size $shar_count"
fi
# ============= b.h ==============
if test -f 'b.h' && test X"$1" != X"-c"; then
  echo 'x - skipping b.h (File already exists)'
else
  echo 'x - extracting b.h (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'b.h' &&
extern int f();
SHAR_EOF
  $shar_touch -am 0928230795 'b.h' &&
  chmod 0644 'b.h' ||
  echo 'restore of b.h failed'
  shar_count="`wc -c < 'b.h'`"
  test 16 -eq "$shar_count" ||
    echo "b.h: original size 16, current size $shar_count"
fi
# ============= Main.cc ==============
if test -f 'Main.cc' && test X"$1" != X"-c"; then
  echo 'x - skipping Main.cc (File already exists)'
else
  echo 'x - extracting Main.cc (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'Main.cc' &&
#include "a.h"
#include "b.h"
#include <dlfcn.h>
#include <iostream.h>
#include <stdlib.h>
X
void Error (char* msg) {
X  cerr << msg << "\t" << dlerror() << endl;
X  exit (1);

Quote:}

X
X
main() {
X  void* X = dlopen ("./a.so", RTLD_LAZY|RTLD_GLOBAL);
X  if (!X)
X    Error (dlerror());
X  void* Y = dlopen ("./b.so", RTLD_LAZY|RTLD_GLOBAL);
X  if (!Y)
X    Error (dlerror());
X  int (*f)() = dlsym (Y, "f");
X  if (!f)
X    Error (dlerror());
X  (*f)();
Quote:}

SHAR_EOF
  $shar_touch -am 1204203995 'Main.cc' &&
  chmod 0644 'Main.cc' ||
  echo 'restore of Main.cc failed'
  shar_count="`wc -c < 'Main.cc'`"
  test 436 -eq "$shar_count" ||
    echo "Main.cc: original size 436, current size $shar_count"
fi
# ============= a.cc ==============
if test -f 'a.cc' && test X"$1" != X"-c"; then
  echo 'x - skipping a.cc (File already exists)'
else
  echo 'x - extracting a.cc (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'a.cc' &&
extern int a = 1;
SHAR_EOF
  $shar_touch -am 0928230695 'a.cc' &&
  chmod 0644 'a.cc' ||
  echo 'restore of a.cc failed'
  shar_count="`wc -c < 'a.cc'`"
  test 18 -eq "$shar_count" ||
    echo "a.cc: original size 18, current size $shar_count"
fi
# ============= b.cc ==============
if test -f 'b.cc' && test X"$1" != X"-c"; then
  echo 'x - skipping b.cc (File already exists)'
else
  echo 'x - extracting b.cc (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'b.cc' &&
#include "a.h"
X
extern int f() { return a; }
SHAR_EOF
  $shar_touch -am 0928230795 'b.cc' &&
  chmod 0644 'b.cc' ||
  echo 'restore of b.cc failed'
  shar_count="`wc -c < 'b.cc'`"
  test 45 -eq "$shar_count" ||
    echo "b.cc: original size 45, current size $shar_count"
fi
# ============= Makefile ==============
if test -f 'Makefile' && test X"$1" != X"-c"; then
  echo 'x - skipping Makefile (File already exists)'
else
  echo 'x - extracting Makefile (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
CC = g++ -g
X
X
%.o : %.cc
X       $(CC) -c $*.cc -fpic
X
%.so : %.o

X
Test : Main.o a.so b.so

SHAR_EOF
  $shar_touch -am 1002223195 'Makefile' &&
  chmod 0644 'Makefile' ||
  echo 'restore of Makefile failed'
  shar_count="`wc -c < 'Makefile'`"
  test 153 -eq "$shar_count" ||
    echo "Makefile: original size 153, current size $shar_count"
fi
exit 0
 
 
 

ld.so-1.7.11 RTLD_GLOBAL working?

Post by David Eng » Thu, 07 Dec 1995 04:00:00



> I'm glad to see ld.so-1.7.11 says that RTLD_GLOBAL is supported!  But
> does it work?  This simple test program seems to show it doesn't.  We
> load a.so, which defines 'a'.  Then we load b.so, and it fails, saying
> 'a' is undefined.

This is due to a known bug in libdl.so.  It is fixed in the version
that will be released later this week.  What is happening is that g++
is silently adding a dependency on libm.so in a.so and dlopen is
marking libm.so as global instead of a.so.

BTW, you have two other serious errors in your test case.  First, you
are calling dlerror twice, once in main and again in Error.  The
second call is invalid and will return NULL.  Second, you are calling
dlsym with the unmagled name for f.  You must use the mangled name,
which is f__Fv.

David
--
David Engel                        Optical Data Systems, Inc.

(214) 234-6400                     Richardson, TX  75081