macos: Add support for Apple Silicon 46/14746/11
authorMarcio Barbosa <mbarbosa@sinenomine.net>
Thu, 7 Apr 2022 22:35:02 +0000 (22:35 +0000)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 13 May 2022 16:53:03 +0000 (12:53 -0400)
This commit introduces the new set of changes / files required to
successfully build the OpenAFS source code on Apple M1 (macOS 11+).

Notice that kexts on Apple silicon must support the arm64e architecture,
since they run in kernel space and must support the same architecture
and restrictions as other kernel code. On the other hand, the utilities
that run on user space, like vos, fs, and others, have to be built for
arm64 (currently).

Change-Id: Ib005215ae9bfb0b9dda94b2e194f05c0ce92fa1e
Reviewed-on: https://gerrit.openafs.org/14746
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Andrew Deason <adeason@sinenomine.net>

src/afsd/afsd.c
src/cf/sysname.m4
src/config/param.darwin_200.h
src/libafs/MakefileProto.DARWIN.in
src/libafs/afs.arm_darwin_200.plist.in [new file with mode: 0644]
src/lwp/Makefile.in
src/rx/xdr.c
src/rx/xdr.h

index 8743bce..0d29767 100644 (file)
 #include <CoreFoundation/CoreFoundation.h>
 
 static int event_pid;
-#ifndef AFS_ARM_DARWIN_ENV
-#define MACOS_EVENT_HANDLING 1
+#if !defined(AFS_ARM_DARWIN_ENV) && !defined(AFS_ARM64_DARWIN_ENV)
+# define MACOS_EVENT_HANDLING 1
 #endif
 #endif /* AFS_DARWIN_ENV */
 
index 469cfe7..c0f4414 100644 (file)
@@ -194,6 +194,10 @@ else
                        AFS_SYSNAME="x86_darwin_200"
                        OSXSDK="macosx11.0"
                        ;;
+               arm-apple-darwin20.*)
+                       AFS_SYSNAME="arm_darwin_200"
+                       OSXSDK="macosx11.0"
+                       ;;
                 sparc-sun-solaris2.8)
                         AFS_SYSNAME="sun4x_58"
                         ;;
index c14ce38..5f91464 100644 (file)
 #  define SYS_NAME_ID                 SYS_NAME_ID_amd64_darwin_200
 #  define AFSLITTLE_ENDIAN            1
 
+# elif defined(__arm64__)
+
+#  define AFS_ARM_ENV                 1
+#  define AFS_ARM64_DARWIN_ENV        1
+
+#  define sys_arm_darwin_200          1
+
+#  define SYS_NAME                    "arm_darwin_200"
+#  define SYS_NAME_ID                 SYS_NAME_ID_arm_darwin_200
+#  define AFSLITTLE_ENDIAN            1
+
 # else
 # error Unsupported architecture
 # endif /* __amd64__ */
index 6fb5173..751ed5f 100644 (file)
@@ -51,23 +51,27 @@ KOPTS_DBUG=-gdwarf-2
 KOPTS_ppc=-static -nostdinc -fno-builtin -finline -fno-keep-inline-functions -msoft-float -mlong-branch -fsigned-bitfields -arch ppc -Dppc -DPPC -D__PPC__ -DPAGE_SIZE_FIXED -mcpu=750 -mmultiple -fschedule-insns -force_cpusubtype_ALL
 KOPTS_x86=-static -nostdinc -fmessage-length=0 -pipe -nostdinc -fno-builtin -Wno-trigraphs -force_cpusubtype_ALL -msoft-float -O0 -fno-common -mkernel -finline -fno-keep-inline-functions -fasm-blocks -arch i386 -Di386 -DI386 -D__I386__ -DPAGE_SIZE_FIXED
 KOPTS_amd64=-static -nostdinc -fno-builtin -finline -fno-keep-inline-functions -msoft-float -fsigned-bitfields -arch x86_64 -Damd64 -DAMD64 -D__AMD64__ -DPAGE_SIZE_FIXED -march=x86-64 -falign-functions=4 -m64 -mkernel -mno-red-zone
