From 2a32ca59449a88ebcf54a65c18f266ee2d9c8e1d Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Wed, 25 Oct 2023 13:28:28 -0700 Subject: [PATCH] Revert "Make the DWARF version emitted by the Swift compiler configurable." --- include/swift/ABI/ObjectFile.h | 3 +- include/swift/AST/IRGenOptions.h | 5 +-- include/swift/Basic/Dwarf.h | 33 +++++++++++++++++++ include/swift/Driver/Driver.h | 3 -- include/swift/Option/Options.td | 8 ++--- lib/ASTSectionImporter/ASTSectionImporter.cpp | 1 + lib/Driver/DarwinToolChains.cpp | 33 +------------------ lib/Driver/Driver.cpp | 10 ------ lib/Driver/ToolChains.cpp | 2 +- lib/Driver/UnixToolChains.cpp | 1 + lib/Driver/WindowsToolChains.cpp | 1 + lib/Frontend/CompilerInvocation.cpp | 11 +------ lib/FrontendTool/FrontendTool.cpp | 5 +-- lib/IRGen/IRGen.cpp | 24 +++++--------- lib/IRGen/IRGenDebugInfo.cpp | 1 + lib/IRGen/IRGenModule.cpp | 1 + lib/Serialization/Serialization.cpp | 1 + test/Driver/options.swift | 8 ----- .../lldb-moduleimport-test.cpp | 22 +++++-------- 19 files changed, 69 insertions(+), 104 deletions(-) create mode 100644 include/swift/Basic/Dwarf.h diff --git a/include/swift/ABI/ObjectFile.h b/include/swift/ABI/ObjectFile.h index 3164eaf5c8291..f352ee91ecfba 100644 --- a/include/swift/ABI/ObjectFile.h +++ b/include/swift/ABI/ObjectFile.h @@ -13,8 +13,7 @@ namespace swift { -/// Represents the nine reflection sections used by Swift + the Swift AST -/// section used by the debugger. +/// Represents the nine reflection sections used by Swift enum ReflectionSectionKind : uint8_t { #define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) KIND, #include "llvm/BinaryFormat/Swift.def" diff --git a/include/swift/AST/IRGenOptions.h b/include/swift/AST/IRGenOptions.h index fae1dc6cd273a..5718e2567cb6d 100644 --- a/include/swift/AST/IRGenOptions.h +++ b/include/swift/AST/IRGenOptions.h @@ -237,7 +237,7 @@ class IRGenOptions { std::string DebugCompilationDir; /// The DWARF version of debug info. - uint8_t DWARFVersion = 4; + unsigned DWARFVersion; /// The command line string that is to be stored in the debug info. std::string DebugFlags; @@ -512,7 +512,8 @@ class IRGenOptions { bool EmitCASIDFile; IRGenOptions() - : OutputKind(IRGenOutputKind::LLVMAssemblyAfterOptimization), + : DWARFVersion(2), + OutputKind(IRGenOutputKind::LLVMAssemblyAfterOptimization), Verify(true), OptMode(OptimizationMode::NotSet), Sanitizers(OptionSet()), SanitizersWithRecoveryInstrumentation(OptionSet()), diff --git a/include/swift/Basic/Dwarf.h b/include/swift/Basic/Dwarf.h new file mode 100644 index 0000000000000..2c6f12dbc7789 --- /dev/null +++ b/include/swift/Basic/Dwarf.h @@ -0,0 +1,33 @@ +//===--- Dwarf.h - DWARF constants ------------------------------*- C++ -*-===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// +// +// This file defines several temporary Swift-specific DWARF constants. +// +//===----------------------------------------------------------------------===// + +#ifndef SWIFT_BASIC_DWARF_H +#define SWIFT_BASIC_DWARF_H + +#include "llvm/BinaryFormat/Dwarf.h" + +namespace swift { + /// The DWARF version emitted by the Swift compiler. + const unsigned DWARFVersion = 4; + + static const char MachOASTSegmentName[] = "__DWARF"; + static const char MachOASTSectionName[] = "__swift_ast"; + static const char ELFASTSectionName[] = ".swift_ast"; + static const char COFFASTSectionName[] = "swiftast"; + static const char WasmASTSectionName[] = ".swift_ast"; +} // end namespace swift + +#endif // SWIFT_BASIC_DWARF_H diff --git a/include/swift/Driver/Driver.h b/include/swift/Driver/Driver.h index ed02a35f650c9..89e9b3fd1af40 100644 --- a/include/swift/Driver/Driver.h +++ b/include/swift/Driver/Driver.h @@ -125,9 +125,6 @@ class OutputInfo { /// What kind of debug info to generate. IRGenDebugInfoFormat DebugInfoFormat = IRGenDebugInfoFormat::None; - /// DWARF output format version number. - std::optional DWARFVersion; - /// Whether or not the driver should generate a module. bool ShouldGenerateModule = false; diff --git a/include/swift/Option/Options.td b/include/swift/Option/Options.td index 431a540505382..b38fe2ac9c477 100644 --- a/include/swift/Option/Options.td +++ b/include/swift/Option/Options.td @@ -991,8 +991,8 @@ def gdwarf_types : Flag<["-"], "gdwarf-types">, Group, Flags<[FrontendOption]>, HelpText<"Emit full DWARF type info.">; def debug_prefix_map : Separate<["-"], "debug-prefix-map">, - Flags<[FrontendOption]>, - HelpText<"Remap source paths in debug info">, MetaVarName<"">; + Flags<[FrontendOption]>, + HelpText<"Remap source paths in debug info">, MetaVarName<"">; def coverage_prefix_map : Separate<["-"], "coverage-prefix-map">, Flags<[FrontendOption]>, HelpText<"Remap source paths in coverage info">, MetaVarName<"">; @@ -1007,10 +1007,6 @@ def file_compilation_dir : Separate<["-"], "file-compilation-dir">, def debug_info_format : Joined<["-"], "debug-info-format=">, Flags<[FrontendOption]>, HelpText<"Specify the debug info format type to either 'dwarf' or 'codeview'">; -def dwarf_version : Joined<["-"], "dwarf-version=">, - Flags<[FrontendOption]>, - HelpText<"DWARF debug info version to produce if requested">, - MetaVarName<"">; def prefix_serialized_debugging_options : Flag<["-"], "prefix-serialized-debugging-options">, Flags<[FrontendOption]>, diff --git a/lib/ASTSectionImporter/ASTSectionImporter.cpp b/lib/ASTSectionImporter/ASTSectionImporter.cpp index 8365dcc47c0d5..e40831410c194 100644 --- a/lib/ASTSectionImporter/ASTSectionImporter.cpp +++ b/lib/ASTSectionImporter/ASTSectionImporter.cpp @@ -18,6 +18,7 @@ #include "swift/ASTSectionImporter/ASTSectionImporter.h" #include "../Serialization/ModuleFormat.h" #include "swift/AST/ASTContext.h" +#include "swift/Basic/Dwarf.h" #include "swift/Serialization/SerializedModuleLoader.h" #include "swift/Serialization/Validation.h" #include "llvm/Support/Debug.h" diff --git a/lib/Driver/DarwinToolChains.cpp b/lib/Driver/DarwinToolChains.cpp index a4973310a1109..9dc66f83a6ead 100644 --- a/lib/Driver/DarwinToolChains.cpp +++ b/lib/Driver/DarwinToolChains.cpp @@ -14,6 +14,7 @@ #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" @@ -625,28 +626,6 @@ 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, @@ -665,16 +644,6 @@ 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 diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 8b7bcdd8d5eff..a15a49956a5a7 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1685,16 +1685,6 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args, : "-gdwarf_types"); } - if (const Arg *A = Args.getLastArg(options::OPT_dwarf_version)) { - unsigned vers; - if (!StringRef(A->getValue()).getAsInteger(10, vers) && vers >= 2 && - vers <= 5) - OI.DWARFVersion = vers; - else - Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value, - A->getAsString(Args), A->getValue()); - } - if (Args.hasArg(options::OPT_emit_module, options::OPT_emit_module_path)) { // The user has requested a module, so generate one and treat it as // top-level output. diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 77923ab21f1fe..718b14354be14 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -13,6 +13,7 @@ #include "ToolChains.h" #include "swift/AST/DiagnosticsDriver.h" +#include "swift/Basic/Dwarf.h" #include "swift/Basic/LLVM.h" #include "swift/Basic/Platform.h" #include "swift/Basic/Range.h" @@ -261,7 +262,6 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI, inputArgs.AddLastArg(arguments, options::OPT_enable_private_imports); inputArgs.AddLastArg(arguments, options::OPT_g_Group); inputArgs.AddLastArg(arguments, options::OPT_debug_info_format); - inputArgs.AddLastArg(arguments, options::OPT_dwarf_version); inputArgs.AddLastArg(arguments, options::OPT_import_underlying_module); inputArgs.AddLastArg(arguments, options::OPT_module_cache_path); inputArgs.AddLastArg(arguments, options::OPT_module_link_name); diff --git a/lib/Driver/UnixToolChains.cpp b/lib/Driver/UnixToolChains.cpp index a146f08b10893..61498c144a28b 100644 --- a/lib/Driver/UnixToolChains.cpp +++ b/lib/Driver/UnixToolChains.cpp @@ -12,6 +12,7 @@ #include "ToolChains.h" +#include "swift/Basic/Dwarf.h" #include "swift/Basic/LLVM.h" #include "swift/Basic/Platform.h" #include "swift/Basic/Range.h" diff --git a/lib/Driver/WindowsToolChains.cpp b/lib/Driver/WindowsToolChains.cpp index d18408d660718..481daa7ba3640 100644 --- a/lib/Driver/WindowsToolChains.cpp +++ b/lib/Driver/WindowsToolChains.cpp @@ -12,6 +12,7 @@ #include "ToolChains.h" +#include "swift/Basic/Dwarf.h" #include "swift/Basic/LLVM.h" #include "swift/Basic/Platform.h" #include "swift/Basic/Range.h" diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 057173d09a81c..e7f82765b141a 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -2472,6 +2472,7 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args, Opts.DebugCompilationDir = std::string(cwd.str()); } } + if (const Arg *A = Args.getLastArg(options::OPT_debug_info_format)) { if (A->containsValue("dwarf")) Opts.DebugInfoFormat = IRGenDebugInfoFormat::DWARF; @@ -2501,16 +2502,6 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args, : "-gdwarf_types"); } - if (auto A = Args.getLastArg(OPT_dwarf_version)) { - unsigned vers; - if (!StringRef(A->getValue()).getAsInteger(10, vers) && vers >= 2 && - vers <= 5) - Opts.DWARFVersion = vers; - else - Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value, - A->getAsString(Args), A->getValue()); - } - for (auto A : Args.getAllArgValues(options::OPT_file_prefix_map)) { auto SplitMap = StringRef(A).split('='); Opts.FilePrefixMap.addMapping(SplitMap.first, SplitMap.second); diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index efe3920cc0257..e143d9ebe47ee 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -36,6 +36,7 @@ #include "swift/AST/TBDGenRequests.h" #include "swift/AST/TypeRefinementContext.h" #include "swift/Basic/Defer.h" +#include "swift/Basic/Dwarf.h" #include "swift/Basic/Edit.h" #include "swift/Basic/FileSystem.h" #include "swift/Basic/LLVMInitialize.h" @@ -2240,9 +2241,9 @@ int swift::performFrontend(ArrayRef Args, trace.emplace(*buffer); }); - // Setting DWARF Version based on frontend options. + // Setting DWARF Version depend on platform IRGenOptions &IRGenOpts = Invocation.getIRGenOptions(); - IRGenOpts.DWARFVersion = IRGenOpts.DWARFVersion; + IRGenOpts.DWARFVersion = swift::DWARFVersion; // The compiler invocation is now fully configured; notify our observer. if (observer) { diff --git a/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index e8ee777bcd4cb..0dd2b50af2e63 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -17,7 +17,6 @@ #include "../Serialization/ModuleFormat.h" #include "IRGenModule.h" #include "swift/ABI/MetadataValues.h" -#include "swift/ABI/ObjectFile.h" #include "swift/AST/DiagnosticsIRGen.h" #include "swift/AST/IRGenOptions.h" #include "swift/AST/IRGenRequests.h" @@ -27,6 +26,7 @@ #include "swift/AST/SILOptimizerRequests.h" #include "swift/AST/TBDGenRequests.h" #include "swift/Basic/Defer.h" +#include "swift/Basic/Dwarf.h" #include "swift/Basic/MD5Stream.h" #include "swift/Basic/Platform.h" #include "swift/Basic/STLExtras.h" @@ -1630,7 +1630,6 @@ void swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer, auto *ASTSym = new llvm::GlobalVariable(M, Ty, /*constant*/ true, llvm::GlobalVariable::InternalLinkage, Data, "__Swift_AST"); - std::string Section; switch (IGM.TargetInfo.OutputObjectFormat) { case llvm::Triple::DXContainer: @@ -1639,23 +1638,18 @@ void swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer, case llvm::Triple::UnknownObjectFormat: llvm_unreachable("unknown object format"); case llvm::Triple::XCOFF: - case llvm::Triple::COFF: { - SwiftObjectFileFormatCOFF COFF; - Section = COFF.getSectionName(ReflectionSectionKind::swiftast); + case llvm::Triple::COFF: + Section = COFFASTSectionName; break; - } case llvm::Triple::ELF: - case llvm::Triple::Wasm: { - SwiftObjectFileFormatELF ELF; - Section = ELF.getSectionName(ReflectionSectionKind::swiftast); + Section = ELFASTSectionName; break; - } - case llvm::Triple::MachO: { - SwiftObjectFileFormatMachO MachO; - Section = std::string(*MachO.getSegmentName()) + "," + - MachO.getSectionName(ReflectionSectionKind::swiftast).str(); + case llvm::Triple::MachO: + Section = std::string(MachOASTSegmentName) + "," + MachOASTSectionName; + break; + case llvm::Triple::Wasm: + Section = WasmASTSectionName; break; - } } ASTSym->setSection(Section); ASTSym->setAlignment(llvm::MaybeAlign(serialization::SWIFTMODULE_ALIGNMENT)); diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index 6c4a684069e23..783e93c888c9d 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -29,6 +29,7 @@ #include "swift/AST/Pattern.h" #include "swift/AST/TypeDifferenceVisitor.h" #include "swift/Basic/Compiler.h" +#include "swift/Basic/Dwarf.h" #include "swift/Basic/SourceManager.h" #include "swift/Basic/Version.h" #include "swift/ClangImporter/ClangImporter.h" diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index bf3fbddf96500..91c65a6e43ad4 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -21,6 +21,7 @@ #include "swift/AST/IRGenOptions.h" #include "swift/AST/IRGenRequests.h" #include "swift/AST/Module.h" +#include "swift/Basic/Dwarf.h" #include "swift/Basic/LLVMExtras.h" #include "swift/ClangImporter/ClangImporter.h" #include "swift/Demangling/ManglingMacros.h" diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index e109f11df1a50..a043aaf4dda92 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -40,6 +40,7 @@ #include "swift/AST/TypeCheckRequests.h" #include "swift/AST/TypeVisitor.h" #include "swift/Basic/Defer.h" +#include "swift/Basic/Dwarf.h" #include "swift/Basic/FileSystem.h" #include "swift/Basic/LLVMExtras.h" #include "swift/Basic/PathRemapper.h" diff --git a/test/Driver/options.swift b/test/Driver/options.swift index 996499f64474c..69de3189ad6f3 100644 --- a/test/Driver/options.swift +++ b/test/Driver/options.swift @@ -116,14 +116,6 @@ // RUN: not %swiftc_driver -debug-info-format=codeview %s 2>&1 | %FileCheck -check-prefix MISSING_OPTION_G_ERROR %s // MISSING_OPTION_G_ERROR: error: option '-debug-info-format={{.*}}' is missing a required argument (-g) -// RUN: %swift_driver -### -g -dwarf-version=3 %s 2>&1 | %FileCheck -check-prefix DWARF_VERSION_3 %s -// DWARF_VERSION_3: -dwarf-version=3 -// RUN: not %swift_driver -dwarf-version=1 %s 2>&1 | %FileCheck -check-prefix INVALID_DWARF_VERSION %s -// RUN: not %swift_driver -dwarf-version=6 %s 2>&1 | %FileCheck -check-prefix INVALID_DWARF_VERSION %s -// RUN: not %swiftc_driver -dwarf-version=1 %s 2>&1 | %FileCheck -check-prefix INVALID_DWARF_VERSION %s -// RUN: not %swiftc_driver -dwarf-version=6 %s 2>&1 | %FileCheck -check-prefix INVALID_DWARF_VERSION %s -// INVALID_DWARF_VERSION: invalid value '{{1|6}}' in '-dwarf-version={{1|6}}' - // RUN: not %swift_driver -gline-tables-only -debug-info-format=codeview %s 2>&1 | %FileCheck -check-prefix BAD_DEBUG_LEVEL_ERROR %s // RUN: not %swift_driver -gdwarf-types -debug-info-format=codeview %s 2>&1 | %FileCheck -check-prefix BAD_DEBUG_LEVEL_ERROR %s // RUN: not %swiftc_driver -gline-tables-only -debug-info-format=codeview %s 2>&1 | %FileCheck -check-prefix BAD_DEBUG_LEVEL_ERROR %s diff --git a/tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp b/tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp index d0612021eff0a..15c2b0e131de2 100644 --- a/tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp +++ b/tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp @@ -16,27 +16,27 @@ // //===----------------------------------------------------------------------===// -#include "swift/ABI/ObjectFile.h" #include "swift/AST/ASTDemangler.h" #include "swift/AST/PrintOptions.h" #include "swift/ASTSectionImporter/ASTSectionImporter.h" -#include "swift/Basic/LLVMInitialize.h" #include "swift/Frontend/Frontend.h" #include "swift/Serialization/SerializedModuleLoader.h" #include "swift/Serialization/Validation.h" -#include "llvm/Object/COFF.h" +#include "swift/Basic/Dwarf.h" #include "llvm/Object/ELFObjectFile.h" +#include "swift/Basic/LLVMInitialize.h" +#include "llvm/Object/COFF.h" #include "llvm/Object/MachO.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" -#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Signals.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Support/ManagedStatic.h" #include #include @@ -209,19 +209,15 @@ collectASTModules(llvm::cl::list &InputNames, continue; } llvm::StringRef Name = *NameOrErr; - if ((MachO && Name == swift::SwiftObjectFileFormatMachO().getSectionName( - swift::ReflectionSectionKind::swiftast)) || - (ELF && Name == swift::SwiftObjectFileFormatELF().getSectionName( - swift::ReflectionSectionKind::swiftast)) || - (COFF && Name == swift::SwiftObjectFileFormatCOFF().getSectionName( - swift::ReflectionSectionKind::swiftast))) { + if ((MachO && Name == swift::MachOASTSectionName) || + (ELF && Name == swift::ELFASTSectionName) || + (COFF && Name == swift::COFFASTSectionName)) { uint64_t Size = Section.getSize(); - llvm::Expected ContentsReference = - Section.getContents(); + llvm::Expected ContentsReference = Section.getContents(); if (!ContentsReference) { llvm::errs() << "error: " << name << " " - << errorToErrorCode(OF.takeError()).message() << "\n"; + << errorToErrorCode(OF.takeError()).message() << "\n"; return false; } char *Module = Alloc.Allocate(Size);