Bug 14047 - [3.4/4.0 Regression] __progmem__ attribute doesn't work
Summary: [3.4/4.0 Regression] __progmem__ attribute doesn't work
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.0
: P1 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2004-02-06 12:45 UTC by Artur Lipowski
Modified: 2004-09-13 14:15 UTC (History)
8 users (show)

See Also:
Host: i686-redhat-linux-gnu
Target: avr-unknown-elf
Build: i686-redhat-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2004-02-11 08:56:03


Attachments
preprocessed testcase (2.00 KB, text/plain)
2004-02-11 08:02 UTC, Artur Lipowski
Details
"Fixes" __progmem__ attribute problem (646 bytes, patch)
2004-02-18 17:01 UTC, Dean Ferreyra
Details | Diff
Fixes the bug (361 bytes, patch)
2004-03-02 20:26 UTC, Oliver Schulz
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Artur Lipowski 2004-02-06 12:45:49 UTC
It seems that this version of the GCC does ignore __progmem__ attribute.

Following code (but the same result for other vriable types) produces elf image
with rotor array placed in .data section

const uint8_t rotor[ANIMSTEPS] __attribute__((__progmem__)) = {
        ~(SEG_A)&SEG_MASK, ~(SEG_B)&SEG_MASK, ~(SEG_C)&SEG_MASK,
        ~(SEG_D)&SEG_MASK, ~(SEG_E)&SEG_MASK, ~(SEG_F)&SEG_MASK };

Where SEG_* are simple numeric defines.

Below a fragment of the map file:
.data           0x00800060       0x2c load address 0x00000604
                0x00800060                PROVIDE (__data_start, .)
 *(.data)
 .data          0x00800060       0x2b display.o
                0x00800078                rotor

(AVR)Binutils version 2.14

GCC version:
Reading specs from /usr/lib/gcc/avr/3.4.0/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-languages=c --disable-nls --target=avr
i686-redhat-linux-gnu
Thread model: single
gcc version 3.4.0 20040206 (prerelease)
Comment 1 Artur Lipowski 2004-02-11 08:02:47 UTC
Created attachment 5722 [details]
preprocessed testcase

Command line was:
avr-gcc -g -Wall -Os -mmcu=attiny26  -Wl,-Map,pgmtst.map -save-temps -o pgmtst
test.c
Comment 2 Andrew Pinski 2004-02-11 08:56:02 UTC
Confirmed.  The problem is that avr was depending on the order of the calls to avr_insert_attributes 
and the actually adding the attribute to the decl.  It really should not depending on them at all.
Comment 3 Dean Ferreyra 2004-02-18 17:01:28 UTC
Created attachment 5766 [details]
"Fixes" __progmem__ attribute problem

This patch has "fixed" the __progmem__ attribute problem for me when applied to
a recent CVS pull of gcc:

  avr-gcc (GCC) 3.5.0 20040216 (experimental)

I tried to take some educated guesses based on Andrew Pinski's comments, but I
don't know the first thing about gcc internals, so beware.
Comment 4 Mark Mitchell 2004-03-01 02:00:44 UTC
AVR is not a primary platform, so I have postponed this until 3.4.1.

The patch here is not quite right.  I believe a correct patch would be to modify
avr_insert_attributes to use 

  avr_progrmem_p (node) || lookup_attribute ("progmem", *attributes)

That would still find a progmem attribute already in the DECL_ATTRIBUTES, which
the patch would not.

If someone will test that change, such a patch would be OK for 3.4.0.
Comment 5 Oliver Schulz 2004-03-02 20:26:42 UTC
Created attachment 5845 [details]
Fixes the bug

This patch contains the suggestion from mmitchel, and it seems, that it works.

I tested it with the supplied test.i attachment, as well with some other
sources.
Would be nice, it it can applied to the 3.4 branch.
Comment 6 Eric Weddington 2004-03-10 05:33:00 UTC
According to comment #4 (by Mark Mitchell) he pre-approved a patch for this for 
3.4 if tested ok. Oliver Schulz tested the patch and confirmed that this works 
on March 2.

Mark, can this be approved and rolled into 3.4 please?