+KOPTS_arm64=-static -nostdinc -fno-builtin -finline -fsigned-bitfields -arch arm64e -Darm64e -DARM64E -D__ARM64E__ -DPAGE_SIZE_FIXED -falign-functions=4 -m64 -mkernel -mno-red-zone
 ARCH_ppc=$(shell echo "${ARCHFLAGS}" | grep -q -w ppc && echo yes || echo ${ARCHFLAGS} | egrep -q -w -v 'ppc|i386|x86_64' && arch | grep -q -w ppc && echo yes)
 ARCH_x86=$(shell echo "${ARCHFLAGS}" | grep -q -w i386 && echo yes || echo ${ARCHFLAGS} | egrep -q -w -v 'ppc|i386|x86_64' && arch | grep -q -w i386 && echo yes)
-ARCH_amd64=$(shell echo "${ARCHFLAGS}" | grep -q -w x86_64 && echo yes || echo ${ARCHFLAGS} | egrep -q -w -v 'ppc|i386|x86_64' && arch | grep -q -w x86_64 && echo yes)
+ARCH_amd64=$(shell echo "${ARCHFLAGS}" | grep -q -w x86_64 && echo yes || echo ${ARCHFLAGS} | egrep -q -w -v 'ppc|i386|x86_64|arm64' && arch | grep -q -w x86_64 && echo yes)
+ARCH_arm64=$(shell echo "${ARCHFLAGS}" | grep -q -w arm64 && echo yes || echo ${ARCHFLAGS} | egrep -q -w -v 'ppc|i386|x86_64|arm64' && arch | grep -q -w arm64 && echo yes)
 OBJ_ppc=$(shell echo "${ARCH_ppc}" | grep -q -w yes && echo "$@.ppc")
 OBJ_x86=$(shell echo "${ARCH_x86}" | grep -q -w yes && echo "$@.x86")
 OBJ_amd64=$(shell echo "${ARCH_amd64}" | grep -q -w yes && echo "$@.amd64")
+OBJ_arm64=$(shell echo "${ARCH_arm64}" | grep -q -w yes && echo "$@.arm64")
 
 <all -ppc_darwin_70 -ppc_darwin_80 -x86_darwin_80 -ppc_darwin_90 -x86_darwin_90>
 KLINKER=-Xlinker -kext
 <all>
-MODLD=$(CC) -static $(KOPTS_DBUG) -nostdlib $(ARCHFLAGS)
+MODLD=$(CC) -static $(KOPTS_DBUG) -nostdlib $(patsubst arm64,arm64e,$(ARCHFLAGS))
 
 <all>
 
 CFLAGS_ppc=-I. -I.. -I${TOP_OBJDIR}/src/config $(DEFINES) $(KDEFS) $(KOPTS_ppc) $(KOPTS_DBUG)
 CFLAGS_x86=-I. -I.. -I${TOP_OBJDIR}/src/config $(DEFINES) $(KDEFS) $(KOPTS_x86) $(KOPTS_DBUG)
 CFLAGS_amd64=-I. -I.. -I${TOP_OBJDIR}/src/config $(DEFINES) $(KDEFS) $(KOPTS_amd64) $(KOPTS_DBUG)
+CFLAGS_arm64=-I. -I.. -I${TOP_OBJDIR}/src/config $(DEFINES) $(KDEFS) $(KOPTS_arm64) $(KOPTS_DBUG)
 
 <all>
 # Name of directory to hold object files and libraries.
@@ -93,17 +97,22 @@ ALL_COMMON_INCLUDES=$(KINCLUDES) $(COMMON_INCLUDE)
        if [ "$(ARCH_amd64)" = "yes" ]; then \
            $(CC) $(ALL_COMMON_INCLUDES) $(KERN_DBG) $(CFLAGS_amd64) $(CFLAGS-$@) -o $(patsubst %.o,%.o.amd64,$@) -c $< || exit(1) \
        fi \
