[swift-reflection-dump] Make ObjC interoperability configurable.

This addresses a FIXME in the code. This allows running swift-reflection-dump
on macOS to dump the contents of an ELF binary.
This commit is contained in:
Adrian Prantl
2022-10-12 12:26:37 -07:00
parent 5d832bf946
commit 33eb213e28
4 changed files with 52 additions and 25 deletions

View File

@@ -78,6 +78,12 @@ static llvm::cl::opt<std::string>
Architecture("arch",
llvm::cl::desc("Architecture to inspect in the binary"),
llvm::cl::Required);
#if SWIFT_OBJC_INTEROP
static llvm::cl::opt<bool> DisableObjCInterop(
"no-objc-interop",
llvm::cl::desc("Disable Objective-C interoperability support"));
#endif
} // end namespace options
static int doDumpReflectionSections(ArrayRef<std::string> BinaryFilenames,
@@ -109,7 +115,12 @@ static int doDumpReflectionSections(ArrayRef<std::string> BinaryFilenames,
ObjectFiles.push_back(O);
}
auto context = makeReflectionContextForObjectFiles(ObjectFiles);
#if SWIFT_OBJC_INTEROP
bool ObjCInterop = !options::DisableObjCInterop;
#else
bool ObjCInterop = false;
#endif
auto context = makeReflectionContextForObjectFiles(ObjectFiles, ObjCInterop);
auto &builder = context->Builder;
switch (Action) {
@@ -117,17 +128,21 @@ static int doDumpReflectionSections(ArrayRef<std::string> BinaryFilenames,
// Dump everything
switch (context->PointerSize) {
case 4:
// FIXME: This could/should be configurable.
#if SWIFT_OBJC_INTEROP
builder.dumpAllSections<WithObjCInterop, 4>(stream);
if (!options::DisableObjCInterop)
builder.dumpAllSections<WithObjCInterop, 4>(stream);
else
builder.dumpAllSections<NoObjCInterop, 4>(stream);
#else
builder.dumpAllSections<NoObjCInterop, 4>(stream);
#endif
break;
case 8:
// FIXME: This could/should be configurable.
#if SWIFT_OBJC_INTEROP
builder.dumpAllSections<WithObjCInterop, 8>(stream);
if (!options::DisableObjCInterop)
builder.dumpAllSections<WithObjCInterop, 8>(stream);
else
builder.dumpAllSections<NoObjCInterop, 8>(stream);
#else
builder.dumpAllSections<NoObjCInterop, 8>(stream);
#endif