build: Fixes for arm64 macOS

* macOS ships an ancient version of GNU Bison which wants
  an '=' after %name-prefix

* macOS awk doesn't support strftime, so try to find a working
  awk.

* _haiku_build_{open,openat,fcntl} are declared and defined with
  different prototypes (variadic vs non-variadic). This is bad
  on its own, but it "happens to" work on most platforms since
  variadic parameters are usually passed in registers, same as other
  arguments. On arm64 macOS, variadic parameters are always passed
  on the stack, so you get weird and confusing bugs when using
  these functions.

Change-Id: I8cee9ecac0ac9b039be6b7e35ceaf8ad7c0f4c44
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10468
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Sam Roberts
2026-03-11 02:21:34 +00:00
committed by waddlesplash
parent a2e4f9f75f
commit 5bb69a0f33
6 changed files with 48 additions and 20 deletions
Vendored
+17
View File
@@ -931,6 +931,22 @@ if [ "$("$HAIKU_NASM" -hf | grep -c elf'[36][24] ')" -ne "2" ]; then
exit 1 exit 1
fi fi
# locate awk
if [ -z "$HOST_AWK" ]; then
HOST_AWK="awk"
awk 'BEGIN{strftime()}' 2>/dev/null
if [ $? -ne 0 ]; then
# awk does not support strftime, try gawk
HOST_AWK="gawk"
fi
fi
$HOST_AWK 'BEGIN{strftime()}' 2>/dev/null
if [ $? -ne 0 ]; then
echo "A working awk was not found. Install gawk or specify"
echo "a different awk with HOST_AWK."
exit 1
fi
# create output directory # create output directory
mkdir -p "$buildOutputDir" || exit 1 mkdir -p "$buildOutputDir" || exit 1
@@ -1171,6 +1187,7 @@ HOST_OBJCOPY ?= ${HOST_GCC_OBJCOPY} ;
HOST_EXTENDED_REGEX_SED ?= ${HOST_EXTENDED_REGEX_SED} ; HOST_EXTENDED_REGEX_SED ?= ${HOST_EXTENDED_REGEX_SED} ;
HOST_SHA256 ?= ${HOST_SHA256} ; HOST_SHA256 ?= ${HOST_SHA256} ;
HOST_PYTHON ?= ${HOST_PYTHON} ; HOST_PYTHON ?= ${HOST_PYTHON} ;
HOST_AWK ?= ${HOST_AWK} ;
HOST_WGET_RETRY_ON_HOST_ERROR ?= ${HOST_WGET_RETRY_ON_HOST_ERROR} ; HOST_WGET_RETRY_ON_HOST_ERROR ?= ${HOST_WGET_RETRY_ON_HOST_ERROR} ;
HAIKU_NASM ?= ${HAIKU_NASM} ; HAIKU_NASM ?= ${HAIKU_NASM} ;
-7
View File
@@ -111,16 +111,9 @@ int _haiku_build_fchownat(int fd, const char* path, uid_t owner,
gid_t group, int flag); gid_t group, int flag);
int _haiku_build_mknodat(int fd, const char* name, mode_t mode, dev_t dev); int _haiku_build_mknodat(int fd, const char* name, mode_t mode, dev_t dev);
int _haiku_build_creat(const char* path, mode_t mode); int _haiku_build_creat(const char* path, mode_t mode);
#ifndef _HAIKU_BUILD_DONT_REMAP_FD_FUNCTIONS
int _haiku_build_open(const char* path, int openMode, ...); int _haiku_build_open(const char* path, int openMode, ...);
int _haiku_build_openat(int fd, const char* path, int openMode, ...); int _haiku_build_openat(int fd, const char* path, int openMode, ...);
int _haiku_build_fcntl(int fd, int op, ...); int _haiku_build_fcntl(int fd, int op, ...);
#else
int _haiku_build_open(const char* path, int openMode, mode_t permissions);
int _haiku_build_openat(int fd, const char* path, int openMode,
mode_t permissions);
int _haiku_build_fcntl(int fd, int op, int argument);
#endif
int _haiku_build_renameat(int fromFD, const char* from, int toFD, int _haiku_build_renameat(int fromFD, const char* from, int toFD,
const char* to); const char* to);
+4 -5
View File
@@ -20,7 +20,7 @@ rule ISAPnPHeaderGen
actions ISAPnPHeaderGen1 actions ISAPnPHeaderGen1
{ {
grep '^PNP[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]]' $(2[1]) \ grep '^PNP[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]]' $(2[1]) \
| awk -f $(2[2]) > $(1) ; | $(HOST_AWK) -f $(2[2]) > $(1) ;
} }
ISAPnPHeaderGen [ FGristFiles isapnpids.h ] : isapnp_devids.txt : devlist2h.awk ; ISAPnPHeaderGen [ FGristFiles isapnpids.h ] : isapnp_devids.txt : devlist2h.awk ;
@@ -37,7 +37,7 @@ rule PCIHeaderGen
actions PCIHeaderGen1 actions PCIHeaderGen1
{ {
awk -v HEADERFILE=$(1) -f $(2[2]) $(2[1]) $(HOST_AWK) -v HEADERFILE=$(1) -f $(2[2]) $(2[1])
} }
local pciidsFile = pci.ids ; local pciidsFile = pci.ids ;
@@ -57,7 +57,7 @@ rule USBHeaderGen
actions USBHeaderGen1 actions USBHeaderGen1
{ {
awk -v HEADERFILE=$(1) -f $(2[2]) $(2[1]) $(HOST_AWK) -v HEADERFILE=$(1) -f $(2[2]) $(2[1])
} }
local usbidsFile = usb.ids ; local usbidsFile = usb.ids ;
@@ -77,7 +77,7 @@ rule ACPIPnPHeaderGen
actions ACPIPnPHeaderGen1 actions ACPIPnPHeaderGen1
{ {
awk -f $(2[1]) $(2[2-]) > $(1) ; $(HOST_AWK) -f $(2[1]) $(2[2-]) > $(1) ;
} }
# files can be updated so: # files can be updated so:
@@ -119,4 +119,3 @@ DoCatalogs Devices :
Includes [ FGristFiles DeviceACPI.cpp ] : [ FGristFiles acpipnpids.h isapnpids.h ] ; Includes [ FGristFiles DeviceACPI.cpp ] : [ FGristFiles acpipnpids.h isapnpids.h ] ;
Includes [ FGristFiles DevicePCI.cpp ] : [ FGristFiles pcihdr.h ] ; Includes [ FGristFiles DevicePCI.cpp ] : [ FGristFiles pcihdr.h ] ;
Includes [ FGristFiles DeviceUSB.cpp ] : [ FGristFiles usbhdr.h ] ; Includes [ FGristFiles DeviceUSB.cpp ] : [ FGristFiles usbhdr.h ] ;
+23 -3
View File
@@ -1526,15 +1526,30 @@ _haiku_build_creat(const char* path, mode_t mode)
int int
_haiku_build_open(const char* path, int openMode, mode_t permissions) _haiku_build_open(const char* path, int openMode, ...)
{ {
mode_t permissions = 0;
if ((openMode & O_CREAT) != 0) {
va_list args;
va_start(args, openMode);
permissions = va_arg(args, int);
va_end(args);
}
return _haiku_build_openat(AT_FDCWD, path, openMode, permissions); return _haiku_build_openat(AT_FDCWD, path, openMode, permissions);
} }
int int
_haiku_build_openat(int fd, const char* path, int openMode, mode_t permissions) _haiku_build_openat(int fd, const char* path, int openMode, ...)
{ {
mode_t permissions = 0;
if ((openMode & O_CREAT) != 0) {
va_list args;
va_start(args, openMode);
permissions = va_arg(args, int);
va_end(args);
}
// adapt the permissions as required by POSIX // adapt the permissions as required by POSIX
mode_t mask = umask(0); mode_t mask = umask(0);
umask(mask); umask(mask);
@@ -1545,8 +1560,13 @@ _haiku_build_openat(int fd, const char* path, int openMode, mode_t permissions)
int int
_haiku_build_fcntl(int fd, int op, int argument) _haiku_build_fcntl(int fd, int op, ...)
{ {
va_list args;
va_start(args, op);
int argument = va_arg(args, int);
va_end(args);
if (is_unknown_or_system_descriptor(fd)) if (is_unknown_or_system_descriptor(fd))
return fcntl(fd, op, argument); return fcntl(fd, op, argument);
+3 -4
View File
@@ -39,10 +39,9 @@ int _haiku_build_fchownat(int fd, const char* path, uid_t owner,
gid_t group, int flag); gid_t group, int flag);
int _haiku_build_mknodat(int fd, const char* name, mode_t mode, dev_t dev); int _haiku_build_mknodat(int fd, const char* name, mode_t mode, dev_t dev);
int _haiku_build_creat(const char* path, mode_t mode); int _haiku_build_creat(const char* path, mode_t mode);
int _haiku_build_open(const char* path, int openMode, mode_t permissions); int _haiku_build_open(const char* path, int openMode, ...);
int _haiku_build_openat(int fd, const char* path, int openMode, int _haiku_build_openat(int fd, const char* path, int openMode, ...);
mode_t permissions); int _haiku_build_fcntl(int fd, int op, ...);
int _haiku_build_fcntl(int fd, int op, int argument);
int _haiku_build_renameat(int fromFD, const char* from, int toFD, int _haiku_build_renameat(int fromFD, const char* from, int toFD,
const char* to); const char* to);
@@ -54,7 +54,7 @@ extern char * _nsyytext;
extern int _nsyylineno; extern int _nsyylineno;
%} %}
%name-prefix "_nsyy" %name-prefix="_nsyy"
%union { %union {
char *str; char *str;