Skip to content

Instantly share code, notes, and snippets.

@tonistiigi
Last active September 10, 2020 04:32
Show Gist options
  • Save tonistiigi/290d2e7118fe6f581e336bf3553b4501 to your computer and use it in GitHub Desktop.
Save tonistiigi/290d2e7118fe6f581e336bf3553b4501 to your computer and use it in GitHub Desktop.
From 234e37c1b338899f1269981aabc651f3b103c7ec Mon Sep 17 00:00:00 2001
From: Tonis Tiigi <[email protected]>
Date: Mon, 13 Jul 2020 22:49:20 -0700
Subject: [PATCH] [go1.13] temp fix for darwin/arm64
Signed-off-by: Tonis Tiigi <[email protected]>
---
src/cmd/link/internal/ld/lib.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index 3fa258d275..84c6e319e5 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -432,7 +432,7 @@ func (ctxt *Link) loadlib() {
toc.Type = sym.SDYNIMPORT
}
- if ctxt.LinkMode == LinkExternal && !iscgo && ctxt.LibraryByPkg["runtime/cgo"] == nil && !(objabi.GOOS == "darwin" && (ctxt.Arch.Family == sys.AMD64 || ctxt.Arch.Family == sys.I386)) {
+ if ctxt.LinkMode == LinkExternal && !iscgo && ctxt.LibraryByPkg["runtime/cgo"] == nil && !(objabi.GOOS == "darwin" && (ctxt.Arch.Family == sys.AMD64 || ctxt.Arch.Family == sys.I386 || ctxt.Arch.Family == sys.ARM64)) {
// This indicates a user requested -linkmode=external.
// The startup code uses an import of runtime/cgo to decide
// whether to initialize the TLS. So give it one. This could
@@ -1483,7 +1483,7 @@ func (ctxt *Link) hostlink() {
Exitf("%s: parsing Mach-O header failed: %v", os.Args[0], err)
}
// Only macOS supports unmapped segments such as our __DWARF segment.
- if machoPlatform == PLATFORM_MACOS {
+ if machoPlatform == PLATFORM_MACOS && ctxt.Arch.Family == sys.AMD64 {
if err := machoCombineDwarf(ctxt, exef, exem, dsym, combinedOutput); err != nil {
Exitf("%s: combining dwarf failed: %v", os.Args[0], err)
}
--
2.24.1
From c52a6757bcf64ed9d8b6c1b5e2775189ea42cce7 Mon Sep 17 00:00:00 2001
From: Tonis Tiigi <[email protected]>
Date: Mon, 13 Jul 2020 18:17:48 -0700
Subject: [PATCH] temp fix for darwin/arm64
Signed-off-by: Tonis Tiigi <[email protected]>
---
src/cmd/link/internal/ld/lib.go | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index 45cc87287c..32e431fbef 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -437,7 +437,7 @@ func (ctxt *Link) loadlib() {
// We now have enough information to determine the link mode.
determineLinkMode(ctxt)
- if ctxt.LinkMode == LinkExternal && !iscgo && ctxt.LibraryByPkg["runtime/cgo"] == nil && !(objabi.GOOS == "darwin" && ctxt.BuildMode != BuildModePlugin && (ctxt.Arch.Family == sys.AMD64 || ctxt.Arch.Family == sys.I386)) {
+ if ctxt.LinkMode == LinkExternal && !iscgo && ctxt.LibraryByPkg["runtime/cgo"] == nil && !(objabi.GOOS == "darwin" && ctxt.BuildMode != BuildModePlugin && (ctxt.Arch.Family == sys.AMD64 || ctxt.Arch.Family == sys.I386 || ctxt.Arch.Family == sys.ARM64)) {
// This indicates a user requested -linkmode=external.
// The startup code uses an import of runtime/cgo to decide
// whether to initialize the TLS. So give it one. This could
@@ -1214,7 +1214,7 @@ func (ctxt *Link) hostlink() {
switch ctxt.HeadType {
case objabi.Hdarwin:
- if machoPlatform == PLATFORM_MACOS {
+ if machoPlatform == PLATFORM_MACOS && !ctxt.Arch.InFamily(sys.ARM, sys.ARM64) {
// -headerpad is incompatible with -fembed-bitcode.
argv = append(argv, "-Wl,-headerpad,1144")
}
@@ -1254,7 +1254,7 @@ func (ctxt *Link) hostlink() {
switch ctxt.BuildMode {
case BuildModeExe:
if ctxt.HeadType == objabi.Hdarwin {
- if machoPlatform == PLATFORM_MACOS {
+ if machoPlatform == PLATFORM_MACOS && !ctxt.Arch.InFamily(sys.ARM, sys.ARM64) {
argv = append(argv, "-Wl,-no_pie")
argv = append(argv, "-Wl,-pagezero_size,4000000")
}
@@ -1561,7 +1561,7 @@ func (ctxt *Link) hostlink() {
Exitf("%s: parsing Mach-O header failed: %v", os.Args[0], err)
}
// Only macOS supports unmapped segments such as our __DWARF segment.
- if machoPlatform == PLATFORM_MACOS {
+ if machoPlatform == PLATFORM_MACOS && ctxt.Arch.Family == sys.AMD64 {
if err := machoCombineDwarf(ctxt, exef, exem, dsym, combinedOutput); err != nil {
Exitf("%s: combining dwarf failed: %v", os.Args[0], err)
}
--
2.24.1
From 80be55061d0d316f48299943fe263d8e3e992e0c Mon Sep 17 00:00:00 2001
From: Tonis Tiigi <[email protected]>
Date: Mon, 13 Jul 2020 18:17:48 -0700
Subject: [PATCH] temp fix for darwin/arm64
Signed-off-by: Tonis Tiigi <[email protected]>
---
src/cmd/link/internal/ld/lib.go | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index b0a9613e4f..fd63f1878a 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -554,7 +554,7 @@ func (ctxt *Link) loadlib() {
// We now have enough information to determine the link mode.
determineLinkMode(ctxt)
- if ctxt.LinkMode == LinkExternal && !iscgo && !(objabi.GOOS == "darwin" && ctxt.BuildMode != BuildModePlugin && ctxt.Arch.Family == sys.AMD64) {
+ if ctxt.LinkMode == LinkExternal && !iscgo && !(objabi.GOOS == "darwin" && ctxt.BuildMode != BuildModePlugin && (ctxt.Arch.Family == sys.AMD64 || ctxt.Arch.Family == sys.ARM64)) {
// This indicates a user requested -linkmode=external.
// The startup code uses an import of runtime/cgo to decide
// whether to initialize the TLS. So give it one. This could
@@ -1368,7 +1368,7 @@ func (ctxt *Link) hostlink() {
switch ctxt.HeadType {
case objabi.Hdarwin:
- if machoPlatform == PLATFORM_MACOS {
+ if machoPlatform == PLATFORM_MACOS && !ctxt.Arch.InFamily(sys.ARM, sys.ARM64) {
// -headerpad is incompatible with -fembed-bitcode.
argv = append(argv, "-Wl,-headerpad,1144")
}
@@ -1408,7 +1408,7 @@ func (ctxt *Link) hostlink() {
switch ctxt.BuildMode {
case BuildModeExe:
if ctxt.HeadType == objabi.Hdarwin {
- if machoPlatform == PLATFORM_MACOS {
+ if machoPlatform == PLATFORM_MACOS && !ctxt.Arch.InFamily(sys.ARM, sys.ARM64) {
argv = append(argv, "-Wl,-no_pie")
argv = append(argv, "-Wl,-pagezero_size,4000000")
}
@@ -1735,7 +1735,7 @@ func (ctxt *Link) hostlink() {
Exitf("%s: parsing Mach-O header failed: %v", os.Args[0], err)
}
// Only macOS supports unmapped segments such as our __DWARF segment.
- if machoPlatform == PLATFORM_MACOS {
+ if machoPlatform == PLATFORM_MACOS && ctxt.Arch.Family == sys.AMD64 {
if err := machoCombineDwarf(ctxt, exef, exem, dsym, combinedOutput); err != nil {
Exitf("%s: combining dwarf failed: %v", os.Args[0], err)
}
--
2.24.1
#!/usr/bin/env sh
# Download "Xcode 12 for macOS Universal Apps" from https://developer.apple.com/download/
# Rebuild go with patches for your branch
# Save this wrapper script and point `CC` env to it: export CC=./path/to/clang_arm64_wrapper.sh
# If needed modify XCODE_PATH
# Set GOOS=darwin GOARCH=arm64
#
# For building universal binaries: lipo -create -output binary binary_arm64 binary_amd64
export XCODE_PATH=$HOME/Downloads/Xcode-beta.app
export SDK_PATH=$XCODE_PATH/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk
export CGO_TARGET=arm64-apple-macos11
export CC=$XCODE_PATH/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
TARGETFLAGS=""
if [ "$GOARCH" == "arm64" ] && [ "$GOOS" == "darwin" ]; then
TARGETFLAGS="-isysroot $SDK_PATH --target=$CGO_TARGET"
fi
$CC "$@" $TARGETFLAGS
@amonshiz
Copy link

I found that I needed to change/add export SDKROOT=$SDK_PATH for the wrapper script to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment