This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Segfaults and double free errors using getaddrinfo_a


On Fri, Jul 13, 2012 at 2:49 PM, Ryan S. Arnold <ryan.arnold@gmail.com> wrote:
> I'm not sure how to rectify this situation.  Perhaps if luajit does
> some linking of the foreign interface code under the covers and you
> can force it to link in the pthread_mutex_lock symbol in the
> dependency list.  You'll probably have to make sure the symbol isn't
> purged, via -lpthread -Wl,-u,__pthread_mutex_lock.

Alright, try the following patch to your luajit script.. it seems to
work for me (at least the crash isn't happening anymore and the lock
is being taken successfully):

It basically dlopens libpthread and binds NOW so that the symbols are
resolved immediately.  You might be able to avoid the RTLD_NOW and do
a dlsym lookup on __pthread_mutex_lock to get the symbol resolved
without binding all of the symbols in the library.

Ryan S. Arnold

--- luajit.lua  2012-07-13 17:11:12.781939994 -0500
+++ new.lua     2012-07-13 17:12:35.731385111 -0500
@@ -5,6 +5,7 @@
 local ffi = require "ffi"
 local bit = require "bit"
 local anl = ffi.load "anl"
+local dl = ffi.load "dl"

 ffi.cdef[[
        char *strerror(int errnum);
@@ -73,6 +74,8 @@
        typedef long int ssize_t;
        ssize_t read(int fd, void *buf, size_t count);

+       void *dlopen(const char *filename, int flag);
+
        enum
        {
          SI_ASYNCNL = -60,
@@ -106,6 +109,12 @@
 GAI_WAIT        = 0
 GAI_NOWAIT      = 1

+RTLD_NOW = 2
+RTLD_DEEPBIND = 8
+RTLD_NOW_DEEPBIND = 10
+RTLD_GLOBAL =  256
+RTLD_ALL = 266
+
 EAI_BADFLAGS    = -1 -- Invalid value for `ai_flags' field.
 EAI_NONAME      = -2 -- NAME or SERVICE is unknown.
 EAI_AGAIN       = -3 -- Temporary failure in name resolution.
@@ -177,6 +186,8 @@
 sigevent.sigev_signo           = signum
 sigevent.sigev_value.sival_ptr = list

+local r = dl.dlopen ( "libpthread.so.0", RTLD_ALL );
+
 local r = anl.getaddrinfo_a ( GAI_NOWAIT, list , n , sigevent )
 if r ~= 0 then
        error ( ffi.string ( ffi.C.strerror ( r ) ) )


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]