Skip to content

Commit 2a32ca5

Browse files
Revert "Make the DWARF version emitted by the Swift compiler configurable."
1 parent 12b5008 commit 2a32ca5

File tree

19 files changed

+69
-104
lines changed

19 files changed

+69
-104
lines changed

Diff for: include/swift/ABI/ObjectFile.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
namespace swift {
1515

16-
/// Represents the nine reflection sections used by Swift + the Swift AST
17-
/// section used by the debugger.
16+
/// Represents the nine reflection sections used by Swift
1817
enum ReflectionSectionKind : uint8_t {
1918
#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) KIND,
2019
#include "llvm/BinaryFormat/Swift.def"

Diff for: include/swift/AST/IRGenOptions.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class IRGenOptions {
237237
std::string DebugCompilationDir;
238238

239239
/// The DWARF version of debug info.
240-
uint8_t DWARFVersion = 4;
240+
unsigned DWARFVersion;
241241

242242
/// The command line string that is to be stored in the debug info.
243243
std::string DebugFlags;
@@ -512,7 +512,8 @@ class IRGenOptions {
512512
bool EmitCASIDFile;
513513

514514
IRGenOptions()
515-
: OutputKind(IRGenOutputKind::LLVMAssemblyAfterOptimization),
515+
: DWARFVersion(2),
516+
OutputKind(IRGenOutputKind::LLVMAssemblyAfterOptimization),
516517
Verify(true), OptMode(OptimizationMode::NotSet),
517518
Sanitizers(OptionSet<SanitizerKind>()),
518519
SanitizersWithRecoveryInstrumentation(OptionSet<SanitizerKind>()),

Diff for: include/swift/Basic/Dwarf.h

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===--- Dwarf.h - DWARF constants ------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines several temporary Swift-specific DWARF constants.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SWIFT_BASIC_DWARF_H
18+
#define SWIFT_BASIC_DWARF_H
19+
20+
#include "llvm/BinaryFormat/Dwarf.h"
21+
22+
namespace swift {
23+
/// The DWARF version emitted by the Swift compiler.
24+
const unsigned DWARFVersion = 4;
25+
26+
static const char MachOASTSegmentName[] = "__DWARF";
27+
static const char MachOASTSectionName[] = "__swift_ast";
28+
static const char ELFASTSectionName[] = ".swift_ast";
29+
static const char COFFASTSectionName[] = "swiftast";
30+
static const char WasmASTSectionName[] = ".swift_ast";
31+
} // end namespace swift
32+
33+
#endif // SWIFT_BASIC_DWARF_H

Diff for: include/swift/Driver/Driver.h

-3
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ class OutputInfo {
125125
/// What kind of debug info to generate.
126126
IRGenDebugInfoFormat DebugInfoFormat = IRGenDebugInfoFormat::None;
127127

128-
/// DWARF output format version number.
129-
std::optional<uint8_t> DWARFVersion;
130-
131128
/// Whether or not the driver should generate a module.
132129
bool ShouldGenerateModule = false;
133130

Diff for: include/swift/Option/Options.td

+2-6
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,8 @@ def gdwarf_types : Flag<["-"], "gdwarf-types">,
991991
Group<g_Group>, Flags<[FrontendOption]>,
992992
HelpText<"Emit full DWARF type info.">;
993993
def debug_prefix_map : Separate<["-"], "debug-prefix-map">,
994-
Flags<[FrontendOption]>,
995-
HelpText<"Remap source paths in debug info">, MetaVarName<"<prefix=replacement>">;
994+
Flags<[FrontendOption]>,
995+
HelpText<"Remap source paths in debug info">, MetaVarName<"<prefix=replacement>">;
996996
def coverage_prefix_map : Separate<["-"], "coverage-prefix-map">,
997997
Flags<[FrontendOption]>,
998998
HelpText<"Remap source paths in coverage info">, MetaVarName<"<prefix=replacement>">;
@@ -1007,10 +1007,6 @@ def file_compilation_dir : Separate<["-"], "file-compilation-dir">,
10071007
def debug_info_format : Joined<["-"], "debug-info-format=">,
10081008
Flags<[FrontendOption]>,
10091009
HelpText<"Specify the debug info format type to either 'dwarf' or 'codeview'">;
1010-
def dwarf_version : Joined<["-"], "dwarf-version=">,
1011-
Flags<[FrontendOption]>,
1012-
HelpText<"DWARF debug info version to produce if requested">,
1013-
MetaVarName<"<version>">;
10141010

10151011
def prefix_serialized_debugging_options : Flag<["-"], "prefix-serialized-debugging-options">,
10161012
Flags<[FrontendOption]>,

Diff for: lib/ASTSectionImporter/ASTSectionImporter.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/ASTSectionImporter/ASTSectionImporter.h"
1919
#include "../Serialization/ModuleFormat.h"
2020
#include "swift/AST/ASTContext.h"
21+
#include "swift/Basic/Dwarf.h"
2122
#include "swift/Serialization/SerializedModuleLoader.h"
2223
#include "swift/Serialization/Validation.h"
2324
#include "llvm/Support/Debug.h"

Diff for: lib/Driver/DarwinToolChains.cpp

+1-32
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "swift/AST/DiagnosticsDriver.h"
1616
#include "swift/AST/PlatformKind.h"
17+
#include "swift/Basic/Dwarf.h"
1718
#include "swift/Basic/LLVM.h"
1819
#include "swift/Basic/Platform.h"
1920
#include "swift/Basic/Range.h"
@@ -625,28 +626,6 @@ toolchains::Darwin::addDeploymentTargetArgs(ArgStringList &Arguments,
625626
}
626627
}
627628

628-
static unsigned getDWARFVersionForTriple(const llvm::Triple &triple) {
629-
llvm::VersionTuple osVersion;
630-
const DarwinPlatformKind kind = getDarwinPlatformKind(triple);
631-
switch (kind) {
632-
case DarwinPlatformKind::MacOS:
633-
triple.getMacOSXVersion(osVersion);
634-
if (osVersion < llvm::VersionTuple(10, 11))
635-
return 2;
636-
return 4;
637-
case DarwinPlatformKind::IPhoneOSSimulator:
638-
case DarwinPlatformKind::IPhoneOS:
639-
case DarwinPlatformKind::TvOS:
640-
case DarwinPlatformKind::TvOSSimulator:
641-
osVersion = triple.getiOSVersion();
642-
if (osVersion < llvm::VersionTuple(9))
643-
return 2;
644-
return 4;
645-
default:
646-
return 4;
647-
}
648-
}
649-
650629
void toolchains::Darwin::addCommonFrontendArgs(
651630
const OutputInfo &OI, const CommandOutput &output,
652631
const llvm::opt::ArgList &inputArgs,
@@ -665,16 +644,6 @@ void toolchains::Darwin::addCommonFrontendArgs(
665644
inputArgs.MakeArgString(variantSDKVersion->getAsString()));
666645
}
667646
}
668-
std::string dwarfVersion;
669-
{
670-
llvm::raw_string_ostream os(dwarfVersion);
671-
os << "-dwarf-version=";
672-
if (OI.DWARFVersion)
673-
os << *OI.DWARFVersion;
674-
else
675-
os << getDWARFVersionForTriple(getTriple());
676-
}
677-
arguments.push_back(inputArgs.MakeArgString(dwarfVersion));
678647
}
679648

680649
/// Add the frontend arguments needed to find external plugins in standard

Diff for: lib/Driver/Driver.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -1685,16 +1685,6 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
16851685
: "-gdwarf_types");
16861686
}
16871687

