Bug #64506 overriding '-O3' with '-O2' during configure
Submitted: 1 Mar 2012 7:21 Modified: 5 Mar 2012 8:57
Reporter: Neil Armstrong Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Compiling Severity:S2 (Serious)
Version:5.5.21, 5.5.23 OS:Linux (CentOS 5.6, FC14)
Assigned to: CPU Architecture:Any
Triage: Needs Triage: D2 (Serious)

[1 Mar 2012 7:21] Neil Armstrong
Description:
CXX flag -O2 is not overrided by manually set flag -O3 even by:
-DCMAKE_CXX_FLAGS="-O3"

How to repeat:
cmake \
-DCMAKE_C_COMPILER=/opt/intel/bin/icc \
-DCMAKE_CXX_COMPILER=/opt/intel/bin/icpc \
-DCMAKE_C_FLAGS="-O3" \
-DCMAKE_CXX_FLAGS="-O3"

cat /root/src/mysql-5.5.21/sql/CMakeFiles/mysqld.dir/flags.make

we see the flags:
---
# compile CXX with /opt/intel/bin/icpc
CXX_FLAGS = -O3 -O2 -g -DDBUG_OFF -I/root/src/mysql-5.5.21/include -I/root/src/mysql-5.5.21/sql -I/root/src/mysql-5.5.21/regex

CXX_DEFINES = -Dmysqld_EXPORTS -DHAVE_CONFIG_H -DMYSQL_SERVER -DHAVE_EVENT_SCHEDULER
---

make

and we get
---
icpc: command line warning #10120: overriding '-O3' with '-O2'
[1 Mar 2012 7:55] Valeriy Kravchuk
Looks either 5.5.21 or Intel compiler specific problem. This is what I get with 5.5.23 and gcc:

[openxs@chief mysql-5.5-work]$ cmake \
> -DCMAKE_C_FLAGS="-O3" \
> -DCMAKE_CXX_FLAGS="-O3"
-- MySQL 5.5.23
-- C warning options: -Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Werror -Wdeclaration-after-statement
-- C++ warning options: -Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Werror -Wno-unused-parameter -Woverloaded-virtual
gcc:  --pipe: No such file or directory
-- Configuring done
-- Generating done
-- Build files have been written to: /home/openxs/bzr/mysql-5.5-work
[openxs@chief mysql-5.5-work]$ cat sql/CMakeFiles/mysqld.dir/flags.make
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8

# compile CXX with /usr/bin/gcc
CXX_FLAGS = -O3 -fPIC -Wall -Wno-unused-parameter -fno-implicit-templates -fno-exceptions -fno-rtti -Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Werror -Wno-unused-parameter -Woverloaded-virtual -g -DENABLED_DEBUG_SYNC -DSAFE_MUTEX -I/home/openxs/bzr/mysql-5.5-work/include -I/home/openxs/bzr/mysql-5.5-work/sql -I/home/openxs/bzr/mysql-5.5-work/regex -I/home/openxs/bzr/mysql-5.5-work/extra/yassl/include -I/home/openxs/bzr/mysql-5.5-work/extra/yassl/taocrypt/include   -DHAVE_YASSL -DYASSL_PURE_C -DYASSL_PREFIX -DHAVE_OPENSSL -DYASSL_THREAD_SAFE

CXX_DEFINES = -Dmysqld_EXPORTS -DHAVE_CONFIG_H -DMYSQL_SERVER -DHAVE_EVENT_SCHEDULER
[1 Mar 2012 13:26] Neil Armstrong
And what I get with 5.5.21 and GCC:

cmake \
-DCMAKE_C_FLAGS="-O3" \
-DCMAKE_CXX_FLAGS="-O3"

cat sql/CMakeFiles/mysqld.dir/flags.make

we see the flags:
----
# compile CXX with /usr/bin/c++
CXX_FLAGS = -O3 -Wall -Wno-unused-parameter -fno-implicit-templates -fno-exceptions -fno-rtti -O2 -g -DDBUG_OFF -I/root/src/mysql-5.5.21/include -I/root/src/mysql-5.5.21/sql -I/root/src/mysql-5.5.21/regex

CXX_DEFINES = -Dmysqld_EXPORTS -DHAVE_RESPONSE_TIME_DISTRIBUTION -DHAVE_CONFIG_H -DMYSQL_SERVER -DHAVE_EVENT_SCHEDULER
-----------------------------------------------------------

