CFLAGS/CXXFLAGS used in our build scripts

Bug #1272732 reported by Raghavendra D Prabhu
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Percona Server moved to https://jira.percona.com/projects/PS
Fix Released
Medium
Tomislav Plavcic
5.1
Fix Released
Medium
Tomislav Plavcic
5.5
Fix Released
Medium
Tomislav Plavcic
5.6
Fix Released
Medium
Tomislav Plavcic
Percona XtraDB Cluster moved to https://jira.percona.com/projects/PXC
Status tracked in 5.6
5.5
Won't Fix
Medium
Unassigned
5.6
Fix Released
Medium
Unassigned

Bug Description

Currently we have following in our build scripts (that we use for releases):

    export CFLAGS="-fPIC -Wall -O3 -g -static-libgcc -fno-omit-frame-pointer -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${CFLAGS:-}"
    export CXXFLAGS="-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${CXXFLAGS:-}"

There are a few anomalies here:

a) -Wp,-D_FORTIFY_SOURCE=2 is used only for CXXFLAGS. Why isn't
it there for CFLAGS. Also, we need to compare the costs to
performance here (also, if stack protection is really desired
then -fstack-protector --param=ssp-buffer-size=4 are required in
addition)

b) Why O3 for CFLAGS and O2 for CXXFLAGS? Again, here the
costs/benefits of O3 need to be analysed (size/icache v/s performance).

c) Is static-libstdc++ required for CXXFLAGS like static-libgcc
in CFLAGS?

In debian/rules we have

"-O3 -DBIG_JOINS=1" for CFLAGS
"-O3 -DBIG_JOINS=1 -felide-constructors -fno-exceptions -fno-rtti" for CXXFLAGS.

These also need to be checked and added to rpm build script if
needed.

Tags: pkg

Related branches

Revision history for this message
Valerii Kravchuk (valerii-kravchuk) wrote :
Download full text (3.2 KiB)

This is easy to confirm using grep:

