Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sources.redhat.com
Subject: [RFA/hpux] SEGV when running program using dlopen
Date: Wed, 15 Dec 2004 09:20:00 -0000	[thread overview]
Message-ID: <20041215073206.GM964@adacore.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2560 bytes --]

This is on HP/UX 11.00.

Compile the following little program:

    #include <stdio.h>
    #include <dl.h>
    
    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  <brobecker@gnat.com>

        * 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

[-- Attachment #2: solib-som.c.diff --]
[-- Type: text/plain, Size: 2085 bytes --]

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);

             reply	other threads:[~2004-12-15  7:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-15  9:20 Joel Brobecker [this message]
2004-12-15 17:14 ` Randolph Chung
2004-12-15 17:23   ` Joel Brobecker
2004-12-15 17:27     ` Randolph Chung
2004-12-15 18:29       ` Joel Brobecker
2004-12-17  7:15       ` Joel Brobecker
2004-12-17  7:44         ` Randolph Chung
2004-12-17 19:22           ` Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041215073206.GM964@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox