public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Relocating Static Local Variables BUG?
@ 2004-04-23 16:10 Richard Schmitt
  2004-04-23 16:37 ` Daniel Jacobowitz
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Schmitt @ 2004-04-23 16:10 UTC (permalink / raw)
  To: gdb; +Cc: rishi75

I've spent a bit of time trying to debug an issue we're having and, to be
honest, I'm completely lost in the symbol table creation of GDB.  Before I
throw my hands up, say some nasty little things that'd make even the most
cynical engineer blush, and vow to never look at the symbol handling in
GDB again without some form of chemical assistance, I thought I'd post to
this group and see if anyone can explain what's happening.

The problem is easy to reproduce and demonstrate.  It has to do with
relocating of static local variables.  Meaning, the symbols never get
relocated.  Our target is a remote ARM processor, but I can reproduce the
problem in linux or cygwin on a local program as well which has led me to
conclude that the problem isn't related to remote debugging, nor is is
platform specific.

To illustrate the problem, here's a simple program:

static int test1 ;

int main (void)
{
  static int test2 ;
  int test3 ;

  test3 = 1 ;
  test2 = test3 ;
  test1 = test2 ;
}

If we compile this program, generate an elf, and load the symbols into gdb
as follows:

$ gdb
gdb> # Add the symbol table for the test.  We won't load the code although
gdb> # we could, except since all we want to show is issues with symbol
gdb> # relocation
gdb> add-symbol-file test.elf 0x10000 -s .bss 0x20000
gdb> # Now let's look at the static global
gdb> print &test1
$1 = (int *) 20008
gdb> # Now let's look at a static local
gdb> print &main::test2
$2 = (int *) 0x804955c

If you do an object dump of the elf file, both test2.0 is located at
offset 0x04 in the .bss section and test1 is located at offset 0x08 in
.bss.   I presume the '.0' is appended because it is defined local to
block 0.

Through some debugging, I've shown that when looking up the symbols in the
routine 'lookup_symbol_aux_symtabs' in symtab.c, after the call to
fixup_symbol_section, the sym->section for test1 is set to 21, yet the
sym->section for test2 is set to 0.  It is for this reason that the symbol
test2 does not get relocated.

So, why is the section for test2 0?  Well, fixup_symbol_section looks up
the symbol in the minimal_symbol_table.  The problem is that since test2
is local to a block, it is actually in the minimal symbol table as
test2.0.  Looking it up as test2 never finds it.  It's too bad 'cause it
is in the minimal symbol table with the right section.

So the next step for the lookup code is to try to find it within blocks
using the routine lookup_block_symbol.  This searches through
'dictionaries' created by reading in the debug (dwarf) info from the elf
file.  The symbol is in there but the dwarf info does not have any section
info so the section number is returned as zero.

So the question is: Should the dwarf info have section info or should
there be some other algorithm used so we find the symbol in the minimal
symbol table.  When the dictionaries are created, should there be some
attempt to pair up the dwarf symbol with a minimal symbol.  I hope there
is someone who can help point me in the right direction?

Thanks,
Rich

-- 
Richard Schmitt
CTO
Blue Peach Solutions
Phone: 877.BLU.PEACH (877.258-7322) x 704
Fax: 508.302.6183
http://www.bluepeach.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Relocating Static Local Variables BUG?
  2004-04-23 16:10 Relocating Static Local Variables BUG? Richard Schmitt
@ 2004-04-23 16:37 ` Daniel Jacobowitz
  2004-04-23 16:41   ` Richard Schmitt
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Jacobowitz @ 2004-04-23 16:37 UTC (permalink / raw)
  To: Richard Schmitt; +Cc: gdb, rishi75

On Fri, Apr 23, 2004 at 12:03:28PM -0400, Richard Schmitt wrote:
> I've spent a bit of time trying to debug an issue we're having and, to be
> honest, I'm completely lost in the symbol table creation of GDB.  Before I
> throw my hands up, say some nasty little things that'd make even the most
> cynical engineer blush, and vow to never look at the symbol handling in
> GDB again without some form of chemical assistance, I thought I'd post to
> this group and see if anyone can explain what's happening.

Could you please add:
 - what GCC and GDB versions you were using when you saw this problem?
 - how did you create the ELF object?
 - What to readelf -r and readelf -s have to say about the ELF object?

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Relocating Static Local Variables BUG?
  2004-04-23 16:37 ` Daniel Jacobowitz
