Added support for newlib

Similar to fixupUClibcEnv, fixupNewlibEnv checks for "newlib" within
the environment of the triple, sets a global flag, then removes [-]newlib
from the triple. This preserves "eabi" if present in the triple, and allows
both arm-unknown-none-eabi-newlib and arm-unknown-none-newlib to
work.
This commit is contained in:
Jake Drahos 2022-03-16 14:02:49 -05:00
parent 20bd6a6e49
commit 7e01c62ef9
3 changed files with 24 additions and 0 deletions

View file

@ -316,6 +316,7 @@ version (IN_LLVM)
// target stuff
const(void)* targetTriple; // const llvm::Triple*
bool isUClibcEnvironment;
bool isNewlibEnvironment;
// Codegen cl options
bool disableRedZone;

View file

@ -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;

View file

@ -595,6 +595,24 @@ void fixupUClibcEnv() {
global.params.isUClibcEnvironment = true;
}
// Check for -newlib and strip out (supports -newlib and -eabi-newlib)
void fixupNewlibEnv() {
llvm::Triple triple(mTargetTriple);
std::string envName(triple.getEnvironmentName());
size_t pos = envName.find("newlib");
if (pos == std::string::npos)
return;
envName.replace(pos, 6, "");
if (envName[envName.length() - 1] == '-') {
envName.replace(envName.length() - 1, 1, "");
}
triple.setEnvironmentName(envName);
mTargetTriple = triple.normalize();
global.params.isNewlibEnvironment = true;
}
/// Register the float ABI.
/// Also defines D_HardFloat or D_SoftFloat depending if FPU should be used
void registerPredefinedFloatABI(const char *soft, const char *hard,
@ -872,6 +890,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());
}
@ -1087,6 +1108,7 @@ int cppmain() {
// check and fix environment for uClibc
fixupUClibcEnv();
fixupNewlibEnv();
// create target machine and finalize floatABI
gTargetMachine = createTargetMachine(