1688-
if (const Arg *A = Args.getLastArg(options::OPT_dwarf_version)) {
1689-
unsigned vers;
1690-
if (!StringRef(A->getValue()).getAsInteger(10, vers) && vers >= 2 &&
1691-
vers <= 5)
1692-
OI.DWARFVersion = vers;
1693-
else
1694-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
1695-
A->getAsString(Args), A->getValue());
1696-
}
1697-
16981688
if (Args.hasArg(options::OPT_emit_module, options::OPT_emit_module_path)) {
16991689
// The user has requested a module, so generate one and treat it as
17001690
// top-level output.

Diff for: lib/Driver/ToolChains.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "ToolChains.h"
1414

1515
#include "swift/AST/DiagnosticsDriver.h"
16+
#include "swift/Basic/Dwarf.h"
1617
#include "swift/Basic/LLVM.h"
1718
#include "swift/Basic/Platform.h"
1819
#include "swift/Basic/Range.h"
@@ -261,7 +262,6 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
261262
inputArgs.AddLastArg(arguments, options::OPT_enable_private_imports);
262263
inputArgs.AddLastArg(arguments, options::OPT_g_Group);
263264
inputArgs.AddLastArg(arguments, options::OPT_debug_info_format);
264-
inputArgs.AddLastArg(arguments, options::OPT_dwarf_version);
265265
inputArgs.AddLastArg(arguments, options::OPT_import_underlying_module);
266266
inputArgs.AddLastArg(arguments, options::OPT_module_cache_path);
267267
inputArgs.AddLastArg(arguments, options::OPT_module_link_name);

Diff for: lib/Driver/UnixToolChains.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "ToolChains.h"
1414

15+
#include "swift/Basic/Dwarf.h"
1516
#include "swift/Basic/LLVM.h"
1617
#include "swift/Basic/Platform.h"
1718
#include "swift/Basic/Range.h"

Diff for: lib/Driver/WindowsToolChains.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "ToolChains.h"
1414

15+
#include "swift/Basic/Dwarf.h"
1516
#include "swift/Basic/LLVM.h"
1617
#include "swift/Basic/Platform.h"
1718
#include "swift/Basic/Range.h"

Diff for: lib/Frontend/CompilerInvocation.cpp

+1-10
Original file line numberDiff line numberDiff line change
@@ -2472,6 +2472,7 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
24722472
Opts.DebugCompilationDir = std::string(cwd.str());
24732473
}
24742474
}
2475+
24752476
if (const Arg *A = Args.getLastArg(options::OPT_debug_info_format)) {
24762477
if (A->containsValue("dwarf"))
24772478
Opts.DebugInfoFormat = IRGenDebugInfoFormat::DWARF;
@@ -2501,16 +2502,6 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
25012502
: "-gdwarf_types");
25022503
}
25032504

