Red Hat Bugzilla – Bug 208667
gcc "used" attribute has no effect on local-scope static variables
Last modified: 2007-11-30 17:11:44 EST
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):
All the time
Steps to Reproduce:
1.compile the attached file with "gcc -O -S t.c"
no evidence of "bar" in the output
"bar" emitted in some form
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.
Created attachment 137451 [details]
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.
Created attachment 137452 [details]
.s output file I get
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
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.