Bug 495296

Summary: Optimization Causes Modify LDT Code Returns a Different Value
Product: [Fedora] Fedora Reporter: Qian Cai <qcai>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: 10CC: drepper, jakub
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-04-11 16:43:41 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
Test Program none

Description Qian Cai 2009-04-11 10:58:56 UTC
Description of problem:
The attached code returns different values with and without compilation optimization.

$ gcc -Wall modify_ldt.c -o modify_ldt
$ ./modify_ldt 
a = 42
a = 99
PASS

$ gcc -Wall -O1 modify_ldt.c -o modify_ldt
$ ./modify_ldt 
a = 42
a = 42
FAIL

Version-Release number of selected component (if applicable):
glibc-2.9-3.i686
gcc-4.3.2-7.i386
kernel-2.6.27.5-117.fc10.i686

How reproducible:
always

The code is based on Ulrich Drepper's test -- Make sure LDT is propagated correctly.

Comment 1 Qian Cai 2009-04-11 11:00:22 UTC
Created attachment 339169 [details]
Test Program

Comment 2 Ulrich Drepper 2009-04-11 16:43:41 UTC
The test code isn't correct.  The compiler cannot look inside the asm statements in main() and see that they are really necessary.  Based on the information given the compiler can drop some of them.

Change all asms in main from

  asm(...)

to

  asm volatile(...)

and the code works fine.

Comment 3 Qian Cai 2009-04-12 05:32:54 UTC
Thanks Ulrich! I have fixed the test program, and it works fine indeed.