Mailinglist Archive: opensuse (1483 mails)

< Previous Next >
[opensuse] destructor in LD_PRELOADed *.so file not run on SuSE
In the GNU coreutils project, there was a discussion about a new
test which uses a destructor in an *.so file loaded into program
space via LD_PRELOAD:

http://lists.gnu.org/archive/html/coreutils/2012-02/msg00173.html

However, the destructor is not run on OpenSuSE (nor on SLES10.x btw.),
but works fine on other systems (e.g. Redhat).

This is Jim's commit:
http://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=b29db6767612cf70e9d4c7eb6ede9822f6173fca

Attached is the relevant C code which intercepts the system calls
getxattr() and lgetxattr(). The number of calls is counted and
should be stored in a file "x" by the destructor print_call_count():

void __attribute__ ((destructor))
print_call_count (void);


Compile / link it:

$ gcc -fPIC -O2 -c k.c
$ ld -G k.o -o k.so

Run it:

$ LD_PRELOAD=./k.so ls --color=always -l .

Now, the file "x" should be created, but it isn't.

(How) are LD_PRELOADed destructors disabled on SuSE?

Ah, yes - I'm running this:

$ head -n 1 /etc/SuSE-release
openSUSE 12.1 (x86_64)
$ gcc --version | head -n 1
gcc (SUSE Linux) 4.6.2
$ uname -rvmspio
Linux 3.1.9-1.4-desktop #1 SMP PREEMPT Fri Jan 27 08:55:10 UTC 2012 (efb5ff4)
x86_64 x86_64 x86_64 GNU/Linux

Have a nice day,
Berny
#include <errno.h>
#include <stdio.h>

static unsigned long int n_calls;

static void __attribute__ ((destructor))
print_call_count (void);

static void __attribute__ ((destructor))
print_call_count (void)
{
FILE *fp = fopen ("x", "w");
if (fp)
fprintf (fp, "%lu\n", n_calls); fclose (fp);
}

static ssize_t incr () {
++n_calls;
errno = ENOTSUP; return -1; }
ssize_t getxattr (const char *path, const char *name, void *value, size_t size)
{ return incr (); }
ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size)
{ return incr (); }
< Previous Next >
Follow Ups