[dsymutil] Remove support for obfuscated bitcode (#85713)

Remove support for obfuscated bitcode in dsymutil and the DWARF linker.
We no longer support bitcode submissions and the obfuscation support has
been removed from the rest of the compiler.

rdar://123863918
This commit is contained in:
Jonas Devlieghere
2024-03-19 08:30:47 -07:00
parent 0b59af4d86
commit 32a6e9d669
30 changed files with 28 additions and 555 deletions

View File

@@ -140,10 +140,6 @@ OPTIONS
(in bytes) to the linked dSYM. The table is sorted by the output size listing
the object files with the largest contribution first.
.. option:: --symbol-map <bcsymbolmap>
Update the existing dSYMs inplace using symbol map specified.
.. option:: -s, --symtab
Dumps the symbol table found in *executable* or object file(s) and exits.

View File

@@ -27,10 +27,7 @@ public:
/// order.
using MapTy = StringMap<DwarfStringPoolEntry, BumpPtrAllocator>;
NonRelocatableStringpool(
std::function<StringRef(StringRef Input)> Translator = nullptr,
bool PutEmptyString = false)
: Translator(Translator) {
NonRelocatableStringpool(bool PutEmptyString = false) {
if (PutEmptyString)
getEntry("");
}
@@ -59,7 +56,6 @@ private:
MapTy Strings;
uint64_t CurrentEndOffset = 0;
unsigned NumEntries = 0;
std::function<StringRef(StringRef Input)> Translator;
};
/// Helper for making strong types.

View File

@@ -45,16 +45,13 @@ class DwarfStreamer : public DwarfEmitter {
public:
DwarfStreamer(DWARFLinkerBase::OutputFileType OutFileType,
raw_pwrite_stream &OutFile,
DWARFLinkerBase::TranslatorFuncTy Translator,
DWARFLinkerBase::MessageHandlerTy Warning)
: OutFile(OutFile), OutFileType(OutFileType), Translator(Translator),
WarningHandler(Warning) {}
: OutFile(OutFile), OutFileType(OutFileType), WarningHandler(Warning) {}
virtual ~DwarfStreamer() = default;
static Expected<std::unique_ptr<DwarfStreamer>> createStreamer(
const Triple &TheTriple, DWARFLinkerBase::OutputFileType FileType,
raw_pwrite_stream &OutFile, DWARFLinkerBase::TranslatorFuncTy Translator,
DWARFLinkerBase::MessageHandlerTy Warning);
raw_pwrite_stream &OutFile, DWARFLinkerBase::MessageHandlerTy Warning);
Error init(Triple TheTriple, StringRef Swift5ReflectionSegmentName);
@@ -295,7 +292,6 @@ private:
/// The output file we stream the linked Dwarf to.
raw_pwrite_stream &OutFile;
DWARFLinker::OutputFileType OutFileType = DWARFLinker::OutputFileType::Object;
std::function<StringRef(StringRef Input)> Translator;
uint64_t RangesSectionSize = 0;
uint64_t RngListsSectionSize = 0;

View File

@@ -82,7 +82,6 @@ public:
std::function<void(const DWARFFile &File, llvm::StringRef Output)>;
using ObjectPrefixMapTy = std::map<std::string, std::string>;
using CompileUnitHandlerTy = function_ref<void(const DWARFUnit &Unit)>;
using TranslatorFuncTy = std::function<StringRef(StringRef)>;
using SwiftInterfacesMapTy = std::map<std::string, std::string>;
/// Type of output file.
enum class OutputFileType : uint8_t {

View File

@@ -123,8 +123,7 @@ public:
/// Creates dwarf linker instance.
static std::unique_ptr<DWARFLinker>
createLinker(MessageHandlerTy ErrorHandler, MessageHandlerTy WarningHandler,
TranslatorFuncTy StringsTranslator = nullptr);
createLinker(MessageHandlerTy ErrorHandler, MessageHandlerTy WarningHandler);
/// Set output DWARF handler. Result of linking DWARF is set of sections
/// containing final debug info. DWARFLinkerBase::link() pass generated

View File

@@ -12,8 +12,6 @@
namespace llvm {
DwarfStringPoolEntryRef NonRelocatableStringpool::getEntry(StringRef S) {
if (Translator)
S = Translator(S);
auto I = Strings.insert({S, DwarfStringPoolEntry()});
auto &Entry = I.first->second;
if (I.second || !Entry.isIndexed()) {
@@ -28,9 +26,6 @@ DwarfStringPoolEntryRef NonRelocatableStringpool::getEntry(StringRef S) {
StringRef NonRelocatableStringpool::internString(StringRef S) {
DwarfStringPoolEntry Entry{nullptr, 0, DwarfStringPoolEntry::NotIndexed};
if (Translator)
S = Translator(S);
auto InsertResult = Strings.insert({S, Entry});
return InsertResult.first->getKey();
}

View File

@@ -2701,8 +2701,8 @@ Error DWARFLinker::link() {
// This Dwarf string pool which is used for emission. It must be used
// serially as the order of calling getStringOffset matters for
// reproducibility.
OffsetsStringPool DebugStrPool(StringsTranslator, true);
OffsetsStringPool DebugLineStrPool(StringsTranslator, false);
OffsetsStringPool DebugStrPool(true);
OffsetsStringPool DebugLineStrPool(false);
DebugDieValuePool StringOffsetPool;
// ODR Contexts for the optimize.

View File

@@ -32,10 +32,9 @@ using namespace dwarf_linker::classic;
Expected<std::unique_ptr<DwarfStreamer>> DwarfStreamer::createStreamer(
const Triple &TheTriple, DWARFLinkerBase::OutputFileType FileType,
raw_pwrite_stream &OutFile, DWARFLinkerBase::TranslatorFuncTy Translator,
DWARFLinkerBase::MessageHandlerTy Warning) {
raw_pwrite_stream &OutFile, DWARFLinkerBase::MessageHandlerTy Warning) {
std::unique_ptr<DwarfStreamer> Streamer =
std::make_unique<DwarfStreamer>(FileType, OutFile, Translator, Warning);
std::make_unique<DwarfStreamer>(FileType, OutFile, Warning);
if (Error Err = Streamer->init(TheTriple, "__DWARF"))
return std::move(Err);
@@ -977,11 +976,10 @@ void DwarfStreamer::emitLineTableString(const DWARFDebugLine::Prologue &P,
switch (String.getForm()) {
case dwarf::DW_FORM_string: {
StringRef TranslatedString =
(Translator) ? Translator(*StringVal) : *StringVal;
Asm->OutStreamer->emitBytes(TranslatedString.data());
StringRef Str = *StringVal;
Asm->OutStreamer->emitBytes(Str.data());
Asm->emitInt8(0);
LineSectionSize += TranslatedString.size() + 1;
LineSectionSize += Str.size() + 1;
} break;
case dwarf::DW_FORM_strp:
case dwarf::DW_FORM_line_strp: {

View File

@@ -15,8 +15,6 @@ using namespace dwarf_linker::parallel;
std::unique_ptr<DWARFLinker>
DWARFLinker::createLinker(MessageHandlerTy ErrorHandler,
MessageHandlerTy WarningHandler,
TranslatorFuncTy StringsTranslator) {
return std::make_unique<DWARFLinkerImpl>(ErrorHandler, WarningHandler,
StringsTranslator);
MessageHandlerTy WarningHandler) {
return std::make_unique<DWARFLinkerImpl>(ErrorHandler, WarningHandler);
}

View File

@@ -21,7 +21,6 @@ class DWARFDie;
namespace dwarf_linker {
namespace parallel {
using TranslatorFuncTy = std::function<StringRef(StringRef)>;
using MessageHandlerTy = std::function<void(
const Twine &Warning, StringRef Context, const DWARFDie *DIE)>;
@@ -95,19 +94,6 @@ public:
/// Returns global string pool.
StringPool &getStringPool() { return Strings; }
/// Set translation function.
void setTranslator(TranslatorFuncTy Translator) {
this->Translator = Translator;
}
/// Translate specified string.
StringRef translateString(StringRef String) {
if (Translator)
return Translator(String);
return String;
}
/// Returns linking options.
const DWARFLinkerOptions &getOptions() const { return Options; }
@@ -161,7 +147,6 @@ public:
protected:
llvm::parallel::PerThreadBumpPtrAllocator Allocator;
StringPool Strings;
TranslatorFuncTy Translator;
DWARFLinkerOptions Options;
MessageHandlerTy WarningHandler;
MessageHandlerTy ErrorHandler;

View File

@@ -20,11 +20,9 @@ using namespace dwarf_linker;
using namespace dwarf_linker::parallel;
DWARFLinkerImpl::DWARFLinkerImpl(MessageHandlerTy ErrorHandler,
MessageHandlerTy WarningHandler,
TranslatorFuncTy StringsTranslator)
MessageHandlerTy WarningHandler)
: UniqueUnitID(0), DebugStrStrings(GlobalData),
DebugLineStrStrings(GlobalData), CommonSections(GlobalData) {
GlobalData.setTranslator(StringsTranslator);
GlobalData.setErrorHandler(ErrorHandler);
GlobalData.setWarningHandler(WarningHandler);
}

View File

@@ -26,8 +26,7 @@ namespace parallel {
class DWARFLinkerImpl : public DWARFLinker {
public:
DWARFLinkerImpl(MessageHandlerTy ErrorHandler,
MessageHandlerTy WarningHandler,
TranslatorFuncTy StringsTranslator);
MessageHandlerTy WarningHandler);
/// Add object file to be linked. Pre-load compile unit die. Call
/// \p OnCUDieLoaded for each compile unit die. If specified \p File

View File

@@ -253,7 +253,7 @@ struct SectionDescriptor : SectionDescriptorBase {
/// Emit specified inplace string value into the current section contents.
void emitInplaceString(StringRef String) {
OS << GlobalData.translateString(String);
OS << String;
emitIntVal(0, 1);
}

View File

@@ -33,7 +33,7 @@ public:
DwarfStringPoolEntryWithExtString *DataPtr =
GlobalData.getAllocator()
.Allocate<DwarfStringPoolEntryWithExtString>();
DataPtr->String = GlobalData.translateString(String->getKey());
DataPtr->String = String->getKey();
DataPtr->Index = DwarfStringPoolEntry::NotIndexed;
DataPtr->Offset = 0;
DataPtr->Symbol = nullptr;

View File

@@ -1,200 +0,0 @@
REQUIRES: system-darwin
RUN: dsymutil --symbol-map %p/../Inputs/obfuscated.map %p/../Inputs/obfuscated.arm64 -f -o - \
RUN: | llvm-dwarfdump -v - \
RUN: | FileCheck %s
RUN: dsymutil --accelerator=Pub --symbol-map %p/../Inputs/obfuscated.map %p/../Inputs/obfuscated.arm64 -f -o - \
RUN: | llvm-dwarfdump -v - \
RUN: | FileCheck --check-prefix=PUB %s
RUN: dsymutil --symbol-map %p/../Inputs/obfuscated.map %p/../Inputs/obfuscated.arm64 -f -o - \
RUN: | llvm-dwarfdump -v - \
RUN: | FileCheck --check-prefix=NOHIDDEN %s
RUN: dsymutil --symbol-map %p/../Inputs/obfuscated.2.map %p/../Inputs/obfuscated.2.arm64 -f -o - \
RUN: | llvm-dwarfdump -v - \
RUN: | FileCheck --check-prefix=NOHIDDEN %s
// Run with plist and make sure dsymutil finds it.
RUN: mkdir -p %t.dSYM/Contents/Resources/DWARF/
RUN: mkdir -p %t.mapdir
RUN: cp %p/../Inputs/obfuscated.arm64 %t.dSYM/Contents/Resources/DWARF/
RUN: cp %p/../Inputs/E828A486-8433-3A5E-B6DB-A6294D28133D.plist %t.dSYM/Contents/Resources/
RUN: cp %p/../Inputs/obfuscated.map %t.mapdir/506AA50A-6B26-3B37-86D2-DC6EBD57B720.bcsymbolmap
RUN: dsymutil --symbol-map %t.mapdir %t.dSYM 2>&1 | FileCheck --check-prefix=OBFUSCATING %s
// Run without plist and make sure dsymutil doesn't crash.
RUN: rm %t.dSYM/Contents/Resources/E828A486-8433-3A5E-B6DB-A6294D28133D.plist
RUN: dsymutil --symbol-map %t.mapdir %t.dSYM 2>&1 | FileCheck --check-prefix=NOTOBFUSCATING %s
// ----------------------------------------
// Repeat the same steps for --linker parallel.
RUN: dsymutil --linker parallel --symbol-map %p/../Inputs/obfuscated.map %p/../Inputs/obfuscated.arm64 -f -o - \
RUN: | llvm-dwarfdump -v - \
RUN: | FileCheck %s
RUN: dsymutil --linker parallel --accelerator=Pub --symbol-map %p/../Inputs/obfuscated.map %p/../Inputs/obfuscated.arm64 -f -o - \
RUN: | llvm-dwarfdump -v - \
RUN: | FileCheck --check-prefix=PUB %s
RUN: dsymutil --linker parallel --symbol-map %p/../Inputs/obfuscated.map %p/../Inputs/obfuscated.arm64 -f -o - \
RUN: | llvm-dwarfdump -v - \
RUN: | FileCheck --check-prefix=NOHIDDEN %s
RUN: dsymutil --linker parallel --symbol-map %p/../Inputs/obfuscated.2.map %p/../Inputs/obfuscated.2.arm64 -f -o - \
RUN: | llvm-dwarfdump -v - \
RUN: | FileCheck --check-prefix=NOHIDDEN %s
// Run with plist and make sure dsymutil finds it.
RUN: mkdir -p %t.dSYM/Contents/Resources/DWARF/
RUN: mkdir -p %t.mapdir
RUN: cp %p/../Inputs/obfuscated.arm64 %t.dSYM/Contents/Resources/DWARF/
RUN: cp %p/../Inputs/E828A486-8433-3A5E-B6DB-A6294D28133D.plist %t.dSYM/Contents/Resources/
RUN: cp %p/../Inputs/obfuscated.map %t.mapdir/506AA50A-6B26-3B37-86D2-DC6EBD57B720.bcsymbolmap
RUN: dsymutil --linker parallel --symbol-map %t.mapdir %t.dSYM 2>&1 | FileCheck --check-prefix=OBFUSCATING %s
// Run without plist and make sure dsymutil doesn't crash.
RUN: rm %t.dSYM/Contents/Resources/E828A486-8433-3A5E-B6DB-A6294D28133D.plist
RUN: dsymutil --linker parallel --symbol-map %t.mapdir %t.dSYM 2>&1 | FileCheck --check-prefix=NOTOBFUSCATING %s
OBFUSCATING-NOT: not unobfuscating
NOTOBFUSCATING: not unobfuscating
NOHIDDEN-NOT: __hidden#
CHECK: .debug_info contents:
CHECK: DW_TAG_compile_unit [1] *
CHECK: DW_AT_producer [DW_FORM_strp] ( {{.*}} "Apple LLVM version 7.0.0 (clang-700.2.38.2)")
CHECK: DW_AT_name [DW_FORM_strp] ( {{.*}} "main.c")
CHECK: DW_AT_comp_dir [DW_FORM_strp] ( {{.*}} "/Users/steven/dev/alpena/tests/src")
CHECK: DW_TAG_subprogram [2]
CHECK: DW_AT_name [DW_FORM_strp] ( {{.*}} "main")
CHECK: DW_TAG_compile_unit [1] *
CHECK: DW_AT_producer [DW_FORM_strp] ( {{.*}} "Apple LLVM version 7.0.0 (clang-700.2.38.2)")
CHECK: DW_AT_name [DW_FORM_strp] ( {{.*}} "one.c")
CHECK: DW_AT_comp_dir [DW_FORM_strp] ( {{.*}} "/Users/steven/dev/alpena/tests/src")
CHECK: DW_TAG_subprogram [2]
CHECK: DW_AT_name [DW_FORM_strp] ( {{.*}} "one")
CHECK: DW_TAG_compile_unit [1] *
CHECK: DW_AT_producer [DW_FORM_strp] ( {{.*}} "Apple LLVM version 7.0.0 (clang-700.2.38.2)")
CHECK: DW_AT_name [DW_FORM_strp] ( {{.*}} "two.c")
CHECK: DW_AT_comp_dir [DW_FORM_strp] ( {{.*}} "/Users/steven/dev/alpena/tests/src")
CHECK: DW_TAG_subprogram [2]
CHECK: DW_AT_name [DW_FORM_strp] ( {{.*}} "two")
CHECK: DW_TAG_compile_unit [1] *
CHECK: DW_AT_producer [DW_FORM_strp] ( {{.*}} "Apple LLVM version 7.0.0 (clang-700.2.38.2)")
CHECK: DW_AT_name [DW_FORM_strp] ( {{.*}} "three.c")
CHECK: DW_AT_comp_dir [DW_FORM_strp] ( {{.*}} "/Users/steven/dev/alpena/tests/src")
CHECK: DW_TAG_subprogram [2]
CHECK: DW_AT_name [DW_FORM_strp] ( {{.*}} "three")
CHECK: DW_TAG_compile_unit [1] *
CHECK: DW_AT_producer [DW_FORM_strp] ( {{.*}} "Apple LLVM version 7.0.0 (clang-700.2.38.2)")
CHECK: DW_AT_name [DW_FORM_strp] ( {{.*}} "four.c")
CHECK: DW_AT_stmt_list [DW_FORM_data4] (0x0000011e)
CHECK: DW_AT_comp_dir [DW_FORM_strp] ( {{.*}} "/Users/steven/dev/alpena/tests/src")
CHECK: DW_TAG_subprogram [2]
CHECK: DW_AT_name [DW_FORM_strp] ( {{.*}} "four")
CHECK: DW_TAG_compile_unit [1] *
CHECK: DW_AT_producer [DW_FORM_strp] ( {{.*}} "Apple LLVM version 7.0.0 (clang-700.2.38.2)")
CHECK: DW_AT_name [DW_FORM_strp] ( {{.*}} "five.c")
CHECK: DW_AT_comp_dir [DW_FORM_strp] ( {{.*}} "/Users/steven/dev/alpena/tests/src")
CHECK: DW_TAG_subprogram [2]
CHECK: DW_AT_name [DW_FORM_strp] ( {{.*}} "five")
CHECK: DW_TAG_compile_unit [1] *
CHECK: DW_AT_producer [DW_FORM_strp] ( {{.*}} "Apple LLVM version 7.0.0 (clang-700.2.38.2)")
CHECK: DW_AT_name [DW_FORM_strp] ( {{.*}} "six.c")
CHECK: DW_AT_comp_dir [DW_FORM_strp] ( {{.*}} "/Users/steven/dev/alpena/tests/src")
CHECK: DW_TAG_subprogram [2]
CHECK: DW_AT_name [DW_FORM_strp] ( {{.*}} "six")
CHECK: .debug_line contents:
CHECK: file_names[ 1]:
CHECK: name: "main.c"
CHECK: dir_index: 0
CHECK: mod_time: 0x00000000
CHECK: file_names[ 1]:
CHECK: name: "one.c"
CHECK: dir_index: 0
CHECK: mod_time: 0x00000000
CHECK: length: 0x00000000
CHECK: file_names[ 1]:
CHECK: name: "two.c"
CHECK: dir_index: 0
CHECK: mod_time: 0x00000000
CHECK: length: 0x00000000
CHECK: file_names[ 1]:
CHECK: name: "three.c"
CHECK: dir_index: 0
CHECK: mod_time: 0x00000000
CHECK: length: 0x00000000
CHECK: file_names[ 1]:
CHECK: name: "four.c"
CHECK: dir_index: 0
CHECK: mod_time: 0x00000000
CHECK: length: 0x00000000
CHECK: file_names[ 1]:
CHECK: name: "five.c"
CHECK: dir_index: 0
CHECK: mod_time: 0x00000000
CHECK: length: 0x00000000
CHECK: file_names[ 1]:
CHECK: name: "six.c"
CHECK: dir_index: 0
CHECK: mod_time: 0x00000000
CHECK: length: 0x00000000
PUB: .debug_pubnames contents:
PUB: length = 0x00000017, format = DWARF32, version = 0x0002, unit_offset = 0x00000000, unit_size = 0x00000044
PUB: 0x0000002e "main"
PUB: length = 0x00000016, format = DWARF32, version = 0x0002, unit_offset = 0x00000044, unit_size = 0x00000044
PUB: 0x0000002e "one"
PUB: length = 0x00000016, format = DWARF32, version = 0x0002, unit_offset = 0x00000088, unit_size = 0x00000044
PUB: 0x0000002e "two"
PUB: length = 0x00000018, format = DWARF32, version = 0x0002, unit_offset = 0x000000cc, unit_size = 0x00000044
PUB: 0x0000002e "three"
PUB: length = 0x00000017, format = DWARF32, version = 0x0002, unit_offset = 0x00000110, unit_size = 0x00000044
PUB: 0x0000002e "four"
PUB: length = 0x00000017, format = DWARF32, version = 0x0002, unit_offset = 0x00000154, unit_size = 0x00000044
PUB: 0x0000002e "five"
PUB: length = 0x00000016, format = DWARF32, version = 0x0002, unit_offset = 0x00000198, unit_size = 0x00000044
PUB: 0x0000002e "six"
CHECK: .apple_names contents:
CHECK: String: 0x00000091 "five"
CHECK-NEXT: Data 0 [
CHECK-NEXT: Atom[0]: 0x00000182
CHECK-NEXT: ]
CHECK: String: 0x0000009c "six"
CHECK-NEXT: Data 0 [
CHECK-NEXT: Atom[0]: 0x000001c6
CHECK-NEXT: ]
CHECK: String: 0x00000078 "three"
CHECK-NEXT: Data 0 [
CHECK-NEXT: Atom[0]: 0x000000fa
CHECK-NEXT: ]
CHECK: String: 0x0000006c "two"
CHECK-NEXT: Data 0 [
CHECK-NEXT: Atom[0]: 0x000000b6
CHECK-NEXT: ]
CHECK: String: 0x00000057 "main"
CHECK-NEXT: Data 0 [
CHECK-NEXT: Atom[0]: 0x0000002e
CHECK-NEXT: ]
CHECK: String: 0x00000085 "four"
CHECK-NEXT: Data 0 [
CHECK-NEXT: Atom[0]: 0x0000013e
CHECK-NEXT: ]
CHECK: String: 0x00000062 "one"
CHECK-NEXT: Data 0 [
CHECK-NEXT: Atom[0]: 0x00000072
CHECK-NEXT: ]

View File

@@ -1,22 +0,0 @@
BCSymbolMap Version: 2.0
_two
_three
_four
_five
_six
LLVM version 3.9.0 (ssh://git@stash.sd.apple.com/devtools/clang.git c74ae34bd917b77f9c848bd599dfde2813fb509f)
main
main.c
/Volumes/Data/dev/BitcodeBuildTests/unit
one
one.c
two
two.c
three
three.c
four
four.c
five
five.c
six
six.c

View File

@@ -1,17 +0,0 @@
one
two
three
four
five
six
.str
Apple LLVM version 7.0.0 (clang-700.2.38.2)
main
main.c
/Users/steven/dev/alpena/tests/src
one.c
two.c
three.c
four.c
five.c
six.c

View File

@@ -28,7 +28,6 @@ CHECK: -remarks-output-format <format>
CHECK: -remarks-prepend-path <path>
CHECK: -reproducer <mode>
CHECK: -statistics
CHECK: -symbol-map
CHECK: -symtab
CHECK: {{-S}}
CHECK: -toolchain

View File

@@ -32,7 +32,6 @@ add_llvm_tool(dsymutil
MachOUtils.cpp
Reproducer.cpp
RelocationMap.cpp
SymbolMap.cpp
DEPENDS
intrinsics_gen

View File

@@ -634,25 +634,19 @@ bool DwarfLinkerForBinary::linkImpl(
DebugMap DebugMap(Map.getTriple(), Map.getBinaryPath());
std::function<StringRef(StringRef)> TranslationLambda = [&](StringRef Input) {
assert(Options.Translator);
return Options.Translator(Input);
};
std::unique_ptr<Linker> GeneralLinker = Linker::createLinker(
[&](const Twine &Error, StringRef Context, const DWARFDie *DIE) {
reportError(Error, Context, DIE);
},
[&](const Twine &Warning, StringRef Context, const DWARFDie *DIE) {
reportWarning(Warning, Context, DIE);
},
Options.Translator ? TranslationLambda : nullptr);
});
std::unique_ptr<classic::DwarfStreamer> Streamer;
if (!Options.NoOutput) {
if (Expected<std::unique_ptr<classic::DwarfStreamer>> StreamerOrErr =
classic::DwarfStreamer::createStreamer(
Map.getTriple(), ObjectType, OutFile, Options.Translator,
Map.getTriple(), ObjectType, OutFile,
[&](const Twine &Warning, StringRef Context,
const DWARFDie *DIE) {
reportWarning(Warning, Context, DIE);
@@ -866,8 +860,8 @@ bool DwarfLinkerForBinary::linkImpl(
if (Map.getTriple().isOSDarwin() && !Map.getBinaryPath().empty() &&
ObjectType == Linker::OutputFileType::Object)
return MachOUtils::generateDsymCompanion(
Options.VFS, Map, Options.Translator,
*Streamer->getAsmPrinter().OutStreamer, OutFile, RelocationsToApply);
Options.VFS, Map, *Streamer->getAsmPrinter().OutStreamer, OutFile,
RelocationsToApply);
Streamer->finish();
return true;

View File

@@ -9,8 +9,6 @@
#ifndef LLVM_TOOLS_DSYMUTIL_LINKOPTIONS_H
#define LLVM_TOOLS_DSYMUTIL_LINKOPTIONS_H
#include "SymbolMap.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Remarks/RemarkFormat.h"
#include "llvm/Support/VirtualFileSystem.h"
@@ -87,9 +85,6 @@ struct LinkOptions {
/// The Resources directory in the .dSYM bundle.
std::optional<std::string> ResourceDir;
/// Symbol map translator.
SymbolMapTranslator Translator;
/// Virtual File System.
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
vfs::getRealFileSystem();

View File

@@ -373,7 +373,7 @@ static unsigned segmentLoadCommandSize(bool Is64Bit, unsigned NumSections) {
// \a OutFile and it must be using a MachObjectWriter object to do so.
bool generateDsymCompanion(
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, const DebugMap &DM,
SymbolMapTranslator &Translator, MCStreamer &MS, raw_fd_ostream &OutFile,
MCStreamer &MS, raw_fd_ostream &OutFile,
const std::vector<MachOUtils::DwarfRelocationApplicationInfo>
&RelocationsToApply) {
auto &ObjectStreamer = static_cast<MCObjectStreamer &>(MS);
@@ -509,12 +509,9 @@ bool generateDsymCompanion(
}
SmallString<0> NewSymtab;
std::function<StringRef(StringRef)> TranslationLambda =
Translator ? [&](StringRef Input) { return Translator(Input); }
: static_cast<std::function<StringRef(StringRef)>>(nullptr);
// Legacy dsymutil puts an empty string at the start of the line table.
// thus we set NonRelocatableStringpool(,PutEmptyString=true)
NonRelocatableStringpool NewStrings(TranslationLambda, true);
NonRelocatableStringpool NewStrings(true);
unsigned NListSize = Is64Bit ? sizeof(MachO::nlist_64) : sizeof(MachO::nlist);
unsigned NumSyms = 0;
uint64_t NewStringsSize = 0;

View File

@@ -8,8 +8,6 @@
#ifndef LLVM_TOOLS_DSYMUTIL_MACHOUTILS_H
#define LLVM_TOOLS_DSYMUTIL_MACHOUTILS_H
#include "SymbolMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/VirtualFileSystem.h"
@@ -59,7 +57,7 @@ bool generateUniversalBinary(SmallVectorImpl<ArchAndFile> &ArchFiles,
StringRef SDKPath, bool Fat64 = false);
bool generateDsymCompanion(
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, const DebugMap &DM,
SymbolMapTranslator &Translator, MCStreamer &MS, raw_fd_ostream &OutFile,
MCStreamer &MS, raw_fd_ostream &OutFile,
const std::vector<MachOUtils::DwarfRelocationApplicationInfo>
&RelocationsToApply);

View File

@@ -128,12 +128,6 @@ def object_prefix_map: Separate<["--", "-"], "object-prefix-map">,
Group<grp_general>;
def: Joined<["--", "-"], "object-prefix-map=">, Alias<object_prefix_map>;
def symbolmap: Separate<["--", "-"], "symbol-map">,
MetaVarName<"<bcsymbolmap>">,
HelpText<"Updates the existing dSYMs inplace using symbol map specified.">,
Group<grp_general>;
def: Joined<["--", "-"], "symbol-map=">, Alias<symbolmap>;
def arch: Separate<["--", "-"], "arch">,
MetaVarName<"<arch>">,
HelpText<"Link DWARF debug information only for specified CPU architecture"

View File

@@ -1,157 +0,0 @@
//===- tools/dsymutil/SymbolMap.cpp ---------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "SymbolMap.h"
#include "DebugMap.h"
#include "MachOUtils.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/WithColor.h"
#ifdef __APPLE__
#include <CoreFoundation/CoreFoundation.h>
#include <uuid/uuid.h>
#endif
namespace llvm {
namespace dsymutil {
StringRef SymbolMapTranslator::operator()(StringRef Input) {
if (!Input.starts_with("__hidden#") && !Input.starts_with("___hidden#"))
return Input;
StringRef Line = Input.drop_front(sizeof("__hidden#") - 1);
bool MightNeedUnderscore = Line.consume_front("#");
std::size_t LineNumber = std::numeric_limits<std::size_t>::max();
Line.split('_').first.getAsInteger(10, LineNumber);
if (LineNumber >= UnobfuscatedStrings.size()) {
WithColor::warning() << "reference to a unexisting unobfuscated string "
<< Input << ": symbol map mismatch?\n"
<< Line << '\n';
return Input;
}
const std::string &Translation = UnobfuscatedStrings[LineNumber];
if (!MightNeedUnderscore || !MangleNames)
return Translation;
// Objective-C symbols for the MachO symbol table start with a \1. Please see
// `MangleContext::mangleObjCMethodName` in clang.
if (Translation[0] == 1)
return StringRef(Translation).drop_front();
// We need permanent storage for the string we are about to create. Just
// append it to the vector containing translations. This should only happen
// during MachO symbol table translation, thus there should be no risk on
// exponential growth.
UnobfuscatedStrings.emplace_back("_" + Translation);
return UnobfuscatedStrings.back();
}
SymbolMapTranslator SymbolMapLoader::Load(StringRef InputFile,
const DebugMap &Map) const {
if (SymbolMap.empty())
return {};
std::string SymbolMapPath = SymbolMap;
#if __APPLE__
// Look through the UUID Map.
if (sys::fs::is_directory(SymbolMapPath) && !Map.getUUID().empty()) {
uuid_string_t UUIDString;
uuid_unparse_upper((const uint8_t *)Map.getUUID().data(), UUIDString);
SmallString<256> PlistPath(
sys::path::parent_path(sys::path::parent_path(InputFile)));
sys::path::append(PlistPath, StringRef(UUIDString).str() + ".plist");
CFStringRef plistFile = CFStringCreateWithCString(
kCFAllocatorDefault, PlistPath.c_str(), kCFStringEncodingUTF8);
CFURLRef fileURL = CFURLCreateWithFileSystemPath(
kCFAllocatorDefault, plistFile, kCFURLPOSIXPathStyle, false);
CFReadStreamRef resourceData =
CFReadStreamCreateWithFile(kCFAllocatorDefault, fileURL);
if (resourceData) {
CFReadStreamOpen(resourceData);
CFDictionaryRef plist = (CFDictionaryRef)CFPropertyListCreateWithStream(
kCFAllocatorDefault, resourceData, 0, kCFPropertyListImmutable,
nullptr, nullptr);
if (plist) {
if (CFDictionaryContainsKey(plist, CFSTR("DBGOriginalUUID"))) {
CFStringRef OldUUID = (CFStringRef)CFDictionaryGetValue(
plist, CFSTR("DBGOriginalUUID"));
StringRef UUID(CFStringGetCStringPtr(OldUUID, kCFStringEncodingUTF8));
SmallString<256> BCSymbolMapPath(SymbolMapPath);
sys::path::append(BCSymbolMapPath, UUID.str() + ".bcsymbolmap");
SymbolMapPath = std::string(BCSymbolMapPath);
}
CFRelease(plist);
}
CFReadStreamClose(resourceData);
CFRelease(resourceData);
}
CFRelease(fileURL);
CFRelease(plistFile);
}
#endif
if (sys::fs::is_directory(SymbolMapPath)) {
SymbolMapPath += (Twine("/") + sys::path::filename(InputFile) + "-" +
MachOUtils::getArchName(Map.getTriple().getArchName()) +
".bcsymbolmap")
.str();
}
auto ErrOrMemBuffer = MemoryBuffer::getFile(SymbolMapPath);
if (auto EC = ErrOrMemBuffer.getError()) {
WithColor::warning() << SymbolMapPath << ": " << EC.message()
<< ": not unobfuscating.\n";
return {};
}
std::vector<std::string> UnobfuscatedStrings;
auto &MemBuf = **ErrOrMemBuffer;
StringRef Data(MemBuf.getBufferStart(),
MemBuf.getBufferEnd() - MemBuf.getBufferStart());
StringRef LHS;
std::tie(LHS, Data) = Data.split('\n');
bool MangleNames = false;
// Check version string first.
if (!LHS.starts_with("BCSymbolMap Version:")) {
// Version string not present, warns but try to parse it.
WithColor::warning() << SymbolMapPath
<< " is missing version string: assuming 1.0.\n";
UnobfuscatedStrings.emplace_back(LHS);
} else if (LHS.equals("BCSymbolMap Version: 1.0")) {
MangleNames = true;
} else if (LHS.equals("BCSymbolMap Version: 2.0")) {
MangleNames = false;
} else {
StringRef VersionNum;
std::tie(LHS, VersionNum) = LHS.split(':');
WithColor::warning() << SymbolMapPath
<< " has unsupported symbol map version" << VersionNum
<< ": not unobfuscating.\n";
return {};
}
while (!Data.empty()) {
std::tie(LHS, Data) = Data.split('\n');
UnobfuscatedStrings.emplace_back(LHS);
}
return SymbolMapTranslator(std::move(UnobfuscatedStrings), MangleNames);
}
} // namespace dsymutil
} // namespace llvm

View File

@@ -1,53 +0,0 @@
//=- tools/dsymutil/SymbolMap.h -----------------------------------*- C++ -*-=//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_DSYMUTIL_SYMBOLMAP_H
#define LLVM_TOOLS_DSYMUTIL_SYMBOLMAP_H
#include "llvm/ADT/StringRef.h"
#include <string>
#include <vector>
namespace llvm {
namespace dsymutil {
class DebugMap;
/// Callable class to unobfuscate strings based on a BCSymbolMap.
class SymbolMapTranslator {
public:
SymbolMapTranslator() : MangleNames(false) {}
SymbolMapTranslator(std::vector<std::string> UnobfuscatedStrings,
bool MangleNames)
: UnobfuscatedStrings(std::move(UnobfuscatedStrings)),
MangleNames(MangleNames) {}
StringRef operator()(StringRef Input);
operator bool() const { return !UnobfuscatedStrings.empty(); }
private:
std::vector<std::string> UnobfuscatedStrings;
bool MangleNames;
};
/// Class to initialize SymbolMapTranslators from a BCSymbolMap.
class SymbolMapLoader {
public:
SymbolMapLoader(std::string SymbolMap) : SymbolMap(std::move(SymbolMap)) {}
SymbolMapTranslator Load(StringRef InputFile, const DebugMap &Map) const;
private:
const std::string SymbolMap;
};
} // namespace dsymutil
} // namespace llvm
#endif // LLVM_TOOLS_DSYMUTIL_SYMBOLMAP_H

View File

@@ -108,7 +108,6 @@ struct DsymutilOptions {
bool Flat = false;
bool InputIsYAMLDebugMap = false;
bool ForceKeepFunctionForStatic = false;
std::string SymbolMap;
std::string OutputFile;
std::string Toolchain;
std::string ReproducerPath;
@@ -341,12 +340,6 @@ static Expected<DsymutilOptions> getOptions(opt::InputArgList &Args) {
return DWARFLinkerType.takeError();
}
if (opt::Arg *SymbolMap = Args.getLastArg(OPT_symbolmap))
Options.SymbolMap = SymbolMap->getValue();
if (Args.hasArg(OPT_symbolmap))
Options.LinkOpts.Update = true;
if (Expected<std::vector<std::string>> InputFiles =
getInputs(Args, Options.LinkOpts.Update)) {
Options.InputFiles = std::move(*InputFiles);
@@ -560,8 +553,7 @@ getOutputFileName(StringRef InputFile, const DsymutilOptions &Options) {
return OutputLocation(Options.OutputFile);
// When updating, do in place replacement.
if (Options.OutputFile.empty() &&
(Options.LinkOpts.Update || !Options.SymbolMap.empty()))
if (Options.OutputFile.empty() && Options.LinkOpts.Update)
return OutputLocation(std::string(InputFile));
// When dumping the debug map, just return an empty output location. This
@@ -668,8 +660,6 @@ int dsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
return EXIT_FAILURE;
}
SymbolMapLoader SymMapLoader(Options.SymbolMap);
for (auto &InputFile : Options.InputFiles) {
// Dump the symbol table for each input file and requested arch
if (Options.DumpStab) {
@@ -760,9 +750,6 @@ int dsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
if (Options.DumpDebugMap)
continue;
if (!Options.SymbolMap.empty())
Options.LinkOpts.Translator = SymMapLoader.Load(InputFile, *Map);
if (Map->begin() == Map->end()) {
std::lock_guard<std::mutex> Guard(ErrorHandlerMutex);
WithColor::warning()

View File

@@ -338,9 +338,9 @@ Error linkDebugInfoImpl(object::ObjectFile &File, const Options &Options,
Triple TargetTriple = File.makeTriple();
std::unique_ptr<classic::DwarfStreamer> Streamer;
if (Expected<std::unique_ptr<classic::DwarfStreamer>> StreamerOrErr =
classic::DwarfStreamer::createStreamer(
TargetTriple, Linker::OutputFileType::Object, OutStream, nullptr,
ReportWarn))
classic::DwarfStreamer::createStreamer(TargetTriple,
Linker::OutputFileType::Object,
OutStream, ReportWarn))
Streamer = std::move(*StreamerOrErr);
else
return StreamerOrErr.takeError();