repairs for AArch64 Mac OS

Still needed: code signing for installed dylibs and generated executables.
This commit is contained in:
Matthew Flatt 2020-12-04 05:11:41 -07:00
parent 908156b92f
commit 4e05a0d058
13 changed files with 165 additions and 53 deletions

View File

@ -9,6 +9,7 @@
("racket-x86_64-macosx-3" #:platform "x86_64-macosx")
("racket-i386-macosx-3" #:platform "i386-macosx")
("racket-ppc-macosx-3" #:platform "ppc-macosx")
("racket-aarch64-macosx-3" #:platform "aarch64-macosx")
("db-ppc-macosx" #:platform "ppc-macosx")
("db-win32-i386" #:platform "win32\\i386")
("db-win32-x86_64" #:platform "win32\\x86_64")

View File

@ -28,7 +28,9 @@
(error 'check-same "not: ~e ~e" a b)))
(define (round-up-page v)
(bitwise-and #xFFFFF000 (+ v #xFFF)))
(if (eq? 'aarch64 (system-type 'arch))
(bitwise-and #xFFFFC000 (+ v #x3FFF))
(bitwise-and #xFFFFF000 (+ v #xFFF))))
(define (mult-of-8 n)
(let ([m (modulo n 8)])
@ -285,8 +287,8 @@
((if link-edit-64? write-xulong write-ulong) outlen out)
((if link-edit-64? write-xulong write-ulong) out-offset out)
((if link-edit-64? write-xulong write-ulong) outlen out)
(write-ulong 0 out)
(write-ulong 0 out)
(write-ulong 0 out) ; maxprot
(write-ulong 0 out) ; minprot
(write-ulong 0 out)
(write-ulong 4 out) ; 4 means SG_NORELOC
;; Shift command positions

View File

@ -283,7 +283,8 @@
;; But if we assume no unaligned data and that fancy types
;; like _m256 won't show up with ObjC, it seems to be as
;; simple as this:
((ctype-sizeof v) . <= . 16))]))
((ctype-sizeof v) . <= . 16))]
[(aarch64-macosx aarch64-darwin) (lambda (v) #t)]))
;; Make `msgSends' access atomic, so that a thread cannot be suspended
;; or killed during access, which would block other threads.

View File

@ -239,18 +239,15 @@ GRAPPSKEL = GRacketCS.app/Contents/Info.plist
MACLIBRKT_LINK_fw = -F. -framework Racket $(LDFLAGS)
MACLIBRKT_LINK_static = $(BOOT_OBJS) $(LDFLAGS) $(LIBS)
racketcs@OSX@: main.o $(RKTFW)
$(CC) $(CFLAGS) -o racketcs main.o $(MACLIBRKT_LINK_@MACLIBRKT_LINK_MODE@)
racketcs@OSX@: raw_racketcs
$(MAKE) link-fw-bootfiles-@MACLIBRKT_LINK_MODE@
$(MAKE) raw_racketcs
$(MAKE) adjust-framework-boot-compress
$(MAKE) mac-embed-boot-@MACLIBRKT_LINK_MODE@ EMBED_DEST=racketcs
$(STRIP_SIGNATURE) racketcs
$(MAKE) mac-embed-boot-@MACLIBRKT_LINK_MODE@ EMBED_SRC=raw_racketcs EMBED_DEST=racketcs
/usr/bin/install_name_tool -change "Racket.framework/Versions/$(FWVERSION)_CS/Racket" "@executable_path/Racket.framework/Versions/$(FWVERSION)_CS/Racket" racketcs
$(RESTORE_SIGNATURE) racketcs
raw_racketcs@OSX@:
ln -s racketcs raw_racketcs
raw_racketcs@OSX@: main.o $(RKTFW)
$(CC) $(CFLAGS) -o raw_racketcs main.o $(MACLIBRKT_LINK_@MACLIBRKT_LINK_MODE@)
GRACKET_BIN = GRacketCS.app/Contents/MacOS/GRacketCS
@ -258,9 +255,8 @@ gracketcs@OSX@:
$(MAKE) $(GRACKET_BIN)
$(GRACKET_BIN): grmain.o $(RKTFW) $(GRAPPSKEL)
$(CC) $(CFLAGS) -o $(GRACKET_BIN) grmain.o $(MACLIBRKT_LINK_@MACLIBRKT_LINK_MODE@)
$(MAKE) mac-embed-boot-@MACLIBRKT_LINK_MODE@ EMBED_DEST=$(GRACKET_BIN)
$(STRIP_SIGNATURE) $(GRACKET_BIN)
$(CC) $(CFLAGS) -o $(GRACKET_BIN)_raw grmain.o $(MACLIBRKT_LINK_@MACLIBRKT_LINK_MODE@)
$(MAKE) mac-embed-boot-@MACLIBRKT_LINK_MODE@ EMBED_SRC=$(GRACKET_BIN)_raw EMBED_DEST=$(GRACKET_BIN)
/usr/bin/install_name_tool -change "Racket.framework/Versions/$(FWVERSION)_CS/Racket" "@executable_path/../../../Racket.framework/Versions/$(FWVERSION)_CS/Racket" $(GRACKET_BIN)
$(RESTORE_SIGNATURE) $(GRACKET_BIN)
@ -284,10 +280,15 @@ adjust-framework-boot-compress:
$(BOOTSTRAP_RACKET) $(srcdir)/adjust-compress.rkt @BOOT_COMPRESS_COMP@ $(FW_BOOT_DEST)/petite.boot $(FW_BOOT_DEST)/scheme.boot $(FW_BOOT_DEST)/racket.boot
mac-embed-boot-fw:
$(NOOP)
cp $(EMBED_SRC) $(EMBED_DEST)
$(STRIP_SIGNATURE) $(EMBED_DEST)
FW_BOOT_DESTS = $(FW_BOOT_DEST)/petite.boot $(FW_BOOT_DEST)/scheme.boot $(FW_BOOT_DEST)/racket.boot
mac-embed-boot-static:
$(BOOTSTRAP_RACKET) $(srcdir)/embed-boot.rkt @BOOT_COMPRESS_COMP@ "" $(EMBED_DEST) $(FW_BOOT_DEST)/petite.boot $(FW_BOOT_DEST)/scheme.boot $(FW_BOOT_DEST)/racket.boot
cp $(EMBED_SRC) $(EMBED_DEST)
$(STRIP_SIGNATURE) $(EMBED_DEST)
$(BOOTSTRAP_RACKET) $(srcdir)/embed-boot.rkt @BOOT_COMPRESS_COMP@ $(EMBED_SRC) $(EMBED_DEST) $(FW_BOOT_DESTS)
link-fw-bootfiles-fw:
$(NOOP)

View File

@ -92,6 +92,7 @@
(define-values (arch) (lookup 'arch-symbol))
(define-values (link) (lookup 'link-symbol))
(define-values (so-suffix) (lookup 'so-suffix-bytes))
(define-values (so-mode) (lookup 'so-mode))
(define-values (lib-subpath)
(string-append
@ -124,7 +125,7 @@
'library-subpath (string->bytes/utf-8 lib-subpath)
'library-subpath-convention (if (eq? os 'windows) 'windows 'unix)
'so-suffix so-suffix
'so-mode 'local
'so-mode so-mode
'fs-change (if (eq? os 'windows)
'#(supported scalable low-latency #f)
;; Warning: not necessarily right for cross compilation:

View File

@ -86,6 +86,11 @@
[(a6nt ta6nt i3nt ti3nt) (string->utf8 ".dll")]
[else (string->utf8 ".so")]))
(define so-mode
(case (machine-type)
[(arm64osx tarm64osx) 'global]
[else 'local]))
;; Force inline of some common cases, so optimization can use
;; the resulting constant:
(define-syntax system-type
@ -118,7 +123,7 @@
[(link) link-symbol]
[(machine) (get-machine-info)]
[(so-suffix) so-suffix-bytes]
[(so-mode) 'local]
[(so-mode) so-mode]
[(fs-change) fs-change-properties]
[(target-machine) (machine-type)]
[(cross) cross-mode]

View File

@ -22,7 +22,7 @@ Currently, we use the following external packages and versions:
openssl-1.1.1g
libiconv-1.15 (Windows only)
zlib-1.2.11 (Windows and Linux only)
libffi-3.2.1
libffi-3.2.1 (AArch64 Mac OS: libffi-3.3)
expat-2.2.5
gettext-0.19.8
glib-2.56.0
@ -37,7 +37,7 @@ Currently, we use the following external packages and versions:
pango-1.42.0
poppler-0.24.5
mpfr-3.1.6
gmp-6.1.2
gmp-6.1.2 (AArch64 Mac OS: gmp-6.2.1)
atk-2.28.1
(Linux only:)

View File

@ -59,6 +59,10 @@
"jpeg"
"atk"
"poppler")
(cond
[mac?
'("libedit")]
[else null])
(cond
[linux?
'("gdk-pixbuf"

View File

@ -189,12 +189,18 @@
(define-runtime-path fcdirs-patch "patches/fcdirs.patch")
(define-runtime-path fonts-conf "patches/fonts.conf")
;; Skip `fc-config` on install:
(define-runtime-path fc-config-patch "patches/fc-config.patch")
;; Avoid problems compiling with an old version of g++
(define-runtime-path harfbuzz-oldcompiler-patch "patches/harfbuzz-oldcompiler.patch")
;; Adapt inline-function handling for an old gcc
(define-runtime-path gmp-inline-patch "patches/gmp-inline.patch")
;; Configure for AArch64
(define-runtime-path openssl-aarch64osx-patch "patches/openssl-aarch64osx.patch")
;; --------------------------------------------------
(define (replace-in-file file orig new)
@ -239,6 +245,11 @@
(list "CC" (~a win-prefix "-gcc -static-libgcc")))])]
[mac?
(cond
[aarch64?
(define flags "-arch arm64 -mmacosx-version-min=11")
(list
(list "CPPFLAGS" (~a flags))
(list "LDFLAGS" (~a flags)))]
[m32?
(define sdk-flags (sdk mac32-sdk))
(list
@ -327,6 +338,7 @@
#:setup [setup null]
#:patches [patches null]
#:post-patches [post-patches null]
#:install-patches [install-patches null]
#:fixup [fixup #f]
#:fixup-proc [fixup-proc #f])
(for ([d (in-list (append (if (or (equal? package-name "pkg-config")
@ -338,7 +350,7 @@
deps))])
(unless (file-exists? (build-path dest "stamps" d))
(error 'build "prerequisite needed: ~a" d)))
(values env exe args make make-install setup patches post-patches fixup fixup-proc))
(values env exe args make make-install setup patches post-patches install-patches fixup fixup-proc))
(define path-flags
(list (list "CPPFLAGS" (~a "-I" dest "/include"))
@ -357,7 +369,7 @@
(error (format "build ~a only for Linux" package-name))))
(define-values (extra-env configure-exe extra-args make-command make-install-command
setup patches post-patches fixup fixup-proc)
setup patches post-patches install-patches fixup fixup-proc)
(case package-name
[("pkg-config") (config #:configure (list "--with-internal-glib"))]
[("sed") (config)]
@ -388,15 +400,20 @@
(~a "mingw" (if m32? "" "64"))
"shared")]
[mac?
(list "./Configure"
#f
"shared"
(cond
[ppc? "darwin-ppc-cc"]
[m32? "darwin-i386-cc"]
[else "darwin64-x86_64-cc"])
(car (regexp-match #rx"-mmacosx-version-min=[0-9.]*"
(cadr (assoc "CPPFLAGS" all-env)))))]
(append
(list "./Configure"
#f
"shared"
(cond
[ppc? "darwin-ppc-cc"]
[m32? "darwin-i386-cc"]
[aarch64? "darwin64-aarch64-cc"]
[else "darwin64-x86_64-cc"])
(car (regexp-match #rx"-mmacosx-version-min=[0-9.]*"
(cadr (assoc "CPPFLAGS" all-env)))))
(if aarch64?
'("no-asm")
null))]
[else
(list "./Configure"
#f
@ -404,6 +421,7 @@
"linux-x86_64")])
#:make make
#:make-install (~a make " install_sw")
#:patches (list openssl-aarch64osx-patch)
#:fixup (and win?
(~a "cd " (build-path dest "bin")
" && mv libssl-1_1" (if m32? "" "-x64") ".dll ssleay32.dll"
@ -463,7 +481,10 @@
" FreeSans.ttf"
" FreeSerif.ttf"
" " dest "/lib/fonts"))]
[("libffi") (config)]
[("libffi")
(if (and mac? aarch64?)
(config #:configure '("-host=aarch64-apple-darwin"))
(config))]
[("zlib")
(nonmac-only)
(config #:make (if win?
@ -511,7 +532,10 @@
`("--without-libiconv-prefix"
"--without-libintl-prefix")
'()))
#:patches (list fcdirs-patch))]
#:patches (list fcdirs-patch)
#:install-patches (cond
[(and mac? aarch64?) (list fc-config-patch)]
[else null]))]
[("pixman") (config #:patches (append
(cond
[(and win? (not m32?)) (list noforceinline-patch)]
@ -582,6 +606,9 @@
[("gmp") (config #:patches (if gcc-4.0? (list gmp-weak-patch) null)
#:configure (append
'("--enable-shared" "--disable-static")
(if (and mac? aarch64?)
'("-host=aarch64-apple-darwin")
null)
(if (and mac? (not ppc?))
'("--build=corei-apple-darwin")
null)
@ -648,6 +675,8 @@
(for ([p (in-list post-patches)])
(system/show (~a "patch -p2 < " p))))
(system/show make-command)
(for ([p (in-list install-patches)])
(system/show (~a "patch -p2 < " p)))
(system/show make-install-command)
(when fixup
(system/show fixup))

View File

@ -2,7 +2,7 @@
(require racket/cmdline)
(provide build-command-line
m32? win? mac? linux? ppc?
m32? win? mac? linux? ppc? aarch64?
archives-dirs)
(define m32? 'unknown)
@ -10,6 +10,7 @@
(define linux? #f)
(define mac? 'unknown)
(define ppc? #f)
(define aarch64? #f)
(define archives-dirs #f)
@ -20,6 +21,7 @@
(define mac? 'unknown)
(define linux? #f)
(define ppc? (regexp-match? #rx"ppc" (system-library-subpath #f)))
(define aarch64? (eq? 'aarch64 (system-type 'arch)))
(define archives-dirs #f)
(begin0
(command-line
@ -34,11 +36,14 @@
#:once-any
[("--m32") "build 32-bit mode x86/PowerPC"
(set! m32? #t)]
[("--m64") "build 64-bit mode x86_64"
[("--m64") "build 64-bit mode x86_64/AArch64"
(set! m32? #f)]
[("--mppc") "build 32-bit mode PowerPC"
(set! m32? #t)
(set! ppc? #t)]
[("--maarch64") "build 64-bit mode AArch64"
(set! m32? #f)
(set! aarch64? #t)]
#:multi
[("--archives") dir "Find archives in <dir>"
(set! archives-dirs (cons dir (or archives-dirs null)))]
@ -51,14 +56,15 @@
(when (and ppc? (not m32?))
(error 'build "cannot use `--m64` on PowerPC"))
(set! mac? (not (or win? linux?)))
(install! m32? win? mac? linux? (and mac? ppc?)
(install! m32? win? mac? linux? (and mac? ppc?) aarch64?
(reverse (or archives-dirs
(list (current-directory))))))))
(define (install! -m32? -win? -mac? -linux? -ppc? -archives-dirs)
(define (install! -m32? -win? -mac? -linux? -ppc? -aarch64? -archives-dirs)
(set! m32? -m32?)
(set! win? -win?)
(set! mac? -mac?)
(set! linux? -linux?)
(set! ppc? -ppc?)
(set! aarch64? -aarch64?)
(set! archives-dirs -archives-dirs))

View File

@ -6,8 +6,22 @@
racket/pretty
"cmdline.rkt")
(define sign-as #f)
(define dest-dir
(build-command-line
#:once-each
[("--sign-as") id "Sign Mac OS X libraries"
(set! sign-as id)]
#:args (dest-dir)
dest-dir))
;; Hack to make AArch64 Mac OS libraries look like other Macs:
(define renames
`(("libffi.7" "libffi.6")))
(define libs
'("libffi.6"
`("libffi.6"
"libgio-2.0.0"
"libgmodule-2.0.0"
"libgthread-2.0.0"
@ -42,12 +56,14 @@
"libpangowin32-1.0.0"))
(define mac-libs
'("libedit.0"
"PSMTabBarControl.framework"))
'("libedit.0"))
(define mac64-libs
'("MMTabBarView.framework"))
(define macx86-libs
'("PSMTabBarControl.framework"))
(define nonwin-libs
'("libcrypto.1.1"
"libssl.1.1"
@ -217,10 +233,11 @@
(or (equal? p "fonts")
(framework? p)))
(define dest-dir
(build-command-line
#:args (dest-dir)
dest-dir))
(define (revert-name p)
(or (for/or ([pr (in-list renames)])
(and (equal? (cadr pr) p)
(car pr)))
p))
(define from (build-path (current-directory) "dest" (if win? "bin" "lib")))
@ -315,10 +332,15 @@
(define pkgs-lic (make-hash))
(define (install lib)
(define p (cond
[(plain-path? lib) lib]
[(procedure? so) (so lib)]
[else (format "~a.~a" lib so)]))
(define-values (p orig-p)
(let ()
(define (both v) (values v v))
(cond
[(plain-path? lib) (both lib)]
[(procedure? so) (both (so lib))]
[else
(define (make lib) (format "~a.~a" lib so))
(values (make lib) (make (revert-name lib)))])))
(define-values (pkg suffix subdir lic) (find-pkg lib))
(define dir (build-path dest-dir
(~a pkg "-" platform suffix)
@ -330,7 +352,7 @@
(cond
[(file-exists? dest) (delete-file dest)]
[(directory-exists? dest) (delete-directory/files dest)])
(define src (build-path from p))
(define src (build-path from orig-p))
(if (directory-exists? src)
(copy-directory/files src dest)
(copy-file src dest)))
@ -360,23 +382,35 @@
(define (fixup p p-new)
(unless (framework? p)
(printf "Fixing ~s\n" p-new)
(when aarch64?
(system (format "codesign --remove-signature ~a" p-new)))
(unless (memq 'write (file-or-directory-permissions p-new))
(file-or-directory-permissions p-new #o744))
(system (format "install_name_tool -id ~a ~a" (file-name-from-path p-new) p-new))
(for-each (lambda (s)
(system (format "install_name_tool -change ~a @loader_path/~a ~a"
(format "~a/~a.dylib" from s)
(format "~a/~a.dylib" from (revert-name s))
(format "~a.dylib" s)
p-new)))
(append libs nonwin-libs))
(system (format "strip -S ~a" p-new))))
(system (format "strip -S ~a" p-new))
(when sign-as
(system (format "codesign -s ~s --timestamp ~a" sign-as p-new)))))
(define platform (~a (if m32?
(if ppc? "ppc" "i386")
"x86_64")
(if aarch64? "aarch64" "x86_64"))
"-macosx"))
(install platform platform "dylib" fixup (append libs mac-libs (if m32? '() mac64-libs) nonwin-libs)))
(install platform platform "dylib" fixup (append libs
mac-libs
(cond
[m32? '()]
[else mac64-libs])
(cond
[aarch64? '()]
[else macx86-libs])
nonwin-libs)))
(define (install-win)
(define exe-prefix (if m32?

View File

@ -0,0 +1,11 @@
diff -r -u old/fontconfig-2.13.0/fc-cache/fc-cache new/fontconfig-2.13.0/fc-cache/fc-cache
--- old/fontconfig-2.13.0/fc-cache/fc-cache 2020-12-03 15:33:48.000000000 -0700
+++ new/fontconfig-2.13.0/fc-cache/fc-cache 2020-12-03 15:33:59.000000000 -0700
@@ -1,5 +1,7 @@
#! /bin/sh
+exit
+
# fc-cache - temporary wrapper script for .libs/fc-cache
# Generated by libtool (GNU libtool) 2.4.6
#

View File

@ -0,0 +1,17 @@
diff -r -u old/openssl-1.1.0h/Configurations/10-main.conf new/openssl-1.1.0h/Configurations/10-main.conf
--- old/openssl-1.1.0h/Configurations/10-main.conf 2020-12-03 16:26:23.000000000 -0700
+++ new/openssl-1.1.0h/Configurations/10-main.conf 2020-12-03 16:26:09.000000000 -0700
@@ -1608,6 +1608,13 @@
perlasm_scheme => "macosx",
shared_ldflag => "-arch x86_64 -dynamiclib",
},
+ "darwin64-aarch64-cc" => {
+ inherit_from => [ "darwin-common", asm("aarch64_asm") ],
+ cflags => add("-arch arm64 -DL_ENDIAN -Wall"),
+ bn_ops => "SIXTY_FOUR_BIT_LONG",
+ perlasm_scheme => "macosx",
+ shared_ldflag => "-arch arm64 -dynamiclib",
+ },
#### iPhoneOS/iOS
#