-       lipo -create ${OBJ_ppc} ${OBJ_x86} ${OBJ_amd64} -output $@;
+       if [ "$(ARCH_arm64)" = "yes" ]; then \
+           $(CC) $(ALL_COMMON_INCLUDES) $(KERN_DBG) $(CFLAGS_arm64) $(CFLAGS-$@) -o $(patsubst %.o,%.o.arm64,$@) -c $< || exit(1) \
+       fi \
+       lipo -create ${OBJ_ppc} ${OBJ_x86} ${OBJ_amd64} ${OBJ_arm64} -output $@;
 
 CRULE_NOOPT_ppc=$(CC) $(ALL_COMMON_INCLUDES) $(KERN_DBG) $(CFLAGS_ppc) $(CFLAGS-$@) -o $(patsubst %.o,%.o.ppc,$@) -c $?
 CRULE_NOOPT_x86=$(CC) $(ALL_COMMON_INCLUDES) $(KERN_DBG) $(CFLAGS_x86) $(CFLAGS-$@) -o $(patsubst %.o,%.o.x86,$@) -c $?
 CRULE_NOOPT_amd64=$(CC) $(ALL_COMMON_INCLUDES) $(KERN_DBG) $(CFLAGS_amd64) $(CFLAGS-$@) -o $(patsubst %.o,%.o.amd64,$@) -c $?
-CRULE_NOOPT=$(shell echo "${ARCH_ppc}" | grep -q -w yes && echo "${CRULE_NOOPT_ppc} && "; echo "${ARCH_x86}" | grep -q -w yes && echo "${CRULE_NOOPT_x86} && "; echo "${ARCH_amd64}" | grep -q -w yes && echo "${CRULE_NOOPT_amd64} && "; echo " lipo -create ${OBJ_ppc} ${OBJ_x86} ${OBJ_amd64} -output $@ && true")
+CRULE_NOOPT_arm64=$(CC) $(ALL_COMMON_INCLUDES) $(KERN_DBG) $(CFLAGS_arm64) $(CFLAGS-$@) -o $(patsubst %.o,%.o.arm64,$@) -c $?
+CRULE_NOOPT=$(shell echo "${ARCH_ppc}" | grep -q -w yes && echo "${CRULE_NOOPT_ppc} && "; echo "${ARCH_x86}" | grep -q -w yes && echo "${CRULE_NOOPT_x86} && "; echo "${ARCH_amd64}" | grep -q -w yes && echo "${CRULE_NOOPT_amd64} && "; echo "${ARCH_arm64}" | grep -q -w yes && echo "${CRULE_NOOPT_arm64} && "; echo " lipo -create ${OBJ_ppc} ${OBJ_x86} ${OBJ_amd64} ${OBJ_arm64} -output $@ && true")
 
 CRULE_OPT_ppc=$(CC) $(ALL_COMMON_INCLUDES) $(KERN_DBG) $(KERN_OPTMZ) $(CFLAGS_ppc) $(CFLAGS-$@) -o $(patsubst %.o,%.o.ppc,$@) -c $? 
 CRULE_OPT_x86=$(CC) $(ALL_COMMON_INCLUDES) $(KERN_DBG) $(KERN_OPTMZ) $(CFLAGS_x86) $(CFLAGS-$@) -o $(patsubst %.o,%.o.x86,$@) -c $? 
 CRULE_OPT_amd64=$(CC) $(ALL_COMMON_INCLUDES) $(KERN_DBG) $(KERN_OPTMZ) $(CFLAGS_amd64) $(CFLAGS-$@) -o $(patsubst %.o,%.o.amd64,$@) -c $? 
-CRULE_OPT=$(shell echo "${ARCH_ppc}" | grep -q -w yes && echo "${CRULE_OPT_ppc} && "; echo "${ARCH_x86}" | grep -q -w yes && echo "${CRULE_OPT_x86} && "; echo "${ARCH_amd64}" | grep -q -w yes && echo "${CRULE_OPT_amd64} && ";echo "lipo -create ${OBJ_ppc} ${OBJ_x86} ${OBJ_amd64} -output $@ && true")
+CRULE_OPT_arm64=$(CC) $(ALL_COMMON_INCLUDES) $(KERN_DBG) $(KERN_OPTMZ) $(CFLAGS_arm64) $(CFLAGS-$@) -o $(patsubst %.o,%.o.arm64,$@) -c $?
+CRULE_OPT=$(shell echo "${ARCH_ppc}" | grep -q -w yes && echo "${CRULE_OPT_ppc} && "; echo "${ARCH_x86}" | grep -q -w yes && echo "${CRULE_OPT_x86} && "; echo "${ARCH_amd64}" | grep -q -w yes && echo "${CRULE_OPT_amd64} && "; echo "${ARCH_arm64}" | grep -q -w yes && echo "${CRULE_OPT_arm64} && "; echo "lipo -create ${OBJ_ppc} ${OBJ_x86} ${OBJ_amd64} ${OBJ_arm64} -output $@ && true")
 
 <ppc_darwin_70>
 CFLAGS=-I. -I.. -I${TOP_OBJDIR}/src/config $(DEFINES) $(KDEFS) $(KOPTS)
