On 02/26/2012 09:41 AM, Jim Meyering wrote:
>> Maybe, but why is LD_PRELOAD honoring the "__attribute__((destructor))",
>> and on some systems not?
>
> Good question.
> There must be some OpenSuSE 12.1 users willing to investigate.
> Filing a bug report should get their attention.

I got an answer on the opensuse mailing list:
(http://lists.opensuse.org/opensuse/2012-02/msg01342.html)

It's a problem when linking with LD directly:

  Cristian Rodríguez wrote:
  > Bernhard Voelker wrote:
  > > This works here, too:
  > >
  > >    gcc -shared -fPIC -O2 k.c -o k.so
  > >
  > > Can you confirm the failure when compiling + linking
  > > is done in 2 separate steps?
  >
  > Well, I expected that to fail so didnt bothered.. You know..
  > distributions have a crapload of broken makefiles that link with LD
  > directly. it fails in subtle ways when you do so, when using GCC, it
  > passes the right options to the linker so we avoid nasty surprises...

I've created the attached patch to make the test pass.

Have a nice day,
Berny
>From fe17ee2b3b322689dde043de08dab4d6b44c58e0 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <[email protected]>
Date: Mon, 27 Feb 2012 21:13:10 +0100
Subject: [PATCH] tests: compile and link shared object with GCC to make
 LD_PRELOAD work
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* tests/ls/getxattr-speedup: Compile and link in one step with $CC.
If the shared object file is created by ld (binutils), then the
destructor print_call_count() may not run (seen on OpenSuSE 12.1).
See http://lists.opensuse.org/opensuse/2012-02/msg01342.html
Thanks to Cristian Rodríguez.
---
 tests/ls/getxattr-speedup |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/ls/getxattr-speedup b/tests/ls/getxattr-speedup
index d32e24a..812a03b 100755
--- a/tests/ls/getxattr-speedup
+++ b/tests/ls/getxattr-speedup
@@ -47,8 +47,8 @@ ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size)
 EOF
 
 # Then compile/link it:
-$CC -fPIC -O2 -c k.c || framework_failure_ 'failed to compile with -fPIC'
-ld -G k.o -o k.so || framework_failure_ 'failed to invoke ld -G ...'
+$CC -shared -fPIC -O2 k.c -o k.so ||
+  framework_failure_ 'failed to compile with -shared -fPIC'
 
 # Create a few files:
 seq 20 | xargs touch || framework_failure_
-- 
1.7.7

Reply via email to