Skip to content

Commit 1611ec4

Browse files
committed
Revert r257003
This revision breaks llvm-config if you set BUILD_SHARED_LIBS=on in a CMake build. Backing out until the fix is ready to land. llvm-svn: 257457
1 parent 31ad542 commit 1611ec4

File tree

6 files changed

+50
-103
lines changed

6 files changed

+50
-103
lines changed

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,8 +911,13 @@ function(llvm_add_go_executable binary pkgpath)
911911
set(cppflags "${cppflags} -I${d}")
912912
endforeach(d)
913913
set(ldflags "${CMAKE_EXE_LINKER_FLAGS}")
914+
if (LLVM_LINK_LLVM_DYLIB)
915+
set(linkmode "dylib")
916+
else()
917+
set(linkmode "component-libs")
918+
endif()
914919
add_custom_command(OUTPUT ${binpath}
915-
COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "go=${GO_EXECUTABLE}" "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}"
920+
COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "go=${GO_EXECUTABLE}" "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}" "linkmode=${linkmode}"
916921
${ARG_GOFLAGS} build -o ${binpath} ${pkgpath}
917922
DEPENDS llvm-config ${CMAKE_BINARY_DIR}/bin/llvm-go${CMAKE_EXECUTABLE_SUFFIX}
918923
${llvmlibs} ${ARG_DEPENDS}

llvm/tools/llvm-config/BuildVariables.inc.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,5 @@
2929
#define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@"
3030
#define LLVM_HAS_RTTI "@LLVM_HAS_RTTI@"
3131
#define LLVM_ENABLE_DYLIB "@LLVM_BUILD_LLVM_DYLIB@"
32-
#define LLVM_LINK_DYLIB "@LLVM_LINK_LLVM_DYLIB@"
3332
#define LLVM_ENABLE_SHARED "@LLVM_ENABLE_SHARED@"
3433
#define LLVM_DYLIB_COMPONENTS "@LLVM_DYLIB_COMPONENTS@"
35-
#define LLVM_DYLIB_VERSION "@LLVM_DYLIB_VERSION@"

llvm/tools/llvm-config/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}
2626
set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
2727
set(LLVM_BUILD_SYSTEM cmake)
2828
set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})
29-
set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}${LLVM_VERSION_SUFFIX}")
3029

3130
# Use the C++ link flags, since they should be a superset of C link flags.
3231
set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")

llvm/tools/llvm-config/Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ else
4444
LLVM_HAS_RTTI := YES
4545
endif
4646

47-
LLVM_DYLIB_VERSION := $(LLVM_VERSION_MAJOR).$(LLVM_VERSION_MINOR)$(LLVM_VERSION_SUFFIX)
48-
4947
# This is blank for now. We need to be careful about adding stuff here:
5048
# LDFLAGS tend not to be portable, and we don't currently require the
5149
# user to use libtool when linking against LLVM.
@@ -85,8 +83,6 @@ $(ObjDir)/BuildVariables.inc: $(BUILDVARIABLES_SRCPATH) Makefile $(ObjDir)/.dir
8583
>> temp.sed
8684
$(Verb) $(ECHO) 's/@LLVM_HAS_RTTI@/$(LLVM_HAS_RTTI)/' \
8785
>> temp.sed
88-
$(Verb) $(ECHO) 's/@LLVM_DYLIB_VERSION@/$(LLVM_DYLIB_VERSION)/' \
89-
>> temp.sed
9086
$(Verb) $(SED) -f temp.sed < $< > $@
9187
$(Verb) $(RM) temp.sed
9288

llvm/tools/llvm-config/llvm-config.cpp

Lines changed: 25 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
#include "llvm/Support/raw_ostream.h"
3030
#include <cstdlib>
3131
#include <set>
32-
#include <unordered_set>
3332
#include <vector>
33+
#include <unordered_set>
3434

3535
using namespace llvm;
3636