2504-
if (auto A = Args.getLastArg(OPT_dwarf_version)) {
2505-
unsigned vers;
2506-
if (!StringRef(A->getValue()).getAsInteger(10, vers) && vers >= 2 &&
2507-
vers <= 5)
2508-
Opts.DWARFVersion = vers;
2509-
else
2510-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
2511-
A->getAsString(Args), A->getValue());
2512-
}
2513-
25142505
for (auto A : Args.getAllArgValues(options::OPT_file_prefix_map)) {
25152506
auto SplitMap = StringRef(A).split('=');
25162507
Opts.FilePrefixMap.addMapping(SplitMap.first, SplitMap.second);

Diff for: lib/FrontendTool/FrontendTool.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "swift/AST/TBDGenRequests.h"
3737
#include "swift/AST/TypeRefinementContext.h"
3838
#include "swift/Basic/Defer.h"
39+
#include "swift/Basic/Dwarf.h"
3940
#include "swift/Basic/Edit.h"
4041
#include "swift/Basic/FileSystem.h"
4142
#include "swift/Basic/LLVMInitialize.h"
@@ -2240,9 +2241,9 @@ int swift::performFrontend(ArrayRef<const char *> Args,
22402241
trace.emplace(*buffer);
22412242
});
22422243

2243-
// Setting DWARF Version based on frontend options.
2244+
// Setting DWARF Version depend on platform
22442245
IRGenOptions &IRGenOpts = Invocation.getIRGenOptions();
2245-
IRGenOpts.DWARFVersion = IRGenOpts.DWARFVersion;
2246+
IRGenOpts.DWARFVersion = swift::DWARFVersion;
22462247

