Skip to content

Commit 5e8c4d9

Browse files
committed
darwin: support Boehm GC (and use by default)
This mostly required some updates to macos-minimal-sdk to add the needed header files and symbols.
1 parent ee76822 commit 5e8c4d9

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

builder/ar.go

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package builder
33
import (
44
"bytes"
55
"debug/elf"
6+
"debug/macho"
67
"debug/pe"
78
"encoding/binary"
89
"errors"
@@ -62,6 +63,20 @@ func makeArchive(arfile *os.File, objs []string) error {
6263
fileIndex int
6364
}{symbol.Name, i})
6465
}
66+
} else if dbg, err := macho.NewFile(objfile); err == nil {
67+
for _, symbol := range dbg.Symtab.Syms {
68+
// See mach-o/nlist.h
69+
if symbol.Type&0x0e != 0xe { // (symbol.Type & N_TYPE) != N_SECT
70+
continue // undefined symbol
71+
}
72+
if symbol.Type&0x01 == 0 { // (symbol.Type & N_EXT) == 0
73+
continue // internal symbol (static, etc)
74+
}
75+
symbolTable = append(symbolTable, struct {
76+
name string
77+
fileIndex int
78+
}{symbol.Name, i})
79+
}
6580
} else if dbg, err := pe.NewFile(objfile); err == nil {
6681
for _, symbol := range dbg.Symbols {
6782
if symbol.StorageClass != 2 {

builder/bdwgc.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var BoehmGC = Library{
2525
"-DALL_INTERIOR_POINTERS", // scan interior pointers (needed for Go)
2626
"-DIGNORE_DYNAMIC_LOADING", // we don't support dynamic loading at the moment
2727
"-DNO_GETCONTEXT", // musl doesn't support getcontext()
28+
"-DGC_DISABLE_INCREMENTAL", // don't mess with SIGSEGV and such
2829

2930
// Use a minimal environment.
3031
"-DNO_MSGBOX_ON_ERROR", // don't call MessageBoxA on Windows
@@ -68,8 +69,6 @@ var BoehmGC = Library{
6869
"new_hblk.c",
6970
"obj_map.c",
7071
"os_dep.c",
71-
"pthread_stop_world.c",
72-
"pthread_support.c",
7372
"reclaim.c",
7473
}
7574
if strings.Split(target, "-")[2] == "windows" {

builder/build.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
150150
var libcJob *compileJob
151151
switch config.Target.Libc {
152152
case "darwin-libSystem":
153-
job := makeDarwinLibSystemJob(config, tmpdir)
154-
libcDependencies = append(libcDependencies, job)
153+
libcJob = makeDarwinLibSystemJob(config, tmpdir)
154+
libcDependencies = append(libcDependencies, libcJob)
155155
case "musl":
156156
var unlock func()
157157
libcJob, unlock, err = libMusl.load(config, tmpdir, nil)

compileopts/target.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
380380
llvmvendor := "unknown"
381381
switch options.GOOS {
382382
case "darwin":
383-
spec.GC = "precise"
383+
spec.GC = "boehm"
384384
platformVersion := "10.12.0"
385385
if options.GOARCH == "arm64" {
386386
platformVersion = "11.0.0" // first macosx platform with arm64 support

lib/macos-minimal-sdk

0 commit comments

Comments
 (0)