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

Also available in: Atom PDF