Skip to content

Use LLVM definitions for Swift section names (NFC) #69255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/swift/ABI/ObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

#include "llvm/Support/ErrorHandling.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Optional.h"

namespace swift {

/// Represents the nine reflection sections used by Swift
/// Represents the nine reflection sections used by Swift + the Swift AST
/// section used by the debugger.
enum ReflectionSectionKind : uint8_t {
#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) KIND,
#include "llvm/BinaryFormat/Swift.def"
Expand Down
33 changes: 0 additions & 33 deletions include/swift/Basic/Dwarf.h

This file was deleted.

1 change: 0 additions & 1 deletion lib/ASTSectionImporter/ASTSectionImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#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"
Expand Down
1 change: 0 additions & 1 deletion lib/Driver/DarwinToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#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"
Expand Down
1 change: 0 additions & 1 deletion lib/Driver/UnixToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "ToolChains.h"

#include "swift/Basic/Dwarf.h"
#include "swift/Basic/LLVM.h"
#include "swift/Basic/Platform.h"
#include "swift/Basic/Range.h"
Expand Down
1 change: 0 additions & 1 deletion lib/Driver/WindowsToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "ToolChains.h"

#include "swift/Basic/Dwarf.h"
#include "swift/Basic/LLVM.h"
#include "swift/Basic/Platform.h"
#include "swift/Basic/Range.h"
Expand Down
5 changes: 0 additions & 5 deletions lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#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"
Expand Down Expand Up @@ -2240,10 +2239,6 @@ int swift::performFrontend(ArrayRef<const char *> Args,
trace.emplace(*buffer);
});

// Setting DWARF Version depend on platform
IRGenOptions &IRGenOpts = Invocation.getIRGenOptions();
IRGenOpts.DWARFVersion = swift::DWARFVersion;

// The compiler invocation is now fully configured; notify our observer.
if (observer) {
observer->parsedArgs(Invocation);
Expand Down
24 changes: 15 additions & 9 deletions lib/IRGen/IRGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#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"
Expand All @@ -26,7 +27,6 @@
#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/Statistic.h"
Expand Down Expand Up @@ -1616,6 +1616,7 @@ 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:
Expand All @@ -1624,19 +1625,24 @@ void swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer,
case llvm::Triple::UnknownObjectFormat:
llvm_unreachable("unknown object format");
case llvm::Triple::XCOFF:
case llvm::Triple::COFF:
Section = COFFASTSectionName;
case llvm::Triple::COFF: {
SwiftObjectFileFormatCOFF COFF;
Section = COFF.getSectionName(ReflectionSectionKind::swiftast);
break;
}
case llvm::Triple::ELF:
Section = ELFASTSectionName;
break;
case llvm::Triple::MachO:
Section = std::string(MachOASTSegmentName) + "," + MachOASTSectionName;
case llvm::Triple::Wasm: {
SwiftObjectFileFormatELF ELF;
Section = ELF.getSectionName(ReflectionSectionKind::swiftast);
break;
case llvm::Triple::Wasm:
Section = WasmASTSectionName;
}
case llvm::Triple::MachO: {
SwiftObjectFileFormatMachO MachO;
Section = std::string(*MachO.getSegmentName()) + "," +
MachO.getSectionName(ReflectionSectionKind::swiftast).str();
break;
}
}
ASTSym->setSection(Section);
ASTSym->setAlignment(llvm::MaybeAlign(serialization::SWIFTMODULE_ALIGNMENT));
::performLLVM(Opts, Ctx.Diags, nullptr, nullptr, IGM.getModule(),
Expand Down
1 change: 0 additions & 1 deletion lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#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"
Expand Down
1 change: 0 additions & 1 deletion lib/IRGen/IRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "swift/AST/GenericSignature.h"
#include "swift/AST/IRGenOptions.h"
#include "swift/AST/IRGenRequests.h"
#include "swift/Basic/Dwarf.h"
#include "swift/Demangling/ManglingMacros.h"
#include "swift/ClangImporter/ClangImporter.h"
#include "swift/IRGen/IRGenPublic.h"
Expand Down
1 change: 0 additions & 1 deletion lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#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/PathRemapper.h"
#include "swift/Basic/STLExtras.h"
Expand Down
22 changes: 13 additions & 9 deletions tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "swift/Basic/Dwarf.h"
#include "llvm/Object/ELFObjectFile.h"
#include "swift/Basic/LLVMInitialize.h"
#include "llvm/Object/COFF.h"
#include "llvm/Object/ELFObjectFile.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 <fstream>
#include <sstream>

Expand Down Expand Up @@ -209,15 +209,19 @@ collectASTModules(llvm::cl::list<std::string> &InputNames,
continue;
}
llvm::StringRef Name = *NameOrErr;
if ((MachO && Name == swift::MachOASTSectionName) ||
(ELF && Name == swift::ELFASTSectionName) ||
(COFF && Name == swift::COFFASTSectionName)) {
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))) {
uint64_t Size = Section.getSize();

llvm::Expected<llvm::StringRef> ContentsReference = Section.getContents();
llvm::Expected<llvm::StringRef> 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<char>(Size);
Expand Down