Patchwork Add missing size directive for arm-*-elf

login
register
mail settings
Submitter Kito Cheng
Date Sept. 1, 2014, 3:30 a.m.
Message ID <CA+yXCZAhAJYTN1XbUxKmu8zg=SAjrLPhp2njffjPKWGhnH68jA@mail.gmail.com>
Download mbox | patch
Permalink /patch/384622/
State New
Headers show

Comments

Kito Cheng - Sept. 1, 2014, 3:30 a.m.
Hi all:

In arm-*-elf target some variable will missing size directive,

for example:

foo.c:

void foo (void) {
  static char bufbuf[8];
}

$ arm-none-eabi-gcc ./foo.c  -S -o -

...
.align 2
bufbuf.4078:
.space 8
...
.ident "GCC: (GNU) 5.0.0 20140828 (experimental)"


And then the size info will missing:

$ arm-none-eabi-objdump ./foo.o  -t

./foo.o:     file format elf32-littlearm

SYMBOL TABLE:
00000000 l    df *ABS* 00000000 zoo.c
00000000 l    d  .text 00000000 .text
00000000 l    d  .data 00000000 .data
00000000 l    d  .bss 00000000 .bss
00000000 l       .bss 00000008 bufbuf.4078
00000000 l    d  .comment 00000000 .comment
00000000 l    d  .ARM.attributes 00000000 .ARM.attributes
00000000 g     F .text 00000018 foo


ChangeLog

2014-09-01  Kito Cheng  <kito@0xlab.org>

        * config/arm/unknown-elf.h (ASM_OUTPUT_ALIGNED_DECL_LOCAL):
Add size directive.
Kito Cheng - Sept. 8, 2014, 1:47 p.m.
ping!

On Mon, Sep 1, 2014 at 11:30 AM, Kito Cheng <kito.cheng@gmail.com> wrote:
> Hi all:
>
> In arm-*-elf target some variable will missing size directive,
>
> for example:
>
> foo.c:
>
> void foo (void) {
>   static char bufbuf[8];
> }
>
> $ arm-none-eabi-gcc ./foo.c  -S -o -
>
> ...
> .align 2
> bufbuf.4078:
> .space 8
> ...
> .ident "GCC: (GNU) 5.0.0 20140828 (experimental)"
>
>
> And then the size info will missing:
>
> $ arm-none-eabi-objdump ./foo.o  -t
>
> ./foo.o:     file format elf32-littlearm
>
> SYMBOL TABLE:
> 00000000 l    df *ABS* 00000000 zoo.c
> 00000000 l    d  .text 00000000 .text
> 00000000 l    d  .data 00000000 .data
> 00000000 l    d  .bss 00000000 .bss
> 00000000 l       .bss 00000008 bufbuf.4078
> 00000000 l    d  .comment 00000000 .comment
> 00000000 l    d  .ARM.attributes 00000000 .ARM.attributes
> 00000000 g     F .text 00000018 foo
>
>
> ChangeLog
>
> 2014-09-01  Kito Cheng  <kito@0xlab.org>
>
>         * config/arm/unknown-elf.h (ASM_OUTPUT_ALIGNED_DECL_LOCAL):
> Add size directive.
Ramana Radhakrishnan - Sept. 9, 2014, 1:32 p.m.
On Mon, Sep 1, 2014 at 4:30 AM, Kito Cheng <kito.cheng@gmail.com> wrote:
> Hi all:
>
> In arm-*-elf target some variable will missing size directive,
>
> for example:
>
> foo.c:
>
> void foo (void) {
>   static char bufbuf[8];
> }
>
> $ arm-none-eabi-gcc ./foo.c  -S -o -
>
> ...
> .align 2
> bufbuf.4078:
> .space 8


Thanks for this patch Kito.

