<div dir="ltr">This commit appears to break llvm-config when llvm/clang is built with shared libraries only which in turn breaks Bindings/Go/go.test<div><br><div>### before r257003:</div><div><div># bin/llvm-config --libs</div><div>-lLLVMLTO -lLLVMObjCARCOpts -lLLVMSymbolize -lLLVMDebugInfoPDB -lLLVMDebugInfoDWARF -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreInfo -lLLVMXCoreAsmPrinter -lLLVMSystemZDisassembler -lLLVMSystemZCodeGen -lLLVMSystemZAsmParser -lLLVMSystemZDesc -lLLVMSystemZInfo -lLLVMSystemZAsmPrinter -lLLVMSparcDisassembler -lLLVMSparcCodeGen -lLLVMSparcAsmParser -lLLVMSparcDesc -lLLVMSparcInfo -lLLVMSparcAsmPrinter -lLLVMPowerPCDisassembler -lLLVMPowerPCCodeGen -lLLVMPowerPCAsmParser -lLLVMPowerPCDesc -lLLVMPowerPCInfo -lLLVMPowerPCAsmPrinter -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMNVPTXAsmPrinter -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMMSP430AsmPrinter -lLLVMMipsDisassembler -lLLVMMipsCodeGen -lLLVMMipsAsmParser -lLLVMMipsDesc -lLLVMMipsInfo -lLLVMMipsAsmPrinter -lLLVMHexagonDisassembler -lLLVMHexagonCodeGen -lLLVMHexagonAsmParser -lLLVMHexagonDesc -lLLVMHexagonInfo -lLLVMCppBackendCodeGen -lLLVMCppBackendInfo -lLLVMBPFCodeGen -lLLVMBPFDesc -lLLVMBPFInfo -lLLVMBPFAsmPrinter -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMARMAsmParser -lLLVMARMDesc -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMAMDGPUCodeGen -lLLVMAMDGPUAsmParser -lLLVMAMDGPUDesc -lLLVMAMDGPUUtils -lLLVMAMDGPUInfo -lLLVMAMDGPUAsmPrinter -lLLVMAArch64Disassembler -lLLVMAArch64CodeGen -lLLVMAArch64AsmParser -lLLVMAArch64Desc -lLLVMAArch64Info -lLLVMAArch64AsmPrinter -lLLVMAArch64Utils -lLLVMMIRParser -lLLVMLibDriver -lLLVMOption -lgtest_main -lgtest -lLLVMTableGen -lLLVMLineEditor -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMMCJIT -lLLVMPasses -lLLVMipo -lLLVMVectorize -lLLVMLinker -lLLVMIRReader -lLLVMAsmParser -lLLVMDebugInfoCodeView -lLLVMInterpreter -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMInstrumentation -lLLVMProfileData -lLLVMBitWriter -lLLVMOrcJIT -lLLVMTransformUtils -lLLVMExecutionEngine -lLLVMTarget -lLLVMAnalysis -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMMC -lLLVMCore -lLLVMSupport</div></div></div><div><br></div><div>### after r257003:</div><div><div># bin/llvm-config --libs</div><div>llvm-config: error: component libraries and shared library</div><div><br></div><div>llvm-config: error: missing: /usr/local/google/home/tra/work/llvm/build/gpu/debug/lib/libLLVMSupport.a</div><div>llvm-config: error: missing: /usr/local/google/home/tra/work/llvm/build/gpu/debug/lib/libLLVMCore.a</div><div>llvm-config: error: missing: /usr/local/google/home/tra/work/llvm/build/gpu/debug/lib/libLLVMMC.a</div><div>llvm-config: error: missing: /usr/local/google/home/tra/work/llvm/build/gpu/debug/lib/libLLVMBitReader.a</div><div>llvm-config: error: missing: /usr/local/google/home/tra/work/llvm/build/gpu/debug/lib/libLLVMMCParser.a</div><div>llvm-config: error: missing: /usr/local/google/home/tra/work/llvm/build/gpu/debug/lib/libLLVMObject.a</div><div>llvm-config: error: missing: /usr/local/google/home/tra/work/llvm/build/gpu/debug/lib/libLLVMRuntimeDyld.a</div><div>llvm-config: error: missing: /usr/local/google/home/tra/work/llvm/build/gpu/debug/lib/libLLVMAnalysis.a</div><div>llvm-config: error: missing: /usr/local/google/home/tra/work/llvm/build/gpu/debug/lib/libLLVMTarget.a</div><div>llvm-config: error: missing: /usr/local/google/home/tra/work/llvm/build/gpu/debug/lib/libLLVMExecutionEngine.a</div><div>llvm-config: error: missing: /usr/local/google/home/tra/work/llvm/build/gpu/debug/lib/libLLVMTransformUtils.a</div><div>llvm-config: error: missing: /usr/local/google/home/tra/work/llvm/build/gpu/debug/lib/libLLVMOrcJIT.a</div><div>llvm-config: error: missing: /usr/local/google/home/tra/work/llvm/build/gpu/debug/lib/libLLVMBitWriter.a</div><div>llvm-config: error: missing: /usr/local/google/home/tra/work/llvm/build/gpu/debug/lib/libLLVMProfileData.a</div><div>llvm-config: error: missing: /usr/local/google/home/tra/work/llvm/build/gpu/debug/lib/libLLVMInstrumentation.a</div><div>llvm-config: error: missing: /usr/local/google/home/tra/work/llvm/build/gpu/debug/lib/libLLVMInstCombine.a</div></div><div>....</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 6, 2016 at 4:18 PM, Andrew Wilkins via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: axw<br>
Date: Wed Jan 6 18:18:56 2016<br>
New Revision: 257003<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=257003&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=257003&view=rev</a><br>
Log:<br>
tools/llvm-config: improve shared library support<br>
<br>
Summary:<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/D15033" rel="noreferrer" target="_blank">http://reviews.llvm.org/D15033</a><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=257003&r1=257002&r2=257003&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/AddLLVM.cmake?rev=257003&r1=257002&r2=257003&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/cmake/modules/AddLLVM.cmake (original)<br>
+++ llvm/trunk/cmake/modules/AddLLVM.cmake Wed Jan 6 18:18:56 2016<br>
@@ -911,13 +911,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=257003&r1=257002&r2=257003&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-config/BuildVariables.inc.in?rev=257003&r1=257002&r2=257003&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> Wed Jan 6 18:18:56 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=257003&r1=257002&r2=257003&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-config/CMakeLists.txt?rev=257003&r1=257002&r2=257003&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-config/CMakeLists.txt (original)<br>
+++ llvm/trunk/tools/llvm-config/CMakeLists.txt Wed Jan 6 18:18:56 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=257003&r1=257002&r2=257003&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-config/Makefile?rev=257003&r1=257002&r2=257003&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-config/Makefile (original)<br>
+++ llvm/trunk/tools/llvm-config/Makefile Wed Jan 6 18:18:56 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=257003&r1=257002&r2=257003&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-config/llvm-config.cpp?rev=257003&r1=257002&r2=257003&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-config/llvm-config.cpp (original)<br>
+++ llvm/trunk/tools/llvm-config/llvm-config.cpp Wed Jan 6 18:18:56 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>
+ // LinkModeDyLib will link with the single dynamic library if it exists,<br>
+ // and return an error if it does not exist.<br>
+ LinkModeDyLib = 1,<br>
+<br>
+ // LinkModeStatic will link with the individual component static libraries<br>
+ // if they exist, and fail if any one does not exist.<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,13 @@ 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::string *ActiveLibDir,<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 +97,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>
+ ActiveLibDir, Missing);<br>
}<br>
<br>
if (GetComponentNames) {<br>
@@ -90,8 +107,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 && ActiveLibDir) {<br>
+ std::string path = *ActiveLibDir + "/" + AC->Library;<br>
+ if (!sys::fs::exists(path))<br>
+ Missing->push_back(path);<br>
}<br>
RequiredLibs.push_back(AC->Library);<br>
}<br>
@@ -108,12 +127,13 @@ 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::string *ActiveLibDir,<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 +153,7 @@ ComputeLibsForComponents(const std::vect<br>
<br>
VisitComponent(ComponentLower, ComponentMap, VisitedComponents,<br>
RequiredLibs, IncludeNonInstalled, GetComponentNames,<br>
- ActiveLibDir, HasMissing);<br>
+ ActiveLibDir, Missing);<br>
}<br>
<br>
// The list is now ordered with leafs first, we want the libraries to printed<br>
@@ -179,6 +199,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 a shared library.\n\<br>
+ --link-static Link the components as a static libraries.\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 +211,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 +265,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 +327,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 +345,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 +384,22 @@ 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 = LinkDyLib ? LinkModeDyLib : 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>
@@ -501,6 +534,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 = LinkModeDyLib;<br>
+ } else if (Arg == "--link-static") {<br>
+ LinkMode = LinkModeStatic;<br>
} else {<br>
usage();<br>
}<br>
@@ -512,6 +549,11 @@ int main(int argc, char **argv) {<br>
if (!HasAnyOption)<br>
usage();<br>
<br>
+ if (LinkMode == LinkModeDyLib && !DyLibExists) {<br>
+ errs() << "llvm-config: error: " << DyLibName << " is missing\n\n";<br>
+ usage();<br>
+ }<br>
+<br>
if (PrintLibs || PrintLibNames || PrintLibFiles || PrintSystemLibs ||<br>
PrintSharedMode) {<br>
<br>
@@ -525,11 +567,31 @@ 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> MissingLibs;<br>
std::vector<std::string> RequiredLibs =<br>
ComputeLibsForComponents(Components,<br>
/*IncludeNonInstalled=*/IsInDevelopmentTree,<br>
- false, &ActiveLibDir, &HasMissing);<br>
+ false, &ActiveLibDir, &MissingLibs);<br>
+ if (!MissingLibs.empty()) {<br>
+ switch (LinkMode) {<br>
+ case LinkModeDyLib:<br>
+ break;<br>
+ case LinkModeAuto:<br>
+ if (DyLibExists) {<br>
+ LinkMode = LinkModeDyLib;<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 +611,7 @@ int main(int argc, char **argv) {<br>
}<br>
FullDyLibComponents.clear();<br>
<br>
- if (HasMissing && DyLibExists) {<br>
+ if (LinkMode == LinkModeDyLib) {<br>
OS << "shared\n";<br>
return 0;<br>
} else {<br>
@@ -581,7 +643,7 @@ int main(int argc, char **argv) {<br>
}<br>
};<br>
<br>
- if (HasMissing && DyLibExists) {<br>
+ if (LinkMode == LinkModeDyLib) {<br>
PrintForLib(DyLibName, true);<br>
} else {<br>
for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) {<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=257003&r1=257002&r2=257003&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-go/llvm-go.go?rev=257003&r1=257002&r2=257003&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-go/llvm-go.go (original)<br>
+++ llvm/trunk/tools/llvm-go/llvm-go.go Wed Jan 6 18:18:56 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">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><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">--Artem Belevich</div></div>
</div>