bin/140143: [patch] dlopen(3) doesn't promote RTLD_GLOBAL for
linked libraries
David Naylor
naylor.b.david at gmail.com
Mon May 31 14:20:08 UTC 2010
The following reply was made to PR bin/140143; it has been noted by GNATS.
From: David Naylor <naylor.b.david at gmail.com>
To: bug-followup at freebsd.org
Cc:
Subject: Re: bin/140143: [patch] dlopen(3) doesn't promote RTLD_GLOBAL for linked libraries
Date: Mon, 31 May 2010 16:14:30 +0200
--Boundary-00=_IR8AMGi1UODzM2B
Content-Type: Text/Plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Attached is an undated test case. Extract and run make. This works without
failure under Linux but fails under FreeBSD.
--Boundary-00=_IR8AMGi1UODzM2B
Content-Type: application/x-shar;
name="rtld_global.shar"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="rtld_global.shar"
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# rtld_global
# rtld_global/Makefile
# rtld_global/libmaster.c
# rtld_global/main.c
# rtld_global/libslave.c
# rtld_global/common.h
# rtld_global/libplugin.c
#
echo c - rtld_global
mkdir -p rtld_global > /dev/null 2>&1
echo x - rtld_global/Makefile
sed 's/^X//' >rtld_global/Makefile << '54185eeffb995a36288ad17f38c2bdc0'
X.ORDER: test clean
X.SUFFIXES: .a .c .o .so .so.1
X.SILENT:
X
XCFLAGS=-Wall -rdynamic
X
X.if defined(TRIGGER)
XCFLAGS+=-DTRIGGER
X.endif
X
XCC=cc
XAR=ar
XLN=ln
X
Xall: clean
X echo "Running test without linking: "
X ${MAKE} test clean #> /dev/null
X echo "done"
X echo
X echo "Running test with linking: "
X ${MAKE} test clean -DLINKED #> /dev/null
X echo "done"
X echo
X echo "Running test with linking (trigger): "
X ${MAKE} test clean -DLINKED -DTRIGGER
X echo "done"
X
Xclean:
X rm -f *.a *.o *.so* main
X
Xtest: main libmaster.so libslave.so
X env LD_LIBRARY_PATH=${PWD} ./main
X
X.c.o:
X ${CC} ${CFLAGS} -c -fPIC -o $@ $<
X
X.c.so:
X ${CC} ${CFLAGS} -fPIC -shared -Wl,-soname,$@ -o $@ $<
X
X.if defined(LINKED)
Xlibplugin.so: libplugin.c libmaster.so
X ${CC} ${CFLAGS} -DLINKED -fPIC -L. -lmaster -shared -Wl,-soname,$@ -o $@ $<
X.endif
X
Xmain: main.o libplugin.so
X cc ${CFLAGS} -o main main.o
54185eeffb995a36288ad17f38c2bdc0
echo x - rtld_global/libmaster.c
sed 's/^X//' >rtld_global/libmaster.c << '4c7e49ccff36dd33ab5357b611fe5d83'
X#include "common.h"
X
Xint master_func() {
X void* libslave;
X func_t func;
X
X printf("libmaster: opening libslave:");
X libslave = dlopen("libslave.so", RTLD_NOW);
X STATUS_CHECK(libslave);
X
X printf("libmaster: getting symbol 'libslave::slave_func':");
X func = (func_t)dlsym(libslave, "slave_func");
X STATUS_CHECK(func);
X
X printf("libmaster: calling 'libslave::slave_func'...\n");
X return func();
X}
X
Xconst char* master_name() {
X return "libmaster.1";
X}
4c7e49ccff36dd33ab5357b611fe5d83
echo x - rtld_global/main.c
sed 's/^X//' >rtld_global/main.c << 'cb6b43e30862d408f1380a58a3050ed8'
X#include "common.h"
X
Xint main(int argc, char** argv) {
X void* libplugin;
X func_t func;
X
X printf("main: opening libplugin:");
X libplugin = dlopen("libplugin.so", RTLD_LAZY /*| RTLD_GLOBAL*/);
X STATUS_CHECK(libplugin);
X
X printf("main: getting symbol 'libplugin::plugin_func':");
X func = (func_t)dlsym(libplugin, "plugin_func");
X STATUS_CHECK(func);
X
X printf("main: calling 'libplugin::plugin_func'...\n");
X return func();
X}
cb6b43e30862d408f1380a58a3050ed8
echo x - rtld_global/libslave.c
sed 's/^X//' >rtld_global/libslave.c << '6027f0c5e11bc3f1d64c5398f3095d35'
X#include <stdio.h>
X
X/* Forward declaration from libmaster */
Xconst char* master_name();
X
Xint slave_func() {
X printf("libslave: %s\n", master_name());
X return 0;
X}
6027f0c5e11bc3f1d64c5398f3095d35
echo x - rtld_global/common.h
sed 's/^X//' >rtld_global/common.h << '96ded3809880f52ca04e85b8175d157f'
X#include <dlfcn.h>
X#include <stdio.h>
X
X#define STATUS_CHECK(var) \
X if ((var) == NULL) { \
X printf(" failure (%s)\n", dlerror()); \
X return 1; \
X } else \
X printf(" success\n")
X
Xtypedef int (*func_t)();
96ded3809880f52ca04e85b8175d157f
echo x - rtld_global/libplugin.c
sed 's/^X//' >rtld_global/libplugin.c << 'a806cc4670bd702634b1d6e2d06150e5'
X#include "common.h"
X
X#ifdef LINKED
Xint master_func();
X#endif
X
Xint plugin_func() {
X func_t func;
X
X#if !defined(LINKED)
X void* libmaster;
X
X printf("libplugin: opening libmaster:");
X libmaster = dlopen("libmaster.so", RTLD_LAZY | RTLD_GLOBAL);
X STATUS_CHECK(libmaster);
X#elif !defined(TRIGGER)
X void* libplugin;
X
X printf("libplugin: exposing symbols globally:");
X libplugin = dlopen("libplugin.so", RTLD_NOLOAD | RTLD_GLOBAL);
X STATUS_CHECK(libplugin);
X#else
X void* libmaster;
X
X printf("libplugin: exposing libmaster symbols globally:");
X libmaster = dlopen("libmaster.so", RTLD_NOLOAD | RTLD_GLOBAL);
X STATUS_CHECK(libmaster);
X#endif
X
X#if !defined(LINKED)
X printf("libplugin: getting symbol 'libmaster::master_func':");
X func = (func_t)dlsym(libmaster, "master_func");
X STATUS_CHECK(func);
X#else
X func = &master_func;
X#endif
X
X printf("libplugin: calling 'libmaster::master_func'...\n");
X return func();
X}
a806cc4670bd702634b1d6e2d06150e5
exit
--Boundary-00=_IR8AMGi1UODzM2B--
More information about the freebsd-bugs
mailing list