I all,
When the dynamic linker load and resolve the library dependencies for an 
executable,
It should use the executable's rpath as searching path for all his needed 
libraries.
Follow a minimal test spotting this issue:

--------------------------------
root@arcidiaf:/home/filippo/rpath-test# cat main_app.c
extern int funca(const char *);

int
main ()
{

   funca("main_app");

   return 0;
}
root@arcidiaf:/home/filippo/rpath-test# cat liba.c
#include <stdio.h>

extern int funcb(const char *);

int
funca (const char *st)
{

   printf ("funca called! From %s.\n", st);
   funcb("funca");

   return 0;
}
root@arcidiaf:/home/filippo/rpath-test# cat libb.c
#include <stdio.h>

int
funcb (const char *st)
{

   printf ("funcb called! From %s.\n", st);

   return 0;
}

gcc -Wall -shared -z def -o libb.so -fPIC -D_GNU_SOURCE libb.c
gcc -Wall -shared -z def -o liba.so -fPIC -D_GNU_SOURCE liba.c -L. -lb
gcc -Wall -o main_app -D_GNU_SOURCE -Wl,-rpath,/home/filippo/rpath-test 
main_app.c -L. -la

root@arcidiaf:/home/filippo/rpath-test# ./main_app 
./main_app: can't load library 'libb.so'
------------------------------------

The problem is, when the DL try to find the libb.so (as dependence of liba.so) 
it searches in
The RPATH of the libray itself (liba.so) that is not set, then in the 
LD_LIBRARY_PATH
At the end in the systems lib path, without success.
To note the glibc use the executable rpath in his library search path, other 
reference
Where this is hilight is http://wiki.debian.org/RpathIssue.
The following patch fixes this problem adding the executable's rpath in library 
search path.

Regards,
Filippo Arcidiacono

>From 24f2c2bbc2d8f3b0fbdc27dfc7018141f36e46ab Mon Sep 17 00:00:00 2001
From: Filippo Arcidiacono <[email protected]>
Date: Wed, 21 Sep 2011 15:00:54 +0200
Subject: [PATCH] ldso: Use the executable's RPATH as library searching path

Signed-off-by: Filippo Arcidiacono <[email protected]>
---
 ldso/ldso/dl-elf.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c
index c28e175..f998aea 100644
--- a/ldso/ldso/dl-elf.c
+++ b/ldso/ldso/dl-elf.c
@@ -234,6 +234,17 @@ struct elf_resolve *_dl_load_shared_library(int secure, 
struct dyn_elf **rpnt,
                if ((tpnt1 = search_for_named_library(libname, secure, pnt, 
rpnt)) != NULL)
                        return tpnt1;
        }
+
+       /*
+        * Try the DT_RPATH of the executable itself.
+        */
+       pnt = (char *) _dl_loaded_modules->dynamic_info[DT_RPATH];
+       if (pnt) {
+               pnt += (unsigned long) 
_dl_loaded_modules->dynamic_info[DT_STRTAB];
+               _dl_if_debug_dprint("\tsearching exe's RPATH='%s'\n", pnt);
+               if ((tpnt1 = search_for_named_library(libname, secure, pnt, 
rpnt)) != NULL)
+                       return tpnt1;
+       }
 #endif
 
        /* Check in LD_{ELF_}LIBRARY_PATH, if specified and allowed */
-- 
1.5.5.6


_______________________________________________
uClibc mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/uclibc

Reply via email to