Re: gcc 4.8.2 -Wno-format feat/broken

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Jonathan,

On Mon, Mar 3, 2014 at 12:16 PM, Jonathan Wakely >
> There should be no warning here, because you have no specified
> -Wformat or -Wall, so that implies you are using a modified GCC, or
> "cc" is a wrapper around GCC which passes some -W options.
>
>
>> C4N1$ cc -c c.c -Wno-format     # Expect no warning
>> c.c: In function 'f':
>> c.c:13:1: warning: format '%llx' expects argument of type 'long long unsigned in
>> t', but argument 2 has type 'uint64' [-Wformat=]
>>  { return printf("a=%#llx\n",a);
>>  ^
>
> This should not warn, and doesn't when I test it.
>
> Again, it seems to me that you are using a modified GCC or a wrapper
> around it that passes additional -W options.

Well my gcc install look pretty standard I didn't made any wrapper


C4N1$ type cc
cc is a tracked alias for /usr/bin/cc

C4N1$ ll /usr/bin/cc
lrwxrwxrwx 1 root root 20 Feb 21  2007 /usr/bin/cc -> /etc/alternatives/cc

C4N1$ ll /etc/alternatives/cc
lrwxrwxrwx 1 root root 12 Feb 21  2007 /etc/alternatives/cc -> /usr/bin/gcc

C4N1$ ll /usr/bin/gcc
lrwxrwxrwx 1 root root 7 Feb 14 12:25 /usr/bin/gcc -> gcc-4.8

C4N1$ cc --version
cc (Ubuntu/Linaro 4.8.2-16ubuntu4) 4.8.2
Copyright (C) 2013 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.


C4N1$ more  /usr/bin/gcc
"/usr/bin/gcc" may be a binary file.  See it anyway?

So at this point gcc-4-8 seems not a script but a pure cc driver and
yet produce this


C4N1$ cc -v -c e.c -Wno-format
Using built-in specs.
COLLECT_GCC=cc
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.8.2-16ub
untu4' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-language
s=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --ena
ble-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-get
text --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir
=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-
debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudfla
p --disable-libitm --disable-libsanitizer --disable-libquadmath --enable-plugin
--with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-c
airo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-arm64/jre --enable-java-ho
me --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-arm64 --with-jvm-jar-dir=
/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-arm64 --with-arch-directory=arm64 --with
-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-multiarch --disable-werror --e
nable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --targ
et=aarch64-linux-gnu
Thread model: posix
gcc version 4.8.2 (Ubuntu/Linaro 4.8.2-16ubuntu4)
COLLECT_GCC_OPTIONS='-v' '-c' '-Wformat=0' <<=====

Note the -Wno-format has been catched up ok and translated into new -Wformat=0

 /usr/lib/gcc/aarch64-linux-gnu/4.8/cc1 -quiet -v -imultiarch aarch64-linux-gnu
e.c -quiet -dumpbase e.c -auxbase e -Wformat=0 -version
-fstack-protector -Wformat -Wformat-security
-o /tmp/ccqm0LDE.s

===============================
Above I am afraid -Wformat=0 is defeated by folowing -Wformat
===================================

GNU C (Ubuntu/Linaro 4.8.2-16ubuntu4) version 4.8.2 (aarch64-linux-gnu)
        compiled by GNU C version 4.8.2, GMP version 5.1.3, MPFR version 3.1.2-p
3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/aarch64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/aarch64-linux-gnu/4.8/../../../../a
arch64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/aarch64-linux-gnu/4.8/include
 /usr/local/include
 /usr/lib/gcc/aarch64-linux-gnu/4.8/include-fixed
 /usr/include/aarch64-linux-gnu
 /usr/include
End of search list.
GNU C (Ubuntu/Linaro 4.8.2-16ubuntu4) version 4.8.2 (aarch64-linux-gnu)
        compiled by GNU C version 4.8.2, GMP version 5.1.3, MPFR version 3.1.2-p
3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: b1f9640663588cd1815d2218adc6f17b
e.c: In function 'f':
e.c:10:1: warning: format '%llx' expects argument of type 'long long unsigned in
t', but argument 2 has type 'uint64' [-Wformat=]
 { return printf("a=%#llx\n",a);
 ^
COLLECT_GCC_OPTIONS='-v' '-c' '-Wformat=0'

=======================
Seems bogus to me we got the warning while it claims it collected -Wformat=0
===================

 as -v -o e.o /tmp/ccqm0LDE.s
GNU assembler version 2.24 (aarch64-linux-gnu) using BFD version (GNU Binutils f
or Ubuntu) 2.24
COMPILER_PATH=/usr/lib/gcc/aarch64-linux-gnu/4.8/:/usr/lib/gcc/aarch64-linux-gnu
/4.8/:/usr/lib/gcc/aarch64-linux-gnu/:/usr/lib/gcc/aarch64-linux-gnu/4.8/:/usr/l
ib/gcc/aarch64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/aarch64-linux-gnu/4.8/:/usr/lib/gcc/aarch64-linux-gnu/
4.8/../../../aarch64-linux-gnu/:/usr/lib/gcc/aarch64-linux-gnu/4.8/../../../../l
ib/:/lib/aarch64-linux-gnu/:/lib/../lib/:/usr/lib/aarch64-linux-gnu/:/usr/lib/..
/lib/:/usr/lib/gcc/aarch64-linux-gnu/4.8/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-c' '-Wformat=0'

C4N1$







>
>> from printf("bla %llx bla\n",a); I want to stay away from
>> printf(__LP64_?"bla %lx bla\n":"bla %llx bla\n",a);
>> Impossible to fix an all project occurences accuratly.
>
> This problem is already solved for you.
>
> Why not just use uint64_t and PRIu64?
>
> int f(uint64_t a)
> {
>   return printf("a=%#" PRIu64 "x\n",a);
> }

I was not using PRIu64   because I was ignorant of it, and the use of
uint64 instead of uint64_t is historical on this project, yet easily
changeable.

I was converging toward this kind of implementation with #if  #define
implementation, yet As you mentioned with a serious namespace
weakness, but I was trying to find a way to do it.

it is a bit ugly, yet catching in a editor "bla bla %ll bla" or
"...%#llx..." is relativly easy (may have specified in between % and
ll).

Well as editing the whole project to remove %..ll with this PRIu64 is
a bit of a burden, I will continue to use the -Wno-format, and for
broken gcc driver (or cpp or compiler), I will fake my own printf()
(using vprintf()) to defeat my broken gcc-4.8.2 and remove printf
format string check, and still pass %llx to lp64, as it seems to be
accepted, i.e for the time being the source code in the project will
still be "%llx" whatever data model we got (ilp32, lp64) and we shut
the compiler mouth with either -Wformat=0 or with an intermadiate call
to my_printf() --> vprintf() static inline.

Thanks for your help

Cheers,
Phi




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux