Bug 208667

Summary: gcc "used" attribute has no effect on local-scope static variables
Product: [Fedora] Fedora Reporter: Jeremy Fitzhardinge <jeremy>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 6   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-09-30 12:01:30 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
C source
none
.s output file I get none

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.