Gold plugin for LLVM 3.3 - build

I built LLVM and was using it, now I want to add Gold plug-in to use as linker, I just followed "build gold with plugin support" in LLVM website,and now have ld-new but I dont want to rebuild LLVM agian, is there any way to add this plugin without rebuilding LLVM?

well I post my solution
there is no way to use gold plug-in without recompiling LLVM.
If you don't want to change any thing in root directory, then you can compile and install binutils and LLVM in same place it will automatically generate ld,ar and as (not ld_new) in bin directory and since llvm first looks to its own directory to find tools (clang -print-search-dirs) so you can be sure that clang will invoke ld gold in link time first. Its not mentioned in LLVMgold.html but its needed to create bfd-plugins directory in lib and install both LLVMgold.so and linLTO.so there.

Related

LLVM filecheck tool

I have built LLVM from source using the instructions given in the read-me of the official github repo. I need to find the path of the Filecheck tool that is supposed to come with llvm, but I cannot find it. LLVM installed several files in /usr/local/bin, such as e.g. llvm-config which I'm supposed to link to for a project and in the same directory in which llvm-config is located, a file for FileCheck is supposed to be, but there is none. Can someone please tell me whether FileCheck comes with the default llvm build and where I can find FileCheck?

How can I bypass dependency builds while building my clang plugin?

Is it possible to build a clang plugin using an already built version of clang?
I've done all the steps to download and build clang but I don't know how to set up a tool so that the Makefile doesn't traverse the entire llvm and clang directories each time that I compile my tool (traversing the Makefile seems to take about as long as building my single file plugin).
Thanks.
If you are using the CMake build system (which you should be with reset LLVM), then CMake creates special targets to bypass dependency checks.
If you target name is target, call:
make target/fast
And then the Makefile will not check/rebuild all the dependent libraries. There is also a make install/fast.

How to compile Quantlib via Xcode?

I am trying to install QuantLib on my Mac running OSX 10.11.6. Installed Boost 1.59 via MacPorts and then followed these instructions.
I used these additional environment variables
./configure --with-boost-include=/opt/local/include/ \
--with-boost-lib=/opt/local/lib/ --prefix=/opt/local/ \
CXXFLAGS='-O2 -stdlib=libstdc++ -mmacosx-version-min=10.6' \
LDFLAGS='-stdlib=libstdc++ -mmacosx-version-min=10.6'
and then make && sudo make install.
However when I run the Bermuda Swaption test it gave me the same error described here.
Little premise: I don't know anything about C++. I need QuantLib to work on Python. So I read carefully the answer by SmallChess and tried to solve it by myself. As I read in his answer
You can't just compile BermudanSwaption.cpp and hope everything would be fine. You have to compile the entire QuantLib library and link with the generated library files. Please google "compiling and linking C++" for more information.
By far, the easiest way to make it happen on Mac is to do it with Xcode. You will need to create a new Xcode project, and import the entire Quantlib project files into it. Next, you will need to create a main() function. Xcode does the compiling and linking for your automatically.
This is what I exactly did:
created a new project in Xcode (version 8.2.1)(file/new project/Command Line Tool/"HelloWorld"/Documents/create)
selected Targets, Build Phases and Link Binary With Library. Added libQuantLib.0.dylib
set libstdc++(GNUC++ standard library) as C++ Standard Library in Build Settings
Modified Header Search Paths to include: /opt/local/include/, and Library Search Paths to include: /opt/local/lib
C++ Language Dialect is set on Compiler Default.
Dragged the ql folder onto the left window of the Xcode
Now, I managed to copy a simple code which includes the library and even if there are many warnings, it runs. Still when I run on the Terminal the command for the Bermuda Swaption test I get the same error. What am I doing wrong?
Additional info (may or may not be useful): if I change the C++ Standard Library setting on Xcode to libc++, I get on Xcode the same error I get when i try the Bermuda Swaption test (ld: symbol(s) not found for architecture x86_64).
Any help would be very much appreciated
Regards
EDIT: you can find a picture of the code at https://i.stack.imgur.com/1zhjO.png