Nick / Richard : Any historical reasons as to why we use .space
instead of the more common .comm / .lcomm directives to the assembler
in the ARM backend ? If there are no reasons should we just move to
using the standard COMMON_ASM_OP here rather than using .space ?
Ofcourse needs to be tested to check if there are any missing corner
cases.

Ramana


> ...
> .ident "GCC: (GNU) 5.0.0 20140828 (experimental)"
>
>
> And then the size info will missing:
>
> $ arm-none-eabi-objdump ./foo.o  -t
>
> ./foo.o:     file format elf32-littlearm
>
> SYMBOL TABLE:
> 00000000 l    df *ABS* 00000000 zoo.c
> 00000000 l    d  .text 00000000 .text
> 00000000 l    d  .data 00000000 .data
> 00000000 l    d  .bss 00000000 .bss
> 00000000 l       .bss 00000008 bufbuf.4078
> 00000000 l    d  .comment 00000000 .comment
> 00000000 l    d  .ARM.attributes 00000000 .ARM.attributes
> 00000000 g     F .text 00000018 foo
>
>
> ChangeLog
>
> 2014-09-01  Kito Cheng  <kito@0xlab.org>
>
>         * config/arm/unknown-elf.h (ASM_OUTPUT_ALIGNED_DECL_LOCAL):
> Add size directive.
Richard Earnshaw - Sept. 9, 2014, 1:33 p.m.
On 09/09/14 14:32, Ramana Radhakrishnan wrote:
> On Mon, Sep 1, 2014 at 4:30 AM, Kito Cheng <kito.cheng@gmail.com> wrote:
>> Hi all:
>>
>> In arm-*-elf target some variable will missing size directive,
>>
>> for example:
>>
>> foo.c:
>>
>> void foo (void) {
>>   static char bufbuf[8];
>> }
>>
>> $ arm-none-eabi-gcc ./foo.c  -S -o -
>>
>> ...
>> .align 2
>> bufbuf.4078:
>> .space 8
> 
> 
> Thanks for this patch Kito.
> 
> Nick / Richard : Any historical reasons as to why we use .space
> instead of the more common .comm / .lcomm directives to the assembler
> in the ARM backend ? If there are no reasons should we just move to
> using the standard COMMON_ASM_OP here rather than using .space ?
> Ofcourse needs to be tested to check if there are any missing corner
> cases.
> 

.space puts space in the current section, I believe.  .comm and .lcomm
put the space in the common section; that's very different behaviour.

R.

> Ramana
> 
> 
>> ...
>> .ident "GCC: (GNU) 5.0.0 20140828 (experimental)"
>>
>>
>> And then the size info will missing:
>>
>> $ arm-none-eabi-objdump ./foo.o  -t
>>
>> ./foo.o:     file format elf32-littlearm
>>
>> SYMBOL TABLE:
>> 00000000 l    df *ABS* 00000000 zoo.c
>> 00000000 l    d  .text 00000000 .text
>> 00000000 l    d  .data 00000000 .data
>> 00000000 l    d  .bss 00000000 .bss
>> 00000000 l       .bss 00000008 bufbuf.4078
>> 00000000 l    d  .comment 00000000 .comment
>> 00000000 l    d  .ARM.attributes 00000000 .ARM.attributes
>> 00000000 g     F .text 00000018 foo
>>
>>
>> ChangeLog
>>
>> 2014-09-01  Kito Cheng  <kito@0xlab.org>
>>
>>         * config/arm/unknown-elf.h (ASM_OUTPUT_ALIGNED_DECL_LOCAL):
>> Add size directive.
>
Andreas Schwab - Sept. 9, 2014, 2:03 p.m.
Richard Earnshaw <rearnsha@arm.com> writes:

> .space puts space in the current section, I believe.  .comm and .lcomm
> put the space in the common section; that's very different behaviour.

The local common section is the .bss section.

Andreas.
Andreas Schwab - Sept. 9, 2014, 2:06 p.m.
Kito Cheng <kito.cheng@gmail.com> writes:

