<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Thu, 21 Jan 2016 at 06:01 Evgenii Stepanov <<a href="mailto:eugeni.stepanov@gmail.com">eugeni.stepanov@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
with this, I get the following failure in Bindings/Go/go.test:<br>
<br>
llvm-config: error: component libraries and shared library<br>
<br>
llvm-config: error: missing: /code/build-llvm/lib/libLLVMGlobalISel.a<br>
llvm-config: error: missing: /code/build-llvm/lib/libLLVMDebugInfoCodeView.a<br></blockquote><div><br></div><div>- Is this a clean build?</div><div>- Do you have BUILD_SHARED_LIBRARIES set?</div><div> - LLVM_LINK_LLVM_DYLIB?</div><div> - LLVM_BUILD_LLVM_DYLIB?</div><div><br></div><div>It's probably due to missing dependencies in CMake. I'll try to look into this later today.</div><div><br></div><div>Cheers,</div><div>Andrew</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
panic: exit status 1<br>
<br>
goroutine 1 [running]:<br>
main.llvmConfig(0xc8200757e0, 0x3, 0x3, 0x0, 0x0)<br>
/code/llvm/tools/llvm-go/llvm-go.go:82 +0x2c3<br>
main.llvmFlags(0x0, 0x0, 0x0, 0x0, 0x0, 0x0)<br>
/code/llvm/tools/llvm-go/llvm-go.go:92 +0xd3<br>
main.runGoWithLLVMEnv(0xc8200a8060, 0x4, 0x6, 0xc820012043, 0x1b,<br>
0xc82000e0c4, 0x1d, 0x7fff14e00cb1, 0x1d, 0x0, ...)<br>
/code/llvm/tools/llvm-go/llvm-go.go:176 +0x8aa<br>
main.main()<br>
/code/llvm/tools/llvm-go/llvm-go.go:275 +0x6c5<br>
<br>
On Tue, Jan 19, 2016 at 8:03 PM, Andrew Wilkins via llvm-commits<br>
<<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br>
> Author: axw<br>
> Date: Tue Jan 19 22:03:09 2016<br>
> New Revision: 258283<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=258283&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=258283&view=rev</a><br>
> Log:<br>
> tools/llvm-config: improve shared library support<br>
><br>
> Summary:<br>
><br>
> This is a re-commit of r257003, which was reverted,<br>
> along with the fixes from <a href="http://reviews.llvm.org/D15986" rel="noreferrer" target="_blank">http://reviews.llvm.org/D15986</a>.<br>
><br>
> r252532 added support for reporting the monolithic library<br>
> when LLVM_BUILD_LLVM_DYLIB is used. This would only be done<br>
> if the individual components were not found, and the dynamic<br>
> library is found.<br>
><br>
> This diff extends this as follows:<br>
> - If LLVM_LINK_LLVM_DYLIB is set, then prefer the shared<br>
> library, even if all component libraries exist.<br>
> - Two flags, --link-shared and --link-static are introduced<br>
> to provide explicit guidance. If --link-shared is passed<br>
> and the shared library does not exist, an error results.<br>
><br>
> Additionally, changed the expected shared library names from<br>
> (e.g.) LLVM-3.8.0 to LLVM-3.8. The former exists only in an<br>
> installation (and then only in CMake builds I think?), and not<br>
> in the build tree; this breaks usage of llvm-config during<br>
> builds, e.g. by llvm-go.<br>
><br>
> Reviewers: DiamondLovesYou, beanz<br>
><br>
> Subscribers: llvm-commits<br>
><br>
> Differential Revision: <a href="http://reviews.llvm.org/D15986" rel="noreferrer" target="_blank">http://reviews.llvm.org/D15986</a><br>
><br>
><br>
> Modified:<br>
> llvm/trunk/cmake/modules/AddLLVM.cmake<br>
> llvm/trunk/tools/llvm-config/<a href="http://BuildVariables.inc.in" rel="noreferrer" target="_blank">BuildVariables.inc.in</a><br>
> llvm/trunk/tools/llvm-config/CMakeLists.txt<br>
> llvm/trunk/tools/llvm-config/Makefile<br>
> llvm/trunk/tools/llvm-config/llvm-config.cpp<br>
> llvm/trunk/tools/llvm-go/llvm-go.go<br>
><br>
> Modified: llvm/trunk/cmake/modules/AddLLVM.cmake<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/AddLLVM.cmake?rev=258283&r1=258282&r2=258283&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/AddLLVM.cmake?rev=258283&r1=258282&r2=258283&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/cmake/modules/AddLLVM.cmake (original)<br>
> +++ llvm/trunk/cmake/modules/AddLLVM.cmake Tue Jan 19 22:03:09 2016<br>
> @@ -913,13 +913,8 @@ function(llvm_add_go_executable binary p<br>
> set(cppflags "${cppflags} -I${d}")<br>
> endforeach(d)<br>
> set(ldflags "${CMAKE_EXE_LINKER_FLAGS}")<br>
> - if (LLVM_LINK_LLVM_DYLIB)<br>
> - set(linkmode "dylib")<br>
> - else()<br>
> - set(linkmode "component-libs")<br>
> - endif()<br>
> add_custom_command(OUTPUT ${binpath}<br>
> - COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "go=${GO_EXECUTABLE}" "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}" "linkmode=${linkmode}"<br>
> + COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "go=${GO_EXECUTABLE}" "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}"<br>
> ${ARG_GOFLAGS} build -o ${binpath} ${pkgpath}<br>
> DEPENDS llvm-config ${CMAKE_BINARY_DIR}/bin/llvm-go${CMAKE_EXECUTABLE_SUFFIX}<br>
> ${llvmlibs} ${ARG_DEPENDS}<br>
><br>
> Modified: llvm/trunk/tools/llvm-config/<a href="http://BuildVariables.inc.in" rel="noreferrer" target="_blank">BuildVariables.inc.in</a><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-config/BuildVariables.inc.in?rev=258283&r1=258282&r2=258283&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-config/BuildVariables.inc.in?rev=258283&r1=258282&r2=258283&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/tools/llvm-config/<a href="http://BuildVariables.inc.in" rel="noreferrer" target="_blank">BuildVariables.inc.in</a> (original)<br>
> +++ llvm/trunk/tools/llvm-config/<a href="http://BuildVariables.inc.in" rel="noreferrer" target="_blank">BuildVariables.inc.in</a> Tue Jan 19 22:03:09 2016<br>
> @@ -29,5 +29,7 @@<br>
> #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@"<br>
> #define LLVM_HAS_RTTI "@LLVM_HAS_RTTI@"<br>
> #define LLVM_ENABLE_DYLIB "@LLVM_BUILD_LLVM_DYLIB@"<br>
> +#define LLVM_LINK_DYLIB "@LLVM_LINK_LLVM_DYLIB@"<br>
> #define LLVM_ENABLE_SHARED "@LLVM_ENABLE_SHARED@"<br>
> #define LLVM_DYLIB_COMPONENTS "@LLVM_DYLIB_COMPONENTS@"<br>
> +#define LLVM_DYLIB_VERSION "@LLVM_DYLIB_VERSION@"<br>
><br>
> Modified: llvm/trunk/tools/llvm-config/CMakeLists.txt<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-config/CMakeLists.txt?rev=258283&r1=258282&r2=258283&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-config/CMakeLists.txt?rev=258283&r1=258282&r2=258283&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/tools/llvm-config/CMakeLists.txt (original)<br>
> +++ llvm/trunk/tools/llvm-config/CMakeLists.txt Tue Jan 19 22:03:09 2016<br>
> @@ -26,6 +26,7 @@ set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAK<br>
> set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")<br>
> set(LLVM_BUILD_SYSTEM cmake)<br>
> set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})<br>
> +set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}${LLVM_VERSION_SUFFIX}")<br>
><br>
> # Use the C++ link flags, since they should be a superset of C link flags.<br>
> set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")<br>
><br>
> Modified: llvm/trunk/tools/llvm-config/Makefile<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-config/Makefile?rev=258283&r1=258282&r2=258283&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-config/Makefile?rev=258283&r1=258282&r2=258283&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/tools/llvm-config/Makefile (original)<br>
> +++ llvm/trunk/tools/llvm-config/Makefile Tue Jan 19 22:03:09 2016<br>
> @@ -44,6 +44,8 @@ else<br>
> LLVM_HAS_RTTI := YES<br>
> endif<br>
><br>
> +LLVM_DYLIB_VERSION := $(LLVM_VERSION_MAJOR).$(LLVM_VERSION_MINOR)$(LLVM_VERSION_SUFFIX)<br>
> +<br>
> # This is blank for now. We need to be careful about adding stuff here:<br>
> # LDFLAGS tend not to be portable, and we don't currently require the<br>
> # user to use libtool when linking against LLVM.<br>
> @@ -83,6 +85,8 @@ $(ObjDir)/BuildVariables.inc: $(BUILDVAR<br>
> >> temp.sed<br>
> $(Verb) $(ECHO) 's/@LLVM_HAS_RTTI@/$(LLVM_HAS_RTTI)/' \<br>
> >> temp.sed<br>
> + $(Verb) $(ECHO) 's/@LLVM_DYLIB_VERSION@/$(LLVM_DYLIB_VERSION)/' \<br>
> + >> temp.sed<br>
> $(Verb) $(SED) -f temp.sed < $< > $@<br>
> $(Verb) $(RM) temp.sed<br>
><br>
><br>
> Modified: llvm/trunk/tools/llvm-config/llvm-config.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-config/llvm-config.cpp?rev=258283&r1=258282&r2=258283&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-config/llvm-config.cpp?rev=258283&r1=258282&r2=258283&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/tools/llvm-config/llvm-config.cpp (original)<br>
> +++ llvm/trunk/tools/llvm-config/llvm-config.cpp Tue Jan 19 22:03:09 2016<br>
> @@ -29,8 +29,8 @@<br>
> #include "llvm/Support/raw_ostream.h"<br>
> #include <cstdlib><br>
> #include <set><br>
> -#include <vector><br>
> #include <unordered_set><br>
> +#include <vector><br>
><br>
> using namespace llvm;<br>
><br>
> @@ -46,6 +46,22 @@ using namespace llvm;<br>
> // create entries for pseudo groups like x86 or all-targets.<br>
> #include "LibraryDependencies.inc"<br>
><br>
> +// LinkMode determines what libraries and flags are returned by llvm-config.<br>
> +enum LinkMode {<br>
> + // LinkModeAuto will link with the default link mode for the installation,<br>
> + // which is dependent on the value of LLVM_LINK_LLVM_DYLIB, and fall back<br>
> + // to the alternative if the required libraries are not available.<br>
> + LinkModeAuto = 0,<br>
> +<br>
> + // LinkModeShared will link with the dynamic component libraries if they<br>
> + // exist, and return an error otherwise.<br>
> + LinkModeShared = 1,<br>
> +<br>
> + // LinkModeStatic will link with the static component libraries if they<br>
> + // exist, and return an error otherwise.<br>
> + LinkModeStatic = 2,<br>
> +};<br>
> +<br>
> /// \brief Traverse a single component adding to the topological ordering in<br>
> /// \arg RequiredLibs.<br>
> ///<br>
> @@ -56,12 +72,14 @@ using namespace llvm;<br>
> /// libraries.<br>
> /// \param GetComponentNames - Get the component names instead of the<br>
> /// library name.<br>
> -static void VisitComponent(const std::string& Name,<br>
> - const StringMap<AvailableComponent*> &ComponentMap,<br>
> - std::set<AvailableComponent*> &VisitedComponents,<br>
> +static void VisitComponent(const std::string &Name,<br>
> + const StringMap<AvailableComponent *> &ComponentMap,<br>
> + std::set<AvailableComponent *> &VisitedComponents,<br>
> std::vector<std::string> &RequiredLibs,<br>
> bool IncludeNonInstalled, bool GetComponentNames,<br>
> - const std::string *ActiveLibDir, bool *HasMissing) {<br>
> + const std::function<std::string(const StringRef &)><br>
> + *GetComponentLibraryPath,<br>
> + std::vector<std::string> *Missing) {<br>
> // Lookup the component.<br>
> AvailableComponent *AC = ComponentMap.lookup(Name);<br>
> assert(AC && "Invalid component name!");<br>
> @@ -80,7 +98,7 @@ static void VisitComponent(const std::st<br>
> for (unsigned i = 0; AC->RequiredLibraries[i]; ++i) {<br>
> VisitComponent(AC->RequiredLibraries[i], ComponentMap, VisitedComponents,<br>
> RequiredLibs, IncludeNonInstalled, GetComponentNames,<br>
> - ActiveLibDir, HasMissing);<br>
> + GetComponentLibraryPath, Missing);<br>
> }<br>
><br>
> if (GetComponentNames) {<br>
> @@ -90,8 +108,10 @@ static void VisitComponent(const std::st<br>
><br>
> // Add to the required library list.<br>
> if (AC->Library) {<br>
> - if (!IncludeNonInstalled && HasMissing && !*HasMissing && ActiveLibDir) {<br>
> - *HasMissing = !sys::fs::exists(*ActiveLibDir + "/" + AC->Library);<br>
> + if (Missing && GetComponentLibraryPath) {<br>
> + std::string path = (*GetComponentLibraryPath)(AC->Library);<br>
> + if (!sys::fs::exists(path))<br>
> + Missing->push_back(path);<br>
> }<br>
> RequiredLibs.push_back(AC->Library);<br>
> }<br>
> @@ -108,12 +128,14 @@ static void VisitComponent(const std::st<br>
> static std::vector<std::string><br>
> ComputeLibsForComponents(const std::vector<StringRef> &Components,<br>
> bool IncludeNonInstalled, bool GetComponentNames,<br>
> - const std::string *ActiveLibDir, bool *HasMissing) {<br>
> + const std::function<std::string(const StringRef &)><br>
> + *GetComponentLibraryPath,<br>
> + std::vector<std::string> *Missing) {<br>
> std::vector<std::string> RequiredLibs;<br>
> std::set<AvailableComponent *> VisitedComponents;<br>
><br>
> // Build a map of component names to information.<br>
> - StringMap<AvailableComponent*> ComponentMap;<br>
> + StringMap<AvailableComponent *> ComponentMap;<br>
> for (unsigned i = 0; i != array_lengthof(AvailableComponents); ++i) {<br>
> AvailableComponent *AC = &AvailableComponents[i];<br>
> ComponentMap[AC->Name] = AC;<br>
> @@ -133,7 +155,7 @@ ComputeLibsForComponents(const std::vect<br>
><br>
> VisitComponent(ComponentLower, ComponentMap, VisitedComponents,<br>
> RequiredLibs, IncludeNonInstalled, GetComponentNames,<br>
> - ActiveLibDir, HasMissing);<br>
> + GetComponentLibraryPath, Missing);<br>
> }<br>
><br>
> // The list is now ordered with leafs first, we want the libraries to printed<br>
> @@ -179,6 +201,8 @@ Options:\n\<br>
> --build-system Print the build system used to build LLVM (autoconf or cmake).\n\<br>
> --has-rtti Print whether or not LLVM was built with rtti (YES or NO).\n\<br>
> --shared-mode Print how the provided components can be collectively linked (`shared` or `static`).\n\<br>
> + --link-shared Link the components as shared libraries.\n\<br>
> + --link-static Link the component libraries statically.\n\<br>
> Typical components:\n\<br>
> all All LLVM libraries (default).\n\<br>
> engine Either a native JIT or a bitcode interpreter.\n";<br>
> @@ -189,7 +213,7 @@ Typical components:\n\<br>
> std::string GetExecutablePath(const char *Argv0) {<br>
> // This just needs to be some symbol in the binary; C++ doesn't<br>
> // allow taking the address of ::main however.<br>
> - void *P = (void*) (intptr_t) GetExecutablePath;<br>
> + void *P = (void *)(intptr_t)GetExecutablePath;<br>
> return llvm::sys::fs::getMainExecutable(Argv0, P);<br>
> }<br>
><br>
> @@ -243,8 +267,8 @@ int main(int argc, char **argv) {<br>
> // Create an absolute path, and pop up one directory (we expect to be inside a<br>
> // bin dir).<br>
> sys::fs::make_absolute(CurrentPath);<br>
> - CurrentExecPrefix = sys::path::parent_path(<br>
> - sys::path::parent_path(CurrentPath)).str();<br>
> + CurrentExecPrefix =<br>
> + sys::path::parent_path(sys::path::parent_path(CurrentPath)).str();<br>
><br>
> // Check to see if we are inside a development tree by comparing to possible<br>
> // locations (prefix style or CMake style).<br>
> @@ -305,8 +329,8 @@ int main(int argc, char **argv) {<br>
> }<br>
><br>
> // We need to include files from both the source and object trees.<br>
> - ActiveIncludeOption = ("-I" + ActiveIncludeDir + " " +<br>
> - "-I" + ActiveObjRoot + "/include");<br>
> + ActiveIncludeOption =<br>
> + ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include");<br>
> } else {<br>
> ActivePrefix = CurrentExecPrefix;<br>
> ActiveIncludeDir = ActivePrefix + "/include";<br>
> @@ -323,25 +347,25 @@ int main(int argc, char **argv) {<br>
> /// in the first place. This can't be done at configure/build time.<br>
><br>
> StringRef SharedExt, SharedVersionedExt, SharedDir, SharedPrefix, StaticExt,<br>
> - StaticPrefix, StaticDir = "lib";<br>
> + StaticPrefix, StaticDir = "lib";<br>
> const Triple HostTriple(Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE));<br>
> if (HostTriple.isOSWindows()) {<br>
> SharedExt = "dll";<br>
> - SharedVersionedExt = PACKAGE_VERSION ".dll";<br>
> + SharedVersionedExt = LLVM_DYLIB_VERSION ".dll";<br>
> StaticExt = "a";<br>
> SharedDir = ActiveBinDir;<br>
> StaticDir = ActiveLibDir;<br>
> StaticPrefix = SharedPrefix = "lib";<br>
> } else if (HostTriple.isOSDarwin()) {<br>
> SharedExt = "dylib";<br>
> - SharedVersionedExt = PACKAGE_VERSION ".dylib";<br>
> + SharedVersionedExt = LLVM_DYLIB_VERSION ".dylib";<br>
> StaticExt = "a";<br>
> StaticDir = SharedDir = ActiveLibDir;<br>
> StaticPrefix = SharedPrefix = "lib";<br>
> } else {<br>
> // default to the unix values:<br>
> SharedExt = "so";<br>
> - SharedVersionedExt = PACKAGE_VERSION ".so";<br>
> + SharedVersionedExt = LLVM_DYLIB_VERSION ".so";<br>
> StaticExt = "a";<br>
> StaticDir = SharedDir = ActiveLibDir;<br>
> StaticPrefix = SharedPrefix = "lib";<br>
> @@ -362,11 +386,23 @@ int main(int argc, char **argv) {<br>
><br>
> bool DyLibExists = false;<br>
> const std::string DyLibName =<br>
> - (SharedPrefix + "LLVM-" + SharedVersionedExt).str();<br>
> + (SharedPrefix + "LLVM-" + SharedVersionedExt).str();<br>
> +<br>
> + // If LLVM_LINK_DYLIB is ON, the single shared library will be returned<br>
> + // for "--libs", etc, if they exist. This behaviour can be overridden with<br>
> + // --link-static or --link-shared.<br>
> + bool LinkDyLib = (std::strcmp(LLVM_LINK_DYLIB, "ON") == 0);<br>
><br>
> if (BuiltDyLib) {<br>
> DyLibExists = sys::fs::exists(SharedDir + "/" + DyLibName);<br>
> + if (!DyLibExists) {<br>
> + // The shared library does not exist: don't error unless the user<br>
> + // explicitly passes --link-shared.<br>
> + LinkDyLib = false;<br>
> + }<br>
> }<br>
> + LinkMode LinkMode =<br>
> + (LinkDyLib || BuiltSharedLibs) ? LinkModeShared : LinkModeAuto;<br>
><br>
> /// Get the component's library name without the lib prefix and the<br>
> /// extension. Returns true if Lib is in a recognized format.<br>
> @@ -392,11 +428,11 @@ int main(int argc, char **argv) {<br>
> };<br>
> /// Maps Unixizms to the host platform.<br>
> auto GetComponentLibraryFileName = [&](const StringRef &Lib,<br>
> - const bool ForceShared) {<br>
> + const bool Shared) {<br>
> std::string LibFileName = Lib;<br>
> StringRef LibName;<br>
> if (GetComponentLibraryNameSlice(Lib, LibName)) {<br>
> - if (BuiltSharedLibs || ForceShared) {<br>
> + if (Shared) {<br>
> LibFileName = (SharedPrefix + LibName + "." + SharedExt).str();<br>
> } else {<br>
> // default to static<br>
> @@ -407,10 +443,9 @@ int main(int argc, char **argv) {<br>
> return LibFileName;<br>
> };<br>
> /// Get the full path for a possibly shared component library.<br>
> - auto GetComponentLibraryPath = [&](const StringRef &Name,<br>
> - const bool ForceShared) {<br>
> - auto LibFileName = GetComponentLibraryFileName(Name, ForceShared);<br>
> - if (BuiltSharedLibs || ForceShared) {<br>
> + auto GetComponentLibraryPath = [&](const StringRef &Name, const bool Shared) {<br>
> + auto LibFileName = GetComponentLibraryFileName(Name, Shared);<br>
> + if (Shared) {<br>
> return (SharedDir + "/" + LibFileName).str();<br>
> } else {<br>
> return (StaticDir + "/" + LibFileName).str();<br>
> @@ -501,6 +536,10 @@ int main(int argc, char **argv) {<br>
> OS << ActivePrefix << '\n';<br>
> } else if (Arg == "--src-root") {<br>
> OS << LLVM_SRC_ROOT << '\n';<br>
> + } else if (Arg == "--link-shared") {<br>
> + LinkMode = LinkModeShared;<br>
> + } else if (Arg == "--link-static") {<br>
> + LinkMode = LinkModeStatic;<br>
> } else {<br>
> usage();<br>
> }<br>
> @@ -512,6 +551,11 @@ int main(int argc, char **argv) {<br>
> if (!HasAnyOption)<br>
> usage();<br>
><br>
> + if (LinkMode == LinkModeShared && !DyLibExists && !BuiltSharedLibs) {<br>
> + errs() << "llvm-config: error: " << DyLibName << " is missing\n";<br>
> + return 1;<br>
> + }<br>
> +<br>
> if (PrintLibs || PrintLibNames || PrintLibFiles || PrintSystemLibs ||<br>
> PrintSharedMode) {<br>
><br>
> @@ -525,11 +569,40 @@ int main(int argc, char **argv) {<br>
> Components.push_back("all");<br>
><br>
> // Construct the list of all the required libraries.<br>
> - bool HasMissing = false;<br>
> - std::vector<std::string> RequiredLibs =<br>
> - ComputeLibsForComponents(Components,<br>
> - /*IncludeNonInstalled=*/IsInDevelopmentTree,<br>
> - false, &ActiveLibDir, &HasMissing);<br>
> + std::function<std::string(const StringRef &)><br>
> + GetComponentLibraryPathFunction = [&](const StringRef &Name) {<br>
> + return GetComponentLibraryPath(Name, LinkMode == LinkModeShared);<br>
> + };<br>
> + std::vector<std::string> MissingLibs;<br>
> + std::vector<std::string> RequiredLibs = ComputeLibsForComponents(<br>
> + Components,<br>
> + /*IncludeNonInstalled=*/IsInDevelopmentTree, false,<br>
> + &GetComponentLibraryPathFunction, &MissingLibs);<br>
> + if (!MissingLibs.empty()) {<br>
> + switch (LinkMode) {<br>
> + case LinkModeShared:<br>
> + if (DyLibExists && !BuiltSharedLibs)<br>
> + break;<br>
> + // Using component shared libraries.<br>
> + for (auto &Lib : MissingLibs)<br>
> + errs() << "llvm-config: error: missing: " << Lib << "\n";<br>
> + return 1;<br>
> + case LinkModeAuto:<br>
> + if (DyLibExists) {<br>
> + LinkMode = LinkModeShared;<br>
> + break;<br>
> + }<br>
> + errs()<br>
> + << "llvm-config: error: component libraries and shared library\n\n";<br>
> + // fall through<br>
> + case LinkModeStatic:<br>
> + for (auto &Lib : MissingLibs)<br>
> + errs() << "llvm-config: error: missing: " << Lib << "\n";<br>
> + return 1;<br>
> + }<br>
> + } else if (LinkMode == LinkModeAuto) {<br>
> + LinkMode = LinkModeStatic;<br>
> + }<br>
><br>
> if (PrintSharedMode) {<br>
> std::unordered_set<std::string> FullDyLibComponents;<br>
> @@ -549,7 +622,7 @@ int main(int argc, char **argv) {<br>
> }<br>
> FullDyLibComponents.clear();<br>
><br>
> - if (HasMissing && DyLibExists) {<br>
> + if (LinkMode == LinkModeShared) {<br>
> OS << "shared\n";<br>
> return 0;<br>
> } else {<br>
> @@ -560,11 +633,12 @@ int main(int argc, char **argv) {<br>
><br>
> if (PrintLibs || PrintLibNames || PrintLibFiles) {<br>
><br>
> - auto PrintForLib = [&](const StringRef &Lib, const bool ForceShared) {<br>
> + auto PrintForLib = [&](const StringRef &Lib) {<br>
> + const bool Shared = LinkMode == LinkModeShared;<br>
> if (PrintLibNames) {<br>
> - OS << GetComponentLibraryFileName(Lib, ForceShared);<br>
> + OS << GetComponentLibraryFileName(Lib, Shared);<br>
> } else if (PrintLibFiles) {<br>
> - OS << GetComponentLibraryPath(Lib, ForceShared);<br>
> + OS << GetComponentLibraryPath(Lib, Shared);<br>
> } else if (PrintLibs) {<br>
> // If this is a typical library name, include it using -l.<br>
> StringRef LibName;<br>
> @@ -572,24 +646,24 @@ int main(int argc, char **argv) {<br>
> if (GetComponentLibraryNameSlice(Lib, LibName)) {<br>
> OS << "-l" << LibName;<br>
> } else {<br>
> - OS << "-l:" << GetComponentLibraryFileName(Lib, ForceShared);<br>
> + OS << "-l:" << GetComponentLibraryFileName(Lib, Shared);<br>
> }<br>
> } else {<br>
> // Otherwise, print the full path.<br>
> - OS << GetComponentLibraryPath(Lib, ForceShared);<br>
> + OS << GetComponentLibraryPath(Lib, Shared);<br>
> }<br>
> }<br>
> };<br>
><br>
> - if (HasMissing && DyLibExists) {<br>
> - PrintForLib(DyLibName, true);<br>
> + if (LinkMode == LinkModeShared && !BuiltSharedLibs) {<br>
> + PrintForLib(DyLibName);<br>
> } else {<br>
> for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) {<br>
> auto Lib = RequiredLibs[i];<br>
> if (i)<br>
> OS << ' ';<br>
><br>
> - PrintForLib(Lib, false);<br>
> + PrintForLib(Lib);<br>
> }<br>
> }<br>
> OS << '\n';<br>
><br>
> Modified: llvm/trunk/tools/llvm-go/llvm-go.go<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-go/llvm-go.go?rev=258283&r1=258282&r2=258283&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-go/llvm-go.go?rev=258283&r1=258282&r2=258283&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/tools/llvm-go/llvm-go.go (original)<br>
> +++ llvm/trunk/tools/llvm-go/llvm-go.go Tue Jan 19 22:03:09 2016<br>
> @@ -88,17 +88,8 @@ func llvmConfig(args ...string) string {<br>
> return outstr<br>
> }<br>
><br>
> -func llvmFlags(linkmode string) compilerFlags {<br>
> - ldflags := llvmConfig("--ldflags")<br>
> - switch linkmode {<br>
> - case linkmodeComponentLibs:<br>
> - ldflags += " " + llvmConfig(append([]string{"--libs"}, components...)...)<br>
> - case linkmodeDylib:<br>
> - ldflags += " -lLLVM"<br>
> - default:<br>
> - panic("invalid linkmode: " + linkmode)<br>
> - }<br>
> - ldflags += " " + llvmConfig("--system-libs")<br>
> +func llvmFlags() compilerFlags {<br>
> + ldflags := llvmConfig("--ldflags", "--libs", "--system-libs")<br>
> if runtime.GOOS != "darwin" {<br>
> // OS X doesn't like -rpath with cgo. See:<br>
> // <a href="https://code.google.com/p/go/issues/detail?id=7293" rel="noreferrer" target="_blank">https://code.google.com/p/go/issues/detail?id=7293</a><br>
> @@ -133,8 +124,8 @@ func printComponents() {<br>
> fmt.Println(strings.Join(components, " "))<br>
> }<br>
><br>
> -func printConfig(linkmode string) {<br>
> - flags := llvmFlags(linkmode)<br>
> +func printConfig() {<br>
> + flags := llvmFlags()<br>
><br>
> fmt.Printf(`// +build !byollvm<br>
><br>
> @@ -153,7 +144,7 @@ type (run_build_sh int)<br>
> `, flags.cpp, flags.cxx, flags.ld)<br>
> }<br>
><br>
> -func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags, linkmode string) {<br>
> +func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags string) {<br>
> args = addTag(args, "byollvm")<br>
><br>
> srcdir := llvmConfig("--src-root")<br>
> @@ -182,7 +173,7 @@ func runGoWithLLVMEnv(args []string, cc,<br>
> newgopathlist = append(newgopathlist, filepath.SplitList(os.Getenv("GOPATH"))...)<br>
> newgopath := strings.Join(newgopathlist, string(filepath.ListSeparator))<br>
><br>
> - flags := llvmFlags(linkmode)<br>
> + flags := llvmFlags()<br>
><br>
> newenv := []string{<br>
> "CC=" + cc,<br>
> @@ -250,7 +241,6 @@ func main() {<br>
> ldflags := os.Getenv("CGO_LDFLAGS")<br>
> gocmd := "go"<br>
> llgo := ""<br>
> - linkmode := linkmodeComponentLibs<br>
><br>
> flags := []struct {<br>
> name string<br>
> @@ -262,7 +252,6 @@ func main() {<br>
> {"llgo", &llgo},<br>
> {"cppflags", &cppflags},<br>
> {"ldflags", &ldflags},<br>
> - {"linkmode", &linkmode},<br>
> }<br>
><br>
> args := os.Args[1:]<br>
> @@ -283,11 +272,11 @@ LOOP:<br>
><br>
> switch args[0] {<br>
> case "build", "get", "install", "run", "test":<br>
> - runGoWithLLVMEnv(args, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags, linkmode)<br>
> + runGoWithLLVMEnv(args, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags)<br>
> case "print-components":<br>
> printComponents()<br>
> case "print-config":<br>
> - printConfig(linkmode)<br>
> + printConfig()<br>
> default:<br>
> usage()<br>
> }<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>