Skip to content

Commit d19fe38

Browse files
committed
Use LLVM definitions for Swift section names (NFC)
1 parent bf64711 commit d19fe38

File tree

13 files changed

+30
-65
lines changed

13 files changed

+30
-65
lines changed

include/swift/ABI/ObjectFile.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
namespace swift {
1515

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

include/swift/Basic/Dwarf.h

Lines changed: 0 additions & 33 deletions
This file was deleted.

lib/ASTSectionImporter/ASTSectionImporter.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "swift/ASTSectionImporter/ASTSectionImporter.h"
1919
#include "../Serialization/ModuleFormat.h"
2020
#include "swift/AST/ASTContext.h"
21-
#include "swift/Basic/Dwarf.h"
2221
#include "swift/Serialization/SerializedModuleLoader.h"
2322
#include "swift/Serialization/Validation.h"
2423
#include "llvm/Support/Debug.h"

lib/Driver/DarwinToolChains.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include "swift/AST/DiagnosticsDriver.h"
1616
#include "swift/AST/PlatformKind.h"
17-
#include "swift/Basic/Dwarf.h"
1817
#include "swift/Basic/LLVM.h"
1918
#include "swift/Basic/Platform.h"
2019
#include "swift/Basic/Range.h"

lib/Driver/ToolChains.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "ToolChains.h"
1414

1515
#include "swift/AST/DiagnosticsDriver.h"
16-
#include "swift/Basic/Dwarf.h"
1716
#include "swift/Basic/LLVM.h"
1817
#include "swift/Basic/Platform.h"
1918
#include "swift/Basic/Range.h"

lib/Driver/UnixToolChains.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include "ToolChains.h"
1414

15-
#include "swift/Basic/Dwarf.h"
1615
#include "swift/Basic/LLVM.h"
1716
#include "swift/Basic/Platform.h"
1817
#include "swift/Basic/Range.h"

lib/Driver/WindowsToolChains.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include "ToolChains.h"
1414

15-
#include "swift/Basic/Dwarf.h"
1615
#include "swift/Basic/LLVM.h"
1716
#include "swift/Basic/Platform.h"
1817
#include "swift/Basic/Range.h"

lib/FrontendTool/FrontendTool.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "swift/AST/TBDGenRequests.h"
3737
#include "swift/AST/TypeRefinementContext.h"
3838
#include "swift/Basic/Defer.h"
39-
#include "swift/Basic/Dwarf.h"
4039
#include "swift/Basic/Edit.h"
4140
#include "swift/Basic/FileSystem.h"
4241
#include "swift/Basic/LLVMInitialize.h"
@@ -2241,10 +2240,6 @@ int swift::performFrontend(ArrayRef<const char *> Args,
22412240
trace.emplace(*buffer);
22422241
});
22432242