openxs@ao756:~/bzr/percona-5.5/build-ps$ grep -n FLAGS *
build-binary.sh:17:TARGET_CFLAGS=''
build-binary.sh:48: TARGET_CFLAGS="-m32 -march=i686"
build-binary.sh:157:export CFLAGS="-fPIC -Wall -O3 -g -static-libgcc -fno-omit-frame-pointer -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${ FLAGS:-}"
build-binary.sh:158:export CXXFLAGS="-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fno-exceptions -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${CXXFLAGS:-}"
build-rpm.sh:20:TARGET_CFLAGS=''
build-rpm.sh:40: TARGET_CFLAGS="-m32 -march=i686"
build-rpm.sh:93: TARGET_CFLAGS='-m32 -march=i686'
build-rpm.sh:126:export CFLAGS="-fPIC -Wall -O3 -g -static-libgcc -fno-omit-frame-pointer -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${CFLAGS:-}"
build-rpm.sh:127:export CXXFLAGS="-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fno-exceptions -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${CXXFLAGS:-}"
build-shared-compat-rpm.sh:21:TARGET_CFLAGS=''
build-shared-compat-rpm.sh:41: TARGET_CFLAGS="-m32 -march=i686"
build-shared-compat-rpm.sh:89: TARGET_CFLAGS='-m32 -march=i686'
build-shared-compat-rpm.sh:116:export CFLAGS="-fPIC -Wall -O3 -g -static-libgcc -fno-omit-frame-pointer $TARGET_CFLAGS"
build-shared-compat-rpm.sh:117:export CXXFLAGS="-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fno-exceptions $TARGET_CFLAGS"
grep: debian: Is a directory
percona-server.spec:344: MYSQL_CFLAGS="-I $RPM_BUILD_DIR/%{src_dir}/release/include" \
percona-server.spec:357: CXXFLAGS="$CXXFLAGS -I$RPM_BUILD_DIR/%{src_dir}/release/include" \
percona-server.spec:369:# name, finally a default. RPM_OPT_FLAGS is assumed to be a part of the
percona-server.spec:378:# This is a hack, $RPM_OPT_FLAGS on ia64 hosts contains flags which break
percona-server.spec:382:RPM_OPT_FLAGS=
percona-server.spec:388:export CFLAGS=${MYSQL_BUILD_CFLAGS:-${CFLAGS:-$RPM_OPT_FLAGS}}
percona-server.spec:389:export CXXFLAGS=${MYSQL_BUILD_CXXFLAGS:-${CXXFLAGS:-$RPM_OPT_FLAGS -felide-constructors -fno-exceptions -fno-rtti}}
percona-server.spec:390:export LDFLAGS=${MYSQL_BUILD_LDFLAGS:-${LDFLAGS:-}}
percona-server.spec:408: CFLAGS=`echo " ${CFLAGS} " | \
percona-server.spec:414: CXXFLAGS=`echo " ${CXXFLAGS} " | \
percona-server.spec:479: libgcc=`$CC $CFLAGS --print-libgcc-file`
percona-server.spec:1341:- Modify CFLAGS and CXXFLAGS such that a debug build is not optimized.
percona-server.spec:1402:- Add CFLAGS to gcc call with --print-libgcc-file, to make sure the
percona-server.spec:1494:- Set $LDFLAGS from $MYSQL_BUILD_LDFLAGS
percona-server.spec:1809:- CFLAGS and CXXFLAGS should honor RPM_OPT_FLAGS
grep: rpm: Is a directory
openxs@ao756:~/bzr/percona-5.5/build-ps$ grep -n FLAGS debian/*
grep: debian/additions: Is a directory
grep: debian/patches: Is a directory
grep: debian/po: Is a directory
debian/rules:81: CFLAGS=$${MYSQL_BUILD_CFLAGS:-"-O3 -DBIG_JOINS=1"} \
debian/rules:83: CXXFLAGS=$${MYSQL_BUILD_CXXFLAGS:-"-O3 -DBIG_JOINS=1 -felide-constructors -fno-exceptio...

Read more...

Revision history for this message
Valerii Kravchuk (valerii-kravchuk) wrote :

In case of 5.6:

openxs@ao756:~/bzr/percona-5.6/build-ps$ grep -rn FLAGS *
build-binary.sh:17:TARGET_CFLAGS=''
build-binary.sh:47: TARGET_CFLAGS="-m32 -march=i686"
build-binary.sh:157:export CFLAGS="-fPIC -Wall -O3 -g -static-libgcc -fno-omit-frame-pointer -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${ FLAGS:-}"
build-binary.sh:158:export CXXFLAGS="-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${CXXFLAGS:-}"
build-rpm.sh:20:TARGET_CFLAGS=''
build-rpm.sh:40: TARGET_CFLAGS="-m32 -march=i686"
build-rpm.sh:93: TARGET_CFLAGS='-m32 -march=i686'
build-rpm.sh:126:export CFLAGS="-fPIC -Wall -O3 -g -static-libgcc -fno-omit-frame-pointer -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${CFLAGS:-}"
build-rpm.sh:127:export CXXFLAGS="-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${CXXFLAGS:-}"
debian/rules:81: CFLAGS=$${MYSQL_BUILD_CFLAGS:-"-O3 -DBIG_JOINS=1"} \
debian/rules:83: CXXFLAGS=$${MYSQL_BUILD_CXXFLAGS:-"-O3 -DBIG_JOINS=1 -felide-constructors -fno-exceptions -fno-rtti"} \
percona-server.spec:340: CXXFLAGS="$CXXFLAGS -I$RPM_BUILD_DIR/%{src_dir}/release/include" \
percona-server.spec:352:# name, finally a default. RPM_OPT_FLAGS is assumed to be a part of the
percona-server.spec:361:# This is a hack, $RPM_OPT_FLAGS on ia64 hosts contains flags which break
percona-server.spec:365:RPM_OPT_FLAGS=
percona-server.spec:371:export CFLAGS=${MYSQL_BUILD_CFLAGS:-${CFLAGS:-$RPM_OPT_FLAGS}}
percona-server.spec:372:export CXXFLAGS=${MYSQL_BUILD_CXXFLAGS:-${CXXFLAGS:-$RPM_OPT_FLAGS -felide-constructors -fno-rtti}}
percona-server.spec:373:export LDFLAGS=${MYSQL_BUILD_LDFLAGS:-${LDFLAGS:-}}
percona-server.spec:391: CFLAGS=`echo " ${CFLAGS} " | \
percona-server.spec:397: CXXFLAGS=`echo " ${CXXFLAGS} " | \
percona-server.spec:470: libgcc=`$CC $CFLAGS --print-libgcc-file`
percona-server.spec:1277:- Modify CFLAGS and CXXFLAGS such that a debug build is not optimized.
percona-server.spec:1338:- Add CFLAGS to gcc call with --print-libgcc-file, to make sure the
percona-server.spec:1430:- Set $LDFLAGS from $MYSQL_BUILD_LDFLAGS
percona-server.spec:1745:- CFLAGS and CXXFLAGS should honor RPM_OPT_FLAGS

Revision history for this message
Valerii Kravchuk (valerii-kravchuk) wrote :

More or less the same for 5.1 also, in build directory (notably more hits):

...
build-rpm.sh:124:export CFLAGS="-fPIC -Wall -O3 -g -static-libgcc -fno-omit-frame-pointer -DPERCONA_INNODB_VERSION=$PERCONA_INNODB_VERSION $TARGET_CFLAGS"
build-rpm.sh:125:export CXXFLAGS="-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fno-exceptions -DPERCONA_INNODB_VERSION=$PERCONA_INNODB_VERSION $TARGET_CFLAGS"
...

openxs@ao756:~/bzr/percona-5.1/build$ grep -n FLAGS debian/*
grep: debian/additions: Is a directory
grep: debian/patches: Is a directory
grep: debian/po: Is a directory
debian/rules:75: CFLAGS=$${MYSQL_BUILD_CFLAGS:-"-O3 -DBIG_JOINS=1 ${FORCE_FPIC_CFLAGS}"} \
debian/rules:77: CXXFLAGS=$${MYSQL_BUILD_CXXFLAGS:-"-O3 -DBIG_JOINS=1 -felide-constructors -fno-exceptions -fno-rtti ${FORCE_FPIC_CFLAGS}"} \

Revision history for this message
Valerii Kravchuk (valerii-kravchuk) wrote :
Download full text (4.0 KiB)

Same with Percona XTraDB Cluster 5.5:

...
build-binary.sh:170:export CFLAGS="-fPIC -Wall -O3 -g -static-libgcc -fno-omit-frame-pointer -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${ FLAGS:-}"
build-binary.sh:171:export CXXFLAGS="-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fno-exceptions -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${CXXFLAGS:-}"
build-dpkg.sh:102:export CFLAGS="-fPIC -Wall -O3 -g -static-libgcc -fno-omit-frame-pointer -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION ${CFLAGS:-}"
build-dpkg.sh:103:export CXXFLAGS="-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fno-exceptions -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION ${CXXFLAGS:-}"
...

and 5.6:

openxs@ao756:~/bzr/pxc-5.6/build$ grep -rn FLAGS *
build-binary-nobzr.sh:17:TARGET_CFLAGS=''
build-binary-nobzr.sh:45: TARGET_CFLAGS="-m32 -march=i686"
build-binary-nobzr.sh:155:export CFLAGS="-fPIC -Wall -O3 -g -static-libgcc -fno-omit-frame-pointer -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${CFLAGS:-}"
build-binary-nobzr.sh:156:export CXXFLAGS="-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${CXXFLAGS:-}"
build-binary.sh:17:TARGET_CFLAGS=''
build-binary.sh:50: TARGET_CFLAGS="-m32 -march=i686"
build-binary.sh:175:export CFLAGS="-fPIC -Wall -O3 -g -static-libgcc -fno-omit-frame-pointer -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${ FLAGS:-}"
build-binary.sh:176:export CXXFLAGS="-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${CXXFLAGS:-}"
build-dpkg.sh:104:export CFLAGS="-fPIC -Wall -O3 -g -static-libgcc -fno-omit-frame-pointer -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION ${CFLAGS:-}"
build-dpkg.sh:105:export CXXFLAGS="-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION ${CXXFLAGS:-}"
build-dpkg.sh:137: DEB_CFLAGS_APPEND="$CFLAGS" DEB_CXXFLAGS_APPEND="$CXXFLAGS" \
build-rpm.sh:20:TARGET_CFLAGS=''
build-rpm.sh:40: TARGET_CFLAGS="-m32 -march=i686"
build-rpm.sh:93: TARGET_CFLAGS='-m32 -march=i686'
build-rpm.sh:130:export CFLAGS="-fPIC -Wall -O3 -g -static-libgcc -fno-omit-frame-pointer -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${CFLAGS:-}"
build-rpm.sh:131:export CXXFLAGS="-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION $TARGET_CFLAGS ${CXXFLAGS:-}"
debian/rules:67: CXX="$${UDF_CXX:-g++}" CXXFLAGS="$(CXXFLAGS) -I$(CURDIR)/release/include" \
percona-xtradb-cluster.spec:416: CXXFLAGS="$CXXFLAGS -I$RPM_BUILD_DIR/%{src_dir}/release/include" \
percona-xtradb-cluster.spec:428:# name, finally a default. RPM_OPT_FLAGS is assumed to be a part of the
percona-xtradb-cluster.spec:437:# This is a hack, $RPM_OPT_FLAGS on ia64 hosts contains flags which break
percona-xtradb-cluster.spec:441:RPM_OPT_FLAGS=
percona-xtradb-cluster.spec:447:export CFLAGS=${MYSQL_BUILD_CFLAGS:-${CFLAGS:-$RPM_OPT_FLAGS}}
perc...

Read more...

tags: added: pkg
Revision history for this message
Raghavendra D Prabhu (raghavendra-prabhu) wrote :

For last 5.6 release, I only fixed point a and b. Not sure about
c or the debian/rules one.

For debian, will check after merging layout changes (which has
fixed some of these).

Revision history for this message
Raghavendra D Prabhu (raghavendra-prabhu) wrote :

With latest merges/build changes, everything should be fine (even in PS) except:

"-O3 -DBIG_JOINS=1" for CFLAGS
"-O3 -DBIG_JOINS=1 -felide-constructors -fno-exceptions -fno-rtti" for CXXFLAGS.

a) There is no BIG_JOINS in the code.

b) Why are "-felide-constructors -fno-exceptions -fno-rtti" only passed for debian? and are they really required?

Revision history for this message
Alexey Bychko (abychko) wrote :

from Ubuntu precise.

apt-get source mysql-5.5

from debian/rules:
               CFLAGS=$${MYSQL_BUILD_CFLAGS:-"-O2 -DBIG_JOINS=1 ${FORCE_FPIC_CFLAGS} -fno-strict-aliasing"} \
                CXX=$${MYSQL_BUILD_CXX:-g++} \
                CXXFLAGS=$${MYSQL_BUILD_CXXFLAGS:-"-O3 -DBIG_JOINS=1 -felide-constructors -fno-exceptions -fno-rtti ${FORCE_FPIC_CFLAGS} -fno-strict-aliasin
g"} \

Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PXC-1097

Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PS-1472

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.