From f20d5676339f6e5c5f8595b19ed5cd9c97654119 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Fri, 12 Jun 2020 18:01:24 -0700 Subject: [PATCH] Fix the hardcoded Swift AST section / segment name for Mach-O to match the one specified in LLVM's Mach-O parser. Otherwise LLDB could not possibly find it! This name is used by the swift -modulewrap subcommand, which is currently unused on Darwin, and primarily intended for use under Linux. However, it may be useful to better support static archives (.a) files with Swift debug info in the future. To fully support this, dsymutil and LLDB need to know to look for Swift AST sections in Mach-O objects other than .dSYM bundled. Implementation note: It would be nice to get the section name out of libObject, but with the current architecture this needs a major refactoring that didn't seem justified, given that there is an end-to-end test to prevent such a mishap in the future. --- include/swift/Basic/Dwarf.h | 4 ++-- lib/IRGen/IRGen.cpp | 4 ++++ test/DebugInfo/ASTSection-single.swift | 14 ++++++++++++++ test/DebugInfo/ASTSection_linker.swift | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 test/DebugInfo/ASTSection-single.swift diff --git a/include/swift/Basic/Dwarf.h b/include/swift/Basic/Dwarf.h index 16e06123f5470..2c6f12dbc7789 100644 --- a/include/swift/Basic/Dwarf.h +++ b/include/swift/Basic/Dwarf.h @@ -23,8 +23,8 @@ namespace swift { /// The DWARF version emitted by the Swift compiler. const unsigned DWARFVersion = 4; - static const char MachOASTSegmentName[] = "__SWIFT"; - static const char MachOASTSectionName[] = "__ast"; + 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"; diff --git a/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index 21a400c8f3213..ca88f2efaccff 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -1364,6 +1364,10 @@ swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer, assert(!Ctx.hadError()); IRGenOptions Opts; + // This tool doesn't pass the necessary runtime library path to + // TypeConverter, because this feature isn't needed. + Opts.DisableLegacyTypeInfo = true; + Opts.OutputKind = IRGenOutputKind::ObjectFile; IRGenerator irgen(Opts, SILMod); diff --git a/test/DebugInfo/ASTSection-single.swift b/test/DebugInfo/ASTSection-single.swift new file mode 100644 index 0000000000000..95f1f05578b92 --- /dev/null +++ b/test/DebugInfo/ASTSection-single.swift @@ -0,0 +1,14 @@ +// REQUIRES: executable_test +// REQUIRES: swift_tools_extra + +// Test that a module-wrapped Swift AST section can be parsed. + +// RUN: %empty-directory(%t) + +// RUN: echo "public let a0 = 0" >%t/a0.swift +// RUN: %target-build-swift %t/a0.swift -emit-module -emit-module-path %t/a0.swiftmodule +// RUN: %target-swift-modulewrap %t/a0.swiftmodule -o %t/a0-mod.o + +// RUN: %lldb-moduleimport-test -verbose %t/a0-mod.o | %FileCheck %s +// CHECK: Importing a0... ok! + diff --git a/test/DebugInfo/ASTSection_linker.swift b/test/DebugInfo/ASTSection_linker.swift index 7fbf987b8ad0f..bf49622056913 100644 --- a/test/DebugInfo/ASTSection_linker.swift +++ b/test/DebugInfo/ASTSection_linker.swift @@ -6,7 +6,7 @@ // RUN: %swift-ide-test -test-CompilerInvocation-from-module -source-filename=%t/ASTSection.swiftmodule // Test the inline section mechanism. -// RUN: %target-ld %t/ASTSection.o -sectcreate __SWIFT __ast %t/ASTSection.swiftmodule -o %t/ASTSection.dylib -dylib -lSystem -lobjc +// RUN: %target-ld %t/ASTSection.o -sectcreate __DWARF __swift_ast %t/ASTSection.swiftmodule -o %t/ASTSection.dylib -dylib -lSystem -lobjc // RUN: %lldb-moduleimport-test -verbose %t/ASTSection.dylib | %FileCheck %s // Test the symbol table entry.