Project

General

Profile

Bug #3718

Sun CC ignores 'volatile' for static variables

Added by Marcel Telka over 7 years ago. Updated over 7 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
tools - gate/build tools
Start date:
2013-04-14
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage
Gerrit CR:

Description

If there is an optimization turned on for Sun CC (-xO1 or better), then the 'volatile' keyword is ignored for global static variables:

$ cat src.c 
static volatile int var = 0x1234;

int main(void)
{
    return var;
}
$ /opt/SUNWspro/bin/cc -xO1 -o a.out src.c
$ echo main::dis | mdb a.out 
main:                           pushl  %ebp
main+1:                         movl   %esp,%ebp
main+3:                         movl   $0x1234,%eax
main+8:                         leave  
main+9:                         ret    
$

Since the illumos gate is compiled with -xO3, then it is possible that at least some 'static volatile' variables are not compiled as expected.

http://src.illumos.org/source/search?q=%22static+volatile%22&project=illumos-gate

Possible workarounds:
  • Do not use optimization
  • Remove the 'static' keyword
  • Use gcc
#1

Updated by Rich Lowe over 7 years ago

If this is another instance of wanting tunables, just make them not static.

#2

Updated by Marcel Telka over 7 years ago

Rich Lowe wrote:

If this is another instance of wanting tunables, just make them not static.

Yes, I found this when I played with tunables. And yes, non-static is one of the possible workarounds as I stated in the Description.

#3

Updated by Ian Collins over 7 years ago

This issue only appears if the variable is initialised at declaration. Fortunately most "static volatile" variables in the code aren't. If this were to be fixed, separating the initialisation from the declaration should do the job.

Also available in: Atom PDF