From a8a1269d8814fe54d5d25619ca138849bca29b78 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 1 Sep 1998 17:19:00 +0000 Subject: Update. 1998-09-01 15:36 Ulrich Drepper * malloc/Makefile: Include Makeconfig before testing config-sysdirs. * malloc/mtrace.c: Add bug report address. Update email address. Add more @XXX@ to print correct address size. * elf/dl-addr.c (_dl_addr): Make sure that map to be examined is really initialized. * elf/dl-close.c (_dl_close): Use l_map_start and l_map_end info for munmap call instead of examining phdr again. Free all malloc()ed strings and arrays. --- ChangeLog | 14 ++++++++++++++ elf/dl-addr.c | 4 +++- elf/dl-close.c | 49 ++++++++++++++++++++++++------------------------- malloc/Makefile | 2 ++ malloc/mtrace.pl | 14 ++++++++------ 5 files changed, 51 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 54e220e..85f2c75 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +1998-09-01 15:36 Ulrich Drepper + + * malloc/Makefile: Include Makeconfig before testing config-sysdirs. + + * malloc/mtrace.c: Add bug report address. Update email address. + Add more @XXX@ to print correct address size. + + * elf/dl-addr.c (_dl_addr): Make sure that map to be examined is + really initialized. + + * elf/dl-close.c (_dl_close): Use l_map_start and l_map_end info + for munmap call instead of examining phdr again. + Free all malloc()ed strings and arrays. + 1998-08-09 Geoff Keating * sysdeps/powerpc/Makefile [subdir=elf]: Add new files split out of diff --git a/elf/dl-addr.c b/elf/dl-addr.c index f88f749..2c9a9dd 100644 --- a/elf/dl-addr.c +++ b/elf/dl-addr.c @@ -34,7 +34,9 @@ _dl_addr (const void *address, Dl_info *info) /* Find the highest-addressed object that ADDRESS is not below. */ match = NULL; for (l = _dl_loaded; l; l = l->l_next) - if (addr >= l->l_addr && (!match || match->l_addr < l->l_addr)) + if (l->l_addr != 0 /* Make sure we do not currently set this map up + in this moment. */ + && addr >= l->l_addr && (!match || match->l_addr < l->l_addr)) match = l; if (match) diff --git a/elf/dl-close.c b/elf/dl-close.c index 0851e20..e89e46d 100644 --- a/elf/dl-close.c +++ b/elf/dl-close.c @@ -89,11 +89,6 @@ _dl_close (struct link_map *map) for (i = 0; i < nsearchlist; ++i) --list[i]->l_opencount; - if (map->l_origin != NULL) - free ((char *) map->l_origin); - /* The name always is allocated. */ - free (map->l_name); - /* Check each element of the search list to see if all references to it are gone. */ for (i = 0; i < nsearchlist; ++i) @@ -101,12 +96,10 @@ _dl_close (struct link_map *map) struct link_map *imap = list[i]; if (imap->l_opencount == 0 && imap->l_type == lt_loaded) { + struct libname_list *lnp; + /* That was the last reference, and this was a dlopen-loaded object. We can unmap it. */ - const ElfW(Phdr) *ph; - const ElfW(Phdr) *first, *last; - ElfW(Addr) mapstart, mapend; - if (imap->l_global) { /* This object is in the global scope list. Remove it. */ @@ -122,22 +115,11 @@ _dl_close (struct link_map *map) --_dl_global_scope_end; } - /* We can unmap all the maps at once. We just have to determine - the length and the `munmap' call does the rest. */ - first = last = NULL; - for (ph = imap->l_phdr; ph < imap->l_phdr + imap->l_phnum; ++ph) - if (ph->p_type == PT_LOAD) - { - if (first == NULL) - first = ph; - last = ph; - } - - /* Now we have all the information we need for the unmapping. - See the method used in `_dl_map_object_from_fd'. */ - mapstart = first->p_vaddr & ~(first->p_align - 1); - mapend = last->p_vaddr + last->p_memsz; - __munmap ((caddr_t) (imap->l_addr + mapstart), mapend - mapstart); + /* We can unmap all the maps at once. We determined the + length when we loaded the object and `munmap' call does + the rest. */ + __munmap ((void *) imap->l_map_start, + imap->l_map_end - imap->l_map_start); /* Finally, unlink the data structure and free it. */ #ifdef PIC @@ -155,6 +137,23 @@ _dl_close (struct link_map *map) imap->l_next->l_prev = imap->l_prev; if (imap->l_searchlist && imap->l_searchlist != list) free (imap->l_searchlist); + + if (imap->l_versions != NULL) + free (imap->l_versions); + if (imap->l_origin != NULL) + free ((char *) imap->l_origin); + + /* These names always is allocated. */ + free (imap->l_name); + lnp = imap->l_libname; + do + { + free (lnp->name); + lnp = lnp->next; + } + while (lnp != NULL); + free (imap->l_libname); + free (imap); } } diff --git a/malloc/Makefile b/malloc/Makefile index 89a49a2..521037a 100644 --- a/malloc/Makefile +++ b/malloc/Makefile @@ -44,6 +44,8 @@ extra-objs = mcheck-init.o libmcheck.a # Include the cleanup handler. aux := set-freeres +include ../Makeconfig + # The AWK script to analyze the output of the mtrace functions. ifneq ($(PERL),no) install-bin = mtrace diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl index f889294..e2032d4 100644 --- a/malloc/mtrace.pl +++ b/malloc/mtrace.pl @@ -29,6 +29,8 @@ sub usage { print "Usage: mtrace [OPTION]... [Binary] MtraceData\n"; print " --help print this help, then exit\n"; print " --version print version number, then exit\n"; + print "\n"; + print "Report bugs using the `glibcbug' script to .\n"; exit 0; } @@ -42,10 +44,10 @@ arglist: while (@ARGV) { $ARGV[0] eq "--vers" || $ARGV[0] eq "--versi" || $ARGV[0] eq "--versio" || $ARGV[0] eq "--version") { print "mtrace (GNU $PACKAGE) $VERSION\n"; - print "Copyright (C) 1997 Free Software Foundation, Inc.\n"; + print "Copyright (C) 1997, 1998 Free Software Foundation, Inc.\n"; print "This is free software; see the source for copying conditions. There is NO\n"; print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"; - print "Written by Ulrich Drepper \n"; + print "Written by Ulrich Drepper \n"; exit 0; } elsif ($ARGV[0] eq "--h" || $ARGV[0] eq "--he" || $ARGV[0] eq "--hel" || @@ -125,7 +127,7 @@ while () { SWITCH: { if ($cols[$n] eq "+") { if (defined $allocated{$allocaddr}) { - printf ("+ %#010x Alloc %d duplicate: %s %s\n", + printf ("+ %#0@XXX@x Alloc %d duplicate: %s %s\n", hex($allocaddr), $nr, $wherewas{$allocaddr}, $where); } else { $allocated{$allocaddr}=$howmuch; @@ -138,7 +140,7 @@ while () { undef $allocated{$allocaddr}; undef $wherewas{$allocaddr}; } else { - printf ("- %#010x Free %d was never alloc'd %s\n", + printf ("- %#0@XXX@x Free %d was never alloc'd %s\n", hex($allocaddr), $nr, &location($where)); } last SWITCH; @@ -148,14 +150,14 @@ while () { undef $allocated{$allocaddr}; undef $wherewas{$allocaddr}; } else { - printf ("- %#010x Realloc %d was never alloc'd %s\n", + printf ("- %#0@XXX@x Realloc %d was never alloc'd %s\n", hex($allocaddr), $nr, &location($where)); } last SWITCH; } if ($cols[$n] eq ">") { if (defined $allocated{$allocaddr}) { - printf ("+ %#010x Realloc %d duplicate: %#010x %s %s\n", + printf ("+ %#0@XXX@x Realloc %d duplicate: %#010x %s %s\n", hex($allocaddr), $nr, $allocated{$allocaddr}, $wherewas{$allocaddr}, &location($where)); } else { -- cgit v1.1