diff options
Diffstat (limited to 'contrib/llvm-project/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/contrib/llvm-project/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp b/contrib/llvm-project/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp index 458a58c12ca7..3e70f460bc58 100644 --- a/contrib/llvm-project/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp +++ b/contrib/llvm-project/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 |