public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Problem about mips .data section
@ 2008-02-04 10:42 robert song
  2008-02-08 16:52 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: robert song @ 2008-02-04 10:42 UTC (permalink / raw)
  To: gcc-help

Hello, everyone.
I have met a problem when I used mips gcc to compile a simple test file.

The file defines two variables as bellow.
const char *h_errlist[] = {
        "Resolver Error 0 (no error)",
        "Unknown host",                         /* 1 HOST_NOT_FOUND */
        "Host name lookup failure",             /* 2 TRY_AGAIN */
        "Unknown server error",                 /* 3 NO_RECOVERY */
        "No address associated with name",      /* 4 NO_ADDRESS */
};
int     h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };

I found that with the -fdata-sections option, the size of the data section
in the library genereated by the file has changed. The results are as bellow.

without -fdata-sections:

00010d20 <h_nerr>:
   10d20:       00000005 00000000 00000000 00000000     ................

00010d30 <h_errlist>:
   10d30:       00000c24 00000c40 00000c50 00000c6c     ...$...@...P...l
   10d40:       00000c84 00000000 00000000 00000000     ................

with -fdata-sections:

00010d30 <h_errlist>:
   10d30:       00000c30 00000c4c 00000c5c 00000c78     ...0...L...\...x
   10d40:       00000c90                                ....

00010d44 <h_nerr>:
   10d44:       00000005 00000000 00000000              ............

I tested it with the compilers of other architectures, and found that
they all keep the same size.

I have totally no idea how the mips gcc compiler acts with the .data section.


BTW, my gcc version : 4.1.1
     binutils version:2.17.50
     glibc:2.5

Thank you for your help!


Best Regards,
robert

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

* Re: Problem about mips .data section
  2008-02-04 10:42 Problem about mips .data section robert song
@ 2008-02-08 16:52 ` Ian Lance Taylor
  2008-02-19  3:48   ` robert song
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2008-02-08 16:52 UTC (permalink / raw)
  To: robert song; +Cc: gcc-help

"robert song" <robertsong.linux@gmail.com> writes:

> without -fdata-sections:
> 
> 00010d20 <h_nerr>:
>    10d20:       00000005 00000000 00000000 00000000     ................
> 
> 00010d30 <h_errlist>:
>    10d30:       00000c24 00000c40 00000c50 00000c6c     ...$...@...P...l
>    10d40:       00000c84 00000000 00000000 00000000     ................
> 
> with -fdata-sections:
> 
> 00010d30 <h_errlist>:
>    10d30:       00000c30 00000c4c 00000c5c 00000c78     ...0...L...\...x
>    10d40:       00000c90                                ....
> 
> 00010d44 <h_nerr>:
>    10d44:       00000005 00000000 00000000              ............

I'm just guessing, but it looks like an alignment issue.  It looks
like the compiler is aligning h_errlist at a 16-byte boundary.  That
is causing an extra 4 zero bytes to be inserted in the "without
-fdata-sections" case.

Ian

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

* Re: Problem about mips .data section
  2008-02-08 16:52 ` Ian Lance Taylor
@ 2008-02-19  3:48   ` robert song
  0 siblings, 0 replies; 3+ messages in thread
From: robert song @ 2008-02-19  3:48 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

08 Feb 2008 08:51:45 -0800, Ian Lance Taylor <iant@google.com>:
> "robert song" <robertsong.linux@gmail.com> writes:
>
> > without -fdata-sections:
> >
> > 00010d20 <h_nerr>:
> >    10d20:       00000005 00000000 00000000 00000000     ................
> >
> > 00010d30 <h_errlist>:
> >    10d30:       00000c24 00000c40 00000c50 00000c6c     ...$...@...P...l
> >    10d40:       00000c84 00000000 00000000 00000000     ................
> >
> > with -fdata-sections:
> >
> > 00010d30 <h_errlist>:
> >    10d30:       00000c30 00000c4c 00000c5c 00000c78     ...0...L...\...x
> >    10d40:       00000c90                                ....
> >
> > 00010d44 <h_nerr>:
> >    10d44:       00000005 00000000 00000000              ............
>
> I'm just guessing, but it looks like an alignment issue.  It looks
> like the compiler is aligning h_errlist at a 16-byte boundary.  That
> is causing an extra 4 zero bytes to be inserted in the "without
> -fdata-sections" case.
>
> Ian
>

lan,
thank you very much for your reply.
I found that in binutils/gas/config/tc-mips.c there are some codes as bellows:

      /* On a native system other than VxWorks, sections must be aligned
         to 16 byte boundaries.  When configured for an embedded ELF
         target, we don't bother.  */
      if (strcmp (TARGET_OS, "elf") != 0
          && strcmp (TARGET_OS, "vxworks") != 0)
        {
          (void) bfd_set_section_alignment (stdoutput, text_section, 4);
          (void) bfd_set_section_alignment (stdoutput, data_section, 4);
          (void) bfd_set_section_alignment (stdoutput, bss_section, 4);
        }

I don't kow why the sections before must be set to 16 byte boundaries,
but not 4 bytes?
Will it cause problems in some target?

Thank you very much.

Robertsong

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

end of thread, other threads:[~2008-02-19  3:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-04 10:42 Problem about mips .data section robert song
2008-02-08 16:52 ` Ian Lance Taylor
2008-02-19  3:48   ` robert song

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