From 29218d94d3881b0a950d89ee8c1bc7e88cf39e6b Mon Sep 17 00:00:00 2001 From: John Polstra Date: Wed, 16 Sep 1998 02:54:08 +0000 Subject: [PATCH] Fix a bug that showed up when debugging dynamically linked programs. References from GDB to "printf" and various other functions would find the versions in the dynamic linker itself, rather than the versions in the program's libc. This fix moves the GDB link map entry for the dynamic linker to the end of the search list, where its symbols will be found only if they are not found anywhere else. It was suggested by Doug Rabson, though I implemented it a little differently. I personally would prefer to leave the dynamic linker's entry out of the GDB search list altogether. But Doug argues that it is handy there for such things as setting breakpoints on dlopen(). So it stays for now, at least. Note, if we ever integrate the dynamic linker with libc (which has several important benefits to recommend it), this whole problem goes away. --- libexec/rtld-elf/rtld.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 4b1eb2ff1d42..86ed413566fb 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -22,7 +22,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: rtld.c,v 1.8 1998/09/05 03:31:00 jdp Exp $ + * $Id: rtld.c,v 1.9 1998/09/15 21:07:52 jdp Exp $ */ /* @@ -1240,11 +1240,21 @@ linkmap_add(Obj_Entry *obj) return; } - for (prev = r_debug.r_map; prev->l_next != NULL; prev = prev->l_next) + /* + * Scan to the end of the list, but not past the entry for the + * dynamic linker, which we want to keep at the very end. + */ + for (prev = r_debug.r_map; + prev->l_next != NULL && prev->l_next != &obj_rtld.linkmap; + prev = prev->l_next) ; + + /* Link in the new entry. */ l->l_prev = prev; + l->l_next = prev->l_next; + if (l->l_next != NULL) + l->l_next->l_prev = l; prev->l_next = l; - l->l_next = NULL; } static void