]> Cypherpunks repositories - gostls13.git/commit
cmd/interal/ld: darwin c-archive buildmode support
authorDavid Crawshaw <crawshaw@golang.org>
Thu, 9 Apr 2015 14:44:05 +0000 (10:44 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Sun, 12 Apr 2015 14:00:32 +0000 (14:00 +0000)
commitced7ffe95ba176b26ef835b2f225255d1cd7808f
tree03e5cbdffd2b109b0fd304d98b2cf5aa1274ffba
parent6e3a6c4d384bb1ca532727bbd7a1cd221786c42a
cmd/interal/ld: darwin c-archive buildmode support

Uses ar to create an archive when -buildmode=c-archive.

A small example (that I hope to turn into a test in a later CL):

goarchive.go:
package main

import "fmt"

import "C"

func init() {
fmt.Println("ran go init")
}

//export FuncInGo
func FuncInGo() {
fmt.Println("called a go function")
}

func main() {
fmt.Println("in main")
}

This can be compiled with:

go build -ldflags=-buildmode=c-archive -o=libgo.a goarchive.go

main.c:

#include <stdio.h>

extern void FuncInGo();

int main(void) {
printf("c hello\n");
FuncInGo();
printf("c goodbye\n");
return 0;
}

Can be compiled with:

cc main.c libgo.a

Apple provide a warning about the lack of PIE, but still produce a
binary which runs and outputs (on darwin/amd64):

c hello
ran go init
called a go function
c goodbye

Change-Id: I7611925f210a83afa6bd1e66a5601dd636a428c8
Reviewed-on: https://go-review.googlesource.com/8711
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/internal/ld/data.go
src/cmd/internal/ld/elf.go
src/cmd/internal/ld/go.go
src/cmd/internal/ld/lib.go
src/cmd/internal/ld/pobj.go