Currently the AVR port is only good up to 3.3.2 (There's a showstopper for 
3.3.3, see #14149). It would be disappointing if we had to wait for 3.4.1 to 
upgrade.

Thanks
Eric
Comment 7 Mark Mitchell 2004-03-11 04:30:07 UTC
The patch needs to go through a full "make bootstrap && make check" process.  I
can't tell if that's been done, or whether just the small program has been
tested.  If the full test process has been done, and it's been confirmed that
there are no regressions, then it's OK to check in this change for GCC 3.4.
Comment 8 Kazu Hirata 2004-03-11 04:52:23 UTC
Being so tiny a microcontroller, I don't think "make bootstrap" is possible.
I've heard that some AVR simulator is available, but I don't know if
it's known to work with dejagnu to run gcc testsuite.
(Well, I guess one could at least test gcc.c-torture/compile and such.)
Comment 9 Mark Mitchell 2004-03-11 04:53:46 UTC
Subject: Re:  [3.4/3.5 Regression] __progmem__ attribute
 doesn't work

kazu at cs dot umass dot edu wrote:

> ------- Additional Comments From kazu at cs dot umass dot edu  2004-03-11 04:52 -------
> Being so tiny a microcontroller, I don't think "make bootstrap" is possible.
> I've heard that some AVR simulator is available, but I don't know if
> it's known to work with dejagnu to run gcc testsuite.
> (Well, I guess one could at least test gcc.c-torture/compile and such.)

If people using this tareget don't normally run DejaGNU, then the patch 
can be checked in with whatever testing would normally be done.  If no 
testing is normally done, then just go ahead and commit the patch. :-)

Comment 10 Eric Weddington 2004-03-11 04:54:09 UTC
The patch only affects 2 files in the config/avr subdir. Doesn't "make 
bootstrap" only apply to building native compilers? The avr port is always 
built as a cross compiler. ... Or do you need the "make bootstrap ..." to test 
that the changes done in config/avr don't affect any of the other ports (that 
are primary targets)?

Also, a simulator is available, but it IIRC it doesn't run with dejagnu.
Comment 11 Eric Weddington 2004-03-12 04:13:20 UTC
Denis and Marek:

Could one of the AVR port maintainers please commit this approved patch for 3.4 
as soon as possible, please?

Thanks
Eric Weddington
Comment 12 Eric Weddington 2004-03-13 06:23:58 UTC
Would *anyone* with CVS write permissions please commit this approved patch for 
3.4?

Thanks
Eric
Comment 13 GCC Commits 2004-03-13 06:38:14 UTC
Subject: Bug 14047

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	denisc@gcc.gnu.org	2004-03-13 06:38:12

Modified files:
	gcc            : ChangeLog 
	gcc/config/avr : avr.c avr-protos.h 

Log message:
	PR target/14047
	* config/avr/avr.c (avr_progmem_p): Add "attributes" parameter.
	(avr_insert_attributes): Pass "attributes" to avr_progmem_p.
	* config/avr/avr-protos.h (avr_progmem_p): Change prototype.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.336&r2=2.2326.2.337
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/avr/avr.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.108.4.1&r2=1.108.4.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/avr/avr-protos.h.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.31&r2=1.31.10.1

Comment 14 denisc 2004-03-13 06:39:36 UTC
Subject: Re:  [3.4/3.5 Regression] __progmem__ attribute doesn't work

"eric at ecentral dot com" <gcc-bugzilla@gcc.gnu.org> writes:

> ------- Additional Comments From eric at ecentral dot com  2004-03-12 04:13 -------
> Denis and Marek:
> 
> Could one of the AVR port maintainers please commit this approved patch for 3.4 
> as soon as possible, please?

Committed as:

2004-03-13  Dean Ferreyra <dferreyra@igc.org>

	PR target/14047
	* config/avr/avr.c (avr_progmem_p): Add "attributes" parameter.
	(avr_insert_attributes): Pass "attributes" to avr_progmem_p.
	* config/avr/avr-protos.h (avr_progmem_p): Change prototype.

Denis.

Comment 15 GCC Commits 2004-03-13 06:43:36 UTC
Subject: Bug 14047

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	denisc@gcc.gnu.org	2004-03-13 06:43:31

Modified files:
	gcc/config/avr : avr.c avr-protos.h 

Log message:
	PR target/14047
	* config/avr/avr.c (avr_progmem_p): Add "attributes" parameter.
	(avr_insert_attributes): Pass "attributes" to avr_progmem_p.
	* config/avr/avr-protos.h (avr_progmem_p): Change prototype.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/avr/avr.c.diff?cvsroot=gcc&r1=1.117&r2=1.118
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/avr/avr-protos.h.diff?cvsroot=gcc&r1=1.31&r2=1.32

Comment 16 Andrew Pinski 2004-03-13 06:45:09 UTC
Fixed for 3.4.0.
Comment 17 GCC Commits 2004-03-13 06:51:58 UTC
Subject: Bug 14047

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	denisc@gcc.gnu.org	2004-03-13 06:51:56

Modified files:
	gcc            : ChangeLog 

Log message:
	PR target/14047
	* config/avr/avr.c (avr_progmem_p): Add "attributes" parameter.
	(avr_insert_attributes): Pass "attributes" to avr_progmem_p.
	* config/avr/avr-protos.h (avr_progmem_p): Change prototype.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.3154&r2=2.3155

Comment 18 Eric Weddington 2004-03-13 06:52:25 UTC
Thanks, Denis!

Eric