Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dmd/globals.d
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ version (IN_LLVM)
// target stuff
const(void)* targetTriple; // const llvm::Triple*
bool isUClibcEnvironment;
const(char)[] cppstdlib; // Cpp runtime library

// Codegen cl options
bool disableRedZone;
Expand Down
1 change: 1 addition & 0 deletions dmd/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ struct Param

const llvm::Triple *targetTriple;
bool isUClibcEnvironment; // not directly supported by LLVM
DString cppstdlib; // Cpp runtime library

// Codegen cl options
bool disableRedZone;
Expand Down
3 changes: 3 additions & 0 deletions dmd/mars.d
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ version (IN_LLVM)
const(char)* getPathToProducedBinary();
void deleteExeFile();
int runProgram();
const (char)* getExplicitCppRuntimeName();
}
else
{
Expand Down Expand Up @@ -431,6 +432,8 @@ else

version (IN_LLVM)
{
import dmd.root.string : toDString;
global.params.cppstdlib = toDString(getExplicitCppRuntimeName());
registerPredefinedVersions();
}
else
Expand Down
8 changes: 8 additions & 0 deletions dmd/root/dcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#pragma once

#include <string>
#include <cstring>
#include "dsystem.h"

/// Represents a D [ ] array
Expand All @@ -33,6 +35,12 @@ struct DString : public DArray<const char>

DString(size_t length, const char *ptr)
: DArray<const char>(length, ptr) { }

int compare (std::string str)
{
return this->length >= str.length() ?
strncmp(this->ptr, str.c_str(), this->length) : -1;
}
};

/// Corresponding C++ type that maps to D size_t
Expand Down
10 changes: 10 additions & 0 deletions driver/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ static llvm::cl::opt<std::string>
llvm::cl::value_desc("libcmt[d]|msvcrt[d]"),
llvm::cl::cat(opts::linkingCategory));

static llvm::cl::opt<std::string>
cppstdlib("cppstdlib", llvm::cl::Optional ,
llvm::cl::desc("C++ runtime library to link with"),
llvm::cl::value_desc("libstd++|libc++"),
llvm::cl::cat(opts::linkingCategory));

//////////////////////////////////////////////////////////////////////////////

// linker-gcc.cpp
Expand Down Expand Up @@ -335,3 +341,7 @@ int runProgram() {
}
return status;
}

//////////////////////////////////////////////////////////////////////////////

const char * getExplicitCppRuntimeName() { return cppstdlib.c_str(); }
5 changes: 5 additions & 0 deletions driver/linker.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,8 @@ void deleteExeFile();
* @return the return status of the executable.
*/
int runProgram();

/**
* Returns the name of the C++ runtime library to link with.
*/
const char *getExplicitCppRuntimeName();
5 changes: 4 additions & 1 deletion driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,10 @@ void registerPredefinedTargetVersions() {
VersionCondition::addPredefinedGlobalIdent("CRuntime_UClibc");
} else {
VersionCondition::addPredefinedGlobalIdent("CRuntime_Glibc");
VersionCondition::addPredefinedGlobalIdent("CppRuntime_Gcc");
if (global.params.cppstdlib.compare("libc++") == 0)
VersionCondition::addPredefinedGlobalIdent("CppRuntime_Clang");
else
VersionCondition::addPredefinedGlobalIdent("CppRuntime_Gcc");
}
break;
case llvm::Triple::Haiku:
Expand Down