@ 2004-04-23 16:41   ` Richard Schmitt
  2004-04-23 16:51     ` Daniel Jacobowitz
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Schmitt @ 2004-04-23 16:41 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: Richard Schmitt, gdb, rishi75


The version of GCC is 3.3.1
The version of GDB is 6.1 (downloaded latest release)

The commands to generate the elf are:

gcc -o test.exe -g test.c
objcopy -O elf32-little test.exe test.elf

Built this way, the code is not relocatable, so there is no output of the
-r command to readelf.  I've done it this way just to demonstrate the
issue that gdb has with relocating symbols, which is independent of code
generated as relocatable.  The -s output is shown below.


Symbol table '.dynsym' contains 4 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 08048234   251 FUNC    GLOBAL DEFAULT  UND
__libc_start_main@GLIBC_2.0 (2)
     2: 08048454     4 OBJECT  GLOBAL DEFAULT   14 _IO_stdin_used
     3: 00000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__

Symbol table '.symtab' contains 111 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 080480f4     0 SECTION LOCAL  DEFAULT    1
     2: 08048108     0 SECTION LOCAL  DEFAULT    2
     3: 08048128     0 SECTION LOCAL  DEFAULT    3
     4: 0804814c     0 SECTION LOCAL  DEFAULT    4
     5: 0804818c     0 SECTION LOCAL  DEFAULT    5
     6: 080481d2     0 SECTION LOCAL  DEFAULT    6
     7: 080481dc     0 SECTION LOCAL  DEFAULT    7
     8: 080481fc     0 SECTION LOCAL  DEFAULT    8
     9: 08048204     0 SECTION LOCAL  DEFAULT    9
    10: 0804820c     0 SECTION LOCAL  DEFAULT   10
    11: 08048224     0 SECTION LOCAL  DEFAULT   11
    12: 08048250     0 SECTION LOCAL  DEFAULT   12
    13: 08048434     0 SECTION LOCAL  DEFAULT   13
    14: 08048450     0 SECTION LOCAL  DEFAULT   14
    15: 08049458     0 SECTION LOCAL  DEFAULT   15
    16: 08049464     0 SECTION LOCAL  DEFAULT   16
    17: 08049468     0 SECTION LOCAL  DEFAULT   17
    18: 08049530     0 SECTION LOCAL  DEFAULT   18
    19: 08049538     0 SECTION LOCAL  DEFAULT   19
    20: 08049540     0 SECTION LOCAL  DEFAULT   20
    21: 08049544     0 SECTION LOCAL  DEFAULT   21
    22: 08049558     0 SECTION LOCAL  DEFAULT   22
    23: 00000000     0 SECTION LOCAL  DEFAULT   23
    24: 00000000     0 SECTION LOCAL  DEFAULT   24
    25: 00000000     0 SECTION LOCAL  DEFAULT   25
    26: 00000000     0 SECTION LOCAL  DEFAULT   26
    27: 00000000     0 SECTION LOCAL  DEFAULT   27
    28: 00000000     0 SECTION LOCAL  DEFAULT   28
    29: 00000000     0 SECTION LOCAL  DEFAULT   29
    30: 00000000     0 SECTION LOCAL  DEFAULT   30
    31: 00000000     0 SECTION LOCAL  DEFAULT   31
    32: 00000000     0 SECTION LOCAL  DEFAULT   32
    33: 00000000     0 SECTION LOCAL  DEFAULT   33
    34: 00000000     0 SECTION LOCAL  DEFAULT   34
    35: 00000000     0 FILE    LOCAL  DEFAULT  ABS <command line>
    36: 00000000     0 FILE    LOCAL  DEFAULT  ABS /usr/src/packages/BUILD/g
    37: 00000000     0 FILE    LOCAL  DEFAULT  ABS <command line>
    38: 00000000     0 FILE    LOCAL  DEFAULT  ABS <built-in>
    39: 00000000     0 FILE    LOCAL  DEFAULT  ABS abi-note.S
    40: 00000000     0 FILE    LOCAL  DEFAULT  ABS /usr/src/packages/BUILD/g
    41: 00000000     0 FILE    LOCAL  DEFAULT  ABS abi-note.S
    42: 00000000     0 FILE    LOCAL  DEFAULT  ABS /usr/src/packages/BUILD/g
    43: 00000000     0 FILE    LOCAL  DEFAULT  ABS abi-note.S
    44: 00000000     0 FILE    LOCAL  DEFAULT  ABS <command line>
    45: 00000000     0 FILE    LOCAL  DEFAULT  ABS /usr/src/packages/BUILD/g
    46: 00000000     0 FILE    LOCAL  DEFAULT  ABS <command line>
    47: 00000000     0 FILE    LOCAL  DEFAULT  ABS <built-in>
    48: 00000000     0 FILE    LOCAL  DEFAULT  ABS abi-note.S
    49: 00000000     0 FILE    LOCAL  DEFAULT  ABS init.c
    50: 00000000     0 FILE    LOCAL  DEFAULT  ABS /usr/src/packages/BUILD/g
    51: 00000000     0 FILE    LOCAL  DEFAULT  ABS /usr/src/packages/BUILD/g
    52: 00000000     0 FILE    LOCAL  DEFAULT  ABS initfini.c
    53: 00000000     0 FILE    LOCAL  DEFAULT  ABS /usr/src/packages/BUILD/g
    54: 00000000     0 FILE    LOCAL  DEFAULT  ABS <command line>
    55: 00000000     0 FILE    LOCAL  DEFAULT  ABS /usr/src/packages/BUILD/g
    56: 00000000     0 FILE    LOCAL  DEFAULT  ABS <command line>
    57: 00000000     0 FILE    LOCAL  DEFAULT  ABS <built-in>
    58: 00000000     0 FILE    LOCAL  DEFAULT  ABS /usr/src/packages/BUILD/g
    59: 08048274     0 FUNC    LOCAL  DEFAULT   12 call_gmon_start
    60: 00000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
    61: 08049530     0 OBJECT  LOCAL  DEFAULT   18 __CTOR_LIST__
    62: 08049538     0 OBJECT  LOCAL  DEFAULT   19 __DTOR_LIST__
    63: 08049540     0 OBJECT  LOCAL  DEFAULT   20 __JCR_LIST__
    64: 08049460     0 OBJECT  LOCAL  DEFAULT   15 p.0
    65: 08049558     1 OBJECT  LOCAL  DEFAULT   22 completed.1
    66: 080482a0     0 FUNC    LOCAL  DEFAULT   12 __do_global_dtors_aux
    67: 080482e0     0 FUNC    LOCAL  DEFAULT   12 frame_dummy
    68: 00000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
    69: 08049534     0 OBJECT  LOCAL  DEFAULT   18 __CTOR_END__
    70: 0804953c     0 OBJECT  LOCAL  DEFAULT   19 __DTOR_END__
    71: 08049464     0 OBJECT  LOCAL  DEFAULT   16 __FRAME_END__
    72: 08049540     0 OBJECT  LOCAL  DEFAULT   20 __JCR_END__
    73: 08048410     0 FUNC    LOCAL  DEFAULT   12 __do_global_ctors_aux
    74: 00000000     0 FILE    LOCAL  DEFAULT  ABS /usr/src/packages/BUILD/g
    75: 00000000     0 FILE    LOCAL  DEFAULT  ABS /usr/src/packages/BUILD/g
    76: 00000000     0 FILE    LOCAL  DEFAULT  ABS initfini.c
    77: 00000000     0 FILE    LOCAL  DEFAULT  ABS /usr/src/packages/BUILD/g
    78: 00000000     0 FILE    LOCAL  DEFAULT  ABS <command line>
    79: 00000000     0 FILE    LOCAL  DEFAULT  ABS /usr/src/packages/BUILD/g
    80: 00000000     0 FILE    LOCAL  DEFAULT  ABS <command line>
    81: 00000000     0 FILE    LOCAL  DEFAULT  ABS <built-in>
    82: 00000000     0 FILE    LOCAL  DEFAULT  ABS /usr/src/packages/BUILD/g
    83: 00000000     0 FILE    LOCAL  DEFAULT  ABS test.c
    84: 0804955c     4 OBJECT  LOCAL  DEFAULT   22 test.0
    85: 08049560     4 OBJECT  LOCAL  DEFAULT   22 test3
    86: 00000000     0 FILE    LOCAL  DEFAULT  ABS elf-init.c
    87: 08049468     0 OBJECT  GLOBAL DEFAULT   17 _DYNAMIC
    88: 08048450     4 OBJECT  GLOBAL DEFAULT   14 _fp_hw
    89: 08049458     0 NOTYPE  GLOBAL DEFAULT  ABS __fini_array_end
    90: 0804945c     0 OBJECT  GLOBAL HIDDEN   15 __dso_handle
    91: 080483a0    96 FUNC    GLOBAL DEFAULT   12 __libc_csu_fini
    92: 0804820c     0 FUNC    GLOBAL DEFAULT   10 _init
    93: 08048250     0 FUNC    GLOBAL DEFAULT   12 _start
    94: 08049458     0 NOTYPE  GLOBAL DEFAULT  ABS __fini_array_start
    95: 08048340    88 FUNC    GLOBAL DEFAULT   12 __libc_csu_init
    96: 08049558     0 NOTYPE  GLOBAL DEFAULT  ABS __bss_start
    97: 0804830c    43 FUNC    GLOBAL DEFAULT   12 main
    98: 08048234   251 FUNC    GLOBAL DEFAULT  UND __libc_start_main@@GLIBC_
    99: 08049458     0 NOTYPE  GLOBAL DEFAULT  ABS __init_array_end
   100: 08049458     0 NOTYPE  WEAK   DEFAULT   15 data_start
   101: 08048434     0 FUNC    GLOBAL DEFAULT   13 _fini
   102: 08049558     0 NOTYPE  GLOBAL DEFAULT  ABS _edata
   103: 08048400     0 FUNC    GLOBAL HIDDEN   12 __i686.get_pc_thunk.bx
   104: 08049544     0 OBJECT  GLOBAL DEFAULT   21 _GLOBAL_OFFSET_TABLE_
   105: 08049564     0 NOTYPE  GLOBAL DEFAULT  ABS _end
   106: 08049458     0 NOTYPE  GLOBAL DEFAULT  ABS __init_array_start
   107: 08048454     4 OBJECT  GLOBAL DEFAULT   14 _IO_stdin_used
   108: 08049458     0 NOTYPE  GLOBAL DEFAULT   15 __data_start
   109: 00000000     0 NOTYPE  WEAK   DEFAULT  UND _Jv_RegisterClasses
   110: 00000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__


