Skip to content

Commit

Permalink
Further attempt to fix Linux-LLVM3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanEngelen committed Dec 23, 2015
1 parent 0a82bd5 commit bd5bd90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
18 changes: 18 additions & 0 deletions driver/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "gen/optimizer.h"
#include "gen/programs.h"
#include "llvm/ADT/Triple.h"
#include "llvm/ProfileData/InstrProf.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/Path.h"
Expand Down Expand Up @@ -192,6 +193,18 @@ static int linkObjToBinaryGcc(bool sharedLib, bool fullyStatic) {
break;
}

// Link with profile-rt library when generating an instrumented binary
if (global.params.genInstrProf) {
#if LDC_LLVM_VER >= 308
if (global.params.targetTriple.isOSLinux()) {
// For Linux, explicitly define __llvm_profile_runtime as undefined
// symbol, so that the initialization part of profile-rt is linked in.
args.push_back(("-Wl,-u," + llvm::getInstrProfRuntimeHookVarName()).str());
}
#endif
args.push_back("-lldc-profile-rt");
}

if (global.params.targetTriple.isWindowsGNUEnvironment()) {
// This is really more of a kludge, as linking in the Winsock functions
// should be handled by the pragma(lib, ...) in std.socket, but it
Expand Down Expand Up @@ -543,6 +556,11 @@ static int linkObjToBinaryWin(bool sharedLib) {
args.push_back("comdlg32.lib");
args.push_back("advapi32.lib");

// Link with profile-rt library when generating an instrumented binary
if (global.params.genInstrProf) {
args.push_back("ldc-profile-rt.lib");
}

Logger::println("Linking with: ");
Stream logstr = Logger::cout();
for (const auto &arg : args) {
Expand Down
13 changes: 0 additions & 13 deletions driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,19 +464,6 @@ static void parseCommandLine(int argc, char **argv, Strings &sourceFiles,
global.params.linkswitches->push(arg);
}
}
// Link with profile-rt library when generating an instrumented binary
if (global.params.genInstrProf) {
global.params.linkswitches->push("-lldc-profile-rt");
#if (LDC_LLVM_VER >= 308)
if (global.params.targetTriple.isOSLinux()) {
// For Linux, explicitly define __llvm_profile_runtime as undefined
// symbol, so that the initialization part of profile-rt is linked in.
std::string profrthook = llvm::getInstrProfRuntimeHookVarName();
global.params.linkswitches->push("-u");
global.params.linkswitches->push(mem.xstrdup(profrthook.c_str()));
}
#endif
}

if (global.params.useUnitTests) {
global.params.useAssert = 1;
Expand Down

0 comments on commit bd5bd90

Please sign in to comment.