Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] MIPS_TEXT symbols should be associated to .text section?
@ 2004-07-22 15:47 David Anderson
  0 siblings, 0 replies; 22+ messages in thread
From: David Anderson @ 2004-07-22 15:47 UTC (permalink / raw)
  To: binutils; +Cc: gdb-patches



oel Brobecker <brobecker@gnat.com> writes:
>I was looking at a fairly high number of regressions in the GDB
>testsuite on mips-irix, and one of them was caused by the fact
>that we searched a symbol by its address and that we match the
>possible candidates against the expected section.
>
>For instance, consider the following symbol "main" from my executable.
>nm on this symbol says:
>
>    [76]    | 268441176|     252|FUNC |GLOB |DEFAULT  |MIPS_TEXT|main
>
>GDB is searching the symbol table for a symbol stored at 0x10001658
>(268441176 = 0x10001658). The first thing it does is going through
>all the sections of the executable, and determine that there is only
>one section that contains this address: .text. So it figures that
>if a symbol matches this address, it will belong to that section.
>...
>
>Not knowing IRIX enough, I am not 110% sure that symbol main is indeed
>in section .text, but it seems pretty obvious: the address range of
>the section matches, .text is the only text section, the MIPS_TEXT
>shndx name... I read various man pages, but couldn't find anything
>that explicitly says MIPS_TEXT = .text section.


SHN_MIPS_TEXT is not mentioned in the ABI books (for any IRIX ABI).
It is set as the section for defined externals in text (normally
this means instructions). (set by ld(1) I mean.)

Nor is SHN_MIPS_DATA (used similarly, but for non-instruction externals).

IRIX ld has created things this way for a very long time.
It should be documented, but is not.  I will see about
documenting it.  I don't know why it is done this way.

Hope this helps.
David B. Anderson davea at sgi dot com http://reality.sgiweb.org/davea


^ permalink raw reply	[flat|nested] 22+ messages in thread
* [RFA] MIPS_TEXT symbols should be associated to .text section?
@ 2004-07-21 20:46 Joel Brobecker
  2004-07-29 22:02 ` Joel Brobecker
  0 siblings, 1 reply; 22+ messages in thread
From: Joel Brobecker @ 2004-07-21 20:46 UTC (permalink / raw)
  To: binutils; +Cc: gdb-patches

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

Hello,

I was looking at a fairly high number of regressions in the GDB
testsuite on mips-irix, and one of them was caused by the fact
that we searched a symbol by its address and that we match the
possible candidates against the expected section.

For instance, consider the following symbol "main" from my executable.
nm on this symbol says:

    [76]    | 268441176|     252|FUNC |GLOB |DEFAULT  |MIPS_TEXT|main

GDB is searching the symbol table for a symbol stored at 0x10001658
(268441176 = 0x10001658). The first thing it does is going through
all the sections of the executable, and determine that there is only
one section that contains this address: .text. So it figures that
if a symbol matches this address, it will belong to that section.

After that, it scans all symbols by address, and only find one symbol,
the symbol above. But unfortunately, because the st_shndx is a bit
special (SHN_MIPS_TEXT = 0xff01), it doesn't point to the .text
section directly. So when bfd was used to read the symbol table,
it defaulted the section of this symbol to an imaginary *ABS* section.
And because of that, GDB discards my symbol because the section
does not match.

Objdump shows the same behavior:

        % objdump -T annota1 | grep main
        10001658 g    DF *ABS*        000000fc main

Not knowing IRIX enough, I am not 110% sure that symbol main is indeed
in section .text, but it seems pretty obvious: the address range of
the section matches, .text is the only text section, the MIPS_TEXT
shndx name... I read various man pages, but couldn't find anything
that explicitly says MIPS_TEXT = .text section.

So I made the following change, which allows us to recognize MIPS_TEXT.
This fixes the symbol section to be .text, and as a consequence fixes
the problem I've seen in GDB.

Another evidence of the change is in the new output from the same
objdump command:


        % objdump -T annota1 | grep main
        10001658 g    DF .text        000000fc main

2004-07-20  Joel Brobecker  <brobecker@gnat.com>

        * elfxx-mips.c (_bfd_mips_elf_symbol_processing): Add handling
        for SHN_MIPS_TEXT symbols.

Tested on mips-irix with no regressoin, by running the following testsuites:
  . binutils
  . libiberty
  . gas
  . ld
  . gdb
OK to apply this patch?

Thanks,
-- 
Joel

[-- Attachment #2: elfxx-mips.c.diff --]
[-- Type: text/plain, Size: 977 bytes --]

Index: elfxx-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
retrieving revision 1.106
diff -u -p -r1.106 elfxx-mips.c
--- elfxx-mips.c	1 Jul 2004 14:53:40 -0000	1.106
+++ elfxx-mips.c	21 Jul 2004 20:24:08 -0000
@@ -4192,6 +4192,20 @@ _bfd_mips_elf_symbol_processing (bfd *ab
       asym->section = bfd_und_section_ptr;
       break;
 
+    case SHN_MIPS_TEXT:
+      { 
+        asection *section = bfd_get_section_by_name (abfd, ".text");
+        if (section != NULL)
+          {
+            asym->section = section;
+            /* MIPS_TEXT is a bit special, the address is not an offset
+               to the base of the .text section.  So substract the section
+               base address to make it an offset.  */
+	    asym->value -= section->vma;
+          }
+        break;
+      }
+    
 #if 0 /* for SGI_COMPAT */
     case SHN_MIPS_TEXT:
       asym->section = mips_elf_text_section_ptr;

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

end of thread, other threads:[~2004-07-30 23:57 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-22 15:47 [RFA] MIPS_TEXT symbols should be associated to .text section? David Anderson
  -- strict thread matches above, loose matches on Subject: below --
2004-07-21 20:46 Joel Brobecker
2004-07-29 22:02 ` Joel Brobecker
2004-07-29 22:19   ` Thiemo Seufer
2004-07-29 23:15     ` Mark Kettenis
2004-07-30  0:31       ` Thiemo Seufer
2004-07-30 11:32         ` Eli Zaretskii
2004-07-30 13:37           ` Andrew Cagney
2004-07-30 18:04             ` Eli Zaretskii
2004-07-30 18:13               ` Joel Brobecker
2004-07-30 18:44                 ` Eli Zaretskii
2004-07-30 18:55                   ` Joel Brobecker
2004-07-30 19:36                     ` Eli Zaretskii
2004-07-30 19:59                     ` Andrew Cagney
2004-07-30 22:29                     ` Michael Chastain
2004-07-30 18:08         ` Joel Brobecker
2004-07-30 18:57           ` Thiemo Seufer
2004-07-30 21:08             ` Mark Kettenis
2004-07-30 23:03             ` Joel Brobecker
2004-07-30 23:57               ` Thiemo Seufer
2004-07-30 18:19         ` Joel Brobecker
2004-07-30  0:17     ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox