2014-10-23 04:33:23 +02:00
|
|
|
//===-- llvm-go.go - go tool wrapper for LLVM -----------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This tool lets us build LLVM components within the tree by setting up a
|
|
|
|
// $GOPATH that resembles a tree fetched in the normal way with "go get".
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
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
2015-09-01 05:14:31 +02:00
|
|
|
const (
|
|
|
|
linkmodeComponentLibs = "component-libs"
|
|
|
|
linkmodeDylib = "dylib"
|
|
|
|
)
|
|
|
|
|
2014-10-23 04:33:23 +02:00
|
|
|
type pkg struct {
|
|
|
|
llvmpath, pkgpath string
|
|
|
|
}
|
|
|
|
|
|
|
|
var packages = []pkg{
|
|
|
|
{"bindings/go/llvm", "llvm.org/llvm/bindings/go/llvm"},
|
|
|
|
}
|
|
|
|
|
|
|
|
type compilerFlags struct {
|
|
|
|
cpp, cxx, ld string
|
|
|
|
}
|
|
|
|
|
|
|
|
var components = []string{
|
|
|
|
"all-targets",
|
|
|
|
"analysis",
|
|
|
|
"asmparser",
|
|
|
|
"asmprinter",
|
|
|
|
"bitreader",
|
|
|
|
"bitwriter",
|
|
|
|
"codegen",
|
|
|
|
"core",
|
2015-01-30 19:07:45 +01:00
|
|
|
"debuginfodwarf",
|
2014-10-23 04:33:23 +02:00
|
|
|
"executionengine",
|
|
|
|
"instrumentation",
|
|
|
|
"interpreter",
|
|
|
|
"ipo",
|
|
|
|
"irreader",
|
|
|
|
"linker",
|
|
|
|
"mc",
|
|
|
|
"mcjit",
|
|
|
|
"objcarcopts",
|
|
|
|
"option",
|
|
|
|
"profiledata",
|
|
|
|
"scalaropts",
|
|
|
|
"support",
|
|
|
|
"target",
|
|
|
|
}
|
|
|
|
|
|
|
|
func llvmConfig(args ...string) string {
|
|
|
|
configpath := os.Getenv("LLVM_CONFIG")
|
|
|
|
if configpath == "" {
|
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
2015-09-01 05:14:31 +02:00
|
|
|
bin, _ := filepath.Split(os.Args[0])
|
|
|
|
configpath = filepath.Join(bin, "llvm-config")
|
2014-10-23 04:33:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd := exec.Command(configpath, args...)
|
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
2015-09-01 05:14:31 +02:00
|
|
|
cmd.Stderr = os.Stderr
|
2014-10-23 04:33:23 +02:00
|
|
|
out, err := cmd.Output()
|
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
outstr := string(out)
|
|
|
|
outstr = strings.TrimSuffix(outstr, "\n")
|
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
2015-09-01 05:14:31 +02:00
|
|
|
outstr = strings.Replace(outstr, "\n", " ", -1)
|
|
|
|
return outstr
|
2014-10-23 04:33:23 +02:00
|
|
|
}
|
|
|
|
|
tools/llvm-config: improve shared library support
Summary:
This is a re-commit of r257003, which was reverted,
along with the fixes from http://reviews.llvm.org/D15986.
r252532 added support for reporting the monolithic library
when LLVM_BUILD_LLVM_DYLIB is used. This would only be done
if the individual components were not found, and the dynamic
library is found.
This diff extends this as follows:
- If LLVM_LINK_LLVM_DYLIB is set, then prefer the shared
library, even if all component libraries exist.
- Two flags, --link-shared and --link-static are introduced
to provide explicit guidance. If --link-shared is passed
and the shared library does not exist, an error results.
Additionally, changed the expected shared library names from
(e.g.) LLVM-3.8.0 to LLVM-3.8. The former exists only in an
installation (and then only in CMake builds I think?), and not
in the build tree; this breaks usage of llvm-config during
builds, e.g. by llvm-go.
Reviewers: DiamondLovesYou, beanz
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D15986
llvm-svn: 258283
2016-01-20 05:03:09 +01:00
|
|
|
func llvmFlags() compilerFlags {
|
2016-01-21 03:33:39 +01:00
|
|
|
args := append([]string{"--ldflags", "--libs", "--system-libs"}, components...)
|
|
|
|
ldflags := llvmConfig(args...)
|
2014-10-23 04:33:23 +02:00
|
|
|
if runtime.GOOS != "darwin" {
|
|
|
|
// OS X doesn't like -rpath with cgo. See:
|
2017-11-14 00:47:58 +01:00
|
|
|
// https://github.com/golang/go/issues/7293
|
2014-10-23 04:33:23 +02:00
|
|
|
ldflags = "-Wl,-rpath," + llvmConfig("--libdir") + " " + ldflags
|
|
|
|
}
|
|
|
|
return compilerFlags{
|
|
|
|
cpp: llvmConfig("--cppflags"),
|
|
|
|
cxx: "-std=c++11",
|
|
|
|
ld: ldflags,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func addTag(args []string, tag string) []string {
|
|
|
|
args = append([]string{}, args...)
|
|
|
|
addedTag := false
|
|
|
|
for i, a := range args {
|
|
|
|
if strings.HasPrefix(a, "-tags=") {
|
|
|
|
args[i] = a + " " + tag
|
|
|
|
addedTag = true
|
|
|
|
} else if a == "-tags" && i+1 < len(args) {
|
|
|
|
args[i+1] = args[i+1] + " " + tag
|
|
|
|
addedTag = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !addedTag {
|
|
|
|
args = append([]string{args[0], "-tags", tag}, args[1:]...)
|
|
|
|
}
|
|
|
|
return args
|
|
|
|
}
|
|
|
|
|
|
|
|
func printComponents() {
|
|
|
|
fmt.Println(strings.Join(components, " "))
|
|
|
|
}
|
|
|
|
|
tools/llvm-config: improve shared library support
Summary:
This is a re-commit of r257003, which was reverted,
along with the fixes from http://reviews.llvm.org/D15986.
r252532 added support for reporting the monolithic library
when LLVM_BUILD_LLVM_DYLIB is used. This would only be done
if the individual components were not found, and the dynamic
library is found.
This diff extends this as follows:
- If LLVM_LINK_LLVM_DYLIB is set, then prefer the shared
library, even if all component libraries exist.
- Two flags, --link-shared and --link-static are introduced
to provide explicit guidance. If --link-shared is passed
and the shared library does not exist, an error results.
Additionally, changed the expected shared library names from
(e.g.) LLVM-3.8.0 to LLVM-3.8. The former exists only in an
installation (and then only in CMake builds I think?), and not
in the build tree; this breaks usage of llvm-config during
builds, e.g. by llvm-go.
Reviewers: DiamondLovesYou, beanz
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D15986
llvm-svn: 258283
2016-01-20 05:03:09 +01:00
|
|
|
func printConfig() {
|
|
|
|
flags := llvmFlags()
|
2014-10-23 04:33:23 +02:00
|
|
|
|
|
|
|
fmt.Printf(`// +build !byollvm
|
|
|
|
|
|
|
|
// This file is generated by llvm-go, do not edit.
|
|
|
|
|
|
|
|
package llvm
|
|
|
|
|
|
|
|
/*
|
|
|
|
#cgo CPPFLAGS: %s
|
|
|
|
#cgo CXXFLAGS: %s
|
|
|
|
#cgo LDFLAGS: %s
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type (run_build_sh int)
|
|
|
|
`, flags.cpp, flags.cxx, flags.ld)
|
|
|
|
}
|
|
|
|
|
2016-07-27 05:21:51 +02:00
|
|
|
func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags string, packages []pkg) {
|
2014-10-23 04:33:23 +02:00
|
|
|
args = addTag(args, "byollvm")
|
|
|
|
|
|
|
|
srcdir := llvmConfig("--src-root")
|
|
|
|
|
|
|
|
tmpgopath, err := ioutil.TempDir("", "gopath")
|
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, p := range packages {
|
|
|
|
path := filepath.Join(tmpgopath, "src", p.pkgpath)
|
|
|
|
err := os.MkdirAll(filepath.Dir(path), os.ModePerm)
|
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
|
|
|
|
2016-07-27 05:21:51 +02:00
|
|
|
abspath := p.llvmpath
|
|
|
|
if !filepath.IsAbs(abspath) {
|
|
|
|
abspath = filepath.Join(srcdir, abspath)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = os.Symlink(abspath, path)
|
2014-10-23 04:33:23 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-27 01:15:21 +01:00
|
|
|
newpath := os.Getenv("PATH")
|
|
|
|
|
2014-10-23 04:33:23 +02:00
|
|
|
newgopathlist := []string{tmpgopath}
|
|
|
|
newgopathlist = append(newgopathlist, filepath.SplitList(os.Getenv("GOPATH"))...)
|
|
|
|
newgopath := strings.Join(newgopathlist, string(filepath.ListSeparator))
|
|
|
|
|
tools/llvm-config: improve shared library support
Summary:
This is a re-commit of r257003, which was reverted,
along with the fixes from http://reviews.llvm.org/D15986.
r252532 added support for reporting the monolithic library
when LLVM_BUILD_LLVM_DYLIB is used. This would only be done
if the individual components were not found, and the dynamic
library is found.
This diff extends this as follows:
- If LLVM_LINK_LLVM_DYLIB is set, then prefer the shared
library, even if all component libraries exist.
- Two flags, --link-shared and --link-static are introduced
to provide explicit guidance. If --link-shared is passed
and the shared library does not exist, an error results.
Additionally, changed the expected shared library names from
(e.g.) LLVM-3.8.0 to LLVM-3.8. The former exists only in an
installation (and then only in CMake builds I think?), and not
in the build tree; this breaks usage of llvm-config during
builds, e.g. by llvm-go.
Reviewers: DiamondLovesYou, beanz
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D15986
llvm-svn: 258283
2016-01-20 05:03:09 +01:00
|
|
|
flags := llvmFlags()
|
2014-10-23 04:33:23 +02:00
|
|
|
|
|
|
|
newenv := []string{
|
|
|
|
"CC=" + cc,
|
|
|
|
"CXX=" + cxx,
|
|
|
|
"CGO_CPPFLAGS=" + flags.cpp + " " + cppflags,
|
|
|
|
"CGO_CXXFLAGS=" + flags.cxx + " " + cxxflags,
|
|
|
|
"CGO_LDFLAGS=" + flags.ld + " " + ldflags,
|
|
|
|
"GOPATH=" + newgopath,
|
2014-11-27 01:15:21 +01:00
|
|
|
"PATH=" + newpath,
|
2014-10-23 04:33:23 +02:00
|
|
|
}
|
2015-02-14 02:45:57 +01:00
|
|
|
if llgo != "" {
|
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
2015-09-01 05:14:31 +02:00
|
|
|
newenv = append(newenv, "GCCGO="+llgo)
|
2015-02-14 02:45:57 +01:00
|
|
|
}
|
|
|
|
|
2014-10-23 04:33:23 +02:00
|
|
|
for _, v := range os.Environ() {
|
|
|
|
if !strings.HasPrefix(v, "CC=") &&
|
|
|
|
!strings.HasPrefix(v, "CXX=") &&
|
|
|
|
!strings.HasPrefix(v, "CGO_CPPFLAGS=") &&
|
|
|
|
!strings.HasPrefix(v, "CGO_CXXFLAGS=") &&
|
|
|
|
!strings.HasPrefix(v, "CGO_LDFLAGS=") &&
|
2015-02-14 02:45:57 +01:00
|
|
|
!strings.HasPrefix(v, "GCCGO=") &&
|
2014-11-27 01:15:21 +01:00
|
|
|
!strings.HasPrefix(v, "GOPATH=") &&
|
|
|
|
!strings.HasPrefix(v, "PATH=") {
|
2014-10-23 04:33:23 +02:00
|
|
|
newenv = append(newenv, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-14 02:45:56 +01:00
|
|
|
gocmdpath, err := exec.LookPath(gocmd)
|
2014-10-23 04:33:23 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
|
|
|
|
2015-02-14 02:45:56 +01:00
|
|
|
proc, err := os.StartProcess(gocmdpath, append([]string{gocmd}, args...),
|
2014-10-23 04:33:23 +02:00
|
|
|
&os.ProcAttr{
|
|
|
|
Env: newenv,
|
|
|
|
Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
|
|
|
ps, err := proc.Wait()
|
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
os.RemoveAll(tmpgopath)
|
|
|
|
|
|
|
|
if !ps.Success() {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func usage() {
|
|
|
|
fmt.Println(`Usage: llvm-go subcommand [flags]
|
|
|
|
|
|
|
|
Available subcommands: build get install run test print-components print-config`)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
cc := os.Getenv("CC")
|
|
|
|
cxx := os.Getenv("CXX")
|
|
|
|
cppflags := os.Getenv("CGO_CPPFLAGS")
|
|
|
|
cxxflags := os.Getenv("CGO_CXXFLAGS")
|
|
|
|
ldflags := os.Getenv("CGO_LDFLAGS")
|
2015-02-14 02:45:56 +01:00
|
|
|
gocmd := "go"
|
2014-11-27 01:15:21 +01:00
|
|
|
llgo := ""
|
2016-07-27 05:21:51 +02:00
|
|
|
packagesString := ""
|
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
2015-09-01 05:14:31 +02:00
|
|
|
|
|
|
|
flags := []struct {
|
|
|
|
name string
|
|
|
|
dest *string
|
|
|
|
}{
|
|
|
|
{"cc", &cc},
|
|
|
|
{"cxx", &cxx},
|
|
|
|
{"go", &gocmd},
|
|
|
|
{"llgo", &llgo},
|
|
|
|
{"cppflags", &cppflags},
|
|
|
|
{"ldflags", &ldflags},
|
2016-07-27 05:21:51 +02:00
|
|
|
{"packages", &packagesString},
|
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
2015-09-01 05:14:31 +02:00
|
|
|
}
|
2014-10-23 04:33:23 +02:00
|
|
|
|
|
|
|
args := os.Args[1:]
|
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
2015-09-01 05:14:31 +02:00
|
|
|
LOOP:
|
|
|
|
for {
|
|
|
|
if len(args) == 0 {
|
2014-10-23 04:33:23 +02:00
|
|
|
usage()
|
|
|
|
}
|
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
2015-09-01 05:14:31 +02:00
|
|
|
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
|
2014-10-23 04:33:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-27 05:21:51 +02:00
|
|
|
packages := packages
|
|
|
|
if packagesString != "" {
|
|
|
|
for _, field := range strings.Fields(packagesString) {
|
|
|
|
pos := strings.IndexRune(field, '=')
|
|
|
|
if pos == -1 {
|
|
|
|
fmt.Fprintf(os.Stderr, "invalid packages value %q, expected 'pkgpath=llvmpath [pkgpath=llvmpath ...]'\n", packagesString)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
packages = append(packages, pkg{
|
|
|
|
pkgpath: field[:pos],
|
|
|
|
llvmpath: field[pos+1:],
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-23 04:33:23 +02:00
|
|
|
switch args[0] {
|
|
|
|
case "build", "get", "install", "run", "test":
|
2016-07-27 05:21:51 +02:00
|
|
|
runGoWithLLVMEnv(args, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags, packages)
|
2014-10-23 04:33:23 +02:00
|
|
|
case "print-components":
|
|
|
|
printComponents()
|
|
|
|
case "print-config":
|
tools/llvm-config: improve shared library support
Summary:
This is a re-commit of r257003, which was reverted,
along with the fixes from http://reviews.llvm.org/D15986.
r252532 added support for reporting the monolithic library
when LLVM_BUILD_LLVM_DYLIB is used. This would only be done
if the individual components were not found, and the dynamic
library is found.
This diff extends this as follows:
- If LLVM_LINK_LLVM_DYLIB is set, then prefer the shared
library, even if all component libraries exist.
- Two flags, --link-shared and --link-static are introduced
to provide explicit guidance. If --link-shared is passed
and the shared library does not exist, an error results.
Additionally, changed the expected shared library names from
(e.g.) LLVM-3.8.0 to LLVM-3.8. The former exists only in an
installation (and then only in CMake builds I think?), and not
in the build tree; this breaks usage of llvm-config during
builds, e.g. by llvm-go.
Reviewers: DiamondLovesYou, beanz
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D15986
llvm-svn: 258283
2016-01-20 05:03:09 +01:00
|
|
|
printConfig()
|
2014-10-23 04:33:23 +02:00
|
|
|
default:
|
|
|
|
usage()
|
|
|
|
}
|
|
|
|
}
|