summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-go
diff options
context:
space:
mode:
authorAndrew Wilkins <axwalk@gmail.com>2015-09-01 03:14:31 +0000
committerAndrew Wilkins <axwalk@gmail.com>2015-09-01 03:14:31 +0000
commit9211396d825dc90e1f1c5d33941853a037b7f842 (patch)
tree5fbf756c4a212abc6f9cf6702931331ca6a77ab3 /llvm/tools/llvm-go
parentb5aaf5a57a466078100ab8d5f1a9146622403e8c (diff)
downloadbcm5719-llvm-9211396d825dc90e1f1c5d33941853a037b7f842.tar.gz
bcm5719-llvm-9211396d825dc90e1f1c5d33941853a037b7f842.zip
Enable linking tools, shared libraries against libLLVM
Summary: Three closely related changes, to have a mode in which we link all executables and shared libraries against libLLVM. 1. Add a new LLVM_LINK_LLVM_DYLIB cmake option, which, when ON, will link executables and shared libraries against libLLVM. For this to work, it is necessary to also set LLVM_BUILD_LLVM_DYLIB and LLVM_DYLIB_EXPORT_ALL. It is not strictly necessary to set LLVM_DISABLE_LLVM_DYLIB_ATEXIT, but we also default to OFF in this mode, or tools tend to misbehave (e.g. stdout may not flush on exit when output is buffered.) llvm-config and Tablegen do not use libLLVM, as they are dependencies of libLLVM. 2. Modify llvm-go to take a new flag, "linkmode=component-libs|dylib". Depending on which one is passed (default is component-libs), we link with the individual libraries or libLLVM respectively. We pass in dylib when LLVM_LINK_LLVM_DYLIB is ON. 3. Fix LLVM_DYLIB_EXPORT_ALL on Linux, and expand the symbols exported to actually export all. Don't strip leading underscore from symbols on Linux, and make sure we get all exported symbols and weak-with-default symbols ("W" in nm output). Without these changes, passes won't load because the "Annotate..." symbols defined in lib/Support/Valigrind.cpp are not found. Testing: - Ran default build ("ninja") with LLVM, clang, compiler-rt, llgo, lldb. - Ran "check", "check-clang", "check-tsan", "check-libgo" targets. I've never had much success with LLDB tests, and llgoi is currently broken so check-llgo fails for an unrelated reason. - Ran "lldb" to ensure it loads. Reviewers: chandlerc, beanz, pcc, rnk Subscribers: rnk, chapuni, sylvestre.ledru, llvm-commits Differential Revision: http://reviews.llvm.org/D12488 llvm-svn: 246527
Diffstat (limited to 'llvm/tools/llvm-go')
-rw-r--r--llvm/tools/llvm-go/llvm-go.go91
1 files changed, 53 insertions, 38 deletions
diff --git a/llvm/tools/llvm-go/llvm-go.go b/llvm/tools/llvm-go/llvm-go.go
index c5c3fd244ca..ed79ca67b89 100644
--- a/llvm/tools/llvm-go/llvm-go.go
+++ b/llvm/tools/llvm-go/llvm-go.go
@@ -24,6 +24,11 @@ import (
"strings"
)
+const (
+ linkmodeComponentLibs = "component-libs"
+ linkmodeDylib = "dylib"
+)
+
type pkg struct {
llvmpath, pkgpath string
}
@@ -66,11 +71,12 @@ var components = []string{
func llvmConfig(args ...string) string {
configpath := os.Getenv("LLVM_CONFIG")
if configpath == "" {
- // strip llvm-go, add llvm-config
- configpath = os.Args[0][:len(os.Args[0])-7] + "llvm-config"
+ bin, _ := filepath.Split(os.Args[0])
+ configpath = filepath.Join(bin, "llvm-config")
}
cmd := exec.Command(configpath, args...)
+ cmd.Stderr = os.Stderr
out, err := cmd.Output()
if err != nil {
panic(err.Error())
@@ -78,11 +84,21 @@ func llvmConfig(args ...string) string {
outstr := string(out)
outstr = strings.TrimSuffix(outstr, "\n")
- return strings.Replace(outstr, "\n", " ", -1)
+ outstr = strings.Replace(outstr, "\n", " ", -1)
+ return outstr
}
-func llvmFlags() compilerFlags {
- ldflags := llvmConfig(append([]string{"--ldflags", "--libs", "--system-libs"}, components...)...)
+func llvmFlags(linkmode string) compilerFlags {
+ ldflags := llvmConfig("--ldflags")
+ switch linkmode {
+ case linkmodeComponentLibs:
+ ldflags += " " + llvmConfig(append([]string{"--libs"}, components...)...)
+ case linkmodeDylib:
+ ldflags += " -lLLVM"
+ default:
+ panic("invalid linkmode: " + linkmode)
+ }
+ ldflags += " " + llvmConfig("--system-libs")
if runtime.GOOS != "darwin" {
// OS X doesn't like -rpath with cgo. See:
// https://code.google.com/p/go/issues/detail?id=7293
@@ -117,8 +133,8 @@ func printComponents() {
fmt.Println(strings.Join(components, " "))
}
-func printConfig() {
- flags := llvmFlags()
+func printConfig(linkmode string) {
+ flags := llvmFlags(linkmode)
fmt.Printf(`// +build !byollvm
@@ -137,7 +153,7 @@ type (run_build_sh int)
`, flags.cpp, flags.cxx, flags.ld)
}
-func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags string) {
+func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags, linkmode string) {
args = addTag(args, "byollvm")
srcdir := llvmConfig("--src-root")
@@ -166,7 +182,7 @@ func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, l
newgopathlist = append(newgopathlist, filepath.SplitList(os.Getenv("GOPATH"))...)
newgopath := strings.Join(newgopathlist, string(filepath.ListSeparator))
- flags := llvmFlags()
+ flags := llvmFlags(linkmode)
newenv := []string{
"CC=" + cc,
@@ -178,7 +194,7 @@ func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, l
"PATH=" + newpath,
}
if llgo != "" {
- newenv = append(newenv, "GCCGO=" + llgo)
+ newenv = append(newenv, "GCCGO="+llgo)
}
for _, v := range os.Environ() {
@@ -234,45 +250,44 @@ func main() {
ldflags := os.Getenv("CGO_LDFLAGS")
gocmd := "go"
llgo := ""
+ linkmode := linkmodeComponentLibs
+
+ flags := []struct {
+ name string
+ dest *string
+ }{
+ {"cc", &cc},
+ {"cxx", &cxx},
+ {"go", &gocmd},
+ {"llgo", &llgo},
+ {"cppflags", &cppflags},
+ {"ldflags", &ldflags},
+ {"linkmode", &linkmode},
+ }
args := os.Args[1:]
- DONE: for {
- switch {
- case len(args) == 0:
+LOOP:
+ for {
+ if len(args) == 0 {
usage()
- case strings.HasPrefix(args[0], "cc="):
- cc = args[0][3:]
- args = args[1:]
- case strings.HasPrefix(args[0], "cxx="):
- cxx = args[0][4:]
- args = args[1:]
- case strings.HasPrefix(args[0], "go="):
- gocmd = args[0][3:]
- args = args[1:]
- case strings.HasPrefix(args[0], "llgo="):
- llgo = args[0][5:]
- args = args[1:]
- case strings.HasPrefix(args[0], "cppflags="):
- cppflags = args[0][9:]
- args = args[1:]
- case strings.HasPrefix(args[0], "cxxflags="):
- cxxflags = args[0][9:]
- args = args[1:]
- case strings.HasPrefix(args[0], "ldflags="):
- ldflags = args[0][8:]
- args = args[1:]
- default:
- break DONE
}
+ for _, flag := range flags {
+ if strings.HasPrefix(args[0], flag.name+"=") {
+ *flag.dest = args[0][len(flag.name)+1:]
+ args = args[1:]
+ continue LOOP
+ }
+ }
+ break
}
switch args[0] {
case "build", "get", "install", "run", "test":
- runGoWithLLVMEnv(args, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags)
+ runGoWithLLVMEnv(args, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags, linkmode)
case "print-components":
printComponents()
case "print-config":
- printConfig()
+ printConfig(linkmode)
default:
usage()
}
OpenPOWER on IntegriCloud