@@ -46,22 +46,6 @@ using namespace llvm;
4646
// create entries for pseudo groups like x86 or all-targets.
4747
#include "LibraryDependencies.inc"
4848

49-
// LinkMode determines what libraries and flags are returned by llvm-config.
50-
enum LinkMode {
51-
// LinkModeAuto will link with the default link mode for the installation,
52-
// which is dependent on the value of LLVM_LINK_LLVM_DYLIB, and fall back
53-
// to the alternative if the required libraries are not available.
54-
LinkModeAuto = 0,
55-
56-
// LinkModeDyLib will link with the single dynamic library if it exists,
57-
// and return an error if it does not exist.
58-
LinkModeDyLib = 1,
59-
60-
// LinkModeStatic will link with the individual component static libraries
61-
// if they exist, and fail if any one does not exist.
62-
LinkModeStatic = 2,
63-
};
64-
6549
/// \brief Traverse a single component adding to the topological ordering in
6650
/// \arg RequiredLibs.
6751
///
@@ -72,13 +56,12 @@ enum LinkMode {
7256
/// libraries.
7357
/// \param GetComponentNames - Get the component names instead of the
7458
/// library name.
75-
static void VisitComponent(const std::string &Name,
76-
const StringMap<AvailableComponent *> &ComponentMap,
77-
std::set<AvailableComponent *> &VisitedComponents,
59+
static void VisitComponent(const std::string& Name,
60+
const StringMap<AvailableComponent*> &ComponentMap,
61+
std::set<AvailableComponent*> &VisitedComponents,
7862
std::vector<std::string> &RequiredLibs,
7963
bool IncludeNonInstalled, bool GetComponentNames,
80-
const std::string *ActiveLibDir,
81-
std::vector<std::string> *Missing) {
64+
const std::string *ActiveLibDir, bool *HasMissing) {
8265
// Lookup the component.
8366
AvailableComponent *AC = ComponentMap.lookup(Name);
8467
assert(AC && "Invalid component name!");
@@ -97,7 +80,7 @@ static void VisitComponent(const std::string &Name,
9780
for (unsigned i = 0; AC->RequiredLibraries[i]; ++i) {
9881
VisitComponent(AC->RequiredLibraries[i], ComponentMap, VisitedComponents,
9982
RequiredLibs, IncludeNonInstalled, GetComponentNames,
100-
ActiveLibDir, Missing);
83+
ActiveLibDir, HasMissing);
10184
}
10285

10386
if (GetComponentNames) {
@@ -107,10 +90,8 @@ static void VisitComponent(const std::string &Name,
10790

10891
// Add to the required library list.
10992
if (AC->Library) {
110-
if (Missing && ActiveLibDir) {
111-
std::string path = *ActiveLibDir + "/" + AC->Library;
112-
if (!sys::fs::exists(path))
113-
Missing->push_back(path);
93+
if (!IncludeNonInstalled && HasMissing && !*HasMissing && ActiveLibDir) {
94+
*HasMissing = !sys::fs::exists(*ActiveLibDir + "/" + AC->Library);
11495
}
11596
RequiredLibs.push_back(AC->Library);
11697
}
@@ -127,13 +108,12 @@ static void VisitComponent(const std::string &Name,
127108
static std::vector<std::string>
128109
ComputeLibsForComponents(const std::vector<StringRef> &Components,
129110
bool IncludeNonInstalled, bool GetComponentNames,
130-
const std::string *ActiveLibDir,
131-
std::vector<std::string> *Missing) {
111+
const std::string *ActiveLibDir, bool *HasMissing) {
132112
std::vector<std::string> RequiredLibs;
133113
std::set<AvailableComponent *> VisitedComponents;
134114

135115
// Build a map of component names to information.
136-
StringMap<AvailableComponent *> ComponentMap;
116+
StringMap<AvailableComponent*> ComponentMap;
137117
for (unsigned i = 0; i != array_lengthof(AvailableComponents); ++i) {
138118
AvailableComponent *AC = &AvailableComponents[i];
139119
ComponentMap[AC->Name] = AC;
@@ -153,7 +133,7 @@ ComputeLibsForComponents(const std::vector<StringRef> &Components,
153133

154134
VisitComponent(ComponentLower, ComponentMap, VisitedComponents,
155135
RequiredLibs, IncludeNonInstalled, GetComponentNames,
156-
ActiveLibDir, Missing);
136+
ActiveLibDir, HasMissing);
157137
}
158138

159139
// The list is now ordered with leafs first, we want the libraries to printed
@@ -199,8 +179,6 @@ Options:\n\
199179
--build-system Print the build system used to build LLVM (autoconf or cmake).\n\
200180
--has-rtti Print whether or not LLVM was built with rtti (YES or NO).\n\
201181
--shared-mode Print how the provided components can be collectively linked (`shared` or `static`).\n\
202-
--link-shared Link the components as a shared library.\n\
203-
--link-static Link the components as a static libraries.\n\
204182
Typical components:\n\
205183
all All LLVM libraries (default).\n\
206184
engine Either a native JIT or a bitcode interpreter.\n";
@@ -211,7 +189,7 @@ Typical components:\n\
211189
std::string GetExecutablePath(const char *Argv0) {
212190
// This just needs to be some symbol in the binary; C++ doesn't
213191
// allow taking the address of ::main however.
214-
void *P = (void *)(intptr_t)GetExecutablePath;
192+
void *P = (void*) (intptr_t) GetExecutablePath;
215193
return llvm::sys::fs::getMainExecutable(Argv0, P);
216194
}
217195

@@ -265,8 +243,8 @@ int main(int argc, char **argv) {
265243
// Create an absolute path, and pop up one directory (we expect to be inside a
266244
// bin dir).
267245
sys::fs::make_absolute(CurrentPath);
268-
CurrentExecPrefix =
269-
sys::path::parent_path(sys::path::parent_path(CurrentPath)).str();
246+
CurrentExecPrefix = sys::path::parent_path(
247+
sys::path::parent_path(CurrentPath)).str();
270248

271249
// Check to see if we are inside a development tree by comparing to possible
272250
// locations (prefix style or CMake style).
@@ -327,8 +305,8 @@ int main(int argc, char **argv) {
327305
}
328306

329307
// We need to include files from both the source and object trees.
330-
ActiveIncludeOption =
331-
("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include");
308+
ActiveIncludeOption = ("-I" + ActiveIncludeDir + " " +
309+
"-I" + ActiveObjRoot + "/include");
332310
} else {
333311
ActivePrefix = CurrentExecPrefix;
334312
ActiveIncludeDir = ActivePrefix + "/include";
@@ -345,25 +323,25 @@ int main(int argc, char **argv) {
345323
/// in the first place. This can't be done at configure/build time.
346324

347325
StringRef SharedExt, SharedVersionedExt, SharedDir, SharedPrefix, StaticExt,
348-
StaticPrefix, StaticDir = "lib";
326+
StaticPrefix, StaticDir = "lib";
349327
const Triple HostTriple(Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE));
350328
if (HostTriple.isOSWindows()) {
351329
SharedExt = "dll";
352-
SharedVersionedExt = LLVM_DYLIB_VERSION ".dll";
330+
SharedVersionedExt = PACKAGE_VERSION ".dll";
353331
StaticExt = "a";
354332
SharedDir = ActiveBinDir;
355333
StaticDir = ActiveLibDir;
356334
StaticPrefix = SharedPrefix = "lib";
357335
} else if (HostTriple.isOSDarwin()) {
358336
SharedExt = "dylib";
359-
SharedVersionedExt = LLVM_DYLIB_VERSION ".dylib";
337+
SharedVersionedExt = PACKAGE_VERSION ".dylib";
360338
StaticExt = "a";
361339
StaticDir = SharedDir = ActiveLibDir;
362340
StaticPrefix = SharedPrefix = "lib";
363341
} else {
364342
// default to the unix values:
365343
SharedExt = "so";
366-
SharedVersionedExt = LLVM_DYLIB_VERSION ".so";
344+
SharedVersionedExt = PACKAGE_VERSION ".so";
367345
StaticExt = "a";
368346
StaticDir = SharedDir = ActiveLibDir;
369347
StaticPrefix = SharedPrefix = "lib";
@@ -384,22 +362,11 @@ int main(int argc, char **argv) {
384362

385363
bool DyLibExists = false;
386364
const std::string DyLibName =
387-
(SharedPrefix + "LLVM-" + SharedVersionedExt).str();
388-
389-
// If LLVM_LINK_DYLIB is ON, the single shared library will be returned
390-
// for "--libs", etc, if they exist. This behaviour can be overridden with
391-
// --link-static or --link-shared.
392-
bool LinkDyLib = (std::strcmp(LLVM_LINK_DYLIB, "ON") == 0);
365+
(SharedPrefix + "LLVM-" + SharedVersionedExt).str();
393366

394367
if (BuiltDyLib) {
395368
DyLibExists = sys::fs::exists(SharedDir + "/" + DyLibName);
396-
if (!DyLibExists) {
397-
// The shared library does not exist: don't error unless the user
398-
// explicitly passes --link-shared.
399-
LinkDyLib = false;
400-
}
401369
}
402-
LinkMode LinkMode = LinkDyLib ? LinkModeDyLib : LinkModeAuto;
403370

404371
/// Get the component's library name without the lib prefix and the
405372
/// extension. Returns true if Lib is in a recognized format.
@@ -534,10 +501,6 @@ int main(int argc, char **argv) {
534501
OS << ActivePrefix << '\n';
535502
} else if (Arg == "--src-root") {
536503
OS << LLVM_SRC_ROOT << '\n';
537-
} else if (Arg == "--link-shared") {
538-
LinkMode = LinkModeDyLib;
539-
} else if (Arg == "--link-static") {
540-
LinkMode = LinkModeStatic;
541504
} else {
542505
usage();
543506
}
@@ -549,11 +512,6 @@ int main(int argc, char **argv) {
549512
if (!HasAnyOption)
550513
usage();
551514

552-
if (LinkMode == LinkModeDyLib && !DyLibExists) {
553-
errs() << "llvm-config: error: " << DyLibName << " is missing\n\n";
554-
usage();
555-
}
556-
557515
if (PrintLibs || PrintLibNames || PrintLibFiles || PrintSystemLibs ||
558516
PrintSharedMode) {
559517

@@ -567,31 +525,11 @@ int main(int argc, char **argv) {
567525
Components.push_back("all");
568526

569527
// Construct the list of all the required libraries.
570-
std::vector<std::string> MissingLibs;
528+
bool HasMissing = false;
571529
std::vector<std::string> RequiredLibs =
572530
ComputeLibsForComponents(Components,
573531
/*IncludeNonInstalled=*/IsInDevelopmentTree,
574-
false, &ActiveLibDir, &MissingLibs);
575-
if (!MissingLibs.empty()) {
576-
switch (LinkMode) {
577-
case LinkModeDyLib:
578-
break;
579-
case LinkModeAuto:
580-
if (DyLibExists) {
581-
LinkMode = LinkModeDyLib;
582-
break;
583-
}
584-
errs()
585-
<< "llvm-config: error: component libraries and shared library\n\n";
586-
// fall through
587-
case LinkModeStatic:
588-
for (auto &Lib : MissingLibs)
589-
errs() << "llvm-config: error: missing: " << Lib << "\n";
590-
return 1;
591-
}
592-
} else if (LinkMode == LinkModeAuto) {
593-
LinkMode = LinkModeStatic;
594-
}
532+
false, &ActiveLibDir, &HasMissing);
595533

596534
if (PrintSharedMode) {
597535
std::unordered_set<std::string> FullDyLibComponents;
@@ -611,7 +549,7 @@ int main(int argc, char **argv) {
611549
}
612550
FullDyLibComponents.clear();
613551

614-
if (LinkMode == LinkModeDyLib) {
552+
if (HasMissing && DyLibExists) {
615553
OS << "shared\n";
616554
return 0;
617555
} else {
@@ -643,7 +581,7 @@ int main(int argc, char **argv) {
643581
}
644582
};
645583

646-
if (LinkMode == LinkModeDyLib) {
584+
if (HasMissing && DyLibExists) {
647585
PrintForLib(DyLibName, true);
648586
} else {
649587
for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) {

llvm/tools/llvm-go/llvm-go.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,17 @@ func llvmConfig(args ...string) string {
8888
return outstr
8989
}
9090

91-
func llvmFlags() compilerFlags {
92-
ldflags := llvmConfig("--ldflags", "--libs", "--system-libs")
91+
func llvmFlags(linkmode string) compilerFlags {
92+
ldflags := llvmConfig("--ldflags")
93+
switch linkmode {
94+
case linkmodeComponentLibs:
95+
ldflags += " " + llvmConfig(append([]string{"--libs"}, components...)...)
96+
case linkmodeDylib:
97+
ldflags += " -lLLVM"
98+
default:
99+
panic("invalid linkmode: " + linkmode)
100+
}
101+
ldflags += " " + llvmConfig("--system-libs")
93102
if runtime.GOOS != "darwin" {
94103
// OS X doesn't like -rpath with cgo. See:
95104
// https://code.google.com/p/go/issues/detail?id=7293
@@ -124,8 +133,8 @@ func printComponents() {
124133
fmt.Println(strings.Join(components, " "))
125134
}
126135

127-
func printConfig() {
128-
flags := llvmFlags()
136+
func printConfig(linkmode string) {
137+
flags := llvmFlags(linkmode)
129138

130139
fmt.Printf(`// +build !byollvm
131140
@@ -144,7 +153,7 @@ type (run_build_sh int)
144153
`, flags.cpp, flags.cxx, flags.ld)
145154
}
146155

147-
func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags string) {
156+
func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags, linkmode string) {
148157
args = addTag(args, "byollvm")
149158

150159
srcdir := llvmConfig("--src-root")
@@ -173,7 +182,7 @@ func runGoWithLLVMEnv(args []string, cc, cxx, gocmd, llgo, cppflags, cxxflags, l
173182
newgopathlist = append(newgopathlist, filepath.SplitList(os.Getenv("GOPATH"))...)
174183
newgopath := strings.Join(newgopathlist, string(filepath.ListSeparator))
175184

176-
flags := llvmFlags()
185+
flags := llvmFlags(linkmode)
177186

178187
newenv := []string{
179188
"CC=" + cc,
@@ -241,6 +250,7 @@ func main() {
241250
ldflags := os.Getenv("CGO_LDFLAGS")
242251
gocmd := "go"
243252
llgo := ""
253+
linkmode := linkmodeComponentLibs
244254

245255
flags := []struct {
246256
name string
@@ -252,6 +262,7 @@ func main() {
252262
{"llgo", &llgo},
253263
{"cppflags", &cppflags},
254264
{"ldflags", &ldflags},
265+
{"linkmode", &linkmode},
255266
}
256267

257268
args := os.Args[1:]
@@ -272,11 +283,11 @@ LOOP:
272283

273284
switch args[0] {
274285
case "build", "get", "install", "run", "test":
275-
runGoWithLLVMEnv(args, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags)
286+
runGoWithLLVMEnv(args, cc, cxx, gocmd, llgo, cppflags, cxxflags, ldflags, linkmode)
276287
case "print-components":
277288
printComponents()
278289
case "print-config":
279-
printConfig()
290+
printConfig(linkmode)
280291
default:
281292
usage()
282293
}

0 commit comments

Comments
 (0)