Bug 208667 - gcc "used" attribute has no effect on local-scope static variables
gcc "used" attribute has no effect on local-scope static variables
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
6
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2006-09-29 19:18 EDT by Jeremy Fitzhardinge
Modified: 2007-11-30 17:11 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-09-30 08:01:30 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


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


External Trackers
Tracker ID Priority Status Summary Last Updated
GNU Compiler Collection 29299 None None None Never

  None (edit)
Description Jeremy Fitzhardinge 2006-09-29 19:18:28 EDT
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 19:18:28 EDT
Created attachment 137451 [details]
C source
Comment 2 Jeremy Fitzhardinge 2006-09-29 19:24:45 EDT
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 19:26:06 EDT
Created attachment 137452 [details]
.s output file I get
Comment 4 Jakub Jelinek 2006-09-30 08:01:30 EDT
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 10:11:26 EDT
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.