gcc O2选项造成的错误
装apache结果出错,invalid argument
debug了一下apache的代码,发现GCC编译时带上了O2的选项,造成了函数调用fstat()出错。
于是我试着自己写了一段测试代码,分别用默认不带优化和带O2优化两种编译,结果果然不带编译的没问题,带了O2选项的返回一个errno为22的“invalid argument”.
测试环境为:
ivan@Redhat101:/localhome/ivan> uname -a
Linux Redhat101 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:39 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
ivan@Redhat101:/localhome/ivan> gcc --version
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
测试代码为:
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
int main ( int argc, char *argv[] )
{
int fd1=-1;
struct stat info1;
fd1=open("/localhome/kana/lingc.txt", O_RDWR);
printf("fd1=%d",fd1);
if(fd1 > 0)
{
if(fstat(fd1,&info1)!=0)
printf("failed to open fd1:%d;errorno:%d\n",fd1,errno);
else printf("sucess");
close(fd1);
}
return 0;
}
请各位指教一下。
或者手头刚好有32位的机器也帮忙验证下,是不是32位就没有这个问题。