2

I'm trying to build LLDB as part of Clang/LLVM. LLVM, Clang, Compiler-RT and Extras build OK. However, LLVM has an issue when building with the other components.

The directory structure is set up according to LLVM/Clang/LLDB instructions. The docs on LLDB are located at Building LLDB. Below was run from the build directory, which lies next to the llvm directory (llvm is where all sources were unpacked):

$ cd build
$ ../llvm/configure --enable-optimized --enable-cxx11 --enable-libcpp --prefix=/usr/local
...
$ make -j4
...
llvm[4]: Compiling ARM_DWARF_Registers.cpp for Release+Asserts build
llvm[4]: Compiling KQueue.cpp for Release+Asserts build
llvm[4]: Compiling PseudoTerminal.cpp for Release+Asserts build
llvm[4]: Compiling Range.cpp for Release+Asserts build
llvm[4]: Compiling SharingPtr.cpp for Release+Asserts build
llvm[4]: Compiling StringExtractor.cpp for Release+Asserts build
llvm[4]: Compiling StringExtractorGDBRemote.cpp for Release+Asserts build
llvm[4]: Compiling TimeSpecTimeout.cpp for Release+Asserts build
llvm[4]: Building Release+Asserts Archive Library liblldbUtility.a
llvm[3]: Linking Release+Asserts Shared Library liblldb.dylib
Undefined symbols for architecture x86_64:
  "SystemRuntimeMacOSX::Initialize()", referenced from:
      lldb_private::Initialize() in liblldbInitAndLog.a(lldb.o)
  "SystemRuntimeMacOSX::Terminate()", referenced from:
      lldb_private::Terminate() in liblldbInitAndLog.a(lldb.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [/Users/jwalton/Clang-3.4.2/build/Release+Asserts/lib/liblldb.dylib] Error 1
make[2]: *** [all] Error 1
make[1]: *** [all] Error 1
make: *** [all] Error 1

EDIT: following Matt's instructions below, I was able to avoid Undefined symbols SystemRuntimeMacOSX::Initialize and SystemRuntimeMacOSX::Terminate. But the build still dies with:

llvm[4]: Compiling ARM_DWARF_Registers.cpp for Release+Asserts build
llvm[4]: Compiling KQueue.cpp for Release+Asserts build
llvm[4]: Compiling PseudoTerminal.cpp for Release+Asserts build
llvm[4]: Compiling Range.cpp for Release+Asserts build
llvm[4]: Compiling SharingPtr.cpp for Release+Asserts build
llvm[4]: Compiling StringExtractor.cpp for Release+Asserts build
llvm[4]: Compiling StringExtractorGDBRemote.cpp for Release+Asserts build
llvm[4]: Compiling TimeSpecTimeout.cpp for Release+Asserts build
llvm[4]: Building Release+Asserts Archive Library liblldbUtility.a
make[3]: *** No rule to make target `/Users/jwalton/Clang-3.4.2/build/Release+Asserts/lib/liblldbPluginSystemRuntimeMacOSX.a',
needed by `/Users/jwalton/Clang-3.4.2/build/Release+Asserts/lib/liblldb.dylib'.  Stop.

The odd thing is, lldbPluginSystemRuntimeMacOSX is handled the same as other plugins like lldbPluginProcessMachCore. The same directives appear in the same places like Cmake.txt.

The host platform is OS X 10.8.5, x64, fully patched. Xcode version is 5.1.1 (5B1008) (which is the latest).

Does anyone know what magical steps I should perform to get lldb to compile with LLVM and Clang?

100 BOUNTY EDIT: There's a pastebin with my recipe in a shell script at Clang 3.4.2 recipe. The recipe uses Missing-Makefile, and Matt provides it below. The recipe patches the makefile, so you won't need to do it manually.

150 BOUNTY EDIT: Cos' answer was the final step. This question need both Matt's answer and Cos' answer. Cos provided an updated recipe. Its available at Clang 3.4.2 Recipe (Final).

Community
  • 1
  • 1
jww
  • 97,681
  • 90
  • 411
  • 885

3 Answers3

5

I believe that Jim's advice above is probably the best option. But, I also experienced this problem attempting to build llvm+clang+lldb 3.4.

I narrowed the problem down to one particular plugin, specific to OS X, not building at all via Make. This was a build system bug, fixed by this commit:

https://github.com/llvm-mirror/lldb/commit/7a53199e140843235d2bd2b12182ceb764419c8a

You can use the commit above as a guide. Only two changes actually need to be made to build successfully. I just patched my local copy.

lldb/lib/Makefile: "lldbPluginSystemRuntimeMacOSX.a" needs to be added after line 98

lldb/source/Plugins/SystemRuntime/MacOSX/Makefile needs to be created with the following contents:

##===- source/Plugins/SystemRuntime/MacOSX/Makefile ---------*- Makefile -*-===##
# 
#                     The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
# 
##===----------------------------------------------------------------------===##

LLDB_LEVEL := ../../../..
LIBRARYNAME := lldbPluginSystemRuntimeMacOSX
BUILD_ARCHIVE = 1

include $(LLDB_LEVEL)/Makefile

With all this done, I was able to finish the build and get a functioning version of liblldb.dylib, which is what I was after. Hope this helps!

Mattie
  • 2,868
  • 2
  • 25
  • 40
  • Thank @Matt. This was step one of two. I resurrected the bounty, and I'm trying to figure out how to get the bounty distributed between you and Cos: [Bounty as reward, award to two recipients](http://meta.stackoverflow.com/questions/268972/bounty-as-reward-award-to-two-recipients). – jww Aug 17 '14 at 05:30
5

You need to add following patch to your script:

sed -i '' '\|DIRS += Process/mach-core|a\
DIRS += SystemRuntime/MacOSX\
' llvm/tools/lldb/source/Plugins/Makefile

Your updated recipe

cos
  • 940
  • 1
  • 10
  • 25
  • Perfect, this was the last step. I resurrected the bounty, and I'm trying to figure out how to get the bounty distributed between you and Matt: [Bounty as reward, award to two recipients](http://meta.stackoverflow.com/questions/268972/bounty-as-reward-award-to-two-recipients). – jww Aug 17 '14 at 03:29
4

I generally build using the Xcode project on MacOS X. Just get the lldb sources, and do:

cd lldb
xcodebuild -configuration Debug

or if you want to debug the Clang side of things as well:

xcodebuild -configuration DebugClang

You don't even need to get the llvm sources, the Xcode project will check them out for you if they aren't present (but won't override the version you have it you want to try to build against a branch or whatever...)

TOT lldb is building fine for me right now.

There are other folks on the lldb-dev mailing list who do use the Makefile build, if you want to build it this way for some reason, you might ask there.some

Jim Ingham
  • 25,260
  • 2
  • 55
  • 63
  • Thanks Jim. I'm building as part of of LLVM and Clang; and not a stand alone Xcode project. LLVM/Clang is a command line project and automatically picks up LLDB during configure. – jww Aug 09 '14 at 01:58
  • I don't think many (any?) of the lldb developers build that way. We all build by including llvm as a subdirectory of the lldb build, and letting lldb configure the cmake for the llvm build (using Xcode or the lldb cmake files.) There's nothing wrong with doing it the way you want, but you are breaking new trails... If you don't mind that, great. Note that the lldb-centric build does result in a working clang et al, just slightly differently arranged. Anyway, if you do get your build working, please submit patches for anything you had to fix to lldb-dev so the work doesn't get lost. – Jim Ingham Aug 11 '14 at 23:21
  • *"please submit patches for anything you had to fix to lldb-dev so the work doesn't get lost"* - Bug 20689, [LLDB fails to compile from command line on OS X (Linux OK)](http://llvm.org/bugs/show_bug.cgi?id=20689) in the LLVM bug tracker. – jww Aug 17 '14 at 05:28
  • Excellent! Thanks... It looks like Todd checked this in, are you all good to go now? – Jim Ingham Aug 19 '14 at 19:33