How to add a X86 backend pass in LLVM without having to rebuild all sorts of shared libraries, including clang?

How to add a X86 backend pass in LLVM without having to rebuild all sorts of shared libraries, including clang?
After having studied the LLVM "middle-end" for a while (IR/opt), I've decided to move into the backend.
Here, I've created a very simply MachineFunctionPass in .../lib/Target/X86/, which compiles just fine.
Now, from what I understand, I cannot just load the LLVM backend pass using llc, like it was possible for opt w.r.t. IR-passes. Instead, I've have to build the new pass into the LLVM infrastructure, so I issue the command cmake . --build from my llvm/build directory.
This has the effect that all sorts of shared libraries are build again, including all kinds of clang specific .so files.
The problem is that this take more than 30 minutes, so this cannot be the correct way of building a simple backend pass. How do I quickly configure and build the pass into LLVM, so that I can use it with llc?
I am not an expert in LLVM, but this seems to work for me:
Go the LLVM build directory: cd ~/llvm/build/.
Proceed to the llc build directory: cd tools/llc/.
Build llc: cmake --build.
Now, instead of using the topmost cmake build script, which causes the entire project to be build (changed files and dependencies), only the llc tool is build.
I haven't tested this thoroughly.
Slightly different from the above post:
cmake -G Ninja ...
to configure llvm.
Then
ninja llc
should work fine.

Can't add dynamic frameworks to Command Line Tool

Goals
I added Command Line Tool target to an iOS app and linked with swift frameworks. (tested with Realm and SwiftyJSON)
Expected Results
Build Command Line tool with those libraries.
Actual Results
Xcode output:
dyld: Library not loaded: #rpath/libswiftCore.dylib
Referenced from: .../Xcode/DerivedData/.../Build/Products/Debug/RealmSwift.framework/Versions/A/RealmSwift
Reason: Incompatible library version: RealmSwift requires version 1.0.0 or later, but libswiftCore.dylib provides version 0.0.0
Steps to Reproduce
Create empty Swift Command Line Tool and link Realm frameworks
Code Sample
CommandLineTest.zip
Version of Frameworks and Tooling
Realm version: github "realm/realm-cocoa" "master"
SwiftyJSON version: github "acegreen/SwiftyJSON" "swift3"
Xcode version: 8 GM (which is on the App Store)
Dependency manager + version: Carthage 0.18
Command-line tools are best with static archives because everything is distributed as a single binary. Looking at Realm, I don't see that there is a static archive option. They do have an iOS static framework that I got compiling for macOS but that's not quite what you want. You might want to try playing with Realm's source a bit more to see if you can get it to produce a static archive.
In the mean time, as a workaround, you'll need to tell Xcode where to find the dylibs at runtime and also to install them somewhere.
In your Build Settings, go down to "Runpath Search Paths" and add "#rpath".
In Build Phases, under Copy Files, click the + button and add both Realm.framework and RealmSwift.framework from your project.
Because Realm is compiled with an older version of Swift, you also need to specify "Use Legacy Swift Language Version" in Build Settings.
That will get your project building and finding the Realm libraries but now it will fail to find libswiftCore.dylib. That's because normally command-line tools are statically linked with the Swift library but as soon as you add a framework/dylib, the linker no longer includes the static version.
Go back to Build Phases, Copy Files, and add the following:
libswiftObjectiveC.dylib
libswiftIOKit.dylib
libswiftFoundation.dylib
libswiftDispatch.dylib
libswiftDarwin.dylib
libswiftCoreGraphics.dylib
libswiftCore.dylib
You can find them inside your Xcode installation and then ./Contents/Developer/Toolchains/Swift_2.3.xctoolchain/usr/lib/swift/macosx/
WARNING: Keep in mind that you will need to distribute the frameworks and the dylibs with your command-line tool and they will need to be in the same directory as the tool. You can put them somewhere else on the system by specifying a different runpath but you'll still need them distributed with your tool.
The nice thing about a .app bundle is that it gives you a place to put this stuff and users can just drag-and-drop it to install it. If you could get a static archive version of Realm, you could distribute everything in one binary.