> .align 2
> bufbuf.4078:
> .space 8
> ...
> .ident "GCC: (GNU) 5.0.0 20140828 (experimental)"
>
>
> And then the size info will missing:
>
> $ arm-none-eabi-objdump ./foo.o  -t
>
> ./foo.o:     file format elf32-littlearm
>
> SYMBOL TABLE:
> 00000000 l    df *ABS* 00000000 zoo.c
> 00000000 l    d  .text 00000000 .text
> 00000000 l    d  .data 00000000 .data
> 00000000 l    d  .bss 00000000 .bss
> 00000000 l       .bss 00000008 bufbuf.4078

The size of bufbuf.4078 appears to be correct.

Andreas.
Kito Cheng - Sept. 9, 2014, 3:51 p.m.
On Tue, Sep 9, 2014 at 10:06 PM, Andreas Schwab <schwab@suse.de> wrote:
> Kito Cheng <kito.cheng@gmail.com> writes:
>
>> .align 2
>> bufbuf.4078:
>> .space 8
>> ...
>> .ident "GCC: (GNU) 5.0.0 20140828 (experimental)"
>>
>>
>> And then the size info will missing:
>>
>> $ arm-none-eabi-objdump ./foo.o  -t
>>
>> ./foo.o:     file format elf32-littlearm
>>
>> SYMBOL TABLE:
>> 00000000 l    df *ABS* 00000000 zoo.c
>> 00000000 l    d  .text 00000000 .text
>> 00000000 l    d  .data 00000000 .data
>> 00000000 l    d  .bss 00000000 .bss
>> 00000000 l       .bss 00000008 bufbuf.4078
>
> The size of bufbuf.4078 appears to be correct.

Oops, my mistake, this will get correct size after this patch,
it will get zero size without this patch :)

$ cat foo.c:
void foo (void) {
  static char bufbuf[8];
}

$ arm-none-eabi-gcc ./foo.c  -S -o -

# before this patch
...
 .bss
 .align 2
 bufbuf.4078:
 .space 8
 .ident "GCC: (GNU) 5.0.0 20140908 (experimental)"

# after this patch (add size directive )
...
.bss
.align 2
bufbuf.4078:
.space 8
.size bufbuf.4078, 8
.ident "GCC: (GNU) 5.0.0 20140909 (experimental)"

Another solution is just don't define ASM_OUTPUT_ALIGNED_DECL_LOCAL
and use default one,
it will use .local + .comm (same as arm-linux-gnueabi)

...
.size foo, .-foo
.local bufbuf.4078
.comm bufbuf.4078,8,4
.ident "GCC: (GNU) 5.0.0 20140909 (experimental)"



> Andreas.

Patch

From e0034653a4d457708fc4d858ea20fab70a42d798 Mon Sep 17 00:00:00 2001
From: Kito Cheng <kito.cheng@gmail.com>
Date: Mon, 1 Sep 2014 11:19:13 +0800
Subject: [PATCH] Add missing size directive for arm-elf

ChangeLog

2014-09-01  Kito Cheng  <kito@0xlab.org>

	* config/arm/unknown-elf.h (ASM_OUTPUT_ALIGNED_DECL_LOCAL): Add size directive.
---
 gcc/config/arm/unknown-elf.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/config/arm/unknown-elf.h b/gcc/config/arm/unknown-elf.h
index 56aa166..b4d1757 100644
--- a/gcc/config/arm/unknown-elf.h
+++ b/gcc/config/arm/unknown-elf.h
@@ -81,6 +81,7 @@ 
       ASM_OUTPUT_ALIGN (FILE, floor_log2 (ALIGN / BITS_PER_UNIT));	\
       ASM_OUTPUT_LABEL (FILE, NAME);					\
       fprintf (FILE, "\t.space\t%d\n", SIZE ? (int)(SIZE) : 1);		\
+      ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, SIZE);			\
     }									\
   while (0)
 
-- 
1.9.3