public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53493] New: [4.7 regression] Compiling with -Os excludes PROGMEM array from generated object file (__attribute__((__progmem__)))
@ 2012-05-26  1:50 jwatte at gmail dot com
  2012-05-26 17:25 ` [Bug c++/53493] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: jwatte at gmail dot com @ 2012-05-26  1:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53493

             Bug #: 53493
           Summary: [4.7 regression] Compiling with -Os excludes PROGMEM
                    array from generated object file
                    (__attribute__((__progmem__)))
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jwatte@gmail.com


I'm using AVR-GCC 4.7.0-1 from Arch Linux, if it matters. 

When compiling with -Os (which is pretty much a must for most source code,) an
exported data array declared as PROGMEM will be removed by the compiler! 

Compare without -Os: 

Code:
$ avr-gcc -mmcu=atmega328p -c foo.cpp -o foo.o && avr-objdump -s foo.o 

foo.o:     file format elf32-avr 

Contents of section .progmem.data: 
 0000 666f6f00                             foo.            
Contents of section .comment: 
 0000 00474343 3a202847 4e552920 342e372e  .GCC: (GNU) 4.7. 
 0010 3000                                 0.              


to with -Os: 

Code:
$ avr-gcc -Os -mmcu=atmega328p -c foo.cpp -o foo.o && avr-objdump -s foo.o 

foo.o:     file format elf32-avr 

Contents of section .comment: 
 0000 00474343 3a202847 4e552920 342e372e  .GCC: (GNU) 4.7. 
 0010 3000                                 0.              


Here is foo.cpp: 

Code:
#include <avr/pgmspace.h> 

unsigned char const foo[4] PROGMEM = { 'f', 'o', 'o', 0 }; 



Must I add some magic GNU make hack to my makefiles to not pass -Os for these
files? That's fairly cumbersome  
Is this a known bug? Is there a patch?


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

* [Bug c++/53493] [4.7 regression] Compiling with -Os excludes PROGMEM array from generated object file (__attribute__((__progmem__)))
  2012-05-26  1:50 [Bug c++/53493] New: [4.7 regression] Compiling with -Os excludes PROGMEM array from generated object file (__attribute__((__progmem__))) jwatte at gmail dot com
@ 2012-05-26 17:25 ` pinskia at gcc dot gnu.org
  2012-05-26 19:26 ` jwatte at gmail dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-05-26 17:25 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53493

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-05-26 17:21:38 UTC ---
Can you provide the preprocessed source?

I think this is done on purpose since foo is not used in the source and the
rules for C++ say the const variable has vague linkage GCC can (and will)
remove those variables which are not used.


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

* [Bug c++/53493] [4.7 regression] Compiling with -Os excludes PROGMEM array from generated object file (__attribute__((__progmem__)))
  2012-05-26  1:50 [Bug c++/53493] New: [4.7 regression] Compiling with -Os excludes PROGMEM array from generated object file (__attribute__((__progmem__))) jwatte at gmail dot com
  2012-05-26 17:25 ` [Bug c++/53493] " pinskia at gcc dot gnu.org
  2012-05-26 19:26 ` jwatte at gmail dot com
@ 2012-05-26 19:26 ` jwatte at gmail dot com
  2012-05-26 19:40 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jwatte at gmail dot com @ 2012-05-26 19:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53493

--- Comment #3 from jwatte at gmail dot com 2012-05-26 19:25:50 UTC ---
Created attachment 27504
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27504
The preprocessed source

Generated with:
avr-gcc -Os -mmcu=atmega328p -c foo.cpp -o foo.E -E

Note that the "-Os" flag does not change the pre-processed source at all -- the
preprocessed output is the same with or without it.


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