5.5.21 and ICC:

cmake \
-DCMAKE_C_COMPILER=/opt/intel/bin/icc \
-DCMAKE_CXX_COMPILER=/opt/intel/bin/icpc \
-DCMAKE_C_FLAGS="-O3" \
-DCMAKE_CXX_FLAGS="-O3"

cat /root/src/mysql-5.5.21/sql/CMakeFiles/mysqld.dir/flags.make

we see the flags:
---
# compile CXX with /opt/intel/bin/icpc
CXX_FLAGS = -O3 -O2 -g -DDBUG_OFF -I/root/src/mysql-5.5.21/include
-I/root/src/mysql-5.5.21/sql -I/root/src/mysql-5.5.21/regex

CXX_DEFINES = -Dmysqld_EXPORTS -DHAVE_CONFIG_H -DMYSQL_SERVER -DHAVE_EVENT_SCHEDULER
-----------------------------------------------------------

A you can see the same result with -O3 and -O2 in one string. It makes impossible to set -O3 optimization..
[3 Mar 2012 6:47] Valeriy Kravchuk
Tried on Mac OS X this time:

...
macbook-pro:mysql-5.5-work openxs$ cat sql/CMakeFiles/mysqld.dir/flags.make
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8

# compile CXX with /usr/bin/gcc
CXX_FLAGS = -O3 -Wall -Wno-unused-parameter -fno-implicit-templates -fno-exceptions -fno-rtti -I/Users/openxs/bzr2/mysql-5.5-work/include -I/Users/openxs/bzr2/mysql-5.5-work/sql -I/Users/openxs/bzr2/mysql-5.5-work/regex  

CXX_DEFINES = -Dmysqld_EXPORTS -DDBUG_OFF -DHAVE_CONFIG_H -DMYSQL_SERVER -DHAVE_EVENT_SCHEDULER

macbook-pro:mysql-5.5-work openxs$ cmake --version
cmake version 2.8.1

I wonder what version of cmake do you use?
[3 Mar 2012 6:55] Neil Armstrong
The latest cmake version 2.8.7 from http://www.cmake.org
[5 Mar 2012 8:57] Valeriy Kravchuk
I was finally able to repeat this on 64-bit FC14 using cmake 2.8.4:

[openxs@chief mysql-5.5-work]$ cat sql/CMakeFiles/mysqld.dir/flags.make 
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8

# compile CXX with /usr/bin/c++
CXX_FLAGS = -O3 -Wall -Wno-unused-parameter -fno-implicit-templates -fno-exceptions -fno-rtti -O2 -g -DDBUG_OFF -I/home/openxs/bzr/mysql-5.5-work/include -I/home/openxs/bzr/mysql-5.5-work/sql -I/home/openxs/bzr/mysql-5.5-work/regex  

CXX_DEFINES = -Dmysqld_EXPORTS -DHAVE_CONFIG_H -DMYSQL_SERVER -DHAVE_EVENT_SCHEDULER

[openxs@chief mysql-5.5-work]$ cmake --version
cmake version 2.8.4
[openxs@chief mysql-5.5-work]$ fc -l
988	 grep -rn '-mp' *
989	 grep -rn -- '-mp' *
990	 cmake -DCMAKE_C_FLAGS="-O3" -DCMAKE_CXX_FLAGS="-O3"
991	 cat sql/CMakeFiles/mysqld.dir/flags.make 
992	 cmake -DCMAKE_C_COMPILER=/opt/intel/bin/icc -DCMAKE_CXX_COMPILER=/opt/intel/bin/icpc -DCMAKE_C_FLAGS="-O3" -DCMAKE_CXX_FLAGS="-O3"
993	 cd ../../dbs/5.5
994	 bin/mysqld_safe --no-defaults &
995	 bin/mysql -uroot test
996	 exit
997	 cd bzr/mysql-5.5-work/
998	 cmake -DCMAKE_C_FLAGS="-O3" -DCMAKE_CXX_FLAGS="-O3"
999	 ls -l CMake*
1000	 rm CMakeCache.txt 
1001	 cmake -DCMAKE_C_FLAGS="-O3" -DCMAKE_CXX_FLAGS="-O3"
1002	 cat sql/CMakeFiles/mysqld.dir/flags.make 
1003	 cmake --version