diff options
Diffstat (limited to 'llvm/tools/llvm-dwarfutil')
| -rw-r--r-- | llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp | 49 | ||||
| -rw-r--r-- | llvm/tools/llvm-dwarfutil/DebugInfoLinker.h | 4 | ||||
| -rw-r--r-- | llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp | 22 |
3 files changed, 55 insertions, 20 deletions
diff --git a/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp b/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp index 458a58c12ca7..3e70f460bc58 100644 --- a/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp +++ b/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp @@ -8,6 +8,7 @@ #include "DebugInfoLinker.h" #include "Error.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/DWARFLinker/DWARFLinker.h" #include "llvm/DWARFLinker/DWARFStreamer.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" @@ -210,8 +211,29 @@ private: const Options &Opts; }; -bool linkDebugInfo(object::ObjectFile &File, const Options &Options, - raw_pwrite_stream &OutStream) { +static bool knownByDWARFUtil(StringRef SecName) { + return llvm::StringSwitch<bool>(SecName) + .Case(".debug_info", true) + .Case(".debug_types", true) + .Case(".debug_abbrev", true) + .Case(".debug_loc", true) + .Case(".debug_loclists", true) + .Case(".debug_frame", true) + .Case(".debug_aranges", true) + .Case(".debug_ranges", true) + .Case(".debug_rnglists", true) + .Case(".debug_line", true) + .Case(".debug_line_str", true) + .Case(".debug_addr", true) + .Case(".debug_macro", true) + .Case(".debug_macinfo", true) + .Case(".debug_str", true) + .Case(".debug_str_offsets", true) + .Default(false); +} + +Error linkDebugInfo(object::ObjectFile &File, const Options &Options, + raw_pwrite_stream &OutStream) { auto ReportWarn = [&](const Twine &Message, StringRef Context, const DWARFDie *Die) { @@ -235,8 +257,11 @@ bool linkDebugInfo(object::ObjectFile &File, const Options &Options, // Create output streamer. DwarfStreamer OutStreamer(OutputFileType::Object, OutStream, nullptr, ReportWarn, ReportWarn); - if (!OutStreamer.init(File.makeTriple(), "")) - return false; + Triple TargetTriple = File.makeTriple(); + if (!OutStreamer.init(TargetTriple, formatv("cannot create a stream for {0}", + TargetTriple.getTriple()) + .str())) + return createStringError(std::errc::invalid_argument, ""); // Create DWARF linker. DWARFLinker DebugInfoLinker(&OutStreamer, DwarfLinkerClient::LLD); @@ -256,6 +281,16 @@ bool linkDebugInfo(object::ObjectFile &File, const Options &Options, std::unique_ptr<DWARFContext> Context = DWARFContext::create(File); + // Unknown debug sections would be removed. Display warning + // for such sections. + for (SectionName Sec : Context->getDWARFObj().getSectionNames()) { + if (isDebugSection(Sec.Name) && !knownByDWARFUtil(Sec.Name)) + warning( + formatv("'{0}' is not currently supported: section will be skipped", + Sec.Name), + Options.InputFileName); + } + // Add object files to the DWARFLinker. AddresssMapForLinking[0] = std::make_unique<ObjFileAddressMap>(*Context, Options, File); @@ -268,9 +303,11 @@ bool linkDebugInfo(object::ObjectFile &File, const Options &Options, DebugInfoLinker.addObjectFile(*ObjectsForLinking[I]); // Link debug info. - DebugInfoLinker.link(); + if (Error Err = DebugInfoLinker.link()) + return Err; + OutStreamer.finish(); - return true; + return Error::success(); } } // end of namespace dwarfutil diff --git a/llvm/tools/llvm-dwarfutil/DebugInfoLinker.h b/llvm/tools/llvm-dwarfutil/DebugInfoLinker.h index e95c83cb9609..d9d99ffc8747 100644 --- a/llvm/tools/llvm-dwarfutil/DebugInfoLinker.h +++ b/llvm/tools/llvm-dwarfutil/DebugInfoLinker.h @@ -22,8 +22,8 @@ inline bool isDebugSection(StringRef SecName) { SecName == ".gdb_index"; } -bool linkDebugInfo(object::ObjectFile &file, const Options &Options, - raw_pwrite_stream &OutStream); +Error linkDebugInfo(object::ObjectFile &file, const Options &Options, + raw_pwrite_stream &OutStream); } // end of namespace dwarfutil } // end of namespace llvm diff --git a/llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp b/llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp index e77c82e0fad9..a6466be37513 100644 --- a/llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp +++ b/llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp @@ -292,7 +292,7 @@ using DebugInfoBits = SmallString<10000>; static Error addSectionsFromLinkedData(objcopy::ConfigManager &Config, ObjectFile &InputFile, DebugInfoBits &LinkedDebugInfoBits) { - if (dyn_cast<ELFObjectFile<ELF32LE>>(&InputFile)) { + if (isa<ELFObjectFile<ELF32LE>>(&InputFile)) { Expected<ELFObjectFile<ELF32LE>> MemFile = ELFObjectFile<ELF32LE>::create( MemoryBufferRef(LinkedDebugInfoBits, "")); if (!MemFile) @@ -300,7 +300,7 @@ static Error addSectionsFromLinkedData(objcopy::ConfigManager &Config, if (Error Err = setConfigToAddNewDebugSections(Config, *MemFile)) return Err; - } else if (dyn_cast<ELFObjectFile<ELF64LE>>(&InputFile)) { + } else if (isa<ELFObjectFile<ELF64LE>>(&InputFile)) { Expected<ELFObjectFile<ELF64LE>> MemFile = ELFObjectFile<ELF64LE>::create( MemoryBufferRef(LinkedDebugInfoBits, "")); if (!MemFile) @@ -308,7 +308,7 @@ static Error addSectionsFromLinkedData(objcopy::ConfigManager &Config, if (Error Err = setConfigToAddNewDebugSections(Config, *MemFile)) return Err; - } else if (dyn_cast<ELFObjectFile<ELF32BE>>(&InputFile)) { + } else if (isa<ELFObjectFile<ELF32BE>>(&InputFile)) { Expected<ELFObjectFile<ELF32BE>> MemFile = ELFObjectFile<ELF32BE>::create( MemoryBufferRef(LinkedDebugInfoBits, "")); if (!MemFile) @@ -316,7 +316,7 @@ static Error addSectionsFromLinkedData(objcopy::ConfigManager &Config, if (Error Err = setConfigToAddNewDebugSections(Config, *MemFile)) return Err; - } else if (dyn_cast<ELFObjectFile<ELF64BE>>(&InputFile)) { + } else if (isa<ELFObjectFile<ELF64BE>>(&InputFile)) { Expected<ELFObjectFile<ELF64BE>> MemFile = ELFObjectFile<ELF64BE>::create( MemoryBufferRef(LinkedDebugInfoBits, "")); if (!MemFile) @@ -426,16 +426,14 @@ static Error applyCLOptions(const struct Options &Opts, ObjectFile &InputFile) { DebugInfoBits LinkedDebugInfo; raw_svector_ostream OutStream(LinkedDebugInfo); - if (linkDebugInfo(InputFile, Opts, OutStream)) { - if (Error Err = - saveLinkedDebugInfo(Opts, InputFile, std::move(LinkedDebugInfo))) - return Err; + if (Error Err = linkDebugInfo(InputFile, Opts, OutStream)) + return Err; - return Error::success(); - } + if (Error Err = + saveLinkedDebugInfo(Opts, InputFile, std::move(LinkedDebugInfo))) + return Err; - return createStringError(std::errc::invalid_argument, - "possible broken debug info"); + return Error::success(); } else if (Opts.BuildSeparateDebugFile) { if (Error Err = splitDebugIntoSeparateFile(Opts, InputFile)) return Err; |
