rizinorg / rizin

UNIX-like reverse engineering framework and command-line toolset.

Home Page:https://rizin.re

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build failures on several macOS versions: `analysis_xtensa.c: error: too many arguments provided to function-like macro invocation`

barracuda156 opened this issue · comments

rizin build fails on a few older macOS versions at the moment. There are two issues:

  1. On macOS 10.12 and below this fails, at least with Clang (cannot test with GCC right now):
FAILED: librz/analysis/librz_analysis.0.7.dylib.p/p_analysis_xtensa.c.o 
/usr/bin/clang -Ilibrz/analysis/librz_analysis.0.7.dylib.p -I. -I../rizin-v0.7.2 -Ilibrz -I../rizin-v0.7.2/librz -Ilibrz/include -I../rizin-v0.7.2/librz/include -I../rizin-v0.7.2/librz/analysis/arch/gb -Ilibrz/util/sdb/src -I../rizin-v0.7.2/librz/util/sdb/src -I../rizin-v0.7.2/librz/asm/arch/include -I../rizin-v0.7.2/librz/asm/arch -I../rizin-v0.7.2/librz/asm/arch/h8300 -I../rizin-v0.7.2/librz/asm/arch/hexagon -I../rizin-v0.7.2/librz/asm/arch/msp430 -I../rizin-v0.7.2/librz/asm/arch/rsp -I../rizin-v0.7.2/librz/asm/arch/mcore -I../rizin-v0.7.2/librz/asm/arch/v850 -I../rizin-v0.7.2/librz/asm/arch/propeller -I../rizin-v0.7.2/librz/asm/arch/ebc -I../rizin-v0.7.2/librz/asm/arch/cr16 -I../rizin-v0.7.2/librz/asm/arch/8051 -I../rizin-v0.7.2/librz/asm/arch/v810 -I../rizin-v0.7.2/librz/asm/arch/or1k -I../rizin-v0.7.2/librz/asm/arch/tricore -I../rizin-v0.7.2/librz/bin/format -I../rizin-v0.7.2/librz/type/parser -I/opt/local/include/capstone -I/opt/local/libexec/openssl3/include -fdiagnostics-color=always -Wall -Winvalid-pch -O2 -g -DRZ_PLUGIN_INCORE=1 -DUSE_SYS_CAPSTONE --std=gnu99 -Werror=sizeof-pointer-memaccess -fvisibility=hidden -pipe -Os -arch x86_64 -MD -MQ librz/analysis/librz_analysis.0.7.dylib.p/p_analysis_xtensa.c.o -MF librz/analysis/librz_analysis.0.7.dylib.p/p_analysis_xtensa.c.o.d -o librz/analysis/librz_analysis.0.7.dylib.p/p_analysis_xtensa.c.o -c ../rizin-v0.7.2/librz/analysis/p/analysis_xtensa.c
../rizin-v0.7.2/librz/analysis/p/analysis_xtensa.c:24:45: error: too many arguments provided to function-like macro invocation
        memcpy(ctx->length_table, (int[16]){ 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 8, 8 }, sizeof(ctx->length_table));
                                                   ^
/usr/include/secure/_string.h:64:9: note: macro 'memcpy' defined here
#define memcpy(dest, src, len)                                  \
        ^
../rizin-v0.7.2/librz/analysis/p/analysis_xtensa.c:24:2: note: parentheses are required around macro argument containing braced initializer list
        memcpy(ctx->length_table, (int[16]){ 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 8, 8 }, sizeof(ctx->length_table));
        ^
                                  (                                                          )
1 error generated.

Log: https://build.macports.org/builders/ports-10.12_x86_64-builder/builds/263721/steps/install-port/logs/stdio

  1. On 10.6 and below this fails (this is an SDK-related issue, not compiler-related):
FAILED: librz/io/librz_io.0.7.dylib.p/p_io_debug.c.o 
/opt/local/bin/clang-mp-11 -Ilibrz/io/librz_io.0.7.dylib.p -I. -I../rizin-v0.7.2 -Ilibrz -I../rizin-v0.7.2/librz -Ilibrz/include -I../rizin-v0.7.2/librz/include -I../rizin-v0.7.2/subprojects/rzgdb/include -I../rizin-v0.7.2/subprojects/rzgdb/include/gdbclient -I../rizin-v0.7.2/subprojects/rzgdb/include/gdbserver -Isubprojects/rzwinkd -I../rizin-v0.7.2/subprojects/rzwinkd -Isubprojects/rzar -I../rizin-v0.7.2/subprojects/rzar -Ilibrz/util/sdb/src -I../rizin-v0.7.2/librz/util/sdb/src -I../rizin-v0.7.2/subprojects/rzqnx/include -I/opt/local/libexec/openssl3/include -fdiagnostics-color=always -Wall -Winvalid-pch -O2 -g -DRZ_PLUGIN_INCORE=1 -DUSE_SYS_CAPSTONE --std=gnu99 -Werror=sizeof-pointer-memaccess -fvisibility=hidden -pipe -Os -arch x86_64 -MD -MQ librz/io/librz_io.0.7.dylib.p/p_io_debug.c.o -MF librz/io/librz_io.0.7.dylib.p/p_io_debug.c.o.d -o librz/io/librz_io.0.7.dylib.p/p_io_debug.c.o -c ../rizin-v0.7.2/librz/io/p/io_debug.c
../rizin-v0.7.2/librz/io/p/io_debug.c:302:2: warning: implicit declaration of function 'posix_spawn_file_actions_addinherit_np' is invalid in C99 [-Wimplicit-function-declaration]
        posix_spawn_file_actions_addinherit_np(&fileActions, STDIN_FILENO);
        ^
