{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/20508","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/20508/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/20508/comments","events_url":"https://api.github.com/repos/golang/go/issues/20508/events","html_url":"https://github.com/golang/go/issues/20508","id":231789647,"number":20508,"title":"cmd/go: static linking fails on OpenBSD 6.1","user":{"login":"cac04","id":13987272,"avatar_url":"https://avatars0.githubusercontent.com/u/13987272?v=4","gravatar_id":"","url":"https://api.github.com/users/cac04","html_url":"https://github.com/cac04","followers_url":"https://api.github.com/users/cac04/followers","following_url":"https://api.github.com/users/cac04/following{/other_user}","gists_url":"https://api.github.com/users/cac04/gists{/gist_id}","starred_url":"https://api.github.com/users/cac04/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cac04/subscriptions","organizations_url":"https://api.github.com/users/cac04/orgs","repos_url":"https://api.github.com/users/cac04/repos","events_url":"https://api.github.com/users/cac04/events{/privacy}","received_events_url":"https://api.github.com/users/cac04/received_events","type":"User","site_admin":false},"labels":[{"id":199753702,"url":"https://api.github.com/repos/golang/go/labels/OS-OpenBSD","name":"OS-OpenBSD","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/56","html_url":"https://github.com/golang/go/milestone/56","labels_url":"https://api.github.com/repos/golang/go/milestones/56/labels","id":2473074,"number":56,"title":"Go1.10","description":"","creator":{"login":"rsc","id":104030,"avatar_url":"https://avatars1.githubusercontent.com/u/104030?v=4","gravatar_id":"","url":"https://api.github.com/users/rsc","html_url":"https://github.com/rsc","followers_url":"https://api.github.com/users/rsc/followers","following_url":"https://api.github.com/users/rsc/following{/other_user}","gists_url":"https://api.github.com/users/rsc/gists{/gist_id}","starred_url":"https://api.github.com/users/rsc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsc/subscriptions","organizations_url":"https://api.github.com/users/rsc/orgs","repos_url":"https://api.github.com/users/rsc/repos","events_url":"https://api.github.com/users/rsc/events{/privacy}","received_events_url":"https://api.github.com/users/rsc/received_events","type":"User","site_admin":false},"open_issues":467,"closed_issues":577,"state":"open","created_at":"2017-04-21T19:22:29Z","updated_at":"2017-11-23T15:40:04Z","due_on":"2018-01-31T08:00:00Z","closed_at":null},"comments":25,"created_at":"2017-05-27T09:31:27Z","updated_at":"2017-11-23T23:27:25Z","closed_at":null,"author_association":"NONE","body":"Please answer these questions before submitting your issue. Thanks!\r\n\r\n### What version of Go are you using (`go version`)?\r\n\r\n```\r\n# go version\r\ngo version go1.8 openbsd/amd64\r\n```\r\n### What operating system and processor architecture are you using (`go env`)?\r\n\r\nOpenBSD 6.1 on amd64.\r\n\r\n```\r\n# go env\r\nGOARCH=\"amd64\"\r\nGOBIN=\"\"\r\nGOEXE=\"\"\r\nGOHOSTARCH=\"amd64\"\r\nGOHOSTOS=\"openbsd\"\r\nGOOS=\"openbsd\"\r\nGOPATH=\"/root/go\"\r\nGORACE=\"\"\r\nGOROOT=\"/usr/local/go\"\r\nGOTOOLDIR=\"/usr/local/go/pkg/tool/openbsd_amd64\"\r\nGCCGO=\"gccgo\"\r\nCC=\"cc\"\r\nGOGCCFLAGS=\"-fPIC -m64 -pthread -fmessage-length=0\"\r\nCXX=\"c++\"\r\nCGO_ENABLED=\"1\"\r\nPKG_CONFIG=\"pkg-config\"\r\nCGO_CFLAGS=\"-g -O2\"\r\nCGO_CPPFLAGS=\"\"\r\nCGO_CXXFLAGS=\"-g -O2\"\r\nCGO_FFLAGS=\"-g -O2\"\r\nCGO_LDFLAGS=\"-g -O2\"\r\n```\r\n### What did you do?\r\n\r\nI attempted to follow the instructions at http://blog.hashbangbash.com/2014/04/linking-golang-statically/ for producing a statically linked binary from a `cgo` program.\r\n\r\nHere is the source:\r\n```\r\npackage main\r\n\r\n/*\r\nchar* foo(void) { return \"hello, world!\"; }\r\n*/\r\nimport \"C\"\r\n\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n        fmt.Println(C.GoString(C.foo()))\r\n}\r\n```\r\n\r\nWhich I built like this:\r\n```\r\ngo build --ldflags '-extldflags \"-static\"' ./cgo-example.go\r\n```\r\n\r\n### What did you expect to see?\r\n\r\nA successful compilation and linking.\r\n\r\n### What did you see instead?\r\n\r\n```\r\n# go build --ldflags '-extldflags \"-static\"' ./cgo-example.go\r\n# command-line-arguments\r\n/usr/local/go/pkg/tool/openbsd_amd64/link: running cc failed: exit status 1\r\n/usr/lib/rcrt0.o: In function `__start':\r\n(.text+0x1a): undefined reference to `_DYNAMIC'\r\n/usr/lib/libpthread.a(rthread.o): In function `_rthread_init':\r\n/usr/src/lib/librthread/rthread.c:231: undefined reference to `_DYNAMIC'\r\n/usr/lib/libpthread.a(rthread_fork.o): In function `_dofork':\r\n/usr/src/lib/librthread/rthread_fork.c:75: undefined reference to `_DYNAMIC'\r\ncollect2: ld returned 1 exit status\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/346708910","html_url":"https://github.com/golang/go/issues/20508#issuecomment-346708910","issue_url":"https://api.github.com/repos/golang/go/issues/20508","id":346708910,"user":{"login":"cac04","id":13987272,"avatar_url":"https://avatars0.githubusercontent.com/u/13987272?v=4","gravatar_id":"","url":"https://api.github.com/users/cac04","html_url":"https://github.com/cac04","followers_url":"https://api.github.com/users/cac04/followers","following_url":"https://api.github.com/users/cac04/following{/other_user}","gists_url":"https://api.github.com/users/cac04/gists{/gist_id}","starred_url":"https://api.github.com/users/cac04/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cac04/subscriptions","organizations_url":"https://api.github.com/users/cac04/orgs","repos_url":"https://api.github.com/users/cac04/repos","events_url":"https://api.github.com/users/cac04/events{/privacy}","received_events_url":"https://api.github.com/users/cac04/received_events","type":"User","site_admin":false},"created_at":"2017-11-23T23:27:25Z","updated_at":"2017-11-23T23:27:25Z","author_association":"NONE","body":"The following patch to enable `-buildmode=pie` on OpenBSD seems to work:\r\n```diff\r\ndiff --git cmd/dist/test.go cmd/dist/test.go\r\nindex bbc2a0f4ad..fd1a79ed52 100644\r\n--- cmd/dist/test.go\r\n+++ cmd/dist/test.go\r\n@@ -879,6 +879,8 @@ func (t *tester) supportedBuildmode(mode string) bool {\r\n \t\t\treturn true\r\n \t\tcase \"darwin-amd64\":\r\n \t\t\treturn true\r\n+\t\tcase \"openbsd-amd64\", \"openbsd-386\", \"openbsd-arm\":\r\n+\t\t\treturn true\r\n \t\t}\r\n \t\treturn false\r\n \r\ndiff --git cmd/go/internal/work/init.go cmd/go/internal/work/init.go\r\nindex 0e17286cf6..ae6942859c 100644\r\n--- cmd/go/internal/work/init.go\r\n+++ cmd/go/internal/work/init.go\r\n@@ -136,6 +136,8 @@ func buildModeInit() {\r\n \t\t\t\tcodegenArg = \"-shared\"\r\n \t\t\tcase \"darwin/amd64\":\r\n \t\t\t\tcodegenArg = \"-shared\"\r\n+\t\t\tcase \"openbsd/amd64\", \"openbsd/386\", \"openbsd/arm\":\r\n+\t\t\t\tcodegenArg = \"-shared\"\r\n \t\t\tdefault:\r\n \t\t\t\tbase.Fatalf(\"-buildmode=pie not supported on %s\\n\", platform)\r\n \t\t\t}\r\ndiff --git cmd/link/internal/ld/config.go cmd/link/internal/ld/config.go\r\nindex cc95392d77..2f5988efb3 100644\r\n--- cmd/link/internal/ld/config.go\r\n+++ cmd/link/internal/ld/config.go\r\n@@ -45,6 +45,12 @@ func (mode *BuildMode) Set(s string) error {\r\n \t\t\tdefault:\r\n \t\t\t\treturn badmode()\r\n \t\t\t}\r\n+\t\tcase \"openbsd\":\r\n+\t\t\tswitch objabi.GOARCH {\r\n+\t\t\tcase \"amd64\", \"386\", \"arm\":\r\n+\t\t\tdefault:\r\n+\t\t\t\treturn badmode()\r\n+\t\t\t}\r\n \t\tdefault:\r\n \t\t\treturn badmode()\r\n \t\t}\r\ndiff --git cmd/link/internal/ld/lib.go cmd/link/internal/ld/lib.go\r\nindex cd8b45cd2e..53a3e4b14b 100644\r\n--- cmd/link/internal/ld/lib.go\r\n+++ cmd/link/internal/ld/lib.go\r\n@@ -1093,7 +1093,9 @@ func (ctxt *Link) hostlink() {\r\n \t\t\targv = append(argv, \"-Wl,-no_pie\")\r\n \t\t}\r\n \tcase objabi.Hopenbsd:\r\n-\t\targv = append(argv, \"-Wl,-nopie\")\r\n+\t\tif ctxt.BuildMode != BuildModePIE {\r\n+\t\t\targv = append(argv, \"-nopie\")\r\n+\t\t}\r\n \tcase objabi.Hwindows:\r\n \t\tif windowsgui {\r\n \t\t\targv = append(argv, \"-mwindows\")\r\n```"}}
{"actor":{"display_login":"cac04"}}