Bug #37582 Insufficient filtering of CXXFLAGS before configure tests causes wrong results
Submitted: 23 Jun 2008 12:47 Modified: 13 Oct 2010 9:03
Reporter: Nico R. Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:5.0.54, 6.0, probably all OS:Any
Assigned to: Davi Arnaut CPU Architecture:Any
Tags: Contribution

[23 Jun 2008 12:47] Nico R.
Description:
configure.in and config/ac-macros/misc.m4 in mysql-5.0.54 fail to filter out parts of CXXFLAGS correctly. This results in wrong test results for configure tests.

For example, one of the tests returns to use ‘size_socket’ instead of ‘socklen_t’ on my system, which causes the code not to compile.

The problem is that ‘-Werror’ is added for some tests, but some flags are not filtered out which might cause warning messages. These warnings become errors which cause tests to fail, even if they would otherwise succeed.

While I have found and examined this bug with mysql-5.0.54, the sources of mysql-5.0.64-20080623 seem to be affected, too. I cannot comment on whether the 5.1 code is also affected, but I assume yes. This should be fixed in all versions, of course.

Use the following command to find the problematic lines:
  grep 'CXXFLAGS=.*sed' configure.in config/ac-macros/misc.m4

How to repeat:
Compile mysql-5.0.54 with, for example, the following flags (and no other options controlling language dialect or warning/error reporting) in CXXFLAGS:
  -Wall -Wformat-y2k -pedantic-errors

(The last one is just to show that the sed expression to remove ‘-pedantic’ will also change ‘-pedantic-errors’ into ‘-errors’.)

Suggested fix:
The following notes apply when using gcc-4.3.1 for compilation. For other compilers/versions, these lists may be incomplete. Additions of flags in order to fix problems (like ‘-Wformat’, because ‘-Wall’ is filtered out[*]) would result in errors if the added flags were not available for the used compiler and version. Look at the gcc documentation or run some tests to see the effect.

[*] Please note that ‘-Wall’ implies ‘-Wformat’.

Flags that should be removed in case ‘-Wformat’ is not set (note that its syntax allows ‘-Wformat=num’):
  -Wformat-y2k
  -Wformat-extra-args
  -Wformat-nonliteral
  -Wformat-security

Note that ‘-Wformat-zero-length’ is not a problem, because this flag does not apply to C++. Users having it in their CXXFLAGS should fix their settings, this belongs into CFLAGS, if anywhere.

If these two flags appear together, at least one of them should be removed:
  -fbranch-target-load-optimize
  -fbranch-target-load-optimize2

These flags should be removed unconditionally:
  -pedantic-errors  (if changing the sed lines, remove it /before/ ‘-pedantic’, of course)
  -std=…  (untested, but I do not know of any machines on which it would be necessary in order to compile MySQL)

Flags like ‘-Werror=foo’ must be handled correctly as well, for example, the following combination would work:
  -Werror=format -Wformat-y2k

while this one would not:
  -Wformat-y2k

Maybe it would be better to filter out all of the following flags unconditionally if gcc is used:
  -W[…]
  -pedantic
  -pedantic-errors
  -ansi
  -std=…
  maybe other flags listed under “Options Controlling C Dialect” or “Options Controlling C++ Dialect” in the gcc manual

Filtering out ‘-fsyntax-only’ is theoretically correct; however, it would be impossible to compile mysql-5.0.54 with it anyway.

I have no idea whether adding ‘-w’ would work, but I think it would be better to remove all these flags instead of adding ‘-w’, just to be on the safe side (and to make things easier to read/debug).
[23 Jun 2008 12:51] Nico R.
Patch to work around some of the issues noted in this bug report. Far from sufficient to fix the bug!

Attachment: mysql-5.0.54-broken_configure_CXXFLAGS_parsing__partial_patch-1.patch (application/octet-stream, text), 4.20 KiB.

[24 Jun 2008 16:21] Hartmut Holzgraefe
Verified, also affects latest 6.0 tree (could not see -pedantic-errors being rewritten to -errors though):

$ CXXFLAGS="-Wall -Wformat-y2k -pedantic-errors" ./configure && make
[...]
if g++ -DDEFAULT_BASEDIR=\"/usr/local\" -DDATADIR="\"/usr/local/var\"" -DDEFAULT_CHARSET_HOME="\"/usr/local\"" -DSHAREDIR="\"/usr/local/share/mysql\"" -DDEFAULT_HOME_ENV=MYSQL_HOME -DDEFAULT_GROUP_SUFFIX_ENV=MYSQL_GROUP_SUFFIX -DDEFAULT_SYSCONFDIR="\"/usr/local/etc\"" -DHAVE_CONFIG_H -I. -I. -I../include -I../include -I../include -I.    -Wall -Wformat-y2k -pedantic-errors   -fno-implicit-templates -fno-exceptions -fno-rtti -MT my_new.o -MD -MP -MF ".deps/my_new.Tpo" -c -o my_new.o my_new.cc; \
	then mv -f ".deps/my_new.Tpo" ".deps/my_new.Po"; else rm -f ".deps/my_new.Tpo"; exit 1; fi
In file included from mysys_priv.h:16,
                 from my_new.cc:21:
../include/my_global.h:1011: error: ISO C++ does not support ‘long long’
../include/my_global.h:1012: error: ISO C++ does not support ‘long long’
../include/my_global.h:1030: error: ISO C++ does not support ‘long long’
make[1]: *** [my_new.o] Error 1
make[1]: Leaving directory `/home/hartmut/projects/mysql/bzr/mysql-6.0/mysys'
make: *** [all-recursive] Error 1
[26 Jun 2008 22:09] Nico R.
Hartmut, the rewritten form is only used in the configure script. You could insert something like
  echo "$CXXFLAGS" > /tmp/CXXFLAGS_used
into the autoconf files in order to see it.

I used
  echo "$CXXFLAGS"
  exit 0
after a line containing such a sed replacement in order to verify the problem (but configure exited then, of course).

Thanks!
[15 Sep 2009 15:51] Liz Drachnik
Hello Nico

In order for us to continue the process of reviewing your contribution to MySQL - We need
you to review and sign the Sun|MySQL contributor agreement (the "SCA")

The process is explained here: 
http://forge.mysql.com/wiki/Sun_Contributor_Agreement

Getting a signed/approved SCA on file will help us facilitate your contribution-- this
one, and others in the future.

Thank you !
[15 Oct 2009 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[13 Oct 2010 9:03] Konstantin Osipov
This has been around since 4.0.
In 5.5 we moved off autotools and use cmake, where the bug is not present.
For 5.1 and below, the bug will not be fixed.