diff --git a/src/libafs/afs.arm_darwin_200.plist.in b/src/libafs/afs.arm_darwin_200.plist.in
new file mode 100644 (file)
index 0000000..a138571
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+       <key>CFBundleDevelopmentRegion</key>
+       <string>English</string>
+       <key>CFBundleExecutable</key>
+       <string>afs</string>
+       <key>CFBundleIdentifier</key>
+       <string>org.openafs.filesystems.afs</string>
+       <key>CFBundleInfoDictionaryVersion</key>
+       <string>8.0</string>
+       <key>CFBundleName</key>
+       <string>afs</string>
+       <key>CFBundlePackageType</key>
+       <string>KEXT</string>
+       <key>CFBundleShortVersionString</key>
+       <string>@MACOS_VERSION@</string>
+       <key>CFBundleSignature</key>
+       <string>????</string>
+       <key>CFBundleVersion</key>
+       <string>@MACOS_VERSION@</string>
+       <key>OSBundleLibraries</key>
+       <dict>
+               <key>com.apple.kpi.bsd</key>
+               <string>8.0.0</string>
+               <key>com.apple.kpi.mach</key>
+               <string>8.0.0</string>
+               <key>com.apple.kpi.libkern</key>
+               <string>8.0</string>
+       </dict>
+</dict>
+</plist>
index 6fe5396..39d7402 100644 (file)
@@ -85,7 +85,8 @@ process.o     : process.default.s process.i386.s process.amd64.s process.c lwp.o
                amd64=`echo $${CURRENTBUILDARCH} | grep -q x86_64 && echo process.amd64.o` ; \
                armv6=`echo $${CURRENTBUILDARCH} | grep -q armv6 && echo process.armv6.o` ; \
                armv7=`echo $${CURRENTBUILDARCH} | grep -q armv7 && echo process.armv7.o` ; \
-               if [ -z "$${ppc}" -a -z "$${i386}" -a -z "$${amd64}" -a -z "$${armv6}" -a -z "$${armv7}" ] ; then \
+               arm64=`echo $${CURRENTBUILDARCH} | grep -q arm64 && echo process.arm64.o` ; \
+               if [ -z "$${ppc}" -a -z "$${i386}" -a -z "$${amd64}" -a -z "$${armv6}" -a -z "$${armv7}" -a -z "$${arm64}" ] ; then \
                        if [ `arch` = ppc ] ; then \
                                ppc=yes ; \
                        else \
@@ -94,36 +95,42 @@ process.o   : process.default.s process.i386.s process.amd64.s process.c lwp.o
                fi ; \
                if [ -n "$${armv6}" ] ; then \
                        $(CC) -x assembler-with-cpp -c -arch armv6 -I${TOP_INCDIR} -I${srcdir} ${srcdir}/process.default.s -o "$${armv6}" ; \
-                       if [ -z "$${i386}" -a -z "$${amd64}" -a -z "$${ppc}" -a -z "$${armv7}" ] ; then \
+                       if [ -z "$${i386}" -a -z "$${amd64}" -a -z "$${ppc}" -a -z "$${armv7}" -a -z "$${arm64}" ] ; then \
                                ${MV} "$${armv6}" process.o ; \
                        fi ; \
                fi ; \
                if [ -n "$${armv7}" ] ; then \
                        $(CC) -x assembler-with-cpp -c -arch armv7 -I${TOP_INCDIR} -I${srcdir} ${srcdir}/process.default.s -o "$${armv7}" ; \
-                       if [ -z "$${i386}" -a -z "$${amd64}" -a -z "$${ppc}" -a -z "$${armv6}" ] ; then \
+                       if [ -z "$${i386}" -a -z "$${amd64}" -a -z "$${ppc}" -a -z "$${armv6}" -a -z "$${arm64}" ] ; then \
                                ${MV} "$${armv7}" process.o ; \
                        fi ; \
                fi ; \
                if [ -n "$${ppc}" ] ; then \
                        $(CC) ${LWP_DBG} ${LWP_OPTMZ} -c -arch ppc -I${TOP_INCDIR} ${srcdir}/process.default.s -o "$${ppc}" ; \