../rizin-v0.7.2/librz/io/p/io_debug.c:306:14: error: use of undeclared identifier 'POSIX_SPAWN_CLOEXEC_DEFAULT'
        ps_flags |= POSIX_SPAWN_CLOEXEC_DEFAULT;
                    ^
1 warning and 1 error generated.

Log: https://build.macports.org/builders/ports-10.6_x86_64-builder/builds/192137/steps/install-port/logs/stdio

P. S. POSIX_SPAWN_CLOEXEC_DEFAULT has been added in 10.7, but apparently is safe to use from 10.8 up. See: python/cpython#109154

Could these be addressed?

GCC gives a better error output:

FAILED: librz/analysis/librz_analysis.0.7.dylib.p/p_analysis_xtensa.c.o 
/opt/local/bin/gcc-mp-13 -Ilibrz/analysis/librz_analysis.0.7.dylib.p -I. -I../rizin-v0.7.2 -Ilibrz -I../rizin-v0.7.2/librz -Ilibrz/include -I../rizin-v0.7.2/librz/include -I../rizin-v0.7.2/librz/analysis/arch/gb -Ilibrz/util/sdb/src -I../rizin-v0.7.2/librz/util/sdb/src -I../rizin-v0.7.2/librz/asm/arch/include -I../rizin-v0.7.2/librz/asm/arch -I../rizin-v0.7.2/librz/asm/arch/h8300 -I../rizin-v0.7.2/librz/asm/arch/hexagon -I../rizin-v0.7.2/librz/asm/arch/msp430 -I../rizin-v0.7.2/librz/asm/arch/rsp -I../rizin-v0.7.2/librz/asm/arch/mcore -I../rizin-v0.7.2/librz/asm/arch/v850 -I../rizin-v0.7.2/librz/asm/arch/propeller -I../rizin-v0.7.2/librz/asm/arch/ebc -I../rizin-v0.7.2/librz/asm/arch/cr16 -I../rizin-v0.7.2/librz/asm/arch/8051 -I../rizin-v0.7.2/librz/asm/arch/v810 -I../rizin-v0.7.2/librz/asm/arch/or1k -I../rizin-v0.7.2/librz/asm/arch/tricore -I../rizin-v0.7.2/librz/bin/format -I../rizin-v0.7.2/librz/type/parser -I/opt/local/include/capstone -I/opt/local/libexec/openssl3/include -fdiagnostics-color=always -Wall -Winvalid-pch -O2 -g -Wimplicit-fallthrough=3 -DRZ_PLUGIN_INCORE=1 -DUSE_SYS_CAPSTONE --std=gnu99 -Werror=sizeof-pointer-memaccess -fvisibility=hidden -pipe -Os -arch ppc -MD -MQ librz/analysis/librz_analysis.0.7.dylib.p/p_analysis_xtensa.c.o -MF librz/analysis/librz_analysis.0.7.dylib.p/p_analysis_xtensa.c.o.d -o librz/analysis/librz_analysis.0.7.dylib.p/p_analysis_xtensa.c.o -c ../rizin-v0.7.2/librz/analysis/p/analysis_xtensa.c
../rizin-v0.7.2/librz/analysis/p/analysis_xtensa.c: In function 'xtensa_init':
../rizin-v0.7.2/librz/analysis/p/analysis_xtensa.c:24:121: error: macro "memcpy" passed 18 arguments, but takes just 3
   24 |         memcpy(ctx->length_table, (int[16]){ 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 8, 8 }, sizeof(ctx->length_table));
      |                                                                                                                         ^
In file included from /usr/include/string.h:148,
                 from ../rizin-v0.7.2/librz/analysis/p/analysis_xtensa.c:4:
/usr/include/secure/_string.h:50: note: macro "memcpy" defined here
   50 | #define memcpy(dest, src, len)                                  \
      | 
../rizin-v0.7.2/librz/analysis/p/analysis_xtensa.c:24:9: warning: statement with no effect [-Wunused-value]
   24 |         memcpy(ctx->length_table, (int[16]){ 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 8, 8 }, sizeof(ctx->length_table));
      |         ^~~~~~

We plan to implement Xtensa in capstone in the long run and switch to using it. Meanwhile, @thestr4ng3r could you please look at it as you have the platform IIRC?

@XVilka Perhaps something like brackets missing, so that number of args gets wrong for memcpy?

