Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for newlib #3946

Merged
merged 4 commits into from
Apr 7, 2022
Merged
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 @@ -316,6 +316,7 @@ version (IN_LLVM)
// target stuff
const(void)* targetTriple; // const llvm::Triple*
bool isUClibcEnvironment;
bool isNewlibEnvironment;

// 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 @@ -284,6 +284,7 @@ struct Param

const llvm::Triple *targetTriple;
bool isUClibcEnvironment; // not directly supported by LLVM
bool isNewlibEnvironment; // not directly supported by LLVM

// Codegen cl options
bool disableRedZone;
Expand Down
26 changes: 14 additions & 12 deletions driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,16 +583,16 @@ static void registerMipsABI() {
}
}

// Check if triple environment name starts with "uclibc" and change it to "gnu"
void fixupUClibcEnv() {
llvm::Triple triple(mTargetTriple);
if (triple.getEnvironmentName().find("uclibc") != 0)
return;
std::string envName(triple.getEnvironmentName());
envName.replace(0, 6, "gnu");
triple.setEnvironmentName(envName);
mTargetTriple = triple.normalize();
global.params.isUClibcEnvironment = true;
// Handle target environments not directly supported by LLVM.
void fixupTripleEnv(std::string &tripleString) {
size_t i;
if ((i = tripleString.find("-uclibc")) != std::string::npos) {
global.params.isUClibcEnvironment = true;
tripleString.replace(i + 1, 6, "gnu"); // -uclibceabihf => -gnueabihf
} else if ((i = tripleString.find("-newlib")) != std::string::npos) {
global.params.isNewlibEnvironment = true;
tripleString.replace(i + 1, 6, ""); // -newlibeabi => -eabi
}
}

/// Register the float ABI.
Expand Down Expand Up @@ -872,6 +872,9 @@ void registerPredefinedTargetVersions() {
llvm::StringRef osName = triple.getOSName();
if (osName.empty() || osName == "unknown" || osName == "none") {
VersionCondition::addPredefinedGlobalIdent("FreeStanding");
if (global.params.isNewlibEnvironment) {
VersionCondition::addPredefinedGlobalIdent("CRuntime_Newlib");
}
} else {
warning(Loc(), "unknown target OS: %s", osName.str().c_str());
}
Expand Down Expand Up @@ -1085,8 +1088,7 @@ int cppmain() {
relocModel = llvm::Reloc::PIC_;
}

// check and fix environment for uClibc
fixupUClibcEnv();
fixupTripleEnv(mTargetTriple);

// create target machine and finalize floatABI
gTargetMachine = createTargetMachine(
Expand Down