-
Notifications
You must be signed in to change notification settings - Fork 17.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/link, cmd/cgo: support -flto in CFLAGS
The linker now accepts unrecognized object files in external linking mode. These objects will simply be passed to the external linker. This permits using -flto which can generate pure byte code objects, whose symbol table the linker does not know how to read. The cgo tool now passes -fno-lto when generating objects whose symbols it needs to read. The cgo tool now emits matching types in different objects, so that the lto linker does not report a mismatch. This is based on https://golang.org/cl/293290 by Derek Parker. For #43505 Fixes #43830 Fixes #46295 Change-Id: I6787de213417466784ddef5af8899e453b4ae1ad Reviewed-on: https://go-review.googlesource.com/c/go/+/322614 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
- Loading branch information
1 parent
2725522
commit 24e9707
Showing
8 changed files
with
140 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# tests golang.org/issue/43830 | ||
|
||
[!cgo] skip 'skipping test without cgo' | ||
[openbsd] env CC='clang' | ||
[openbsd] [!exec:clang] skip 'skipping test without clang present' | ||
[!openbsd] env CC='gcc' | ||
[!openbsd] [!exec:gcc] skip 'skipping test without gcc present' | ||
|
||
env CGO_CFLAGS='-Wno-ignored-optimization-argument -flto -ffat-lto-objects' | ||
|
||
go build main.go | ||
|
||
-- main.go -- | ||
|
||
package main | ||
|
||
import "fmt" | ||
|
||
// #include "hello.h" | ||
import "C" | ||
|
||
func main() { | ||
hello := C.hello | ||
fmt.Printf("%v\n", hello) | ||
} | ||
|
||
-- hello.h -- | ||
|
||
#include <stdio.h> | ||
|
||
void hello(void) { | ||
printf("hello\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# tests golang.org/issue/43830 | ||
|
||
[!cgo] skip 'skipping test without cgo' | ||
[openbsd] env CC='clang' | ||
[openbsd] [!exec:clang] skip 'skipping test without clang present' | ||
[!openbsd] env CC='gcc' | ||
[!openbsd] [!exec:gcc] skip 'skipping test without gcc present' | ||
|
||
env CGO_CFLAGS='-Wno-ignored-optimization-argument -flto -ffat-lto-objects' | ||
|
||
go build main.go add.go | ||
|
||
-- main.go -- | ||
|
||
package main | ||
|
||
/* | ||
int c_add(int a, int b) { | ||
return myadd(a, b); | ||
} | ||
*/ | ||
import "C" | ||
|
||
func main() { | ||
println(C.c_add(1, 2)) | ||
} | ||
|
||
-- add.go -- | ||
|
||
package main | ||
|
||
import "C" | ||
|
||
/* test */ | ||
|
||
//export myadd | ||
func myadd(a C.int, b C.int) C.int { | ||
return a + b | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters