Using the progmem attribute in C++ sources produce warning messages about uninitialized variables. The following preprocessor output works correctly under 4.1 but produces said warnings (in every warning level): # 1 "is.cpp" # 1 "<built-in>" # 1 "<command-line>" # 1 "is.cpp" int i1 __attribute__((__progmem__)) = 1; int __attribute__((__progmem__)) i2 = 2; __attribute__((__progmem__)) int i3 = 3; extern int i4 __attribute__((__progmem__)); int i4 = 4; extern int __attribute__((__progmem__)) i5; int i5 = 5; extern __attribute__((__progmem__)) int i6; int i6 = 6; typedef int i7_t __attribute__((__progmem__)); i7_t i7 = 7; typedef int __attribute__((__progmem__)) i8_t; i8_t i8 = 8; typedef __attribute__((__progmem__)) int i9_t; i9_t i9 = 9; const char s1[] __attribute__((__progmem__)) = "string 1"; const char __attribute__((__progmem__)) s2[] = "string 2"; const __attribute__((__progmem__)) char s3[] = "string 3"; __attribute__((__progmem__)) const char s4[] = "string 4"; extern const char s5[] __attribute__((__progmem__)); const char s5[] = "string 5"; extern const char __attribute__((__progmem__)) s6[]; const char s6[] = "string 6"; extern const __attribute__((__progmem__)) char s7[]; const char s7[] = "string 7"; extern __attribute__((__progmem__)) const char s8[]; const char s8[] = "string 8"; typedef const char s9_t __attribute__((__progmem__)); const s9_t s9[] = "string 9"; typedef const char __attribute__((__progmem__)) s10_t; const s10_t s10[] = "string 10"; typedef const __attribute__((__progmem__)) char s11_t; const s11_t s11[] = "string 11"; typedef __attribute__((__progmem__)) const char s12_t; const s12_t s12[] = "string 12"; This is the used command line and the compiler output: /usr/local/avr-4.2.2/bin/avr-gcc -Wall -save-temps -mmcu=atmega88 -Os -c -o /tmp/x.o is.cpp is.cpp:1: warning: only initialized variables can be placed into program memory area is.cpp:2: warning: only initialized variables can be placed into program memory area is.cpp:3: warning: only initialized variables can be placed into program memory area is.cpp:10: warning: only initialized variables can be placed into program memory area is.cpp:11: warning: only initialized variables can be placed into program memory area is.cpp:12: warning: only initialized variables can be placed into program memory area is.cpp:13: warning: only initialized variables can be placed into program memory area Please note that the same source compiled as C works properly without any warnings.
after upgrading to WinAVR-20071221 my C++ projects trigger the same warning message. for completeness, my sources look like: // usb_user_device_descriptor PROGMEM S_usb_device_descriptor usb_dev_desc = { sizeof( usb_dev_desc ), DEVICE_DESCRIPTOR, U_WORD( USB_SPECIFICATION ), DEVICE_CLASS, DEVICE_SUB_CLASS, DEVICE_PROTOCOL, EP_CONTROL_LENGTH, U_WORD( VENDOR_ID ), U_WORD( PRODUCT_ID ), U_WORD( RELEASE_NUMBER ), STRING_INDEX_MAN, STRING_INDEX_PROD, STRING_INDEX_SN, NB_CONFIGURATION }; Liviu
version 4.2.1 seems to be affected as well: -------------------------------------------- holger@x:~/scratch$ cat foo.cpp #include <avr/pgmspace.h> const int foobar1 = 42; int foobar2 = 42; const int PROGMEM foobar3 = 42; int PROGMEM foobar4 = 42; holger@x:~/scratch$ avr-g++ -Wall -mmcu=atmega1281 -c foo.cpp foo.cpp:5: warning: only initialized variables can be placed into program memory area foo.cpp:6: warning: only initialized variables can be placed into program memory area holger@x:~/scratch$ avr-g++ --version avr-g++ (GCC) 4.2.1 (SUSE Linux) Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*** Bug 40112 has been marked as a duplicate of this bug. ***
I found a way to place data in program memory for C++ without producing the annoying warnings. The trick is omiting __attribute__((__progmem__)) and instead always use __attribute__((section(".progmem.something"))) for placing your data into a special section beginning with ".progmem.". I tested this with different avr-g++ compiler versions (3.4.4, 4.1.1, 4.2.1, 4.3.3, 4.4.0, and 4.4.3), and it always results in the desired behavior. Example: [mschulze@teeth tst]$ cat progmem.cpp static char __attribute((section(".progmem.something"))) str[]="program memory data"; const char* test() { return str; } [mschulze@teeth tst]$ /usr/bin/avr-g++ -Wall -mmcu=atmega1281 -c progmem.cpp [mschulze@teeth tst]$ /usr/bin/avr-g++ --version avr-g++ (GCC) 4.3.3 Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. [mschulze@teeth tst]$ Regards, Michael
same problem in 4.5.2. Maybe importance of this bug should be increased? Imho it's a little bit embarrassing to keep this bug so long... (since 2008, over 3 yrs!) regards
Author: gjl Date: Wed Jun 29 07:57:25 2011 New Revision: 175621 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175621 Log: PR target/34734 * config/avr/avr.c (avr_handle_progmem_attribute): Move warning about uninitialized data attributed 'progmem' from here... (avr_encode_section_info): ...to this new function. (TARGET_ENCODE_SECTION_INFO): New define. (avr_section_type_flags): For data in ".progmem.data", remove section flag SECTION_WRITE. Modified: trunk/gcc/ChangeLog trunk/gcc/config/avr/avr.c
Author: gjl Date: Thu Jun 30 13:28:43 2011 New Revision: 175705 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175705 Log: PR target/34734 Backport from mainline * config/avr/avr.c (avr_handle_progmem_attribute): Move warning about uninitialized data attributed 'progmem' from here... (avr_encode_section_info): ...to this new function. (TARGET_ENCODE_SECTION_INFO): New define. (avr_section_type_flags): For data in ".progmem.data", remove section flag SECTION_WRITE. Modified: branches/gcc-4_6-branch/gcc/ChangeLog branches/gcc-4_6-branch/gcc/config/avr/avr.c
Closed as resolved+fixed. (In reply to comment #5) > same problem in 4.5.2. > Maybe importance of this bug should be increased? Imho it's a little bit > embarrassing to keep this bug so long... (since 2008, over 3 yrs!) > regards Increasing importance won't help. The only thing that would help is increasing number of people that are inclined to improve avr-gcc. regards Note that progmem on types is not documented an not supposed to work at all.
Author: gjl Date: Thu Jun 30 13:45:04 2011 New Revision: 175706 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175706 Log: PR target/34734 Backport from mainline (avr_section_type_flags): For data in ".progmem.data", remove section flag SECTION_WRITE. Modified: branches/gcc-4_6-branch/gcc/ChangeLog branches/gcc-4_6-branch/gcc/config/avr/avr.c
Author: gjl Date: Mon Jul 4 12:48:04 2011 New Revision: 175811 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175811 Log: PR target/34734 PR target/44643 * gcc.target/avr/avr.exp: Run over cpp files, too. * gcc.target/avr/torture/avr-torture.exp: Ditto. * gcc.target/avr/progmem.h: New file. * gcc.target/avr/exit-abort.h: New file. * gcc.target/avr/progmem-error-1.c: New file. * gcc.target/avr/progmem-error-1.cpp: New file. * gcc.target/avr/progmem-warning-1.c: New file. * gcc.target/avr/torture/progmem-1.c: New file. * gcc.target/avr/torture/progmem-1.cpp: New file. Added: trunk/gcc/testsuite/gcc.target/avr/exit-abort.h trunk/gcc/testsuite/gcc.target/avr/progmem-error-1.c trunk/gcc/testsuite/gcc.target/avr/progmem-error-1.cpp trunk/gcc/testsuite/gcc.target/avr/progmem-warning-1.c trunk/gcc/testsuite/gcc.target/avr/progmem.h trunk/gcc/testsuite/gcc.target/avr/torture/progmem-1.c trunk/gcc/testsuite/gcc.target/avr/torture/progmem-1.cpp Modified: trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gcc.target/avr/avr.exp trunk/gcc/testsuite/gcc.target/avr/torture/avr-torture.exp
*** Bug 260998 has been marked as a duplicate of this bug. *** Seen from the domain http://volichat.com Marked for reference. Resolved as fixed @bugzilla.