This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/78818] New: msp430 persistent attribute is not applied correctly in some cases


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78818

            Bug ID: 78818
           Summary: msp430 persistent attribute is not applied correctly
                    in some cases
           Product: gcc
           Version: 6.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: awygle at gmail dot com
  Target Milestone: ---

The MS430 variable attribute "persistent" places variables in a special section
.persistent so that they will not be re-initialized on reset and so that the
linker can place them in non-volatile storage. Variables with this attribute
aren't placed in this section when:

1) the variables are specified as "static" AND are not initialized or are
initialized to 0. In this case the variables are placed in the .bss section.
2) the program is compiled with the -fdata-sections optimization option. In
this case the variables are placed in either .bss.foo or .text.foo.

An example program and two compilations:

test.i:
# 1 "test.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.c"

__attribute__((persistent)) int persist = 1;
__attribute__((persistent)) int global_persist = 0;
static __attribute__((persistent)) int static_persist = 1;
static __attribute__((persistent)) int static_nopersist = 0;

void main() {

  while(1);
}


Compilation without -fdata-sections:

% msp430-elf-gcc -msim -c test.i -o test.o
% msp430-elf-objdump -x --syms test.o

test.o:     file format elf32-msp430
test.o
architecture: MSP430X, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000004  00000000  00000000  00000034  2**1
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  1 .data         00000000  00000000  00000000  00000038  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000002  00000000  00000000  00000038  2**1
                  ALLOC
  3 .persistent   00000006  00000000  00000000  00000038  2**1
                  CONTENTS, ALLOC, LOAD, DATA
  4 .comment      00000012  00000000  00000000  0000003e  2**0
                  CONTENTS, READONLY
  5 .MSP430.attributes 00000017  00000000  00000000  00000050  2**0
                  CONTENTS, READONLY
SYMBOL TABLE:
00000000 l    df *ABS*  00000000 test.c
00000000 l    d  .text  00000000 .text
00000000 l    d  .data  00000000 .data
00000000 l    d  .bss   00000000 .bss
00000000 l    d  .persistent    00000000 .persistent
00000004 l     O .persistent    00000002 static_persist
00000000 l     O .bss   00000002 static_nopersist
00000000 l    d  .comment       00000000 .comment
00000000 l    d  .MSP430.attributes     00000000 .MSP430.attributes
00000000 g     O .persistent    00000002 persist
00000002 g     O .persistent    00000002 global_persist
00000000         *UND*  00000000 __crt0_init_bss
00000000 g     F .text  00000004 main


RELOCATION RECORDS FOR [.text]:
OFFSET   TYPE              VALUE
00000002 R_MSP430X_ABS16   .L2

Compilation with -fdata-sections:

% msp430-elf-gcc -msim -fdata-sections -c test.i -o test.o
% msp430-elf-objdump -x --syms test.o

test.o:     file format elf32-msp430
test.o
architecture: MSP430X, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000004  00000000  00000000  00000034  2**1
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  1 .data         00000000  00000000  00000000  00000038  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000000  00000000  00000000  00000038  2**0
                  ALLOC
  3 .data.persist 00000002  00000000  00000000  00000038  2**1
                  CONTENTS, ALLOC, LOAD, DATA
  4 .bss.global_persist 00000002  00000000  00000000  0000003a  2**1
                  ALLOC
  5 .data.static_persist 00000002  00000000  00000000  0000003a  2**1
                  CONTENTS, ALLOC, LOAD, DATA
  6 .bss.static_nopersist 00000002  00000000  00000000  0000003c  2**1
                  ALLOC
  7 .comment      00000012  00000000  00000000  0000003c  2**0
                  CONTENTS, READONLY
  8 .MSP430.attributes 00000017  00000000  00000000  0000004e  2**0
                  CONTENTS, READONLY
SYMBOL TABLE:
00000000 l    df *ABS*  00000000 test.c
00000000 l    d  .text  00000000 .text
00000000 l    d  .data  00000000 .data
00000000 l    d  .bss   00000000 .bss
00000000 l    d  .data.persist  00000000 .data.persist
00000000 l    d  .bss.global_persist    00000000 .bss.global_persist
00000000 l    d  .data.static_persist   00000000 .data.static_persist
00000000 l     O .data.static_persist   00000002 static_persist
00000000 l    d  .bss.static_nopersist  00000000 .bss.static_nopersist
00000000 l     O .bss.static_nopersist  00000002 static_nopersist
00000000 l    d  .comment       00000000 .comment
00000000 l    d  .MSP430.attributes     00000000 .MSP430.attributes
00000000 g     O .data.persist  00000002 persist
00000000         *UND*  00000000 __crt0_movedata
00000000 g     O .bss.global_persist    00000002 global_persist
00000000         *UND*  00000000 __crt0_init_bss
00000000 g     F .text  00000004 main


RELOCATION RECORDS FOR [.text]:
OFFSET   TYPE              VALUE
00000002 R_MSP430X_ABS16   .L2

The GCC build information:

% msp430-elf-gcc -v
Using built-in specs.
COLLECT_GCC=msp430-elf-gcc
COLLECT_LTO_WRAPPER=/home/awygle/toolchain/install/bin/../libexec/gcc/msp430-elf/6.2.0/lto-wrapper
Target: msp430-elf
Configured with: ../gcc-6.2.0/configure
--prefix=/home/awygle/toolchain/toolchain_new --target=msp430-elf
--without-headers --with-newlib --enable-languages=c,c++ -v
Thread model: single
gcc version 6.2.0 (GCC)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]