ld.so slight difference Linux and FreeBSD ports/127946

Maho NAKATA chat95 at mac.com
Sun Jun 14 20:47:37 UTC 2009


Hi Konstantin,

Your patch rocks! tested on FBSD7/i386 and it works!

* Small test program works.
* also PR 127946 and Issue 22253 went away.
 
Is your patch can be commit to FBSD8 or MFC'ed to 7?
Best,

From: Kostik Belousov <kostikbel at gmail.com>
Subject: Re: ld.so slight difference Linux and FreeBSD ports/127946
Date: Sun, 14 Jun 2009 12:41:41 +0300

> On Sun, Jun 14, 2009 at 08:14:57AM +0900, Maho NAKATA wrote:
>> Hello Konstantin, and *
>> 
>> We have a longstanding OpenOffice.org porting issue for FreeBSD.
>> Strange crashes.
>> So I'd like to ask you about following issue. 
>> http://www.openoffice.org/issues/show_bug.cgi?id=22253
>> .
>> There are some small difference between ld.so implementation
>> between FreeBSD and Linux. Here is the test program that identify
>> the difference clearly. (it also applies to NetBSD)
>> 
>> ------------------------------------------------
>> "dlsym() search _on_the_main_program_" i.e. the handle is not the
>> dlopen()ed shared library itself, but the main program (which you get
>> back with dlopen(NULL, RTLD_LAZY) )
>> I've modified your test program a bit:
>> 
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <dlfcn.h>
>> 
>> int main(int argc, char **argv) {
>>   void *handle, *handlemain;
>>   double (*cosine)(double);
>>   char *error;
>> 
>>   handle = dlopen ("libm.so", RTLD_LAZY|RTLD_GLOBAL);
>>   if (!handle) {
>>     fprintf (stderr, "%s\n", dlerror());
>>     exit(1);
>>   }
>> 
>>   handlemain = dlopen(NULL, RTLD_LAZY);
>>   cosine = dlsym(handlemain, "cos");
>>   if ((error = dlerror()) != NULL)  {
>>     fprintf (stderr, "%s\n", error);
>>     exit(1);
>>   }
>> 
>>   printf ("%f\n", (*cosine)(2.0));
>>   dlclose(handle);
>>   return 0;
>> }
>> 
>> On Linux:
>> bash-2.05b$ ./a.out 
>> -0.416147
>> 
>> while on NetBSD:
>> -bash-2.05b$ ./a.out 
>> Undefined symbol "cos"
>> ------------------------------------------------
>> 
>> It seems that this is the root cause of some issues.
>> http://www.openoffice.org/issues/show_bug.cgi?id=22253
>> http://www.openoffice.org/issues/show_bug.cgi?id=98781
>> maybe also
>> http://www.freebsd.org/cgi/query-pr.cgi?pr=128176
>> 
>> It seems ld.so employs same mechanism between Linux and MacOSX.
>> 
>> Could you please help me a bit?
> 
> According to the Solaris dlopen(3) and dlsym(3) documentation,
> objects opened with RTLD_GLOBAL shall participate in any dlsym()
> search. Please, try the following patch.
> 
> diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
> index 40ed6ed..2badcfc 100644
> --- a/libexec/rtld-elf/rtld.c
> +++ b/libexec/rtld-elf/rtld.c
> @@ -2141,6 +2141,11 @@ do_dlsym(void *handle, const char *name, void *retaddr, const Ver_Entry *ve,
>  				 &donelist);
>  	}
>      }
> +    if (def == NULL) {
> +	donelist_init(&donelist);
> +	def = symlook_list(name, hash, &list_global, &defobj, ve, flags,
> +			   &donelist);
> +    }
>  
>      if (def != NULL) {
>  	rlock_release(rtld_bind_lock, lockstate);


More information about the freebsd-openoffice mailing list