Bug 26702 - .size is not emitted for BSS variables
Summary: .size is not emitted for BSS variables
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.1.0
: P4 enhancement
Target Milestone: 6.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-15 18:30 UTC by Shaun Jackman
Modified: 2015-05-21 09:23 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: arm-elf
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2009-04-29 16:50:24


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shaun Jackman 2006-03-15 18:30:44 UTC
When an object file is compiled by arm-elf-gcc 4.1.0, nm -S 2.16.*
always shows zero as the size of a static variable.

Thanks,
Shaun

$ cat foo.c
int foo;
static int static_foo;
$ arm-elf-gcc -c foo.c
$ arm-elf-readelf -s foo.o | grep foo
     1: 00000000     0 FILE    LOCAL  DEFAULT  ABS foo.c
     6: 00000000     0 NOTYPE  LOCAL  DEFAULT    3 static_foo
     8: 00000004     4 OBJECT  GLOBAL DEFAULT  COM foo
$ gcc -c foo.c
$ readelf -s foo.o | grep foo
     1: 00000000     0 FILE    LOCAL  DEFAULT  ABS foo.c
     5: 00000000     4 OBJECT  LOCAL  DEFAULT    3 static_foo
     8: 00000004     4 OBJECT  GLOBAL DEFAULT  COM foo
$ arm-elf-gcc --version | head -1
arm-elf-gcc (GCC) 4.1.0
$ arm-elf-readelf --version | head -1
GNU readelf 2.16.91 20060309
$ gcc --version | head -1
gcc (GCC) 4.0.3 20060212 (prerelease) (Debian 4.0.2-9)
$ readelf --version | head -1
GNU readelf 2.16.91-multiarch 20060118 Debian GNU/Linux
Comment 1 Andrew Pinski 2006-03-15 18:38:46 UTC
What does the output of -S show?  I bet it is just putting static_foo in a BSS using lcomm but I could be wrong.  This might not be a gcc bug.
Comment 2 Shaun Jackman 2006-03-15 18:51:29 UTC
Subject: Re:  Size of static variables always zero on arm-elf

On 15 Mar 2006 18:38:46 -0000, pinskia at gcc dot gnu dot org
<gcc-bugzilla@gcc.gnu.org> wrote:
> What does the output of -S show?  I bet it is just putting static_foo in a BSS
> using lcomm but I could be wrong.  This might not be a gcc bug.

$ arm-elf-readelf -S foo.o
There are 8 section headers, starting at offset 0x7c:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00000000 000034 000000 00  AX  0   0  1
  [ 2] .data             PROGBITS        00000000 000034 000000 00  WA  0   0  1
  [ 3] .bss              NOBITS          00000000 000034 000004 00  WA  0   0  4
  [ 4] .comment          PROGBITS        00000000 000034 000012 00      0   0  1
  [ 5] .shstrtab         STRTAB          00000000 000046 000035 00      0   0  1
  [ 6] .symtab           SYMTAB          00000000 0001bc 000090 10      7   8  4
  [ 7] .strtab           STRTAB          00000000 00024c 000019 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)
Comment 3 Andrew Pinski 2006-03-15 18:53:52 UTC
No I mean what is the assembly output from GCC which you get by invoking gcc with -S.
Comment 4 Shaun Jackman 2006-03-15 19:03:54 UTC
Subject: Re:  Size of static variables always zero on arm-elf

On 15 Mar 2006 18:53:53 -0000, pinskia at gcc dot gnu dot org
<gcc-bugzilla@gcc.gnu.org> wrote:
> No I mean what is the assembly output from GCC which you get by invoking gcc
> with -S.

It does not appear to use lcomm for static_foo. If it's not a gcc bug,
is it a gas bug or a binutils bug?

-- sdj

$ arm-elf-gcc -S foo.c
$ cat foo.s
        .file   "foo.c"
        .bss
        .align  2
static_foo:
        .space  4
        .comm   foo,4,4
        .ident  "GCC: (GNU) 4.1.0"
Comment 5 Andrew Pinski 2006-03-15 19:07:12 UTC
Can you try one more thing:
static int static_foo = 1;

And then use readelf -s on the object file?
Comment 6 Shaun Jackman 2006-03-15 20:01:02 UTC
Subject: Re:  Size of static variables always zero on arm-elf

On 15 Mar 2006 19:07:12 -0000, pinskia at gcc dot gnu dot org > Can
you try one more thing:
> static int static_foo = 1;
>
> And then use readelf -s on the object file?

$ cat foo.c
int foo;
static int static_foo = 1;
$ arm-elf-gcc -c foo.c
$ arm-elf-readelf -s foo.o | grep foo
     1: 00000000     0 FILE    LOCAL  DEFAULT  ABS foo.c
     5: 00000000     4 OBJECT  LOCAL  DEFAULT    2 static_foo
     8: 00000004     4 OBJECT  GLOBAL DEFAULT  COM foo
$ arm-elf-gcc -S foo.c
$ cat foo.s
        .file   "foo.c"
        .data
        .align  2
        .type   static_foo, %object
        .size   static_foo, 4
static_foo:
        .word   1
        .comm   foo,4,4
        .ident  "GCC: (GNU) 4.1.0"
Comment 7 Andrew Pinski 2006-03-15 20:02:46 UTC
Ok, this is a GCC bug for not outputing .size.
Comment 8 Shaun Jackman 2006-03-15 20:10:55 UTC
Subject: Re:  Size of static variables always zero on arm-elf

GCC is not emitting the type or size information for static bss symbols.

-- sdj

$ echo 'static int foo = 1;' >foo.c
$ arm-elf-gcc -S foo.c -odata.s
$ echo 'static int foo;' >foo.c
$ arm-elf-gcc -S foo.c -obss.s
$ diff -u data.s bss.s
--- data.s      2006-03-15 13:08:17.000000000 -0700
+++ bss.s       2006-03-15 13:08:17.000000000 -0700
@@ -1,8 +1,6 @@
        .file   "foo.c"
-       .data
+       .bss
        .align  2
-       .type   foo, %object
-       .size   foo, 4
 foo:
-       .word   1
+       .space  4
        .ident  "GCC: (GNU) 4.1.0"
Comment 9 Ramana Radhakrishnan 2009-04-29 16:50:24 UTC
This appears today with trunk and eabi at r146638.
Comment 10 Richard Earnshaw 2009-12-14 23:14:45 UTC
While getting the size right is useful, it's not something that can be relied on by users, so this is really an enhancement.

Comment 11 Ramana Radhakrishnan 2015-04-23 14:50:16 UTC
Author: ramana
Date: Thu Apr 23 14:49:45 2015
New Revision: 222371

URL: https://gcc.gnu.org/viewcvs?rev=222371&root=gcc&view=rev
Log:
Fix PR target/26702

For Kwok Cheung Yeung.


Added:
    trunk/gcc/testsuite/gcc.target/arm/pr26702.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/arm/unknown-elf.h
    trunk/gcc/testsuite/ChangeLog
Comment 12 Ramana Radhakrishnan 2015-04-23 14:54:49 UTC
Fixed -
Comment 13 Ramana Radhakrishnan 2015-05-21 09:23:46 UTC
Author: ramana
Date: Thu May 21 09:23:14 2015
New Revision: 223473

URL: https://gcc.gnu.org/viewcvs?rev=223473&root=gcc&view=rev
Log:
Fix PR target/26702

For Kwok Cheung Yeung.


Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.target/arm/pr26702.c