>  - how did you create the ELF object?
>  - What to readelf -r and readelf -s have to say about the ELF object?
>
> --
> Daniel Jacobowitz
> MontaVista Software                         Debian GNU/Linux Developer
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Relocating Static Local Variables BUG?
  2004-04-23 16:41   ` Richard Schmitt
@ 2004-04-23 16:51     ` Daniel Jacobowitz
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Jacobowitz @ 2004-04-23 16:51 UTC (permalink / raw)
  To: Richard Schmitt; +Cc: gdb, rishi75

On Fri, Apr 23, 2004 at 12:36:41PM -0400, Richard Schmitt wrote:
> 
> The version of GCC is 3.3.1
> The version of GDB is 6.1 (downloaded latest release)
> 
> The commands to generate the elf are:
> 
> gcc -o test.exe -g test.c
> objcopy -O elf32-little test.exe test.elf
> 
> Built this way, the code is not relocatable, so there is no output of the
> -r command to readelf.  I've done it this way just to demonstrate the
> issue that gdb has with relocating symbols, which is independent of code
> generated as relocatable.  The -s output is shown below.

Well, it's not surprising that doesn't work.  You are taking
non-relocatable output, and giving GDB offsets at which to relocate it. 
The debug information no longer has relocation information, since final
relocation has already been performed.

I assume that's your simplified testcase rather than the one you were
actually trying to debug, and you've oversimplified it - since f you
needed to have .bss at the offset you told GDB about, then your code
would be referencing it in the wrong place.  How is the original code
for your target built?

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-04-23 16:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-23 16:10 Relocating Static Local Variables BUG? Richard Schmitt
2004-04-23 16:37 ` Daniel Jacobowitz
2004-04-23 16:41   ` Richard Schmitt
2004-04-23 16:51     ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).