Skip to content

Commit 6c6872b

Browse files
authored
Merge pull request #7761 from bulbazord/20230725-reflection-is-no-object
[lldb][NFCI] Remove ObjectFile::GetReflectionSectionIdentifier
2 parents 562cad1 + 3efbc3c commit 6c6872b

File tree

9 files changed

+43
-95
lines changed

9 files changed

+43
-95
lines changed

lldb/include/lldb/Symbol/ObjectFile.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
#include "llvm/Support/VersionTuple.h"
2525
#include <optional>
2626

27-
namespace swift {
28-
enum ReflectionSectionKind : uint8_t;
29-
}
3027
namespace lldb_private {
3128

3229
/// \class ObjectFile ObjectFile.h "lldb/Symbol/ObjectFile.h"
@@ -721,9 +718,6 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
721718
/// Creates a plugin-specific call frame info
722719
virtual std::unique_ptr<CallFrameInfo> CreateCallFrameInfo();
723720

724-
virtual llvm::StringRef
725-
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section);
726-
727721
/// Load binaries listed in a corefile
728722
///
729723
/// A corefile may have metadata listing binaries that can be loaded,

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,32 @@ class SwiftLanguageRuntimeStub {
419419
operator=(const SwiftLanguageRuntimeStub &) = delete;
420420
};
421421

422+
static std::unique_ptr<swift::SwiftObjectFileFormat>
423+
GetObjectFileFormat(llvm::Triple::ObjectFormatType obj_format_type) {
424+
std::unique_ptr<swift::SwiftObjectFileFormat> obj_file_format;
425+
switch (obj_format_type) {
426+
case llvm::Triple::MachO:
427+
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatMachO>();
428+
break;
429+
case llvm::Triple::ELF:
430+
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatELF>();
431+
break;
432+
case llvm::Triple::COFF:
433+
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatCOFF>();
434+
break;
435+
default:
436+
if (Log *log = GetLog(LLDBLog::Types))
437+
log->Printf("%s: Could not find out swift reflection section names for "
438+
"object format type.",
439+
__FUNCTION__);
440+
}
441+
return obj_file_format;
442+
}
443+
422444
static bool HasReflectionInfo(ObjectFile *obj_file) {
445+
if (!obj_file)
446+
return false;
447+
423448
auto findSectionInObject = [&](StringRef name) {
424449
ConstString section_name(name);
425450
SectionSP section_sp =
@@ -429,18 +454,24 @@ static bool HasReflectionInfo(ObjectFile *obj_file) {
429454
return false;
430455
};
431456

432-
StringRef field_md = obj_file->GetReflectionSectionIdentifier(
433-
swift::ReflectionSectionKind::fieldmd);
434-
StringRef assocty = obj_file->GetReflectionSectionIdentifier(
435-
swift::ReflectionSectionKind::assocty);
436-
StringRef builtin = obj_file->GetReflectionSectionIdentifier(
437-
swift::ReflectionSectionKind::builtin);
438-
StringRef capture = obj_file->GetReflectionSectionIdentifier(
439-
swift::ReflectionSectionKind::capture);
440-
StringRef typeref = obj_file->GetReflectionSectionIdentifier(
441-
swift::ReflectionSectionKind::typeref);
442-
StringRef reflstr = obj_file->GetReflectionSectionIdentifier(
443-
swift::ReflectionSectionKind::reflstr);
457+
const auto obj_format_type =
458+
obj_file->GetArchitecture().GetTriple().getObjectFormat();
459+
auto obj_file_format_up = GetObjectFileFormat(obj_format_type);
460+
if (!obj_file_format_up)
461+
return false;
462+
463+
StringRef field_md =
464+
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::fieldmd);
465+
StringRef assocty =
466+
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::assocty);
467+
StringRef builtin =
468+
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::builtin);
469+
StringRef capture =
470+
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::capture);
471+
StringRef typeref =
472+
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::typeref);
473+
StringRef reflstr =
474+
obj_file_format_up->getSectionName(swift::ReflectionSectionKind::reflstr);
444475

445476
bool hasReflectionSection = false;
446477
hasReflectionSection |= findSectionInObject(field_md);
@@ -626,28 +657,6 @@ void SwiftLanguageRuntime::ModulesDidLoad(const ModuleList &module_list) {
626657
}
627658
}
628659

