Bug 208667 - gcc "used" attribute has no effect on local-scope static variables
Summary: gcc "used" attribute has no effect on local-scope static variables
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 6
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2006-09-29 23:18 UTC by Jeremy Fitzhardinge
Modified: 2007-11-30 22:11 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2006-09-30 12:01:30 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
C source (93 bytes, text/plain)
2006-09-29 23:18 UTC, Jeremy Fitzhardinge
no flags Details
.s output file I get (242 bytes, text/plain)
2006-09-29 23:26 UTC, Jeremy Fitzhardinge
no flags Details


Links
System ID Private Priority Status Summary Last Updated
GNU Compiler Collection 29299 0 None None None Never

Description Jeremy Fitzhardinge 2006-09-29 23:18:28 UTC
Description of problem:
The "used" attribute does not cause a local static to be emitted to the .s/.o file

Version-Release number of selected component (if applicable):
gcc-4.1.1-24

How reproducible:
All the time

Steps to Reproduce:
1.compile the attached file with "gcc -O -S t.c"
2.
3.
  
Actual results:
no evidence of "bar" in the output

Expected results:
"bar" emitted in some form

Additional info:
I'm actually using this in the kernel to emit things into a section, so it
doesn't matter what actual name the variable gets.

Comment 1 Jeremy Fitzhardinge 2006-09-29 23:18:28 UTC
Created attachment 137451 [details]
C source

Comment 2 Jeremy Fitzhardinge 2006-09-29 23:24:45 UTC
As a workaround, I'm adding asm("" : : "m" (bar)) to force a reference to the
variable.  Unfortunately, this seems to provoke some other bug when I use it in
the kernel; I get references to labels which don't exist.  I'll try to winnow
something down to file a separate bug.

Comment 3 Jeremy Fitzhardinge 2006-09-29 23:26:06 UTC
Created attachment 137452 [details]
.s output file I get

Comment 4 Jakub Jelinek 2006-09-30 12:01:30 UTC
I don't think that's a bug, local statics are very different from global ones.
For global statics you know their name and can reference it from asm, for
local statics if you don't reference them, you can't guess their name.

Also, this is nothing Fedora gcc specific, upstream GCC behaves the same way,
so if you insist this is a GCC bug, you should file it to upstream instead
(http://gcc.gnu.org/bugzilla/).

Comment 5 Jeremy Fitzhardinge 2006-09-30 14:11:26 UTC
As I said in the original report: "I'm actually using this in the kernel to emit
things into a section, so it doesn't matter what actual name the variable gets."
I want to emit a record for each BUG() into the __bug_table section; since BUG
is necessarily used within code, everything that happens within it needs to have
some kind of local scope. 

I thought I'd report it here in case there was some local change, but I'll
report it upstream.


Note You need to log in before you can comment on or make changes to this bug.