Revert "Revert "Make the DWARF version emitted by the Swift compiler configurable.""

This commit is contained in:
Adrian Prantl
2023-10-26 12:29:18 -07:00
committed by GitHub
parent 7afa4cfdc6
commit 5d978b44ca
19 changed files with 104 additions and 69 deletions

View File

@@ -14,7 +14,6 @@
#include "swift/AST/DiagnosticsDriver.h"
#include "swift/AST/PlatformKind.h"
#include "swift/Basic/Dwarf.h"
#include "swift/Basic/LLVM.h"
#include "swift/Basic/Platform.h"
#include "swift/Basic/Range.h"
@@ -626,6 +625,28 @@ toolchains::Darwin::addDeploymentTargetArgs(ArgStringList &Arguments,
}
}
static unsigned getDWARFVersionForTriple(const llvm::Triple &triple) {
llvm::VersionTuple osVersion;
const DarwinPlatformKind kind = getDarwinPlatformKind(triple);
switch (kind) {
case DarwinPlatformKind::MacOS:
triple.getMacOSXVersion(osVersion);
if (osVersion < llvm::VersionTuple(10, 11))
return 2;
return 4;
case DarwinPlatformKind::IPhoneOSSimulator:
case DarwinPlatformKind::IPhoneOS:
case DarwinPlatformKind::TvOS:
case DarwinPlatformKind::TvOSSimulator:
osVersion = triple.getiOSVersion();
if (osVersion < llvm::VersionTuple(9))
return 2;
return 4;
default:
return 4;
}
}
void toolchains::Darwin::addCommonFrontendArgs(
const OutputInfo &OI, const CommandOutput &output,
const llvm::opt::ArgList &inputArgs,
@@ -644,6 +665,16 @@ void toolchains::Darwin::addCommonFrontendArgs(
inputArgs.MakeArgString(variantSDKVersion->getAsString()));
}
}
std::string dwarfVersion;
{
llvm::raw_string_ostream os(dwarfVersion);
os << "-dwarf-version=";
if (OI.DWARFVersion)
os << *OI.DWARFVersion;
else
os << getDWARFVersionForTriple(getTriple());
}
arguments.push_back(inputArgs.MakeArgString(dwarfVersion));
}
/// Add the frontend arguments needed to find external plugins in standard