Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 Aug 1997 17:41:37 -0600 (MDT)
From:      Nate Williams <nate@mt.sri.com>
To:        Nate Williams <nate@mt.sri.com>
Cc:        "Jordan K. Hubbard" <jkh@freebsd.org>, hackers@freebsd.org
Subject:   Re: [Fwd: Re: Please Help Me Understand dlopen()]
Message-ID:  <199708182341.RAA03607@rocky.mt.sri.com>
In-Reply-To: <199708182250.QAA03442@rocky.mt.sri.com>
References:  <33F869F3.446B9B3D@FreeBSD.org> <199708182158.PAA03256@rocky.mt.sri.com> <199708182250.QAA03442@rocky.mt.sri.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> > > The freeBSD dlsym() is - as far as I know - the only dlsym()
> > > implementation that doesn't search for _funktion() ...

> I didn't even send out the original patch, but in any case here's the
> next version of it..

Which leaks memory, and doesn't allocate room enough for the new
string.  Thanks to sef for pointing it out, here's the new and improved
patch, which allocates enough memory and frees it as well. :)


Nate
-------
Index: rtld.c
===================================================================
RCS file: /home/CVS/src/gnu/usr.bin/ld/rtld/rtld.c,v
retrieving revision 1.40.2.3
diff -c -r1.40.2.3 rtld.c
*** rtld.c	1997/08/08 02:18:14	1.40.2.3
--- rtld.c	1997/08/18 23:39:28
***************
*** 1916,1922 ****
  }
  
  	static void *
! __dlsym3(fd, sym, retaddr)
  	void	*fd;
  	char	*sym;
  	void	*retaddr;
--- 1916,1922 ----
  }
  
  	static void *
! __resolvesym_(fd, sym, retaddr)
  	void	*fd;
  	char	*sym;
  	void	*retaddr;
***************
*** 1973,1978 ****
--- 1973,2003 ----
  		addr += (long)src_map->som_addr;
  
  	return (void *)addr;
+ }
+ 
+ 	static void *
+ __dlsym3(fd, sym, retaddr)
+ 	void	*fd;
+ 	char	*sym;
+ 	void	*retaddr;
+ {
+ 	void *result;
+ 
+ 	result = __resolvesym_(fd, sym, retaddr);
+ 	/*
+ 	 * XXX - Ugly, but it makes the least impact on the run-time loader
+ 	 * sources.
+ 	 */
+ 	if (result == NULL && !strcmp(dlerror_msg, "Undefined symbol")) {
+ 		/* Prepend an underscore and try again */
+ 		char *newsym = malloc(strlen(sym) + 2);
+ 
+ 		newsym[0] = '_';
+ 		strcpy(&newsym[1], sym);
+ 		result = __resolvesym_(fd, newsym, retaddr);
+ 		free(newsym);
+ 	}
+ 	return result;
  }
  
  	static char *



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199708182341.RAA03607>