* [Bug c++/53493] [4.7 regression] Compiling with -Os excludes PROGMEM array from generated object file (__attribute__((__progmem__)))
  2012-05-26  1:50 [Bug c++/53493] New: [4.7 regression] Compiling with -Os excludes PROGMEM array from generated object file (__attribute__((__progmem__))) jwatte at gmail dot com
  2012-05-26 17:25 ` [Bug c++/53493] " pinskia at gcc dot gnu.org
@ 2012-05-26 19:26 ` jwatte at gmail dot com
  2012-05-26 19:26 ` jwatte at gmail dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jwatte at gmail dot com @ 2012-05-26 19:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53493

--- Comment #2 from jwatte at gmail dot com 2012-05-26 19:22:01 UTC ---
Note that there is not yet any linkage involved -- this is simply a compile
pass. Specifically, the problem here is that I run into a missing symbol error
when linking a program that does use the symbol.

I'm pretty sure that the C++ standard does not specify that separate
compilation should break unless all const variables are used in the compilation
unit where they are defined.

I will attach the preprocessed source.


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

* [Bug c++/53493] [4.7 regression] Compiling with -Os excludes PROGMEM array from generated object file (__attribute__((__progmem__)))
  2012-05-26  1:50 [Bug c++/53493] New: [4.7 regression] Compiling with -Os excludes PROGMEM array from generated object file (__attribute__((__progmem__))) jwatte at gmail dot com
                   ` (2 preceding siblings ...)
  2012-05-26 19:26 ` jwatte at gmail dot com
@ 2012-05-26 19:40 ` pinskia at gcc dot gnu.org
  2012-05-26 20:30 ` jwatte at gmail dot com
  2012-05-26 20:31 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-05-26 19:40 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53493

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-05-26 19:26:27 UTC ---
> I'm pretty sure that the C++ standard does not specify that separate
> compilation should break unless all const variables are used in the compilation
> unit where they are defined.

It defines them if they have const keyword, they have to be defined in each
translational unit.  If not then the one where it is declared has to be marked
extern.

Something like:
extern unsigned char const foo[4];
unsigned char const foo[4] = { 'f', 'o', 'o', 0 }; 
---- CUT ----
is required and that turns the linkage to be external.  Otherwise foo has vague
linkage (a C++ term saying it has to be the same in each translational unit
that it is used).


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

* [Bug c++/53493] [4.7 regression] Compiling with -Os excludes PROGMEM array from generated object file (__attribute__((__progmem__)))
  2012-05-26  1:50 [Bug c++/53493] New: [4.7 regression] Compiling with -Os excludes PROGMEM array from generated object file (__attribute__((__progmem__))) jwatte at gmail dot com
                   ` (3 preceding siblings ...)
  2012-05-26 19:40 ` pinskia at gcc dot gnu.org
@ 2012-05-26 20:30 ` jwatte at gmail dot com
  2012-05-26 20:31 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jwatte at gmail dot com @ 2012-05-26 20:30 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53493

jwatte at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |

--- Comment #5 from jwatte at gmail dot com 2012-05-26 20:22:55 UTC ---

"it has to be the same in each translational unit that it is used"

That doesn't mean it has to be /deleted/. An argument can be made that deleting
it from the compilation unit is not very useful. If I remember correctly, the
source of vague linkage was for allowing for the merging of inline template
instantiations (rather than explicitly.

Anyway, including the forward declaration in the definition translation unit as
well as the using translation unit does make it work, so it works around this
problem. Whether the behavior is useful or correct, I don't want to enter into
an argument about.


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

* [Bug c++/53493] [4.7 regression] Compiling with -Os excludes PROGMEM array from generated object file (__attribute__((__progmem__)))
  2012-05-26  1:50 [Bug c++/53493] New: [4.7 regression] Compiling with -Os excludes PROGMEM array from generated object file (__attribute__((__progmem__))) jwatte at gmail dot com
                   ` (4 preceding siblings ...)
  2012-05-26 20:30 ` jwatte at gmail dot com
@ 2012-05-26 20:31 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-05-26 20:31 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53493

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-05-26 20:30:00 UTC ---
(In reply to comment #5)
> "it has to be the same in each translational unit that it is used"
> 
> That doesn't mean it has to be /deleted/.

It means it can be deleted.  This is not a bug in GCC but rather your source. 
C++ is different from C here.  Simple as that.  If it is deleted it exposes a
ODR violation in your source.


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

end of thread, other threads:[~2012-05-26 20:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-26  1:50 [Bug c++/53493] New: [4.7 regression] Compiling with -Os excludes PROGMEM array from generated object file (__attribute__((__progmem__))) jwatte at gmail dot com
2012-05-26 17:25 ` [Bug c++/53493] " pinskia at gcc dot gnu.org
2012-05-26 19:26 ` jwatte at gmail dot com
2012-05-26 19:26 ` jwatte at gmail dot com
2012-05-26 19:40 ` pinskia at gcc dot gnu.org
2012-05-26 20:30 ` jwatte at gmail dot com
2012-05-26 20:31 ` pinskia at gcc dot gnu.org

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