diff options
Diffstat (limited to 'contrib/llvm/lib/MC')
45 files changed, 218 insertions, 239 deletions
diff --git a/contrib/llvm/lib/MC/ELFObjectWriter.cpp b/contrib/llvm/lib/MC/ELFObjectWriter.cpp index e86db933af3c..4d139132df46 100644 --- a/contrib/llvm/lib/MC/ELFObjectWriter.cpp +++ b/contrib/llvm/lib/MC/ELFObjectWriter.cpp @@ -13,11 +13,12 @@  #include "llvm/ADT/ArrayRef.h"  #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/STLExtras.h"  #include "llvm/ADT/SmallString.h"  #include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/STLExtras.h"  #include "llvm/ADT/StringRef.h"  #include "llvm/ADT/Twine.h" +#include "llvm/BinaryFormat/ELF.h"  #include "llvm/MC/MCAsmInfo.h"  #include "llvm/MC/MCAsmLayout.h"  #include "llvm/MC/MCAssembler.h" @@ -36,7 +37,6 @@  #include "llvm/Support/Allocator.h"  #include "llvm/Support/Casting.h"  #include "llvm/Support/Compression.h" -#include "llvm/Support/ELF.h"  #include "llvm/Support/Endian.h"  #include "llvm/Support/Error.h"  #include "llvm/Support/ErrorHandling.h" @@ -1020,18 +1020,24 @@ void ELFObjectWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec,    MCSectionELF &Section = static_cast<MCSectionELF &>(Sec);    StringRef SectionName = Section.getSectionName(); +  auto &MC = Asm.getContext(); +  const auto &MAI = MC.getAsmInfo(); +    // Compressing debug_frame requires handling alignment fragments which is    // more work (possibly generalizing MCAssembler.cpp:writeFragment to allow    // for writing to arbitrary buffers) for little benefit.    bool CompressionEnabled = -      Asm.getContext().getAsmInfo()->compressDebugSections() != -      DebugCompressionType::DCT_None; +      MAI->compressDebugSections() != DebugCompressionType::None;    if (!CompressionEnabled || !SectionName.startswith(".debug_") ||        SectionName == ".debug_frame") {      Asm.writeSectionData(&Section, Layout);      return;    } +  assert((MAI->compressDebugSections() == DebugCompressionType::Z || +          MAI->compressDebugSections() == DebugCompressionType::GNU) && +         "expected zlib or zlib-gnu style compression"); +    SmallVector<char, 128> UncompressedData;    raw_svector_ostream VecOS(UncompressedData);    raw_pwrite_stream &OldStream = getStream(); @@ -1048,8 +1054,7 @@ void ELFObjectWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec,      return;    } -  bool ZlibStyle = Asm.getContext().getAsmInfo()->compressDebugSections() == -                   DebugCompressionType::DCT_Zlib; +  bool ZlibStyle = MAI->compressDebugSections() == DebugCompressionType::Z;    if (!maybeWriteCompression(UncompressedData.size(), CompressedContents,                               ZlibStyle, Sec.getAlignment())) {      getStream() << UncompressedData; @@ -1061,8 +1066,7 @@ void ELFObjectWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec,      Section.setFlags(Section.getFlags() | ELF::SHF_COMPRESSED);    else      // Add "z" prefix to section name. This is zlib-gnu style. -    Asm.getContext().renameELFSection(&Section, -                                      (".z" + SectionName.drop_front(1)).str()); +    MC.renameELFSection(&Section, (".z" + SectionName.drop_front(1)).str());    getStream() << CompressedContents;  } diff --git a/contrib/llvm/lib/MC/MCAsmBackend.cpp b/contrib/llvm/lib/MC/MCAsmBackend.cpp index fc0aa788f6d3..3642f37aa855 100644 --- a/contrib/llvm/lib/MC/MCAsmBackend.cpp +++ b/contrib/llvm/lib/MC/MCAsmBackend.cpp @@ -7,9 +7,9 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCAsmBackend.h"  #include "llvm/ADT/None.h"  #include "llvm/ADT/STLExtras.h" -#include "llvm/MC/MCAsmBackend.h"  #include "llvm/MC/MCFixupKindInfo.h"  #include <cassert>  #include <cstddef> diff --git a/contrib/llvm/lib/MC/MCAsmInfo.cpp b/contrib/llvm/lib/MC/MCAsmInfo.cpp index b9be685cedc4..f05904048e0b 100644 --- a/contrib/llvm/lib/MC/MCAsmInfo.cpp +++ b/contrib/llvm/lib/MC/MCAsmInfo.cpp @@ -13,10 +13,10 @@  //===----------------------------------------------------------------------===//  #include "llvm/MC/MCAsmInfo.h" +#include "llvm/BinaryFormat/Dwarf.h"  #include "llvm/MC/MCContext.h"  #include "llvm/MC/MCExpr.h"  #include "llvm/MC/MCStreamer.h" -#include "llvm/Support/Dwarf.h"  using namespace llvm; diff --git a/contrib/llvm/lib/MC/MCAsmInfoDarwin.cpp b/contrib/llvm/lib/MC/MCAsmInfoDarwin.cpp index 4b2001764e97..c74840982fb7 100644 --- a/contrib/llvm/lib/MC/MCAsmInfoDarwin.cpp +++ b/contrib/llvm/lib/MC/MCAsmInfoDarwin.cpp @@ -13,9 +13,9 @@  //===----------------------------------------------------------------------===//  #include "llvm/MC/MCAsmInfoDarwin.h" +#include "llvm/BinaryFormat/MachO.h"  #include "llvm/MC/MCDirectives.h"  #include "llvm/MC/MCSectionMachO.h" -#include "llvm/Support/MachO.h"  using namespace llvm; diff --git a/contrib/llvm/lib/MC/MCAsmInfoELF.cpp b/contrib/llvm/lib/MC/MCAsmInfoELF.cpp index e44c08b50d76..b0dc43c6c868 100644 --- a/contrib/llvm/lib/MC/MCAsmInfoELF.cpp +++ b/contrib/llvm/lib/MC/MCAsmInfoELF.cpp @@ -13,9 +13,9 @@  //===----------------------------------------------------------------------===//  #include "llvm/MC/MCAsmInfoELF.h" +#include "llvm/BinaryFormat/ELF.h"  #include "llvm/MC/MCContext.h"  #include "llvm/MC/MCSectionELF.h" -#include "llvm/Support/ELF.h"  using namespace llvm; diff --git a/contrib/llvm/lib/MC/MCAssembler.cpp b/contrib/llvm/lib/MC/MCAssembler.cpp index c2bb7b277181..53cdaac3aa54 100644 --- a/contrib/llvm/lib/MC/MCAssembler.cpp +++ b/contrib/llvm/lib/MC/MCAssembler.cpp @@ -7,6 +7,7 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCAssembler.h"  #include "llvm/ADT/ArrayRef.h"  #include "llvm/ADT/SmallString.h"  #include "llvm/ADT/SmallVector.h" @@ -16,7 +17,6 @@  #include "llvm/MC/MCAsmBackend.h"  #include "llvm/MC/MCAsmInfo.h"  #include "llvm/MC/MCAsmLayout.h" -#include "llvm/MC/MCAssembler.h"  #include "llvm/MC/MCCodeEmitter.h"  #include "llvm/MC/MCCodeView.h"  #include "llvm/MC/MCContext.h" @@ -37,9 +37,9 @@  #include "llvm/Support/LEB128.h"  #include "llvm/Support/MathExtras.h"  #include "llvm/Support/raw_ostream.h" -#include <cstring>  #include <cassert>  #include <cstdint> +#include <cstring>  #include <tuple>  #include <utility> diff --git a/contrib/llvm/lib/MC/MCCodeView.cpp b/contrib/llvm/lib/MC/MCCodeView.cpp index 6c9a4f9f982d..92b1e12da552 100644 --- a/contrib/llvm/lib/MC/MCCodeView.cpp +++ b/contrib/llvm/lib/MC/MCCodeView.cpp @@ -13,6 +13,7 @@  #include "llvm/MC/MCCodeView.h"  #include "llvm/ADT/STLExtras.h" +#include "llvm/BinaryFormat/COFF.h"  #include "llvm/DebugInfo/CodeView/CodeView.h"  #include "llvm/DebugInfo/CodeView/Line.h"  #include "llvm/DebugInfo/CodeView/SymbolRecord.h" @@ -20,7 +21,6 @@  #include "llvm/MC/MCContext.h"  #include "llvm/MC/MCObjectStreamer.h"  #include "llvm/MC/MCValue.h" -#include "llvm/Support/COFF.h"  #include "llvm/Support/EndianStream.h"  using namespace llvm; diff --git a/contrib/llvm/lib/MC/MCContext.cpp b/contrib/llvm/lib/MC/MCContext.cpp index 4628d0ab88f3..48ee84edb096 100644 --- a/contrib/llvm/lib/MC/MCContext.cpp +++ b/contrib/llvm/lib/MC/MCContext.cpp @@ -7,14 +7,16 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCContext.h"  #include "llvm/ADT/SmallString.h"  #include "llvm/ADT/SmallVector.h"  #include "llvm/ADT/StringMap.h"  #include "llvm/ADT/StringRef.h"  #include "llvm/ADT/Twine.h" +#include "llvm/BinaryFormat/COFF.h" +#include "llvm/BinaryFormat/ELF.h"  #include "llvm/MC/MCAsmInfo.h"  #include "llvm/MC/MCCodeView.h" -#include "llvm/MC/MCContext.h"  #include "llvm/MC/MCDwarf.h"  #include "llvm/MC/MCExpr.h"  #include "llvm/MC/MCFragment.h" @@ -32,14 +34,12 @@  #include "llvm/MC/MCSymbolWasm.h"  #include "llvm/MC/SectionKind.h"  #include "llvm/Support/Casting.h" -#include "llvm/Support/COFF.h"  #include "llvm/Support/CommandLine.h" -#include "llvm/Support/ELF.h"  #include "llvm/Support/ErrorHandling.h"  #include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/raw_ostream.h"  #include "llvm/Support/Signals.h"  #include "llvm/Support/SourceMgr.h" +#include "llvm/Support/raw_ostream.h"  #include <cassert>  #include <cstdlib>  #include <tuple> diff --git a/contrib/llvm/lib/MC/MCDisassembler/Disassembler.cpp b/contrib/llvm/lib/MC/MCDisassembler/Disassembler.cpp index aa5072743bdf..ef1d8335e1bd 100644 --- a/contrib/llvm/lib/MC/MCDisassembler/Disassembler.cpp +++ b/contrib/llvm/lib/MC/MCDisassembler/Disassembler.cpp @@ -27,8 +27,8 @@  #include "llvm/MC/MCSubtargetInfo.h"  #include "llvm/Support/ErrorHandling.h"  #include "llvm/Support/FormattedStream.h" -#include "llvm/Support/raw_ostream.h"  #include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/raw_ostream.h"  #include <cassert>  #include <cstddef>  #include <cstring> diff --git a/contrib/llvm/lib/MC/MCDisassembler/MCRelocationInfo.cpp b/contrib/llvm/lib/MC/MCDisassembler/MCRelocationInfo.cpp index 5805fd7007d2..8f932a3f0d48 100644 --- a/contrib/llvm/lib/MC/MCDisassembler/MCRelocationInfo.cpp +++ b/contrib/llvm/lib/MC/MCDisassembler/MCRelocationInfo.cpp @@ -8,8 +8,8 @@  //===----------------------------------------------------------------------===//  #include "llvm/MC/MCDisassembler/MCRelocationInfo.h" -#include "llvm/Support/TargetRegistry.h"  #include "llvm-c/Disassembler.h" +#include "llvm/Support/TargetRegistry.h"  using namespace llvm; diff --git a/contrib/llvm/lib/MC/MCDwarf.cpp b/contrib/llvm/lib/MC/MCDwarf.cpp index 1a320b0165fa..a2beee32f2cb 100644 --- a/contrib/llvm/lib/MC/MCDwarf.cpp +++ b/contrib/llvm/lib/MC/MCDwarf.cpp @@ -7,19 +7,20 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCDwarf.h"  #include "llvm/ADT/ArrayRef.h"  #include "llvm/ADT/DenseMap.h"  #include "llvm/ADT/Hashing.h"  #include "llvm/ADT/None.h" +#include "llvm/ADT/STLExtras.h"  #include "llvm/ADT/SmallString.h"  #include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/STLExtras.h"  #include "llvm/ADT/StringRef.h"  #include "llvm/ADT/Twine.h" +#include "llvm/BinaryFormat/Dwarf.h"  #include "llvm/Config/config.h"  #include "llvm/MC/MCAsmInfo.h"  #include "llvm/MC/MCContext.h" -#include "llvm/MC/MCDwarf.h"  #include "llvm/MC/MCExpr.h"  #include "llvm/MC/MCObjectFileInfo.h"  #include "llvm/MC/MCObjectStreamer.h" @@ -28,7 +29,6 @@  #include "llvm/MC/MCStreamer.h"  #include "llvm/MC/MCSymbol.h"  #include "llvm/Support/Casting.h" -#include "llvm/Support/Dwarf.h"  #include "llvm/Support/Endian.h"  #include "llvm/Support/EndianStream.h"  #include "llvm/Support/ErrorHandling.h" diff --git a/contrib/llvm/lib/MC/MCELFStreamer.cpp b/contrib/llvm/lib/MC/MCELFStreamer.cpp index c8e0223c0573..50c1f6e79f8a 100644 --- a/contrib/llvm/lib/MC/MCELFStreamer.cpp +++ b/contrib/llvm/lib/MC/MCELFStreamer.cpp @@ -11,14 +11,15 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCELFStreamer.h"  #include "llvm/ADT/SmallString.h"  #include "llvm/ADT/SmallVector.h" +#include "llvm/BinaryFormat/ELF.h"  #include "llvm/MC/MCAsmBackend.h"  #include "llvm/MC/MCAsmInfo.h"  #include "llvm/MC/MCAssembler.h"  #include "llvm/MC/MCCodeEmitter.h"  #include "llvm/MC/MCContext.h" -#include "llvm/MC/MCELFStreamer.h"  #include "llvm/MC/MCExpr.h"  #include "llvm/MC/MCFixup.h"  #include "llvm/MC/MCFragment.h" @@ -27,10 +28,9 @@  #include "llvm/MC/MCSection.h"  #include "llvm/MC/MCSectionELF.h"  #include "llvm/MC/MCStreamer.h" -#include "llvm/MC/MCSymbolELF.h"  #include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCSymbolELF.h"  #include "llvm/Support/Casting.h" -#include "llvm/Support/ELF.h"  #include "llvm/Support/ErrorHandling.h"  #include "llvm/Support/TargetRegistry.h"  #include "llvm/Support/raw_ostream.h" diff --git a/contrib/llvm/lib/MC/MCExpr.cpp b/contrib/llvm/lib/MC/MCExpr.cpp index 8149aa27327c..38a8af49c194 100644 --- a/contrib/llvm/lib/MC/MCExpr.cpp +++ b/contrib/llvm/lib/MC/MCExpr.cpp @@ -7,13 +7,13 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCExpr.h"  #include "llvm/ADT/Statistic.h"  #include "llvm/ADT/StringSwitch.h"  #include "llvm/MC/MCAsmInfo.h"  #include "llvm/MC/MCAsmLayout.h"  #include "llvm/MC/MCAssembler.h"  #include "llvm/MC/MCContext.h" -#include "llvm/MC/MCExpr.h"  #include "llvm/MC/MCObjectWriter.h"  #include "llvm/MC/MCSymbol.h"  #include "llvm/MC/MCValue.h" @@ -655,8 +655,12 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,          // the OS X assembler will completely drop the 4. We should probably          // include it in the relocation or produce an error if that is not          // possible. +        // Allow constant expressions.          if (!A && !B)            return true; +        // Allows aliases with zero offset. +        if (Res.getConstant() == 0 && (!A || !B)) +          return true;        }      } diff --git a/contrib/llvm/lib/MC/MCFragment.cpp b/contrib/llvm/lib/MC/MCFragment.cpp index 90b44177cf5e..f3d0eb55eecd 100644 --- a/contrib/llvm/lib/MC/MCFragment.cpp +++ b/contrib/llvm/lib/MC/MCFragment.cpp @@ -7,15 +7,15 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCFragment.h"  #include "llvm/ADT/SmallVector.h"  #include "llvm/ADT/StringExtras.h"  #include "llvm/ADT/Twine.h" -#include "llvm/MC/MCAssembler.h"  #include "llvm/MC/MCAsmLayout.h" +#include "llvm/MC/MCAssembler.h"  #include "llvm/MC/MCContext.h"  #include "llvm/MC/MCExpr.h"  #include "llvm/MC/MCFixup.h" -#include "llvm/MC/MCFragment.h"  #include "llvm/MC/MCSection.h"  #include "llvm/MC/MCSymbol.h"  #include "llvm/MC/MCValue.h" diff --git a/contrib/llvm/lib/MC/MCInstPrinter.cpp b/contrib/llvm/lib/MC/MCInstPrinter.cpp index 912179095974..9296fcedb72b 100644 --- a/contrib/llvm/lib/MC/MCInstPrinter.cpp +++ b/contrib/llvm/lib/MC/MCInstPrinter.cpp @@ -7,10 +7,10 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCInstPrinter.h"  #include "llvm/ADT/ArrayRef.h"  #include "llvm/ADT/StringRef.h"  #include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCInstPrinter.h"  #include "llvm/MC/MCInstrInfo.h"  #include "llvm/Support/ErrorHandling.h"  #include "llvm/Support/Format.h" diff --git a/contrib/llvm/lib/MC/MCInstrAnalysis.cpp b/contrib/llvm/lib/MC/MCInstrAnalysis.cpp index 566944c53548..280b5cf68c98 100644 --- a/contrib/llvm/lib/MC/MCInstrAnalysis.cpp +++ b/contrib/llvm/lib/MC/MCInstrAnalysis.cpp @@ -7,8 +7,8 @@  //  //===----------------------------------------------------------------------===// -#include "llvm/MC/MCInst.h"  #include "llvm/MC/MCInstrAnalysis.h" +#include "llvm/MC/MCInst.h"  #include "llvm/MC/MCInstrDesc.h"  #include "llvm/MC/MCInstrInfo.h"  #include <cstdint> diff --git a/contrib/llvm/lib/MC/MCMachOStreamer.cpp b/contrib/llvm/lib/MC/MCMachOStreamer.cpp index 1e9ef4163256..674c7b9bf619 100644 --- a/contrib/llvm/lib/MC/MCMachOStreamer.cpp +++ b/contrib/llvm/lib/MC/MCMachOStreamer.cpp @@ -32,8 +32,8 @@  #include "llvm/MC/MCValue.h"  #include "llvm/Support/Casting.h"  #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/raw_ostream.h"  #include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/raw_ostream.h"  #include <cassert>  #include <vector> diff --git a/contrib/llvm/lib/MC/MCNullStreamer.cpp b/contrib/llvm/lib/MC/MCNullStreamer.cpp index d156f5d05a31..4db9a2c8d8de 100644 --- a/contrib/llvm/lib/MC/MCNullStreamer.cpp +++ b/contrib/llvm/lib/MC/MCNullStreamer.cpp @@ -7,10 +7,10 @@  //  //===----------------------------------------------------------------------===// -#include "llvm/MC/MCStreamer.h"  #include "llvm/MC/MCContext.h"  #include "llvm/MC/MCInst.h"  #include "llvm/MC/MCSectionMachO.h" +#include "llvm/MC/MCStreamer.h"  #include "llvm/MC/MCSymbol.h"  using namespace llvm; diff --git a/contrib/llvm/lib/MC/MCObjectFileInfo.cpp b/contrib/llvm/lib/MC/MCObjectFileInfo.cpp index b685790910d0..21c5516785ef 100644 --- a/contrib/llvm/lib/MC/MCObjectFileInfo.cpp +++ b/contrib/llvm/lib/MC/MCObjectFileInfo.cpp @@ -10,6 +10,8 @@  #include "llvm/MC/MCObjectFileInfo.h"  #include "llvm/ADT/StringExtras.h"  #include "llvm/ADT/Triple.h" +#include "llvm/BinaryFormat/COFF.h" +#include "llvm/BinaryFormat/ELF.h"  #include "llvm/MC/MCAsmInfo.h"  #include "llvm/MC/MCContext.h"  #include "llvm/MC/MCSection.h" @@ -17,8 +19,6 @@  #include "llvm/MC/MCSectionELF.h"  #include "llvm/MC/MCSectionMachO.h"  #include "llvm/MC/MCSectionWasm.h" -#include "llvm/Support/COFF.h" -#include "llvm/Support/ELF.h"  using namespace llvm; @@ -241,6 +241,9 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {    DwarfStrSection =        Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,                             SectionKind::getMetadata(), "info_string"); +  DwarfStrOffSection = +      Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG, +                           SectionKind::getMetadata(), "section_str_off");    DwarfLocSection =        Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,                             SectionKind::getMetadata(), "section_debug_loc"); @@ -557,6 +560,11 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T) {    DwarfAccelTypesSection =        Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0); +  // String Offset and Address Sections +  DwarfStrOffSection = +      Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0); +  DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0); +    // Fission Sections    DwarfInfoDWOSection =        Ctx->getELFSection(".debug_info.dwo", DebugSecType, 0); @@ -573,7 +581,6 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T) {        Ctx->getELFSection(".debug_loc.dwo", DebugSecType, 0);    DwarfStrOffDWOSection =        Ctx->getELFSection(".debug_str_offsets.dwo", DebugSecType, 0); -  DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);    // DWP Sections    DwarfCUIndexSection = @@ -695,6 +702,11 @@ void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {        COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |            COFF::IMAGE_SCN_MEM_READ,        SectionKind::getMetadata(), "info_string"); +  DwarfStrOffSection = Ctx->getCOFFSection( +      ".debug_str_offsets", +      COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | +          COFF::IMAGE_SCN_MEM_READ, +      SectionKind::getMetadata(), "section_str_off");    DwarfLocSection = Ctx->getCOFFSection(        ".debug_loc",        COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | @@ -749,7 +761,7 @@ void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {        ".debug_str_offsets.dwo",        COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |            COFF::IMAGE_SCN_MEM_READ, -      SectionKind::getMetadata()); +      SectionKind::getMetadata(), "section_str_off_dwo");    DwarfAddrSection = Ctx->getCOFFSection(        ".debug_addr",        COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | diff --git a/contrib/llvm/lib/MC/MCObjectWriter.cpp b/contrib/llvm/lib/MC/MCObjectWriter.cpp index 478b4e84e74a..98ac48a23f91 100644 --- a/contrib/llvm/lib/MC/MCObjectWriter.cpp +++ b/contrib/llvm/lib/MC/MCObjectWriter.cpp @@ -7,10 +7,10 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCObjectWriter.h"  #include "llvm/MC/MCAssembler.h" -#include "llvm/MC/MCFragment.h"  #include "llvm/MC/MCExpr.h" -#include "llvm/MC/MCObjectWriter.h" +#include "llvm/MC/MCFragment.h"  #include "llvm/MC/MCSymbol.h"  using namespace llvm; diff --git a/contrib/llvm/lib/MC/MCParser/AsmLexer.cpp b/contrib/llvm/lib/MC/MCParser/AsmLexer.cpp index 38dadfe62135..2b963607b837 100644 --- a/contrib/llvm/lib/MC/MCParser/AsmLexer.cpp +++ b/contrib/llvm/lib/MC/MCParser/AsmLexer.cpp @@ -11,12 +11,12 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCParser/AsmLexer.h"  #include "llvm/ADT/APInt.h"  #include "llvm/ADT/ArrayRef.h"  #include "llvm/ADT/StringRef.h"  #include "llvm/ADT/StringSwitch.h"  #include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCParser/AsmLexer.h"  #include "llvm/MC/MCParser/MCAsmLexer.h"  #include "llvm/Support/SMLoc.h"  #include "llvm/Support/SaveAndRestore.h" diff --git a/contrib/llvm/lib/MC/MCParser/AsmParser.cpp b/contrib/llvm/lib/MC/MCParser/AsmParser.cpp index 3b213ef4ce09..dad47e49e2c2 100644 --- a/contrib/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/contrib/llvm/lib/MC/MCParser/AsmParser.cpp @@ -15,12 +15,13 @@  #include "llvm/ADT/APInt.h"  #include "llvm/ADT/ArrayRef.h"  #include "llvm/ADT/None.h" +#include "llvm/ADT/STLExtras.h"  #include "llvm/ADT/SmallString.h"  #include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/STLExtras.h"  #include "llvm/ADT/StringMap.h"  #include "llvm/ADT/StringRef.h"  #include "llvm/ADT/Twine.h" +#include "llvm/BinaryFormat/Dwarf.h"  #include "llvm/MC/MCAsmInfo.h"  #include "llvm/MC/MCCodeView.h"  #include "llvm/MC/MCContext.h" @@ -47,7 +48,6 @@  #include "llvm/MC/MCValue.h"  #include "llvm/Support/Casting.h"  #include "llvm/Support/CommandLine.h" -#include "llvm/Support/Dwarf.h"  #include "llvm/Support/ErrorHandling.h"  #include "llvm/Support/MathExtras.h"  #include "llvm/Support/MemoryBuffer.h" @@ -703,7 +703,7 @@ const AsmToken &AsmParser::Lex() {    // if it's a end of statement with a comment in it    if (getTok().is(AsmToken::EndOfStatement)) {      // if this is a line comment output it. -    if (getTok().getString().front() != '\n' && +    if (!getTok().getString().empty() && getTok().getString().front() != '\n' &&          getTok().getString().front() != '\r' && MAI.preserveAsmComments())        Out.addExplicitComment(Twine(getTok().getString()));    } @@ -1523,7 +1523,7 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,      Lex();    if (Lexer.is(AsmToken::EndOfStatement)) {      // if this is a line comment we can drop it safely -    if (getTok().getString().front() == '\r' || +    if (getTok().getString().empty() || getTok().getString().front() == '\r' ||          getTok().getString().front() == '\n')        Out.AddBlankLine();      Lex(); diff --git a/contrib/llvm/lib/MC/MCParser/COFFAsmParser.cpp b/contrib/llvm/lib/MC/MCParser/COFFAsmParser.cpp index bec62ccb2f7f..b83d68d4fe20 100644 --- a/contrib/llvm/lib/MC/MCParser/COFFAsmParser.cpp +++ b/contrib/llvm/lib/MC/MCParser/COFFAsmParser.cpp @@ -7,10 +7,11 @@  //  //===----------------------------------------------------------------------===// -#include "llvm/ADT/StringSwitch.h"  #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringSwitch.h"  #include "llvm/ADT/Triple.h"  #include "llvm/ADT/Twine.h" +#include "llvm/BinaryFormat/COFF.h"  #include "llvm/MC/MCContext.h"  #include "llvm/MC/MCDirectives.h"  #include "llvm/MC/MCObjectFileInfo.h" @@ -21,7 +22,6 @@  #include "llvm/MC/MCSectionCOFF.h"  #include "llvm/MC/MCStreamer.h"  #include "llvm/MC/SectionKind.h" -#include "llvm/Support/COFF.h"  #include "llvm/Support/SMLoc.h"  #include <cassert>  #include <cstdint> diff --git a/contrib/llvm/lib/MC/MCParser/DarwinAsmParser.cpp b/contrib/llvm/lib/MC/MCParser/DarwinAsmParser.cpp index 73a7ad0500c3..f4152a9067a0 100644 --- a/contrib/llvm/lib/MC/MCParser/DarwinAsmParser.cpp +++ b/contrib/llvm/lib/MC/MCParser/DarwinAsmParser.cpp @@ -7,12 +7,13 @@  //  //===----------------------------------------------------------------------===// -#include "llvm/ADT/SmallVector.h"  #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h"  #include "llvm/ADT/StringRef.h"  #include "llvm/ADT/StringSwitch.h"  #include "llvm/ADT/Triple.h"  #include "llvm/ADT/Twine.h" +#include "llvm/BinaryFormat/MachO.h"  #include "llvm/MC/MCContext.h"  #include "llvm/MC/MCDirectives.h"  #include "llvm/MC/MCObjectFileInfo.h" @@ -25,10 +26,9 @@  #include "llvm/MC/SectionKind.h"  #include "llvm/Support/FileSystem.h"  #include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/MachO.h" -#include "llvm/Support/raw_ostream.h"  #include "llvm/Support/SMLoc.h"  #include "llvm/Support/SourceMgr.h" +#include "llvm/Support/raw_ostream.h"  #include <algorithm>  #include <cstddef>  #include <cstdint> diff --git a/contrib/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/contrib/llvm/lib/MC/MCParser/ELFAsmParser.cpp index 401011a027f4..f1dfb91aafbb 100644 --- a/contrib/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/contrib/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -7,8 +7,9 @@  //  //===----------------------------------------------------------------------===// -#include "llvm/ADT/StringSwitch.h"  #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/BinaryFormat/ELF.h"  #include "llvm/MC/MCAsmInfo.h"  #include "llvm/MC/MCContext.h"  #include "llvm/MC/MCDirectives.h" @@ -23,7 +24,6 @@  #include "llvm/MC/MCSymbolELF.h"  #include "llvm/MC/SectionKind.h"  #include "llvm/Support/Casting.h" -#include "llvm/Support/ELF.h"  #include "llvm/Support/MathExtras.h"  #include "llvm/Support/SMLoc.h"  #include <cassert> diff --git a/contrib/llvm/lib/MC/MCParser/MCAsmLexer.cpp b/contrib/llvm/lib/MC/MCParser/MCAsmLexer.cpp index 1d12ab858284..8f845ee1d76f 100644 --- a/contrib/llvm/lib/MC/MCParser/MCAsmLexer.cpp +++ b/contrib/llvm/lib/MC/MCParser/MCAsmLexer.cpp @@ -7,8 +7,8 @@  //  //===----------------------------------------------------------------------===// -#include "llvm/ADT/StringRef.h"  #include "llvm/MC/MCParser/MCAsmLexer.h" +#include "llvm/ADT/StringRef.h"  #include "llvm/Support/SMLoc.h"  using namespace llvm; diff --git a/contrib/llvm/lib/MC/MCParser/MCAsmParser.cpp b/contrib/llvm/lib/MC/MCParser/MCAsmParser.cpp index 27b37f3e2dfb..ea36b3b9b3b2 100644 --- a/contrib/llvm/lib/MC/MCParser/MCAsmParser.cpp +++ b/contrib/llvm/lib/MC/MCParser/MCAsmParser.cpp @@ -7,10 +7,10 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCParser/MCAsmParser.h"  #include "llvm/ADT/StringRef.h"  #include "llvm/ADT/Twine.h"  #include "llvm/MC/MCParser/MCAsmLexer.h" -#include "llvm/MC/MCParser/MCAsmParser.h"  #include "llvm/MC/MCParser/MCParsedAsmOperand.h"  #include "llvm/MC/MCParser/MCTargetAsmParser.h"  #include "llvm/Support/Debug.h" diff --git a/contrib/llvm/lib/MC/MCParser/MCTargetAsmParser.cpp b/contrib/llvm/lib/MC/MCParser/MCTargetAsmParser.cpp index 5f821443bb96..64ac82a6c66f 100644 --- a/contrib/llvm/lib/MC/MCParser/MCTargetAsmParser.cpp +++ b/contrib/llvm/lib/MC/MCParser/MCTargetAsmParser.cpp @@ -7,8 +7,8 @@  //  //===----------------------------------------------------------------------===// -#include "llvm/MC/MCContext.h"  #include "llvm/MC/MCParser/MCTargetAsmParser.h" +#include "llvm/MC/MCContext.h"  using namespace llvm; diff --git a/contrib/llvm/lib/MC/MCRegisterInfo.cpp b/contrib/llvm/lib/MC/MCRegisterInfo.cpp index a75100a4876b..0f76c1838b51 100644 --- a/contrib/llvm/lib/MC/MCRegisterInfo.cpp +++ b/contrib/llvm/lib/MC/MCRegisterInfo.cpp @@ -11,8 +11,8 @@  //  //===----------------------------------------------------------------------===// -#include "llvm/ADT/DenseMap.h"  #include "llvm/MC/MCRegisterInfo.h" +#include "llvm/ADT/DenseMap.h"  #include "llvm/Support/ErrorHandling.h"  #include <algorithm>  #include <cassert> diff --git a/contrib/llvm/lib/MC/MCSection.cpp b/contrib/llvm/lib/MC/MCSection.cpp index 7986c0122043..b961cb3968e8 100644 --- a/contrib/llvm/lib/MC/MCSection.cpp +++ b/contrib/llvm/lib/MC/MCSection.cpp @@ -7,10 +7,10 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCSection.h"  #include "llvm/ADT/SmallVector.h"  #include "llvm/MC/MCContext.h"  #include "llvm/MC/MCFragment.h" -#include "llvm/MC/MCSection.h"  #include "llvm/MC/MCSymbol.h"  #include "llvm/Support/Compiler.h"  #include "llvm/Support/ErrorHandling.h" diff --git a/contrib/llvm/lib/MC/MCSectionCOFF.cpp b/contrib/llvm/lib/MC/MCSectionCOFF.cpp index f0709cbc2515..72a7fc36a460 100644 --- a/contrib/llvm/lib/MC/MCSectionCOFF.cpp +++ b/contrib/llvm/lib/MC/MCSectionCOFF.cpp @@ -8,8 +8,8 @@  //===----------------------------------------------------------------------===//  #include "llvm/MC/MCSectionCOFF.h" +#include "llvm/BinaryFormat/COFF.h"  #include "llvm/MC/MCSymbol.h" -#include "llvm/Support/COFF.h"  #include "llvm/Support/raw_ostream.h"  #include <cassert> diff --git a/contrib/llvm/lib/MC/MCSectionELF.cpp b/contrib/llvm/lib/MC/MCSectionELF.cpp index 78fe01cca24a..a75068ebf05a 100644 --- a/contrib/llvm/lib/MC/MCSectionELF.cpp +++ b/contrib/llvm/lib/MC/MCSectionELF.cpp @@ -7,11 +7,11 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCSectionELF.h"  #include "llvm/ADT/Triple.h" +#include "llvm/BinaryFormat/ELF.h"  #include "llvm/MC/MCAsmInfo.h"  #include "llvm/MC/MCExpr.h" -#include "llvm/MC/MCSectionELF.h" -#include "llvm/Support/ELF.h"  #include "llvm/Support/ErrorHandling.h"  #include "llvm/Support/raw_ostream.h"  #include <cassert> diff --git a/contrib/llvm/lib/MC/MCStreamer.cpp b/contrib/llvm/lib/MC/MCStreamer.cpp index c9a6f12b6a58..2bfb9a63eedb 100644 --- a/contrib/llvm/lib/MC/MCStreamer.cpp +++ b/contrib/llvm/lib/MC/MCStreamer.cpp @@ -7,9 +7,11 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCStreamer.h"  #include "llvm/ADT/SmallString.h"  #include "llvm/ADT/StringRef.h"  #include "llvm/ADT/Twine.h" +#include "llvm/BinaryFormat/COFF.h"  #include "llvm/MC/MCAsmBackend.h"  #include "llvm/MC/MCAsmInfo.h"  #include "llvm/MC/MCCodeView.h" @@ -21,19 +23,17 @@  #include "llvm/MC/MCObjectFileInfo.h"  #include "llvm/MC/MCSection.h"  #include "llvm/MC/MCSectionCOFF.h" -#include "llvm/MC/MCStreamer.h"  #include "llvm/MC/MCSymbol.h"  #include "llvm/MC/MCWin64EH.h"  #include "llvm/MC/MCWinEH.h"  #include "llvm/Support/Casting.h" -#include "llvm/Support/COFF.h"  #include "llvm/Support/ErrorHandling.h"  #include "llvm/Support/LEB128.h"  #include "llvm/Support/MathExtras.h"  #include "llvm/Support/raw_ostream.h" -#include <cstdlib>  #include <cassert>  #include <cstdint> +#include <cstdlib>  #include <utility>  using namespace llvm; diff --git a/contrib/llvm/lib/MC/MCSubtargetInfo.cpp b/contrib/llvm/lib/MC/MCSubtargetInfo.cpp index 777b4e3d6b67..385cdcc62320 100644 --- a/contrib/llvm/lib/MC/MCSubtargetInfo.cpp +++ b/contrib/llvm/lib/MC/MCSubtargetInfo.cpp @@ -7,11 +7,11 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCSubtargetInfo.h"  #include "llvm/ADT/ArrayRef.h"  #include "llvm/ADT/StringRef.h"  #include "llvm/MC/MCInstrItineraries.h"  #include "llvm/MC/MCSchedule.h" -#include "llvm/MC/MCSubtargetInfo.h"  #include "llvm/MC/SubtargetFeature.h"  #include "llvm/Support/raw_ostream.h"  #include <algorithm> diff --git a/contrib/llvm/lib/MC/MCSymbol.cpp b/contrib/llvm/lib/MC/MCSymbol.cpp index cb262542b89f..9abaaef2fe84 100644 --- a/contrib/llvm/lib/MC/MCSymbol.cpp +++ b/contrib/llvm/lib/MC/MCSymbol.cpp @@ -7,12 +7,12 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCSymbol.h"  #include "llvm/ADT/StringRef.h"  #include "llvm/MC/MCAsmInfo.h"  #include "llvm/MC/MCContext.h"  #include "llvm/MC/MCExpr.h"  #include "llvm/MC/MCFragment.h" -#include "llvm/MC/MCSymbol.h"  #include "llvm/Support/Compiler.h"  #include "llvm/Support/Debug.h"  #include "llvm/Support/ErrorHandling.h" diff --git a/contrib/llvm/lib/MC/MCSymbolELF.cpp b/contrib/llvm/lib/MC/MCSymbolELF.cpp index ffa8260d4342..67449eb6dcf9 100644 --- a/contrib/llvm/lib/MC/MCSymbolELF.cpp +++ b/contrib/llvm/lib/MC/MCSymbolELF.cpp @@ -7,10 +7,10 @@  //  //===----------------------------------------------------------------------===// -#include "llvm/MC/MCAssembler.h"  #include "llvm/MC/MCSymbolELF.h" +#include "llvm/BinaryFormat/ELF.h" +#include "llvm/MC/MCAssembler.h"  #include "llvm/MC/MCFixupKindInfo.h" -#include "llvm/Support/ELF.h"  namespace llvm { diff --git a/contrib/llvm/lib/MC/MCTargetOptions.cpp b/contrib/llvm/lib/MC/MCTargetOptions.cpp index 5d666b67fddb..b85e53db5d61 100644 --- a/contrib/llvm/lib/MC/MCTargetOptions.cpp +++ b/contrib/llvm/lib/MC/MCTargetOptions.cpp @@ -7,8 +7,8 @@  //  //===----------------------------------------------------------------------===// -#include "llvm/ADT/StringRef.h"  #include "llvm/MC/MCTargetOptions.h" +#include "llvm/ADT/StringRef.h"  using namespace llvm; diff --git a/contrib/llvm/lib/MC/MCWasmObjectTargetWriter.cpp b/contrib/llvm/lib/MC/MCWasmObjectTargetWriter.cpp index a09a17d7a124..301f30d4f6ec 100644 --- a/contrib/llvm/lib/MC/MCWasmObjectTargetWriter.cpp +++ b/contrib/llvm/lib/MC/MCWasmObjectTargetWriter.cpp @@ -17,11 +17,5 @@ using namespace llvm;  MCWasmObjectTargetWriter::MCWasmObjectTargetWriter(bool Is64Bit_)      : Is64Bit(Is64Bit_) {} -bool MCWasmObjectTargetWriter::needsRelocateWithSymbol(const MCSymbol &Sym, -                                                       unsigned Type) const { -  return false; -} - -void MCWasmObjectTargetWriter::sortRelocs( -    const MCAssembler &Asm, std::vector<WasmRelocationEntry> &Relocs) { -} +// Pin the vtable to this object file +MCWasmObjectTargetWriter::~MCWasmObjectTargetWriter() = default; diff --git a/contrib/llvm/lib/MC/MCWinEH.cpp b/contrib/llvm/lib/MC/MCWinEH.cpp index 21a913999f64..a5d0f5a2cb75 100644 --- a/contrib/llvm/lib/MC/MCWinEH.cpp +++ b/contrib/llvm/lib/MC/MCWinEH.cpp @@ -7,14 +7,14 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/MCWinEH.h"  #include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/COFF.h"  #include "llvm/MC/MCContext.h"  #include "llvm/MC/MCObjectFileInfo.h"  #include "llvm/MC/MCSectionCOFF.h"  #include "llvm/MC/MCStreamer.h"  #include "llvm/MC/MCSymbol.h" -#include "llvm/MC/MCWinEH.h" -#include "llvm/Support/COFF.h"  namespace llvm {  namespace WinEH { diff --git a/contrib/llvm/lib/MC/MachObjectWriter.cpp b/contrib/llvm/lib/MC/MachObjectWriter.cpp index d9ccf0dd661f..c4e7cdbe095e 100644 --- a/contrib/llvm/lib/MC/MachObjectWriter.cpp +++ b/contrib/llvm/lib/MC/MachObjectWriter.cpp @@ -8,8 +8,9 @@  //===----------------------------------------------------------------------===//  #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/iterator_range.h"  #include "llvm/ADT/Twine.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/BinaryFormat/MachO.h"  #include "llvm/MC/MCAsmBackend.h"  #include "llvm/MC/MCAsmLayout.h"  #include "llvm/MC/MCAssembler.h" @@ -27,7 +28,6 @@  #include "llvm/Support/Casting.h"  #include "llvm/Support/Debug.h"  #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/MachO.h"  #include "llvm/Support/MathExtras.h"  #include "llvm/Support/raw_ostream.h"  #include <algorithm> diff --git a/contrib/llvm/lib/MC/StringTableBuilder.cpp b/contrib/llvm/lib/MC/StringTableBuilder.cpp index a0fb33846fcf..6025a20a9c19 100644 --- a/contrib/llvm/lib/MC/StringTableBuilder.cpp +++ b/contrib/llvm/lib/MC/StringTableBuilder.cpp @@ -7,11 +7,11 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/StringTableBuilder.h"  #include "llvm/ADT/CachedHashString.h"  #include "llvm/ADT/SmallString.h"  #include "llvm/ADT/StringRef.h" -#include "llvm/MC/StringTableBuilder.h" -#include "llvm/Support/COFF.h" +#include "llvm/BinaryFormat/COFF.h"  #include "llvm/Support/Endian.h"  #include "llvm/Support/MathExtras.h"  #include "llvm/Support/raw_ostream.h" diff --git a/contrib/llvm/lib/MC/SubtargetFeature.cpp b/contrib/llvm/lib/MC/SubtargetFeature.cpp index 51aaa4b0aa25..b68e88ca5725 100644 --- a/contrib/llvm/lib/MC/SubtargetFeature.cpp +++ b/contrib/llvm/lib/MC/SubtargetFeature.cpp @@ -11,12 +11,12 @@  //  //===----------------------------------------------------------------------===// +#include "llvm/MC/SubtargetFeature.h"  #include "llvm/ADT/ArrayRef.h"  #include "llvm/ADT/SmallVector.h"  #include "llvm/ADT/StringExtras.h"  #include "llvm/ADT/StringRef.h"  #include "llvm/ADT/Triple.h" -#include "llvm/MC/SubtargetFeature.h"  #include "llvm/Support/Compiler.h"  #include "llvm/Support/Debug.h"  #include "llvm/Support/Format.h" diff --git a/contrib/llvm/lib/MC/WasmObjectWriter.cpp b/contrib/llvm/lib/MC/WasmObjectWriter.cpp index 9b2031f05043..4b3dc6e0c211 100644 --- a/contrib/llvm/lib/MC/WasmObjectWriter.cpp +++ b/contrib/llvm/lib/MC/WasmObjectWriter.cpp @@ -13,6 +13,7 @@  #include "llvm/ADT/STLExtras.h"  #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/BinaryFormat/Wasm.h"  #include "llvm/MC/MCAsmBackend.h"  #include "llvm/MC/MCAsmInfo.h"  #include "llvm/MC/MCAsmLayout.h" @@ -31,7 +32,6 @@  #include "llvm/Support/ErrorHandling.h"  #include "llvm/Support/LEB128.h"  #include "llvm/Support/StringSaver.h" -#include "llvm/Support/Wasm.h"  #include <vector>  using namespace llvm; @@ -127,6 +127,38 @@ struct WasmGlobal {    uint32_t ImportIndex;  }; +// Information about a single relocation. +struct WasmRelocationEntry { +  uint64_t Offset;            // Where is the relocation. +  const MCSymbolWasm *Symbol; // The symbol to relocate with. +  int64_t Addend;             // A value to add to the symbol. +  unsigned Type;              // The type of the relocation. +  MCSectionWasm *FixupSection;// The section the relocation is targeting. + +  WasmRelocationEntry(uint64_t Offset, const MCSymbolWasm *Symbol, +                      int64_t Addend, unsigned Type, +                      MCSectionWasm *FixupSection) +      : Offset(Offset), Symbol(Symbol), Addend(Addend), Type(Type), +        FixupSection(FixupSection) {} + +  bool hasAddend() const { +    switch (Type) { +    case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB: +    case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB: +    case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32: +      return true; +    default: +      return false; +    } +  } + +  void print(raw_ostream &Out) const { +    Out << "Off=" << Offset << ", Sym=" << Symbol << ", Addend=" << Addend +        << ", Type=" << Type << ", FixupSection=" << FixupSection; +  } +  void dump() const { print(errs()); } +}; +  class WasmObjectWriter : public MCObjectWriter {    /// Helper struct for containing some precomputed information on symbols.    struct WasmSymbolData { @@ -146,11 +178,14 @@ class WasmObjectWriter : public MCObjectWriter {    // Relocations for fixing up references in the data section.    std::vector<WasmRelocationEntry> DataRelocations; -  // Fixups for call_indirect type indices. -  std::vector<WasmRelocationEntry> TypeIndexFixups; -    // Index values to use for fixing up call_indirect type indices. -  std::vector<uint32_t> TypeIndexFixupTypes; +  // Maps function symbols to the index of the type of the function +  DenseMap<const MCSymbolWasm *, uint32_t> TypeIndices; + +  DenseMap<const MCSymbolWasm *, uint32_t> SymbolIndices; + +  DenseMap<WasmFunctionType, int32_t, WasmFunctionTypeDenseMapInfo> +      FunctionTypeIndices;    // TargetObjectWriter wrappers.    bool is64Bit() const { return TargetObjectWriter->is64Bit(); } @@ -170,6 +205,15 @@ public:  private:    ~WasmObjectWriter() override; +  void reset() override { +    CodeRelocations.clear(); +    DataRelocations.clear(); +    TypeIndices.clear(); +    SymbolIndices.clear(); +    FunctionTypeIndices.clear(); +    MCObjectWriter::reset(); +  } +    void writeHeader(const MCAssembler &Asm);    void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout, @@ -195,21 +239,23 @@ private:    void writeExportSection(const SmallVector<WasmExport, 4> &Exports);    void writeElemSection(const SmallVector<uint32_t, 4> &TableElems);    void writeCodeSection(const MCAssembler &Asm, const MCAsmLayout &Layout, -                        DenseMap<const MCSymbolWasm *, uint32_t> &SymbolIndices,                          const SmallVector<WasmFunction, 4> &Functions);    uint64_t -  writeDataSection(const SmallVector<char, 0> &DataBytes, -                   DenseMap<const MCSymbolWasm *, uint32_t> &SymbolIndices); +  writeDataSection(const SmallVector<char, 0> &DataBytes);    void writeNameSection(const SmallVector<WasmFunction, 4> &Functions,                          const SmallVector<WasmImport, 4> &Imports,                          uint32_t NumFuncImports); -  void writeCodeRelocSection( -      DenseMap<const MCSymbolWasm *, uint32_t> &SymbolIndices); -  void writeDataRelocSection( -      DenseMap<const MCSymbolWasm *, uint32_t> &SymbolIndices, -      uint64_t DataSectionHeaderSize); +  void writeCodeRelocSection(); +  void writeDataRelocSection(uint64_t DataSectionHeaderSize);    void writeLinkingMetaDataSection(bool HasStackPointer,                                     uint32_t StackPointerGlobal); + +  void applyRelocations(ArrayRef<WasmRelocationEntry> Relocations, +                        uint64_t ContentsOffset); + +  void writeRelocations(ArrayRef<WasmRelocationEntry> Relocations, +                        uint64_t HeaderSize); +  uint32_t getRelocationIndexValue(const WasmRelocationEntry &RelEntry);  };  } // end anonymous namespace @@ -356,19 +402,7 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,        SymA->setUsedInReloc();    } -  if (RefA) { -    if (RefA->getKind() == MCSymbolRefExpr::VK_WebAssembly_TYPEINDEX) { -      assert(C == 0); -      WasmRelocationEntry Rec(FixupOffset, SymA, C, -                              wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB, -                              &FixupSection); -      TypeIndexFixups.push_back(Rec); -      return; -    } -  } -    unsigned Type = getRelocType(Ctx, Target, Fixup, IsPCRel); -    WasmRelocationEntry Rec(FixupOffset, SymA, C, Type, &FixupSection);    if (FixupSection.hasInstructions()) @@ -427,124 +461,85 @@ static uint32_t ProvisionalValue(const WasmRelocationEntry &RelEntry) {    return Value;  } +uint32_t WasmObjectWriter::getRelocationIndexValue( +    const WasmRelocationEntry &RelEntry) { +  switch (RelEntry.Type) { +  case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB: +  case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB: +  case wasm::R_WEBASSEMBLY_TABLE_INDEX_I32: +  case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB: +  case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB: +  case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32: +    assert(SymbolIndices.count(RelEntry.Symbol)); +    return SymbolIndices[RelEntry.Symbol]; +  case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB: +    assert(TypeIndices.count(RelEntry.Symbol)); +    return TypeIndices[RelEntry.Symbol]; +  default: +    llvm_unreachable("invalid relocation type"); +  } +} +  // Apply the portions of the relocation records that we can handle ourselves  // directly. -static void ApplyRelocations( -    ArrayRef<WasmRelocationEntry> Relocations, -    raw_pwrite_stream &Stream, -    DenseMap<const MCSymbolWasm *, uint32_t> &SymbolIndices, -    uint64_t ContentsOffset) -{ +void WasmObjectWriter::applyRelocations( +    ArrayRef<WasmRelocationEntry> Relocations, uint64_t ContentsOffset) { +  raw_pwrite_stream &Stream = getStream();    for (const WasmRelocationEntry &RelEntry : Relocations) {      uint64_t Offset = ContentsOffset +                        RelEntry.FixupSection->getSectionOffset() +                        RelEntry.Offset; -    switch (RelEntry.Type) { -    case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB: { -      assert(SymbolIndices.count(RelEntry.Symbol)); -      uint32_t Index = SymbolIndices[RelEntry.Symbol]; -      assert(RelEntry.Addend == 0); -      WritePatchableLEB(Stream, Index, Offset); +    switch (RelEntry.Type) { +    case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB: +    case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB: +    case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB: { +      uint32_t Index = getRelocationIndexValue(RelEntry); +      WritePatchableSLEB(Stream, Index, Offset);        break;      } -    case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB: { -      assert(SymbolIndices.count(RelEntry.Symbol)); -      uint32_t Index = SymbolIndices[RelEntry.Symbol]; -      assert(RelEntry.Addend == 0); - -      WritePatchableSLEB(Stream, Index, Offset); +    case wasm::R_WEBASSEMBLY_TABLE_INDEX_I32: { +      uint32_t Index = getRelocationIndexValue(RelEntry); +      WriteI32(Stream, Index, Offset);        break;      }      case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB: {        uint32_t Value = ProvisionalValue(RelEntry); -        WritePatchableSLEB(Stream, Value, Offset);        break;      }      case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB: {        uint32_t Value = ProvisionalValue(RelEntry); -        WritePatchableLEB(Stream, Value, Offset);        break;      } -    case wasm::R_WEBASSEMBLY_TABLE_INDEX_I32: { -      assert(SymbolIndices.count(RelEntry.Symbol)); -      uint32_t Index = SymbolIndices[RelEntry.Symbol]; -      assert(RelEntry.Addend == 0); - -      WriteI32(Stream, Index, Offset); -      break; -    }      case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32: {        uint32_t Value = ProvisionalValue(RelEntry); -        WriteI32(Stream, Value, Offset);        break;      }      default: -      break; +      llvm_unreachable("unsupported relocation type");      }    }  }  // Write out the portions of the relocation records that the linker will  // need to handle. -static void -WriteRelocations(ArrayRef<WasmRelocationEntry> Relocations, -                 raw_pwrite_stream &Stream, -                 DenseMap<const MCSymbolWasm *, uint32_t> &SymbolIndices, -                 uint64_t HeaderSize) { -  for (const WasmRelocationEntry RelEntry : Relocations) { -    encodeULEB128(RelEntry.Type, Stream); +void WasmObjectWriter::writeRelocations( +    ArrayRef<WasmRelocationEntry> Relocations, uint64_t HeaderSize) { +  raw_pwrite_stream &Stream = getStream(); +  for (const WasmRelocationEntry& RelEntry : Relocations) {      uint64_t Offset = RelEntry.Offset +                        RelEntry.FixupSection->getSectionOffset() + HeaderSize; -    assert(SymbolIndices.count(RelEntry.Symbol)); -    uint32_t Index = SymbolIndices[RelEntry.Symbol]; -    int64_t Addend = RelEntry.Addend; +    uint32_t Index = getRelocationIndexValue(RelEntry); -    switch (RelEntry.Type) { -    case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB: -    case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB: -    case wasm::R_WEBASSEMBLY_TABLE_INDEX_I32: -      encodeULEB128(Offset, Stream); -      encodeULEB128(Index, Stream); -      assert(Addend == 0 && "addends not supported for functions"); -      break; -    case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB: -    case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB: -    case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32: -      encodeULEB128(Offset, Stream); -      encodeULEB128(Index, Stream); -      encodeSLEB128(Addend, Stream); -      break; -    default: -      llvm_unreachable("unsupported relocation type"); -    } -  } -} - -// Write out the the type relocation records that the linker will -// need to handle. -static void WriteTypeRelocations( -    ArrayRef<WasmRelocationEntry> TypeIndexFixups, -    ArrayRef<uint32_t> TypeIndexFixupTypes, -    raw_pwrite_stream &Stream) -{ -  for (size_t i = 0, e = TypeIndexFixups.size(); i < e; ++i) { -    const WasmRelocationEntry &Fixup = TypeIndexFixups[i]; -    uint32_t Type = TypeIndexFixupTypes[i]; - -    assert(Fixup.Type == wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB); -    assert(Fixup.Addend == 0); - -    uint64_t Offset = Fixup.Offset + -                      Fixup.FixupSection->getSectionOffset(); - -    encodeULEB128(Fixup.Type, Stream); +    encodeULEB128(RelEntry.Type, Stream);      encodeULEB128(Offset, Stream); -    encodeULEB128(Type, Stream); +    encodeULEB128(Index, Stream); +    if (RelEntry.hasAddend()) +      encodeSLEB128(RelEntry.Addend, Stream);    }  } @@ -733,7 +728,6 @@ void WasmObjectWriter::writeElemSection(  void WasmObjectWriter::writeCodeSection(      const MCAssembler &Asm, const MCAsmLayout &Layout, -    DenseMap<const MCSymbolWasm *, uint32_t> &SymbolIndices,      const SmallVector<WasmFunction, 4> &Functions) {    if (Functions.empty())      return; @@ -768,34 +762,14 @@ void WasmObjectWriter::writeCodeSection(      Asm.writeSectionData(&FuncSection, Layout);    } -  // Apply the type index fixups for call_indirect etc. instructions. -  for (size_t i = 0, e = TypeIndexFixups.size(); i < e; ++i) { -    uint32_t Type = TypeIndexFixupTypes[i]; -    unsigned Padding = PaddingFor5ByteULEB128(Type); - -    const WasmRelocationEntry &Fixup = TypeIndexFixups[i]; -    assert(Fixup.Addend == 0); -    assert(Fixup.Type == wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB); -    uint64_t Offset = Fixup.Offset + -                      Fixup.FixupSection->getSectionOffset(); - -    uint8_t Buffer[16]; -    unsigned SizeLen = encodeULEB128(Type, Buffer, Padding); -    assert(SizeLen == 5); -    getStream().pwrite((char *)Buffer, SizeLen, -                       Section.ContentsOffset + Offset); -  } -    // Apply fixups. -  ApplyRelocations(CodeRelocations, getStream(), SymbolIndices, -                   Section.ContentsOffset); +  applyRelocations(CodeRelocations, Section.ContentsOffset);    endSection(Section);  }  uint64_t WasmObjectWriter::writeDataSection( -    const SmallVector<char, 0> &DataBytes, -    DenseMap<const MCSymbolWasm *, uint32_t> &SymbolIndices) { +    const SmallVector<char, 0> &DataBytes) {    if (DataBytes.empty())      return 0; @@ -812,8 +786,7 @@ uint64_t WasmObjectWriter::writeDataSection(    writeBytes(DataBytes); // data    // Apply fixups. -  ApplyRelocations(DataRelocations, getStream(), SymbolIndices, -                   Section.ContentsOffset + HeaderSize); +  applyRelocations(DataRelocations, Section.ContentsOffset + HeaderSize);    endSection(Section);    return HeaderSize; @@ -853,8 +826,7 @@ void WasmObjectWriter::writeNameSection(    endSection(Section);  } -void WasmObjectWriter::writeCodeRelocSection( -    DenseMap<const MCSymbolWasm *, uint32_t> &SymbolIndices) { +void WasmObjectWriter::writeCodeRelocSection() {    // See: https://github.com/WebAssembly/tool-conventions/blob/master/Linking.md    // for descriptions of the reloc sections. @@ -865,17 +837,14 @@ void WasmObjectWriter::writeCodeRelocSection(    startSection(Section, wasm::WASM_SEC_CUSTOM, "reloc.CODE");    encodeULEB128(wasm::WASM_SEC_CODE, getStream()); -  encodeULEB128(CodeRelocations.size() + TypeIndexFixups.size(), getStream()); +  encodeULEB128(CodeRelocations.size(), getStream()); -  WriteRelocations(CodeRelocations, getStream(), SymbolIndices, 0); -  WriteTypeRelocations(TypeIndexFixups, TypeIndexFixupTypes, getStream()); +  writeRelocations(CodeRelocations, 0);    endSection(Section);  } -void WasmObjectWriter::writeDataRelocSection( -    DenseMap<const MCSymbolWasm *, uint32_t> &SymbolIndices, -    uint64_t DataSectionHeaderSize) { +void WasmObjectWriter::writeDataRelocSection(uint64_t DataSectionHeaderSize) {    // See: https://github.com/WebAssembly/tool-conventions/blob/master/Linking.md    // for descriptions of the reloc sections. @@ -888,8 +857,7 @@ void WasmObjectWriter::writeDataRelocSection(    encodeULEB128(wasm::WASM_SEC_DATA, getStream());    encodeULEB128(DataRelocations.size(), getStream()); -  WriteRelocations(DataRelocations, getStream(), SymbolIndices, -                   DataSectionHeaderSize); +  writeRelocations(DataRelocations, DataSectionHeaderSize);    endSection(Section);  } @@ -915,15 +883,12 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,    wasm::ValType PtrType = is64Bit() ? wasm::ValType::I64 : wasm::ValType::I32;    // Collect information from the available symbols. -  DenseMap<WasmFunctionType, int32_t, WasmFunctionTypeDenseMapInfo> -      FunctionTypeIndices;    SmallVector<WasmFunctionType, 4> FunctionTypes;    SmallVector<WasmFunction, 4> Functions;    SmallVector<uint32_t, 4> TableElems;    SmallVector<WasmGlobal, 4> Globals;    SmallVector<WasmImport, 4> Imports;    SmallVector<WasmExport, 4> Exports; -  DenseMap<const MCSymbolWasm *, uint32_t> SymbolIndices;    SmallPtrSet<const MCSymbolWasm *, 4> IsAddressTaken;    unsigned NumFuncImports = 0;    unsigned NumGlobalImports = 0; @@ -1194,9 +1159,9 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,    }    // Add types for indirect function calls. -  for (const WasmRelocationEntry &Fixup : TypeIndexFixups) { -    assert(Fixup.Addend == 0); -    assert(Fixup.Type == wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB); +  for (const WasmRelocationEntry &Fixup : CodeRelocations) { +    if (Fixup.Type != wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB) +      continue;      WasmFunctionType F;      F.Returns = Fixup.Symbol->getReturns(); @@ -1206,7 +1171,7 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,      if (Pair.second)        FunctionTypes.push_back(F); -    TypeIndexFixupTypes.push_back(Pair.first->second); +    TypeIndices[Fixup.Symbol] = Pair.first->second;    }    // Write out the Wasm header. @@ -1221,11 +1186,11 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,    writeExportSection(Exports);    // TODO: Start Section    writeElemSection(TableElems); -  writeCodeSection(Asm, Layout, SymbolIndices, Functions); -  uint64_t DataSectionHeaderSize = writeDataSection(DataBytes, SymbolIndices); +  writeCodeSection(Asm, Layout, Functions); +  uint64_t DataSectionHeaderSize = writeDataSection(DataBytes);    writeNameSection(Functions, Imports, NumFuncImports); -  writeCodeRelocSection(SymbolIndices); -  writeDataRelocSection(SymbolIndices, DataSectionHeaderSize); +  writeCodeRelocSection(); +  writeDataRelocSection(DataSectionHeaderSize);    writeLinkingMetaDataSection(HasStackPointer, StackPointerGlobal);    // TODO: Translate the .comment section to the output. diff --git a/contrib/llvm/lib/MC/WinCOFFObjectWriter.cpp b/contrib/llvm/lib/MC/WinCOFFObjectWriter.cpp index e99a548ac001..53dee3e8b9f3 100644 --- a/contrib/llvm/lib/MC/WinCOFFObjectWriter.cpp +++ b/contrib/llvm/lib/MC/WinCOFFObjectWriter.cpp @@ -12,11 +12,12 @@  //===----------------------------------------------------------------------===//  #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/STLExtras.h"  #include "llvm/ADT/SmallString.h"  #include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/STLExtras.h"  #include "llvm/ADT/StringRef.h"  #include "llvm/ADT/Twine.h" +#include "llvm/BinaryFormat/COFF.h"  #include "llvm/MC/MCAsmLayout.h"  #include "llvm/MC/MCAssembler.h"  #include "llvm/MC/MCContext.h" @@ -32,13 +33,12 @@  #include "llvm/MC/MCWinCOFFObjectWriter.h"  #include "llvm/MC/StringTableBuilder.h"  #include "llvm/Support/Casting.h" -#include "llvm/Support/COFF.h"  #include "llvm/Support/Endian.h"  #include "llvm/Support/ErrorHandling.h"  #include "llvm/Support/JamCRC.h"  #include "llvm/Support/MathExtras.h"  #include "llvm/Support/raw_ostream.h" -#include <algorithm>  +#include <algorithm>  #include <cassert>  #include <cstddef>  #include <cstdint> diff --git a/contrib/llvm/lib/MC/WinCOFFStreamer.cpp b/contrib/llvm/lib/MC/WinCOFFStreamer.cpp index c26d87f36f83..b4d0d7a87f1d 100644 --- a/contrib/llvm/lib/MC/WinCOFFStreamer.cpp +++ b/contrib/llvm/lib/MC/WinCOFFStreamer.cpp @@ -15,6 +15,7 @@  #include "llvm/ADT/SmallVector.h"  #include "llvm/ADT/Triple.h"  #include "llvm/ADT/Twine.h" +#include "llvm/BinaryFormat/COFF.h"  #include "llvm/MC/MCAsmBackend.h"  #include "llvm/MC/MCAssembler.h"  #include "llvm/MC/MCCodeEmitter.h" @@ -28,11 +29,10 @@  #include "llvm/MC/MCSymbolCOFF.h"  #include "llvm/MC/MCWinCOFFStreamer.h"  #include "llvm/Support/Casting.h" -#include "llvm/Support/COFF.h"  #include "llvm/Support/ErrorHandling.h"  #include "llvm/Support/MathExtras.h" -#include "llvm/Support/raw_ostream.h"  #include "llvm/Support/SMLoc.h" +#include "llvm/Support/raw_ostream.h"  #include <algorithm>  #include <cassert>  #include <cstdint>  | 
