Skip to content

Commit

Permalink
Fix build on ARM platform
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Aug 27, 2021
1 parent 3da5f56 commit e6fa77b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 21 deletions.
40 changes: 27 additions & 13 deletions src/wrapped/wrappedlibc.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ typedef int32_t (*iFiiiV_t)(int, int, int, ...);
typedef int32_t (*iFippi_t)(int32_t, void*, void*, int32_t);
typedef int32_t (*iFpppp_t)(void*, void*, void*, void*);
typedef int32_t (*iFpipp_t)(void*, int32_t, void*, void*);
typedef int32_t (*iFpLpp_t)(void*, size_t, void*, void*);
typedef int32_t (*iFppii_t)(void*, void*, int32_t, int32_t);
typedef int32_t (*iFipuu_t)(int32_t, void*, uint32_t, uint32_t);
typedef int32_t (*iFipiI_t)(int32_t, void*, int32_t, int64_t);
Expand Down Expand Up @@ -692,7 +693,8 @@ EXPORT int my_printf(x86emu_t *emu, void* fmt, void* b) {
// need to align on arm
myStackAlign((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
return vprintf(fmt, VARARGS);
void* f = vprintf;
return ((iFpp_t)f)(fmt, VARARGS);
#else
// other platform don't need that
return vprintf((const char*)fmt, b);
Expand All @@ -705,7 +707,8 @@ EXPORT int my_vprintf(x86emu_t *emu, void* fmt, void* b) {
// need to align on arm
myStackAlign((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
return vprintf(fmt, VARARGS);
void* f = vprintf;
return ((iFpp_t)f)(fmt, VARARGS);
#else
// other platform don't need that
return vprintf(fmt, b);
Expand All @@ -718,7 +721,8 @@ EXPORT int my_vfprintf(x86emu_t *emu, void* F, void* fmt, void* b) {
// need to align on arm
myStackAlign((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
return vfprintf(F, fmt, VARARGS);
void* f = vfprintf;
return ((iFppp_t)f)(F, fmt, VARARGS);
#else
// other platform don't need that
return vfprintf(F, fmt, b);
Expand All @@ -732,7 +736,8 @@ EXPORT int my_fprintf(x86emu_t *emu, void* F, void* fmt, void* V) {
// need to align on arm
myStackAlign((const char*)fmt, V, emu->scratch);
PREPARE_VALIST;
return vfprintf((FILE*)F, (const char*)fmt, VARARGS);
void* f = vfprintf;
return ((iFppp_t)f)(F, fmt, VARARGS);
#else
return vfprintf((FILE*)F, (const char*)fmt, (va_list)V);
#endif
Expand All @@ -744,7 +749,8 @@ EXPORT int my_wprintf(x86emu_t *emu, void* fmt, void* V) {
// need to align on arm
myStackAlignW((const char*)fmt, V, emu->scratch);
PREPARE_VALIST;
return vwprintf(fmt, VARARGS);
void* f = vwprintf;
return ((iFpp_t)f)(fmt, VARARGS);
#else
// other platform don't need that
return vwprintf((const wchar_t*)fmt, (va_list)V);
Expand All @@ -755,7 +761,8 @@ EXPORT int my___wprintf_chk(x86emu_t *emu, int flag, void* fmt, void* V) {
// need to align on arm
myStackAlignW((const char*)fmt, V, emu->scratch);
PREPARE_VALIST;
return vwprintf(fmt, VARARGS);
void* f = vwprintf;
return ((iFpp_t)f)(fmt, VARARGS);
#else
// other platform don't need that
return vwprintf((const wchar_t*)fmt, (va_list)V);
Expand All @@ -766,7 +773,8 @@ EXPORT int my_fwprintf(x86emu_t *emu, void* F, void* fmt, void* V) {
// need to align on arm
myStackAlignW((const char*)fmt, V, emu->scratch);
PREPARE_VALIST;
return vfwprintf(F, fmt, VARARGS);
void* f = vfwprintf;
return ((iFppp_t)f)(F, fmt, VARARGS);
#else
// other platform don't need that
return vfwprintf((FILE*)F, (const wchar_t*)fmt, V);
Expand All @@ -778,7 +786,8 @@ EXPORT int my_vfwprintf(x86emu_t *emu, void* F, void* fmt, void* b) {
#ifndef NOALIGN
myStackAlignW((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
return vfwprintf(F, fmt, VARARGS);
void* f = vfwprintf;
return ((iFppp_t)f)(F, fmt, VARARGS);
#else
return vfwprintf(F, fmt, b);
#endif
Expand Down Expand Up @@ -806,7 +815,8 @@ EXPORT int my_snprintf(x86emu_t* emu, void* buff, size_t s, void * fmt, void * b
// need to align on arm
myStackAlign((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
return vsnprintf(buff, s, fmt, VARARGS);
void* f = vsnprintf;
return ((iFpLpp_t)f)(buff, s, fmt, VARARGS);
#else
return vsnprintf((char*)buff, s, (char*)fmt, b);
#endif
Expand All @@ -819,7 +829,8 @@ EXPORT int my___snprintf_chk(x86emu_t* emu, void* buff, size_t s, int f1, int f2
// need to align on arm
myStackAlign((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
return vsnprintf(buff, s, fmt, VARARGS);
void* f = vsnprintf;
return ((iFpLpp_t)f)(buff, s, fmt, VARARGS);
#else
return vsnprintf((char*)buff, s, (char*)fmt, b);
#endif
Expand All @@ -831,7 +842,8 @@ EXPORT int my_sprintf(x86emu_t* emu, void* buff, void * fmt, void * b) {
// need to align on arm
myStackAlign((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
return vsprintf(buff, fmt, VARARGS);
void* f = vsprintf;
return ((iFppp_t)f)(buff, fmt, VARARGS);
#else
return vsprintf((char*)buff, (char*)fmt, b);
#endif
Expand All @@ -843,7 +855,8 @@ EXPORT int my_asprintf(x86emu_t* emu, void** buff, void * fmt, void * b) {
// need to align on arm
myStackAlign((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
return vasprintf(buff, fmt, VARARGS);
void* f = vasprintf;
return ((iFppp_t)f)(buff, fmt, VARARGS);
#else
return vasprintf((char**)buff, (char*)fmt, b);
#endif
Expand Down Expand Up @@ -971,7 +984,8 @@ EXPORT int my___asprintf_chk(x86emu_t* emu, void* result_ptr, int flags, void* f
#ifndef NOALIGN
myStackAlign((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
return vasprintf(result_ptr, fmt, VARARGS);
void* f = vasprintf;
return ((iFppp_t)f)(result_ptr, fmt, VARARGS);
#else
return vasprintf((char**)result_ptr, (char*)fmt, b);
#endif
Expand Down
8 changes: 6 additions & 2 deletions src/wrapped/wrappedlibncurses.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const char* libncursesName = "libncurses.so.5";

static library_t* my_lib = NULL;

typedef int32_t (*iFppp_t)(void*, void*, void*);

#define ADDED_FUNCTIONS() GO(stdscr, void*)
#include "generated/wrappedlibncursestypes.h"

Expand Down Expand Up @@ -57,7 +59,8 @@ EXPORT int my_mvwprintw(x86emu_t* emu, void* win, int y, int x, void* fmt, void*
#ifndef NOALIGN
myStackAlign((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
vasprintf(&buf, fmt, VARARGS);
iFppp_t f = (iFppp_t)vasprintf;
f(&buf, fmt, VARARGS);
#else
vasprintf(&buf, fmt, b);
#endif
Expand Down Expand Up @@ -88,7 +91,8 @@ EXPORT int my_mvprintw(x86emu_t* emu, int x, int y, void* fmt, void* b)
#ifndef NOALIGN
myStackAlign((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
vasprintf(&buf, fmt, VARARGS);
iFppp_t f = (iFppp_t)vasprintf;
f(&buf, fmt, VARARGS);
#else
vasprintf(&buf, fmt, b);
#endif
Expand Down
8 changes: 6 additions & 2 deletions src/wrapped/wrappedlibncurses6.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const char* libncurses6Name = "libncurses.so.6";

static library_t* my_lib = NULL;

typedef int32_t (*iFppp_t)(void*, void*, void*);

#define ADDED_FUNCTIONS() GO(stdscr, void*)
#include "generated/wrappedlibncurses6types.h"

Expand Down Expand Up @@ -57,7 +59,8 @@ EXPORT int my6_mvwprintw(x86emu_t* emu, void* win, int y, int x, void* fmt, void
#ifndef NOALIGN
myStackAlign((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
vasprintf(&buf, fmt, VARARGS);
iFppp_t f = (iFppp_t)vasprintf;
f(&buf, fmt, VARARGS);
#else
vasprintf(&buf, fmt, b);
#endif
Expand Down Expand Up @@ -88,7 +91,8 @@ EXPORT int my6_mvprintw(x86emu_t* emu, int x, int y, void* fmt, void* b)
#ifndef NOALIGN
myStackAlign((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
vasprintf(&buf, fmt, VARARGS);
iFppp_t f = (iFppp_t)vasprintf;
f(&buf, fmt, VARARGS);
#else
vasprintf(&buf, fmt, b);
#endif
Expand Down
8 changes: 6 additions & 2 deletions src/wrapped/wrappedlibncursesw.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const char* libncurseswName = "libncursesw.so.5";

static library_t* my_lib = NULL;

typedef int32_t (*iFppp_t)(void*, void*, void*);

#define ADDED_FUNCTIONS() GO(stdscr, void*)
#include "generated/wrappedlibncurseswtypes.h"

Expand Down Expand Up @@ -57,7 +59,8 @@ EXPORT int myw_mvwprintw(x86emu_t* emu, void* win, int y, int x, void* fmt, void
#ifndef NOALIGN
myStackAlign((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
vasprintf(&buf, fmt, VARARGS);
iFppp_t f = (iFppp_t)vasprintf;
f(&buf, fmt, VARARGS);
#else
vasprintf(&buf, fmt, b);
#endif
Expand Down Expand Up @@ -88,7 +91,8 @@ EXPORT int myw_mvprintw(x86emu_t* emu, int x, int y, void* fmt, void* b)
#ifndef NOALIGN
myStackAlign((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
vasprintf(&buf, fmt, VARARGS);
iFppp_t f = (iFppp_t)vasprintf;
f(&buf, fmt, VARARGS);
#else
vasprintf(&buf, fmt, b);
#endif
Expand Down
7 changes: 5 additions & 2 deletions src/wrapped/wrappedsdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const char* sdl2Name = "libSDL2-2.0.so.0";

typedef void (*vFv_t)();
typedef void (*vFiupp_t)(int32_t, uint32_t, void*, void*);
typedef int32_t (*iFpLpp_t)(void*, size_t, void*, void*);
typedef int32_t (*iFpupp_t)(void*, uint32_t, void*, void*);

#define ADDED_FUNCTIONS() \
Expand Down Expand Up @@ -560,7 +561,8 @@ EXPORT int my2_SDL_vsnprintf(x86emu_t* emu, void* buff, uint32_t s, void * fmt,
// need to align on arm
myStackAlign((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
return vsnprintf(buff, s, fmt, VARARGS);
void* f = vsnprintf;
return ((iFpLpp_t)f)(buff, s, fmt, VARARGS);
#else
return vsnprintf(buff, s, fmt, b);
#endif
Expand All @@ -579,7 +581,8 @@ EXPORT int my2_SDL_snprintf(x86emu_t* emu, void* buff, uint32_t s, void * fmt, v
// need to align on arm
myStackAlign((const char*)fmt, b, emu->scratch);
PREPARE_VALIST;
return vsnprintf(buff, s, fmt, VARARGS);
void* f = vsnprintf;
return ((iFpLpp_t)f)(buff, s, fmt, VARARGS);
#else
return vsnprintf((char*)buff, s, (char*)fmt, b);
#endif
Expand Down

3 comments on commit e6fa77b

@WheezyE
Copy link
Contributor

@WheezyE WheezyE commented on e6fa77b Aug 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m getting this when building on RPi4 too


[  3%] Built target dynarec_arm
make: *** [Makefile:163: all] Error 2
[  0%] Generating ../src/wrapped/generated/functions_list.txt
  File "/home/pi/box86/box86/rebuild_wrappers.py", line 264
    def __init__(self, string: str, filespec: FileSpec, /) -> None:
                                                        ^
SyntaxError: invalid syntax
make[2]: *** [CMakeFiles/WRAPPERS.dir/build.make:334: ../src/wrapped/generated/functions_list.txt] Error 1
make[1]: *** [CMakeFiles/Makefile2:313: CMakeFiles/WRAPPERS.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

Might be from the new python files rewrite?

My build script:

#!/bin/bash
cd /home/pi/box86
sudo rm -rf box86
git clone https://github.com/ptitSeb/box86
sudo cp /usr/local/bin/box86 box86/backup
cd box86/
git pull origin master
mkdir build; cd build; cmake .. -DRPI4=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo
make -j3
sudo make install
sudo systemctl restart systemd-binfmt
exit

@ptitSeb
Copy link
Owner Author

@ptitSeb ptitSeb commented on e6fa77b Aug 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good now.

@WheezyE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Yeah, everything compiles now. Thank you

Please sign in to comment.