From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9781 invoked by alias); 15 Dec 2004 07:32:41 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 9553 invoked from network); 15 Dec 2004 07:32:12 -0000 Received: from unknown (HELO smtp4.wanadoo.fr) (193.252.22.27) by sourceware.org with SMTP; 15 Dec 2004 07:32:12 -0000 Received: from me-wanadoo.net (unknown [127.0.0.1]) by mwinf0403.wanadoo.fr (SMTP Server) with SMTP id ACACC1C0033E for ; Wed, 15 Dec 2004 08:32:10 +0100 (CET) Received: from takamaka.act-europe.fr (AStDenis-101-1-4-120.w80-13.abo.wanadoo.fr [80.13.18.120]) by mwinf0403.wanadoo.fr (SMTP Server) with ESMTP id B2F581C00325 for ; Wed, 15 Dec 2004 08:32:09 +0100 (CET) Received: by takamaka.act-europe.fr (Postfix, from userid 507) id C554847DAD; Wed, 15 Dec 2004 11:32:06 +0400 (RET) Date: Wed, 15 Dec 2004 09:20:00 -0000 From: Joel Brobecker To: gdb-patches@sources.redhat.com Subject: [RFA/hpux] SEGV when running program using dlopen Message-ID: <20041215073206.GM964@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="fUYQa+Pmc3FrFX/N" Content-Disposition: inline User-Agent: Mutt/1.4i X-SW-Source: 2004-12/txt/msg00380.txt.bz2 --fUYQa+Pmc3FrFX/N Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 2560 This is on HP/UX 11.00. Compile the following little program: #include #include int main (void) { void * o = shl_load ("/usr/lib/libnss_files.1", BIND_IMMEDIATE, 0L); printf ("Got o = %p\n", o); shl_unload (o); return 0; } With this command: % gcc -g -o dl dl.c /opt/langtools/lib/end.o Now try to run the program under the debugger: % gdb dl (gdb) run Starting program: /[...]/dl Program received signal SIGSEGV, Segmentation fault. 0xc08ee090 in ?? () The expected behavior is: (gdb) run Starting program: /[...]/dl Got o = 7b03d180 Program exited normally. The problem is in solib-som.c:som_solib_create_inferior_hook(): We're looking up the address of __d_trap, and end up finding the address of the function. But we need the stub, not the function. So we have the following code that tries to do that: /* Grrr, this might not be an export symbol! We have to find the export stub. */ ALL_OBJFILES (objfile) { struct unwind_table_entry *u; struct minimal_symbol *msymbol2; /* What a crock. */ msymbol2 = lookup_minimal_symbol_solib_trampoline (SYMBOL_LINKAGE_NAME (msymbol), objfile); /* Found a symbol with the right name. */ if (msymbol2) { struct unwind_table_entry *u; /* It must be a shared library trampoline. */ if (SYMBOL_TYPE (msymbol2) != mst_solib_trampoline) continue; /* It must also be an export stub. */ u = find_unwind_entry (SYMBOL_VALUE (msymbol2)); if (!u || u->stub_unwind.stub_type != EXPORT) continue; /* OK. Looks like the correct import stub. */ anaddr = SYMBOL_VALUE (msymbol2); dld_cache.hook_stub.address = anaddr; } } Unfortunately for us, that doesnt' work for __d_trap, as that symbol lives in crt0. So lookup_minimal_symbol_solib_trampoline never returns any match, and we end up stuck with the non-stub address. I replaced the above block by a simply ALL_MSYMBOLS loop that simply matches the msymbol name before checking for the associated stub type. That fixes the problem. 2004-12-15 Joel Brobecker * solib-som.c (som_solib_create_inferior_hook): Extend stub msymbol search to all objfiles, not just shared libraries. Tested on HP/UX 11.00, no regression. OK to commit? Thanks, -- Joel --fUYQa+Pmc3FrFX/N Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="solib-som.c.diff" Content-length: 2085 Index: solib-som.c =================================================================== RCS file: /cvs/src/src/gdb/solib-som.c,v retrieving revision 1.1 diff -u -p -r1.1 solib-som.c --- solib-som.c 8 Dec 2004 01:36:42 -0000 1.1 +++ solib-som.c 15 Dec 2004 07:30:02 -0000 @@ -157,7 +157,7 @@ som_relocate_section_addresses (struct s static void som_solib_create_inferior_hook (void) { - struct minimal_symbol *msymbol; + struct minimal_symbol *msymbol, *msymbol2; unsigned int dld_flags, status, have_endo; asection *shlib_info; char buf[4]; @@ -226,33 +226,22 @@ som_solib_create_inferior_hook (void) /* Grrr, this might not be an export symbol! We have to find the export stub. */ - ALL_OBJFILES (objfile) - { - struct unwind_table_entry *u; - struct minimal_symbol *msymbol2; - - /* What a crock. */ - msymbol2 = - lookup_minimal_symbol_solib_trampoline (SYMBOL_LINKAGE_NAME (msymbol), - objfile); - /* Found a symbol with the right name. */ - if (msymbol2) - { - struct unwind_table_entry *u; - /* It must be a shared library trampoline. */ - if (SYMBOL_TYPE (msymbol2) != mst_solib_trampoline) - continue; - - /* It must also be an export stub. */ - u = find_unwind_entry (SYMBOL_VALUE (msymbol2)); - if (!u || u->stub_unwind.stub_type != EXPORT) - continue; - - /* OK. Looks like the correct import stub. */ - anaddr = SYMBOL_VALUE (msymbol2); - dld_cache.hook_stub.address = anaddr; - } - } + ALL_MSYMBOLS (objfile, msymbol2) + { + if (strcmp (SYMBOL_LINKAGE_NAME (msymbol2), + SYMBOL_LINKAGE_NAME (msymbol)) == 0) + { + struct unwind_table_entry *u; + + u = find_unwind_entry (SYMBOL_VALUE (msymbol2)); + if (u != NULL && u->stub_unwind.stub_type == EXPORT) + { + anaddr = SYMBOL_VALUE (msymbol2); + dld_cache.hook_stub.address = anaddr; + break; + } + } + } store_unsigned_integer (buf, 4, anaddr); msymbol = lookup_minimal_symbol ("__dld_hook", NULL, symfile_objfile); --fUYQa+Pmc3FrFX/N--