This service will be undergoing maintenance at 00:00 UTC, 2017-10-23 It is expected to last about 30 minutes
Bug 490821 - [RHEL5] Optimizing Causes Incorrect "errno"
[RHEL5] Optimizing Causes Incorrect "errno"
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: glibc (Show other bugs)
5.3
All Linux
low Severity medium
: rc
: ---
Assigned To: Jakub Jelinek
BaseOS QE
:
Depends On:
Blocks: 490822
  Show dependency treegraph
 
Reported: 2009-03-18 03:47 EDT by CAI Qian
Modified: 2009-09-02 07:45 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 490822 (view as bug list)
Environment:
Last Closed: 2009-09-02 07:45:57 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Sourceware 3493 None None None Never

  None (edit)
Description CAI Qian 2009-03-18 03:47:38 EDT
Description of problem:
If compile the following program with -O2. The "errno" is incorrect.

#include <stdio.h>
#include <errno.h>
#include <unistd.h>

int
main(void)
{
  int retval;

  errno = 0;
  retval = sysconf(-1);
  printf ("retval = %d, errno = %d\n", retval, errno);

  return 0;
}

# gcc -O2 errno.c -o errno
# ./errno
retval = -1, errno = 0

Without compilation optimization, it works fine.
# gcc errno.c -o errno
# ./errno
retval = -1, errno = 22

It is also fine even with -O2, if remove the line "errno = 0;" from the program.

RHEL4-U7 has the same problem.

Version-Release number of selected component (if applicable):
gcc-4.1.2-44.el5
gcc-3.4.6-10

How reproducible:
always

Steps to Reproduce:
1. compile the reproducer with -O2
2. run the reproducer.
  
Actual results:
retval = -1, errno = 0

Expected results:
retval = -1, errno = 22

Additional info:
Comment 1 CAI Qian 2009-03-18 03:56:57 EDT
Looks like gcc in Fedora 10 works fine.

# cat errno.c
#include <stdio.h>
#include <errno.h>
#include <unistd.h>

int
main(void)
{
  int retval;

  errno = 0;
  retval = sysconf(-1);
  printf ("retval = %d, errno = %d\n", retval, errno);

  return 0;
}

# gcc -O2 errno.c -o errno
# ./errno
retval = -1, errno = 22

# rpm -qf /usr/bin/gcc
gcc-4.3.2-7.i386
Comment 2 Jakub Jelinek 2009-03-18 05:29:25 EDT
That's because sysconf used to have const attribute up to 2006-11-09.
Comment 9 errata-xmlrpc 2009-09-02 07:45:57 EDT
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2009-1415.html

Note You need to log in before you can comment on or make changes to this bug.