Opened 8 months ago
Last modified 8 months ago
#69551 new defect
libsdl2_image error with gcc: error: attributes should be specified before the declarator in a function definition
Reported by: | barracuda156 | Owned by: | |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | ports | Version: | 2.9.1 |
Keywords: | tiger, leopard, snowleopard | Cc: | jmroot (Joshua Root) |
Port: | libsdl2_image |
Description
The error confirmed on Tiger and Snow Leopard when building with gcc:
libtool: compile: /opt/local/bin/gcc-mp-7 -DPACKAGE_NAME=\"SDL2_image\" -DPACKAGE_TARNAME=\"SDL2_image\" -DPACKAGE_VERSION=\"2.8.2\" "-DPACKAGE_STRING=\"SDL2_image 2.8.2\"" -DPACKAGE_BUGREPORT=\"https://github.com/libsdl-org/SDL_image/issues\" -DPACKAGE_URL=\"\" -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DSDL_BUILD_MAJOR_VERSION=2 -DSDL_BUILD_MINOR_VERSION=8 -DSDL_BUILD_MICRO_VERSION=2 -DPACKAGE=\"SDL2_image\" -DVERSION=\"2.8.2\" -DUSE_STBIMAGE=1 -DLOAD_JPG=1 -DLOAD_PNG=1 -DLOAD_TIF=1 -DLOAD_WEBP=1 -DLOAD_BMP=1 -DLOAD_GIF=1 -DLOAD_LBM=1 -DLOAD_PCX=1 -DLOAD_PNM=1 -DLOAD_SVG=1 -DLOAD_TGA=1 -DLOAD_XCF=1 -DLOAD_XPM=1 -DLOAD_XV=1 -DLOAD_QOI=1 -DSDL_IMAGE_SAVE_PNG=1 -DSDL_IMAGE_SAVE_JPG=1 -I. -I./include -I/opt/local/include -I/opt/local/include/webp -pipe -Os -arch ppc -DSDL_IMAGE_USE_COMMON_BACKEND -D_THREAD_SAFE -I/opt/local/include/SDL2 -Wall -fvisibility=hidden -MT src/libSDL2_image_la-IMG_webp.lo -MD -MP -MF src/.deps/libSDL2_image_la-IMG_webp.Tpo -c src/IMG_webp.c -fno-common -DPIC -o src/.libs/libSDL2_image_la-IMG_webp.o libtool: compile: /opt/local/bin/gcc-mp-7 -DPACKAGE_NAME=\"SDL2_image\" -DPACKAGE_TARNAME=\"SDL2_image\" -DPACKAGE_VERSION=\"2.8.2\" "-DPACKAGE_STRING=\"SDL2_image 2.8.2\"" -DPACKAGE_BUGREPORT=\"https://github.com/libsdl-org/SDL_image/issues\" -DPACKAGE_URL=\"\" -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DSDL_BUILD_MAJOR_VERSION=2 -DSDL_BUILD_MINOR_VERSION=8 -DSDL_BUILD_MICRO_VERSION=2 -DPACKAGE=\"SDL2_image\" -DVERSION=\"2.8.2\" -DUSE_STBIMAGE=1 -DLOAD_JPG=1 -DLOAD_PNG=1 -DLOAD_TIF=1 -DLOAD_WEBP=1 -DLOAD_BMP=1 -DLOAD_GIF=1 -DLOAD_LBM=1 -DLOAD_PCX=1 -DLOAD_PNM=1 -DLOAD_SVG=1 -DLOAD_TGA=1 -DLOAD_XCF=1 -DLOAD_XPM=1 -DLOAD_XV=1 -DLOAD_QOI=1 -DSDL_IMAGE_SAVE_PNG=1 -DSDL_IMAGE_SAVE_JPG=1 -I. -I./include -I/opt/local/include -I/opt/local/include/webp -pipe -Os -arch ppc -DSDL_IMAGE_USE_COMMON_BACKEND -D_THREAD_SAFE -I/opt/local/include/SDL2 -Wall -fvisibility=hidden -MT src/libSDL2_image_la-IMG_stb.lo -MD -MP -MF src/.deps/libSDL2_image_la-IMG_stb.Tpo -c src/IMG_stb.c -o src/libSDL2_image_la-IMG_stb.o >/dev/null 2>&1 libtool: compile: /opt/local/bin/gcc-mp-7 -DPACKAGE_NAME=\"SDL2_image\" -DPACKAGE_TARNAME=\"SDL2_image\" -DPACKAGE_VERSION=\"2.8.2\" "-DPACKAGE_STRING=\"SDL2_image 2.8.2\"" -DPACKAGE_BUGREPORT=\"https://github.com/libsdl-org/SDL_image/issues\" -DPACKAGE_URL=\"\" -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DSDL_BUILD_MAJOR_VERSION=2 -DSDL_BUILD_MINOR_VERSION=8 -DSDL_BUILD_MICRO_VERSION=2 -DPACKAGE=\"SDL2_image\" -DVERSION=\"2.8.2\" -DUSE_STBIMAGE=1 -DLOAD_JPG=1 -DLOAD_PNG=1 -DLOAD_TIF=1 -DLOAD_WEBP=1 -DLOAD_BMP=1 -DLOAD_GIF=1 -DLOAD_LBM=1 -DLOAD_PCX=1 -DLOAD_PNM=1 -DLOAD_SVG=1 -DLOAD_TGA=1 -DLOAD_XCF=1 -DLOAD_XPM=1 -DLOAD_XV=1 -DLOAD_QOI=1 -DSDL_IMAGE_SAVE_PNG=1 -DSDL_IMAGE_SAVE_JPG=1 -I. -I./include -I/opt/local/include -I/opt/local/include/webp -pipe -Os -arch ppc -DSDL_IMAGE_USE_COMMON_BACKEND -D_THREAD_SAFE -I/opt/local/include/SDL2 -Wall -fvisibility=hidden -MT src/libSDL2_image_la-IMG_xv.lo -MD -MP -MF src/.deps/libSDL2_image_la-IMG_xv.Tpo -c src/IMG_xv.c -o src/libSDL2_image_la-IMG_xv.o >/dev/null 2>&1 src/IMG_webp.c:74:1: error: attributes should be specified before the declarator in a function definition int IMG_InitWEBP() ^~~ make[1]: *** [src/libSDL2_image_la-IMG_webp.lo] Error 1 make[1]: *** Waiting for unfinished jobs.... mv -f src/.deps/libSDL2_image_la-IMG_xv.Tpo src/.deps/libSDL2_image_la-IMG_xv.Plo make[1]: *** Waiting for unfinished jobs.... mv -f src/.deps/libSDL2_image_la-IMG_svg.Tpo src/.deps/libSDL2_image_la-IMG_svg.Plo mv -f src/.deps/libSDL2_image_la-IMG_stb.Tpo src/.deps/libSDL2_image_la-IMG_stb.Plo make[1]: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_libsdl2_image/libsdl2_image/work/SDL2_image-2.8.2' make: *** [all-recursive] Error 1
This happens due to a wrong code in IMG_webp.c
:
#ifdef __APPLE__ /* Need to turn off optimizations so weak framework load check works */ __attribute__ ((optnone)) #endif
Once this is removed, the port builds fine. So perhaps it is clang-only and should be conditional, or otherwise some alternative fix is needed.
Change History (8)
comment:1 Changed 8 months ago by barracuda156
comment:2 follow-ups: 4 5 Changed 8 months ago by kencu (Ken)
moving the attribute setting before the function declaration like this also works, and I think this is the proper way to do it anyway:
#ifdef __APPLE__ /* Need to turn off optimizations so weak framework load check works */ __attribute__ ((optnone)) #endif int IMG_InitWEBP()
comment:3 Changed 8 months ago by kencu (Ken)
same issue in libsdl2_mixer (although the build there later fails with other errors on 10.5 once this is fixed).
comment:4 Changed 8 months ago by barracuda156
Replying to kencu:
moving the attribute setting before the function declaration like this also works, and I think this is the proper way to do it anyway:
#ifdef __APPLE__ /* Need to turn off optimizations so weak framework load check works */ __attribute__ ((optnone)) #endif int IMG_InitWEBP()
Thank you, Ken!
I will try that, and we should make a PR to allow building with GCC.
comment:5 Changed 8 months ago by barracuda156
Replying to kencu:
moving the attribute setting before the function declaration like this also works, and I think this is the proper way to do it anyway:
#ifdef __APPLE__ /* Need to turn off optimizations so weak framework load check works */ __attribute__ ((optnone)) #endif int IMG_InitWEBP()
Yes, it works. GCC says it ignores it :)
src/IMG_webp.c:79:1: warning: 'optnone' attribute directive ignored [-Wattributes] 79 | { | ^
comment:6 follow-up: 7 Changed 8 months ago by kencu (Ken)
it looks like optnone is not an attribute accepted by gcc.
there is a different specifier used
__attribute__((optimize("O0"))
the exact location where this can be placed in the function definition is also a bit of reading, eg
comment:7 Changed 8 months ago by barracuda156
Replying to kencu:
it looks like optnone is not an attribute accepted by gcc.
there is a different specifier used
__attribute__((optimize("O0"))the exact location where this can be placed in the function definition is also a bit of reading, eg
Could you suggest how to better do it in this case?
Everything builds with just moving those as you suggested earlier, but of course it is better to use a supported attribute.
- S. I will convert the PR into a draft for now, so it is not accidentally merged: https://github.com/macports/macports-ports/pull/23293
comment:8 Changed 8 months ago by barracuda156
Wonder if SDL upstream may be interested to have it fixed, it is a genuine bug in their code then.
UPD. Hmm, apparently the same block is used in two other places, but only here it fails.
Commit introducing it: https://github.com/libsdl-org/SDL_image/commit/25a57e23071b0d5a70c1a417966fb37bb6e78033