I refferd to the core of static linked in GDB.  However, the backtrace
command did not display the symbols correctly.

$ cat main.c
#include <stdio.h>

void
sub2(int argc, char *argv[])
{
        int i;
        for (int i = 0; i <= argc; i++)
                argv[i][0] = '\0';
}

void
sub1(int argc, char *argv[])
{
        sub2(argc, argv);
}

int
main(int argc, char *argv[])
{
        sub1(argc, argv);
        return (0);
}
$ cc -g -static main.c
$ ./a.out
Segmentation fault (core dumped)
$ /usr/bin/gdb a.out a.out.core
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-unknown-openbsd6.8"...
Core was generated by `a.out'.
Program terminated with signal 11, Segmentation fault.
#0  0x0000060eed558f45 in ?? ()
(gdb) bt
#0  0x0000060eed558f45 in ?? ()
#1  0x00007f7ffffe3480 in ?? ()
#2  0x0000060eed558f98 in ?? ()
#3  0x0000000000000000 in ?? ()
(gdb) quit
$ 

The patch is below.
ok?

diff --git a/gnu/usr.bin/binutils/gdb/solib-svr4.c 
b/gnu/usr.bin/binutils/gdb/solib-svr4.c
index eebeddd..7428bda 100644
--- a/gnu/usr.bin/binutils/gdb/solib-svr4.c
+++ b/gnu/usr.bin/binutils/gdb/solib-svr4.c
@@ -619,7 +619,40 @@ svr4_current_sos (void)
       /* If we can't find the dynamic linker's base structure, this
         must not be a dynamically linked executable.  Hmm.  */
       if (! debug_base)
-       return 0;
+       {
+         if (exec_bfd != NULL &&
+             bfd_get_section_by_name (exec_bfd, ".interp") == NULL &&
+             (bfd_get_file_flags (exec_bfd) & DYNAMIC) != 0 &&
+             bfd_get_start_address (exec_bfd) != entry_point_address ())
+           {
+             /* this is relocatable static link.
+                cf. svr4_relocate_main_executable() */
+             struct cleanup *old_chain;
+             struct section_offsets *new_offsets;
+             int i, changed;
+             CORE_ADDR displacement;
+
+             displacement = entry_point_address () - bfd_get_start_address 
(exec_bfd);
+             changed = 0;
+
+             new_offsets = xcalloc (symfile_objfile->num_sections,
+                                    sizeof (struct section_offsets));
+             old_chain = make_cleanup (xfree, new_offsets);
+
+             for (i = 0; i < symfile_objfile->num_sections; i++)
+               {
+                 if (displacement != ANOFFSET 
(symfile_objfile->section_offsets, i))
+                   changed = 1;
+                 new_offsets->offsets[i] = displacement;
+               }
+
+             if (changed)
+               objfile_relocate (symfile_objfile, new_offsets);
+
+             do_cleanups (old_chain);
+           }
+         return 0;
+       }
     }
 
   /* Walk the inferior's link map list, and build our list of
--
ASOU Masato

Reply via email to