Fixing the memcpy one first since this is a regression and the fix is trivial.

The POSIX_SPAWN_CLOEXEC_DEFAULT needs a little bit more care and testing, the resources linked by @barracuda156 are quite helpful. Currently there is an #if __APPLE__ && !__POWERPC__, but __POWERPC__ is the wrong condition here.

As a workaround, passing -Ddebugger=false to meson can be used to at least have a working rizin without debugging.

@thestr4ng3r #if __APPLE__ && !__POWERPC__ is strange there indeed. If a threshold for macOS version is needed (which would make more sense), then there is AvailabilityMacros.h with respective defines. (Excluding PowerPC in addition can be sensible though, since there is some stuff in 10.6 SDK which has only Intel support – for instance, notorious pthread_threadid_np.)

Also, I believe, correct form is defined(__POWERPC__).

The errors mentioned in this issue should be fixed now. Keep in mind that the debugging functionality itself is still completely broken as it has only been tested on the latest macOS versions for years and even there it has issues. But the build should work and it should be useful for any static analysis task.
If anything else comes up, feel free to open a new issue! We try to support these platforms as good as possible with the resources we have.

@thestr4ng3r Ah, sorry, the memcpy error remains (with gcc as well, I just did not get that far earlier):

FAILED: librz/analysis/librz_analysis.0.7.dylib.p/p_analysis_xtensa.c.o 
/opt/local/bin/gcc-mp-13 -Ilibrz/analysis/librz_analysis.0.7.dylib.p -I. -I../rizin-v0.7.2 -Ilibrz -I../rizin-v0.7.2/librz -Ilibrz/include -I../rizin-v0.7.2/librz/include -I../rizin-v0.7.2/librz/analysis/arch/gb -Ilibrz/util/sdb/src -I../rizin-v0.7.2/librz/util/sdb/src -I../rizin-v0.7.2/librz/asm/arch/include -I../rizin-v0.7.2/librz/asm/arch -I../rizin-v0.7.2/librz/asm/arch/h8300 -I../rizin-v0.7.2/librz/asm/arch/hexagon -I../rizin-v0.7.2/librz/asm/arch/msp430 -I../rizin-v0.7.2/librz/asm/arch/rsp -I../rizin-v0.7.2/librz/asm/arch/mcore -I../rizin-v0.7.2/librz/asm/arch/v850 -I../rizin-v0.7.2/librz/asm/arch/propeller -I../rizin-v0.7.2/librz/asm/arch/ebc -I../rizin-v0.7.2/librz/asm/arch/cr16 -I../rizin-v0.7.2/librz/asm/arch/8051 -I../rizin-v0.7.2/librz/asm/arch/v810 -I../rizin-v0.7.2/librz/asm/arch/or1k -I../rizin-v0.7.2/librz/asm/arch/tricore -I../rizin-v0.7.2/librz/bin/format -I../rizin-v0.7.2/librz/type/parser -I/opt/local/include/capstone -I/opt/local/libexec/openssl3/include -fdiagnostics-color=always -Wall -Winvalid-pch -O2 -g -Wimplicit-fallthrough=3 -DRZ_PLUGIN_INCORE=1 -DUSE_SYS_CAPSTONE --std=gnu99 -Werror=sizeof-pointer-memaccess -fvisibility=hidden -pipe -Os -arch ppc -MD -MQ librz/analysis/librz_analysis.0.7.dylib.p/p_analysis_xtensa.c.o -MF librz/analysis/librz_analysis.0.7.dylib.p/p_analysis_xtensa.c.o.d -o librz/analysis/librz_analysis.0.7.dylib.p/p_analysis_xtensa.c.o -c ../rizin-v0.7.2/librz/analysis/p/analysis_xtensa.c
../rizin-v0.7.2/librz/analysis/p/analysis_xtensa.c: In function 'xtensa_init':
../rizin-v0.7.2/librz/analysis/p/analysis_xtensa.c:24:121: error: macro "memcpy" passed 18 arguments, but takes just 3
   24 |         memcpy(ctx->length_table, (int[16]){ 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 8, 8 }, sizeof(ctx->length_table));
      |                                                                                                                         ^
In file included from /usr/include/string.h:148,
                 from ../rizin-v0.7.2/librz/analysis/p/analysis_xtensa.c:4:
/usr/include/secure/_string.h:50: note: macro "memcpy" defined here
   50 | #define memcpy(dest, src, len)                                  \
      | 
../rizin-v0.7.2/librz/analysis/p/analysis_xtensa.c:24:9: warning: statement with no effect [-Wunused-value]
   24 |         memcpy(ctx->length_table, (int[16]){ 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 8, 8 }, sizeof(ctx->length_table));
      |         ^~~~~~

Or should I make a separate issue for this?

@barracuda156 You currently have to use the latest state of the dev branch, not the 0.7.2 release as it is not included there. Likely the next release to have all the fixes is 0.8.0, but you could backport the individual commits if it is needed e.g. in MacPorts.