kanaka / wac

WebAssembly interpreter in C
Other
469 stars 44 forks source link

-Wformat error #10

Closed IngwiePhoenix closed 5 years ago

IngwiePhoenix commented 5 years ago
platform_libc.c:18:53: error: format specifies type 'int' but the argument has type 'unsigned long' [-Werror,-Wformat]
        FATAL("Could not allocate %d bytes for %s", (int)nmemb * size, name);
                                  ~~                ^~~~~~~~~~~~~~~~~
                                  %lu
./util.h:20:21: note: expanded from macro 'FATAL'
    fprintf(stderr, __VA_ARGS__); exit(1); \
                    ^~~~~~~~~~~
platform_libc.c:28:53: error: format specifies type 'int' but the argument has type 'unsigned long' [-Werror,-Wformat]
        FATAL("Could not allocate %d bytes for %s", (int)nmemb * size, name);
                                  ~~                ^~~~~~~~~~~~~~~~~
                                  %lu
./util.h:20:21: note: expanded from macro 'FATAL'
    fprintf(stderr, __VA_ARGS__); exit(1); \
                    ^~~~~~~~~~~
2 errors generated.
make: *** [platform_libc.o] Error 1

I can fix the Makefile on my own but you may want to fix this. :)

IngwiePhoenix commented 5 years ago

Also as a side note, on Mac OS, this happens later on:

Ingwie@Ingwies-MBP.fritz.box ~/W/g/wac $ emmake make 
gcc  -DPLATFORM=1 -std=gnu99 -m32 -g -c wa.c -o wa.o
gcc  -DPLATFORM=1 -std=gnu99 -m32 -g -c util.c -o util.o
gcc  -DPLATFORM=1 -std=gnu99 -m32 -g -c thunk.c -o thunk.o
gcc  -DPLATFORM=1 -std=gnu99 -m32 -g -c platform_libc.c -o platform_libc.o
platform_libc.c:18:53: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
        FATAL("Could not allocate %d bytes for %s", (int)nmemb * size, name);
                                  ~~                ^~~~~~~~~~~~~~~~~
                                  %lu
./util.h:20:21: note: expanded from macro 'FATAL'
    fprintf(stderr, __VA_ARGS__); exit(1); \
                    ^~~~~~~~~~~
platform_libc.c:28:53: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
        FATAL("Could not allocate %d bytes for %s", (int)nmemb * size, name);
                                  ~~                ^~~~~~~~~~~~~~~~~
                                  %lu
./util.h:20:21: note: expanded from macro 'FATAL'
    fprintf(stderr, __VA_ARGS__); exit(1); \
                    ^~~~~~~~~~~
2 warnings generated.
ar rcs wa.a wa.o util.o thunk.o platform_libc.o
gcc  -DPLATFORM=1 -std=gnu99 -m32 -g -c wac.c -o wac.o
gcc  -DPLATFORM=1 -std=gnu99 -m32 -g -rdynamic -Wl,--no-as-needed -o wac \
        -Wl,--start-group wa.a wac.o -Wl,--end-group -lm -ldl -ledit
ld: unknown option: --no-as-needed
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [wac] Error 1
kanaka commented 5 years ago

@IngwiePhoenix I wasn't seeing those warning with my version of gcc (5.4.0) but I've pushed changes that should fix that. Can you check and verify that it builds for you?

IngwiePhoenix commented 5 years ago

On OS X, the default compiler is LLVM Clang. Howeve,r as you mentioned GCC, I decided to change my make invocation into this:

Ingwie@Ingwies-Macbook-Pro.local ~/W/g/wac $ env HOST_CC=/usr/local/opt/gcc/bin/gcc-8 CFLAGS="-I "(xcrun --show-sdk-path)/usr/include make
/usr/local/opt/gcc/bin/gcc-8 -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -DPLATFORM=1 -std=gnu99 -m32 -g -c wa.c -o wa.o
/usr/local/opt/gcc/bin/gcc-8 -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -DPLATFORM=1 -std=gnu99 -m32 -g -c util.c -o util.o
/usr/local/opt/gcc/bin/gcc-8 -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -DPLATFORM=1 -std=gnu99 -m32 -g -c thunk.c -o thunk.o
/usr/local/opt/gcc/bin/gcc-8 -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -DPLATFORM=1 -std=gnu99 -m32 -g -c platform_libc.c -o platform_libc.o
ar rcs wa.a wa.o util.o thunk.o platform_libc.o
/usr/local/opt/gcc/bin/gcc-8 -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -DPLATFORM=1 -std=gnu99 -m32 -g -c wac.c -o wac.o
/usr/local/opt/gcc/bin/gcc-8 -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -DPLATFORM=1 -std=gnu99 -m32 -g -rdynamic -Wl,--no-as-needed -o wac \
        -Wl,--start-group wa.a wac.o -Wl,--end-group -lm -ldl -ledit
ld: unknown option: --no-as-needed
collect2: error: ld returned 1 exit status
make: *** [wac] Error 1

Note, I am using the Fish shell - that is why the command substition is a little bit off and weird-looking.

But as you see, warnings gone! :)

kanaka commented 5 years ago

That means that the ld on OS X doesn't support the --no-as-needed flag. I suspect that you can probably drop that flag and you should be okay. It might not be needed on Linux (I think --no-as-needed is default but there was a valid reason I needed it in the past). But it will probably be a while before I can around to testing that for sure. I'm going to close the bug for now since the issue is specific to OS X ld.