[PATCH] D43070: Add an instruction to avoid cgo compilation error from Go 1.9.4

Ryuichi Hayashida via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 8 06:17:49 PST 2018


rhysd created this revision.
rhysd added reviewers: axw, sammccall, echristo.
Herald added a subscriber: llvm-commits.

Because of CVE-2018-6574, some compiler options and linker options are restricted to prevent arbitrary code execution.

https://github.com/golang/go/issues/23672

By this change, building a Go code with LLVM Go bindings causes a compilation error as follows.

  go build llvm.org/llvm/bindings/go/llvm: invalid flag in #cgo LDFLAGS: -Wl,-headerpad_max_install_names

llvm-go tool generates cgo LDFLAGS directive from `llvm-config --ldflags` and it contains -Wl,option options. But -Wl,option is banned by default. To avoid this problem, we need to set $CGO_LDFLAGS_ALLOW environment variable to notify a compiler that the flags should be allowed.

  $ export CGO_LDFLAGS_ALLOW='-Wl,(-search_paths_first|-headerpad_max_install_names)'

I added an instruction about how to avoid the compilation error and build the code properly.


Repository:
  rL LLVM

https://reviews.llvm.org/D43070

Files:
  bindings/go/README.txt


Index: bindings/go/README.txt
===================================================================
--- bindings/go/README.txt
+++ bindings/go/README.txt
@@ -51,3 +51,11 @@
     $ export CGO_CXXFLAGS=-std=c++11
     $ export CGO_LDFLAGS="`/path/to/llvm-build/bin/llvm-config --ldflags --libs --system-libs all`"
     $ go build -tags byollvm
+
+If you see a compilation error while compiling your code with Go 1.9.4 or later as follows,
+
+    go build llvm.org/llvm/bindings/go/llvm: invalid flag in #cgo LDFLAGS: -Wl,-headerpad_max_install_names
+
+you need to setup $CGO_LDFLAGS_ALLOW to allow a compiler to specify some linker options:
+
+    $ export CGO_LDFLAGS_ALLOW='-Wl,(-search_paths_first|-headerpad_max_install_names)'


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43070.133409.patch
Type: text/x-patch
Size: 729 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180208/7f1e6654/attachment.bin>


More information about the llvm-commits mailing list