629-
static std::unique_ptr<swift::SwiftObjectFileFormat>
630-
GetObjectFileFormat(llvm::Triple::ObjectFormatType obj_format_type) {
631-
std::unique_ptr<swift::SwiftObjectFileFormat> obj_file_format;
632-
switch (obj_format_type) {
633-
case llvm::Triple::MachO:
634-
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatMachO>();
635-
break;
636-
case llvm::Triple::ELF:
637-
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatELF>();
638-
break;
639-
case llvm::Triple::COFF:
640-
obj_file_format = std::make_unique<swift::SwiftObjectFileFormatCOFF>();
641-
break;
642-
default:
643-
if (Log *log = GetLog(LLDBLog::Types))
644-
log->Printf("%s: Could not find out swift reflection section names for "
645-
"object format type.",
646-
__FUNCTION__);
647-
}
648-
return obj_file_format;
649-
}
650-
651660
static llvm::SmallVector<llvm::StringRef, 1>
652661
GetLikelySwiftImageNamesForModule(ModuleSP module) {
653662
if (!module || !module->GetFileSpec())

lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@
4545
#include "llvm/Support/MemoryBuffer.h"
4646
#include "llvm/Support/MipsABIFlags.h"
4747

48-
#ifdef LLDB_ENABLE_SWIFT
49-
#include "swift/ABI/ObjectFile.h"
50-
#endif //LLDB_ENABLE_SWIFT
51-
5248
#define CASE_AND_STREAM(s, def, width) \
5349
case def: \
5450
s->Printf("%-*s", width, #def); \
@@ -3587,13 +3583,3 @@ ObjectFileELF::MapFileDataWritable(const FileSpec &file, uint64_t Size,
35873583
return FileSystem::Instance().CreateWritableDataBuffer(file.GetPath(), Size,
35883584
Offset);
35893585
}
3590-
3591-
llvm::StringRef ObjectFileELF::GetReflectionSectionIdentifier(
3592-
swift::ReflectionSectionKind section) {
3593-
#ifdef LLDB_ENABLE_SWIFT
3594-
swift::SwiftObjectFileFormatELF file_format_elf;
3595-
return file_format_elf.getSectionName(section);
3596-
#else
3597-
llvm_unreachable("Swift support disabled");
3598-
#endif //LLDB_ENABLE_SWIFT
3599-
}

lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,6 @@ class ObjectFileELF : public lldb_private::ObjectFile {
398398
/// .gnu_debugdata section or \c nullptr if an error occured or if there's no
399399
/// section with that name.
400400
std::shared_ptr<ObjectFileELF> GetGnuDebugDataObjectFile();
401-
402-
llvm::StringRef
403-
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section) override;
404401
};
405402

406403
#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_ELF_OBJECTFILEELF_H

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353

5454
#include "ObjectFileMachO.h"
5555
#ifdef LLDB_ENABLE_SWIFT
56-
#include "swift/ABI/ObjectFile.h"
5756
#include "Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h"
5857
#endif //LLDB_ENABLE_SWIFT
5958

@@ -6951,16 +6950,6 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
69516950
return false;
69526951
}
69536952

6954-
llvm::StringRef ObjectFileMachO::GetReflectionSectionIdentifier(
6955-
swift::ReflectionSectionKind section) {
6956-
#ifdef LLDB_ENABLE_SWIFT
6957-
swift::SwiftObjectFileFormatMachO file_format_mach_o;
6958-
return file_format_mach_o.getSectionName(section);
6959-
#else
6960-
llvm_unreachable("Swift support disabled");
6961-
#endif //LLDB_ENABLE_SWIFT
6962-
}
6963-
69646953
ObjectFileMachO::MachOCorefileAllImageInfos
69656954
ObjectFileMachO::GetCorefileAllImageInfos() {
69666955
MachOCorefileAllImageInfos image_infos;

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,6 @@ class ObjectFileMachO : public lldb_private::ObjectFile {
228228

229229
bool SectionIsLoadable(const lldb_private::Section *section);
230230

231-
llvm::StringRef
232-
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section) override;
233-
234231
/// A corefile may include metadata about all of the binaries that were
235232
/// present in the process when the corefile was taken. This is only
236233
/// implemented for Mach-O files for now; we'll generalize it when we

lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
#include "llvm/TargetParser/Host.h"
4141
#include <optional>
4242

43-
#ifdef LLDB_ENABLE_SWIFT
44-
#include "swift/ABI/ObjectFile.h"
45-
#endif //LLDB_ENABLE_SWIFT
46-
4743
#define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
4844
#define IMAGE_NT_SIGNATURE 0x00004550 // PE00
4945
#define OPT_HEADER_MAGIC_PE32 0x010b
@@ -1435,13 +1431,3 @@ ObjectFile::Type ObjectFilePECOFF::CalculateType() {
14351431
}
14361432

14371433
ObjectFile::Strata ObjectFilePECOFF::CalculateStrata() { return eStrataUser; }
1438-
1439-
llvm::StringRef ObjectFilePECOFF::GetReflectionSectionIdentifier(
1440-
swift::ReflectionSectionKind section) {
1441-
#ifdef LLDB_ENABLE_SWIFT
1442-
swift::SwiftObjectFileFormatCOFF file_format_coff;
1443-
return file_format_coff.getSectionName(section);
1444-
#else
1445-
llvm_unreachable("Swift support disabled");
1446-
#endif //LLDB_ENABLE_SWIFT
1447-
}

lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,6 @@ class ObjectFilePECOFF : public lldb_private::ObjectFile {
265265
const section_header_t &sect);
266266
size_t GetSectionDataSize(lldb_private::Section *section) override;
267267

268-
llvm::StringRef
269-
GetReflectionSectionIdentifier(swift::ReflectionSectionKind section) override;
270-
271268
typedef std::vector<section_header_t> SectionHeaderColl;
272269
typedef SectionHeaderColl::iterator SectionHeaderCollIter;
273270
typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter;

lldb/source/Symbol/ObjectFile.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -733,13 +733,6 @@ void llvm::format_provider<ObjectFile::Strata>::format(
733733
}
734734
}
735735

736-
llvm::StringRef ObjectFile::GetReflectionSectionIdentifier(
737-
swift::ReflectionSectionKind section) {
738-
assert(false &&
739-
"Base class's GetReflectionSectionIdentifier should not be called");
740-
return "";
741-
}
742-
743736
Symtab *ObjectFile::GetSymtab() {
744737
ModuleSP module_sp(GetModule());
745738
if (module_sp) {

0 commit comments

Comments
 (0)