2244-
// Setting DWARF Version depend on platform
2245-
IRGenOptions &IRGenOpts = Invocation.getIRGenOptions();
2246-
IRGenOpts.DWARFVersion = swift::DWARFVersion;
2247-
22482243
// The compiler invocation is now fully configured; notify our observer.
22492244
if (observer) {
22502245
observer->parsedArgs(Invocation);

lib/IRGen/IRGen.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "../Serialization/ModuleFormat.h"
1818
#include "IRGenModule.h"
1919
#include "swift/ABI/MetadataValues.h"
20+
#include "swift/ABI/ObjectFile.h"
2021
#include "swift/AST/DiagnosticsIRGen.h"
2122
#include "swift/AST/IRGenOptions.h"
2223
#include "swift/AST/IRGenRequests.h"
@@ -26,7 +27,6 @@
2627
#include "swift/AST/SILOptimizerRequests.h"
2728
#include "swift/AST/TBDGenRequests.h"
2829
#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,6 +1630,7 @@ 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+
16331634
std::string Section;
16341635
switch (IGM.TargetInfo.OutputObjectFormat) {
16351636
case llvm::Triple::DXContainer:
@@ -1638,19 +1639,24 @@ void swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer,
16381639
case llvm::Triple::UnknownObjectFormat:
16391640
llvm_unreachable("unknown object format");
16401641
case llvm::Triple::XCOFF:
1641-
case llvm::Triple::COFF:
1642-
Section = COFFASTSectionName;
1642+
case llvm::Triple::COFF: {
1643+
SwiftObjectFileFormatCOFF COFF;
1644+
Section = COFF.getSectionName(ReflectionSectionKind::swiftast);
16431645
break;
1646+
}
16441647
case llvm::Triple::ELF:
1645-
Section = ELFASTSectionName;
1646-
break;
1647-
case llvm::Triple::MachO:
1648-
Section = std::string(MachOASTSegmentName) + "," + MachOASTSectionName;
1648+
case llvm::Triple::Wasm: {
1649+
SwiftObjectFileFormatELF ELF;
1650+
Section = ELF.getSectionName(ReflectionSectionKind::swiftast);
16491651
break;
1650-
case llvm::Triple::Wasm:
1651-
Section = WasmASTSectionName;
1652+
}
1653+
case llvm::Triple::MachO: {
1654+
SwiftObjectFileFormatMachO MachO;
1655+
Section = std::string(*MachO.getSegmentName()) + "," +
1656+
MachO.getSectionName(ReflectionSectionKind::swiftast).str();
16521657
break;
16531658
}
1659+
}
16541660
ASTSym->setSection(Section);
16551661
ASTSym->setAlignment(llvm::MaybeAlign(serialization::SWIFTMODULE_ALIGNMENT));
16561662
::performLLVM(Opts, Ctx.Diags, nullptr, nullptr, IGM.getModule(),

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "swift/AST/Pattern.h"
3030
#include "swift/AST/TypeDifferenceVisitor.h"
3131
#include "swift/Basic/Compiler.h"
32-
#include "swift/Basic/Dwarf.h"
3332
#include "swift/Basic/SourceManager.h"
3433
#include "swift/Basic/Version.h"
3534
#include "swift/ClangImporter/ClangImporter.h"

lib/IRGen/IRGenModule.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "swift/AST/IRGenOptions.h"
2222
#include "swift/AST/IRGenRequests.h"
2323
#include "swift/AST/Module.h"
24-
#include "swift/Basic/Dwarf.h"
2524
#include "swift/Basic/LLVMExtras.h"
2625
#include "swift/ClangImporter/ClangImporter.h"
2726
#include "swift/Demangling/ManglingMacros.h"

lib/Serialization/Serialization.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include "swift/AST/TypeCheckRequests.h"
4141
#include "swift/AST/TypeVisitor.h"
4242
#include "swift/Basic/Defer.h"
43-
#include "swift/Basic/Dwarf.h"
4443
#include "swift/Basic/FileSystem.h"
4544
#include "swift/Basic/LLVMExtras.h"
4645
#include "swift/Basic/PathRemapper.h"

tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@
1616
//
1717
//===----------------------------------------------------------------------===//
1818

19+
#include "swift/ABI/ObjectFile.h"
1920
#include "swift/AST/ASTDemangler.h"
2021
#include "swift/AST/PrintOptions.h"
2122
#include "swift/ASTSectionImporter/ASTSectionImporter.h"
23+
#include "swift/Basic/LLVMInitialize.h"
2224
#include "swift/Frontend/Frontend.h"
2325
#include "swift/Serialization/SerializedModuleLoader.h"
2426
#include "swift/Serialization/Validation.h"
25-
#include "swift/Basic/Dwarf.h"
26-
#include "llvm/Object/ELFObjectFile.h"
27-
#include "swift/Basic/LLVMInitialize.h"
2827
#include "llvm/Object/COFF.h"
28+
#include "llvm/Object/ELFObjectFile.h"
2929
#include "llvm/Object/MachO.h"
3030
#include "llvm/Object/ObjectFile.h"
3131
#include "llvm/Support/CommandLine.h"
3232
#include "llvm/Support/FileSystem.h"
33+
#include "llvm/Support/ManagedStatic.h"
3334
#include "llvm/Support/MemoryBuffer.h"
3435
#include "llvm/Support/Path.h"
3536
#include "llvm/Support/PrettyStackTrace.h"
3637
#include "llvm/Support/Signals.h"
3738
#include "llvm/Support/TargetSelect.h"
3839
#include "llvm/Support/raw_ostream.h"
39-
#include "llvm/Support/ManagedStatic.h"
4040
#include <fstream>
4141
#include <sstream>
4242

@@ -209,15 +209,19 @@ collectASTModules(llvm::cl::list<std::string> &InputNames,
209209
continue;
210210
}
211211
llvm::StringRef Name = *NameOrErr;
212-
if ((MachO && Name == swift::MachOASTSectionName) ||
213-
(ELF && Name == swift::ELFASTSectionName) ||
214-
(COFF && Name == swift::COFFASTSectionName)) {
212+
if ((MachO && Name == swift::SwiftObjectFileFormatMachO().getSectionName(
213+
swift::ReflectionSectionKind::swiftast)) ||
214+
(ELF && Name == swift::SwiftObjectFileFormatELF().getSectionName(
215+
swift::ReflectionSectionKind::swiftast)) ||
216+
(COFF && Name == swift::SwiftObjectFileFormatCOFF().getSectionName(
217+
swift::ReflectionSectionKind::swiftast))) {
215218
uint64_t Size = Section.getSize();
216219

217-
llvm::Expected<llvm::StringRef> ContentsReference = Section.getContents();
220+
llvm::Expected<llvm::StringRef> ContentsReference =
221+
Section.getContents();
218222
if (!ContentsReference) {
219223
llvm::errs() << "error: " << name << " "
220-
<< errorToErrorCode(OF.takeError()).message() << "\n";
224+
<< errorToErrorCode(OF.takeError()).message() << "\n";
221225
return false;
222226
}
223227
char *Module = Alloc.Allocate<char>(Size);

0 commit comments

Comments
 (0)