22472248
// The compiler invocation is now fully configured; notify our observer.
22482249
if (observer) {

Diff for: lib/IRGen/IRGen.cpp

+9-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "../Serialization/ModuleFormat.h"
1818
#include "IRGenModule.h"
1919
#include "swift/ABI/MetadataValues.h"
20-
#include "swift/ABI/ObjectFile.h"
2120
#include "swift/AST/DiagnosticsIRGen.h"
2221
#include "swift/AST/IRGenOptions.h"
2322
#include "swift/AST/IRGenRequests.h"
@@ -27,6 +26,7 @@
2726
#include "swift/AST/SILOptimizerRequests.h"
2827
#include "swift/AST/TBDGenRequests.h"
2928
#include "swift/Basic/Defer.h"
29+
#include "swift/Basic/Dwarf.h"
3030
#include "swift/Basic/MD5Stream.h"
3131
#include "swift/Basic/Platform.h"
3232
#include "swift/Basic/STLExtras.h"
@@ -1630,7 +1630,6 @@ void swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer,
16301630
auto *ASTSym = new llvm::GlobalVariable(M, Ty, /*constant*/ true,
16311631
llvm::GlobalVariable::InternalLinkage,
16321632
Data, "__Swift_AST");
1633-
16341633
std::string Section;
16351634
switch (IGM.TargetInfo.OutputObjectFormat) {
16361635
case llvm::Triple::DXContainer:
@@ -1639,23 +1638,18 @@ void swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer,
16391638
case llvm::Triple::UnknownObjectFormat:
16401639
llvm_unreachable("unknown object format");
16411640
case llvm::Triple::XCOFF:
1642-
case llvm::Triple::COFF: {
1643-
SwiftObjectFileFormatCOFF COFF;
1644-
Section = COFF.getSectionName(ReflectionSectionKind::swiftast);
1641+
case llvm::Triple::COFF:
1642+
Section = COFFASTSectionName;
16451643
break;
1646-
}
16471644
case llvm::Triple::ELF:
1648-
case llvm::Triple::Wasm: {
1649-
SwiftObjectFileFormatELF ELF;
1650-
Section = ELF.getSectionName(ReflectionSectionKind::swiftast);
1645+
Section = ELFASTSectionName;
16511646
break;
1652-
}
1653-
case llvm::Triple::MachO: {
1654-
SwiftObjectFileFormatMachO MachO;
1655-
Section = std::string(*MachO.getSegmentName()) + "," +
1656-
MachO.getSectionName(ReflectionSectionKind::swiftast).str();
1647+
case llvm::Triple::MachO:
1648+
Section = std::string(MachOASTSegmentName) + "," + MachOASTSectionName;
1649+
break;
1650+
case llvm::Triple::Wasm:
1651+
Section = WasmASTSectionName;
16571652
break;
1658-
}
16591653
}
16601654
ASTSym->setSection(Section);
16611655
ASTSym->setAlignment(llvm::MaybeAlign(serialization::SWIFTMODULE_ALIGNMENT));

Diff for: lib/IRGen/IRGenDebugInfo.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "swift/AST/Pattern.h"
3030
#include "swift/AST/TypeDifferenceVisitor.h"
3131
#include "swift/Basic/Compiler.h"
32+
#include "swift/Basic/Dwarf.h"
3233
#include "swift/Basic/SourceManager.h"
3334
#include "swift/Basic/Version.h"
3435
#include "swift/ClangImporter/ClangImporter.h"

Diff for: lib/IRGen/IRGenModule.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/AST/IRGenOptions.h"
2222
#include "swift/AST/IRGenRequests.h"
2323
#include "swift/AST/Module.h"
24+
#include "swift/Basic/Dwarf.h"
2425
#include "swift/Basic/LLVMExtras.h"
2526
#include "swift/ClangImporter/ClangImporter.h"
2627
#include "swift/Demangling/ManglingMacros.h"

Diff for: lib/Serialization/Serialization.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "swift/AST/TypeCheckRequests.h"
4141
#include "swift/AST/TypeVisitor.h"
4242
#include "swift/Basic/Defer.h"
43+
#include "swift/Basic/Dwarf.h"
4344
#include "swift/Basic/FileSystem.h"
4445
#include "swift/Basic/LLVMExtras.h"
4546
#include "swift/Basic/PathRemapper.h"

Diff for: test/Driver/options.swift

-8
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,6 @@
116116
// RUN: not %swiftc_driver -debug-info-format=codeview %s 2>&1 | %FileCheck -check-prefix MISSING_OPTION_G_ERROR %s
117117
// MISSING_OPTION_G_ERROR: error: option '-debug-info-format={{.*}}' is missing a required argument (-g)
118118

119-
// RUN: %swift_driver -### -g -dwarf-version=3 %s 2>&1 | %FileCheck -check-prefix DWARF_VERSION_3 %s
120-
// DWARF_VERSION_3: -dwarf-version=3
121-
// RUN: not %swift_driver -dwarf-version=1 %s 2>&1 | %FileCheck -check-prefix INVALID_DWARF_VERSION %s
122-
// RUN: not %swift_driver -dwarf-version=6 %s 2>&1 | %FileCheck -check-prefix INVALID_DWARF_VERSION %s
123-
// RUN: not %swiftc_driver -dwarf-version=1 %s 2>&1 | %FileCheck -check-prefix INVALID_DWARF_VERSION %s
124-
// RUN: not %swiftc_driver -dwarf-version=6 %s 2>&1 | %FileCheck -check-prefix INVALID_DWARF_VERSION %s
125-
// INVALID_DWARF_VERSION: invalid value '{{1|6}}' in '-dwarf-version={{1|6}}'
126-
127119
// RUN: not %swift_driver -gline-tables-only -debug-info-format=codeview %s 2>&1 | %FileCheck -check-prefix BAD_DEBUG_LEVEL_ERROR %s
128120
// RUN: not %swift_driver -gdwarf-types -debug-info-format=codeview %s 2>&1 | %FileCheck -check-prefix BAD_DEBUG_LEVEL_ERROR %s
129121
// RUN: not %swiftc_driver -gline-tables-only -debug-info-format=codeview %s 2>&1 | %FileCheck -check-prefix BAD_DEBUG_LEVEL_ERROR %s

0 commit comments

Comments
 (0)