Red Hat Bugzilla – Bug 490821
[RHEL5] Optimizing Causes Incorrect "errno"
Last modified: 2009-09-02 07:45:57 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:
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
That's because sysconf used to have const attribute up to 2006-11-09.
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