-                       if [ -z "$${i386}" -a -z "$${amd64}" -a -z "$${armv6}" -a -z "$${armv7}" ] ; then \
+                       if [ -z "$${i386}" -a -z "$${amd64}" -a -z "$${armv6}" -a -z "$${armv7}" -a -z "$${arm64}" ] ; then \
                                ${MV} "$${ppc}" process.o ; \
                        fi ; \
                fi ; \
                if [ -n "$${i386}" ] ; then \
                        $(CC) -x assembler-with-cpp -c -arch i386 -I${TOP_INCDIR} -I${srcdir} ${srcdir}/process.i386.s -o "$${i386}" ; \
-                       if [ -z "$${ppc}" -a -z "$${amd64}" -a -z "$${armv6}" -a -z "$${armv7}" ] ; then \
+                       if [ -z "$${ppc}" -a -z "$${amd64}" -a -z "$${armv6}" -a -z "$${armv7}" -a -z "$${arm64}" ] ; then \
                                ${MV} "$${i386}" process.o ; \
                        fi ; \
                fi ; \
                if [ -n "$${amd64}" ] ; then \
                        $(CC) -x assembler-with-cpp -c -arch x86_64 -I${TOP_INCDIR} -I${srcdir} ${srcdir}/process.amd64.s -o "$${amd64}" ; \
-                       if [ -z "$${ppc}" -a -z "$${i386}" -a -z "$${armv6}" -a -z "$${armv7}" ] ; then \
+                       if [ -z "$${ppc}" -a -z "$${i386}" -a -z "$${armv6}" -a -z "$${armv7}" -a -z "$${arm64}" ] ; then \
                                ${MV} "$${amd64}" process.o ; \
                        fi ; \
                fi ; \
+               if [ -n "$${arm64}" ] ; then \
+                       $(CC) ${LWP_DBG} ${LWP_OPTMZ} -c -arch arm64 -I${TOP_INCDIR} -I${srcdir} -I. -I${TOP_OBJDIR}/src/config ${srcdir}/process.c -o "$${arm64}" ; \
+                       if [ -z "$${ppc}" -a -z "$${i386}" -a -z "$${armv6}" -a -z "$${armv7}" -a -z "$${amd64}" ] ; then \
+                               ${MV} "$${arm64}" process.o ; \
+                       fi ; \
+               fi ; \
                if [ ! -f process.o ] ; then \
-                       lipo -create $${amd64} $${i386} $${ppc} $${armv6} $${armv7} -output process.o ;\
+                       lipo -create $${amd64} $${i386} $${ppc} $${armv6} $${armv7} $${arm64} -output process.o ;\
                fi ;; \
        i386_*bsd*) \
                cp ${srcdir}/process.i386.s process.S ; \
index 7ef772d..bfc1b7f 100644 (file)
@@ -591,7 +591,7 @@ xdr_free(xdrproc_t proc, void *obj)
     x.x_op = XDR_FREE;
 
     /* See note in xdr.h for the method behind this madness */
-#if defined(AFS_I386_LINUX_ENV) && defined(KERNEL) && !defined(UKERNEL)
+#ifdef AFS_XDRPROC_NO_VARARG
     (*proc)(&x, obj, 0);
 #else
     (*proc)(&x, obj);
index 2567372..b0e892c 100644 (file)
@@ -184,8 +184,18 @@ enum xdr_op {
  * uses a register (rather than stack) based calling convention. The
  * normal va_args prototype results in the arguments being placed on the
  * stack, where they aren't accessible to the 'real' function.
+ *
+ * On apple-arm64, if you implement a function with fixed parameters, but
+ * redeclare it with variadic parameters, the mismatch causes unexpected
+ * behavior.
  */
 #if defined(AFS_I386_LINUX_ENV) && defined(KERNEL) && !defined(UKERNEL)
+# define AFS_XDRPROC_NO_VARARG
+#elif defined(AFS_ARM64_DARWIN_ENV)
+# define AFS_XDRPROC_NO_VARARG
+#endif
+
+#ifdef AFS_XDRPROC_NO_VARARG
 typedef bool_t(*xdrproc_t) (void *, caddr_t, u_int);
 #else
 typedef bool_t(*xdrproc_t) (void *, ...);