diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 |
commit | eb11fae6d08f479c0799db45860a98af528fa6e7 (patch) | |
tree | 44d492a50c8c1a7eb8e2d17ea3360ec4d066f042 /lib/MC/MCContext.cpp | |
parent | b8a2042aa938069e862750553db0e4d82d25822c (diff) |
Notes
Diffstat (limited to 'lib/MC/MCContext.cpp')
-rw-r--r-- | lib/MC/MCContext.cpp | 69 |
1 files changed, 58 insertions, 11 deletions
diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 5c25e902bbe7..606da2526890 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/MC/MCContext.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" @@ -104,6 +105,7 @@ void MCContext::reset() { MachOUniquingMap.clear(); ELFUniquingMap.clear(); COFFUniquingMap.clear(); + WasmUniquingMap.clear(); NextID.clear(); AllowTemporaryLabels = true; @@ -490,8 +492,10 @@ MCSectionWasm *MCContext::getWasmSection(const Twine &Section, SectionKind K, const Twine &Group, unsigned UniqueID, const char *BeginSymName) { MCSymbolWasm *GroupSym = nullptr; - if (!Group.isTriviallyEmpty() && !Group.str().empty()) + if (!Group.isTriviallyEmpty() && !Group.str().empty()) { GroupSym = cast<MCSymbolWasm>(getOrCreateSymbol(Group)); + GroupSym->setComdat(true); + } return getWasmSection(Section, K, GroupSym, UniqueID, BeginSymName); } @@ -512,13 +516,18 @@ MCSectionWasm *MCContext::getWasmSection(const Twine &Section, SectionKind Kind, StringRef CachedName = Entry.first.SectionName; - MCSymbol *Begin = nullptr; - if (BeginSymName) - Begin = createTempSymbol(BeginSymName, false); + MCSymbol *Begin = createSymbol(CachedName, false, false); + cast<MCSymbolWasm>(Begin)->setType(wasm::WASM_SYMBOL_TYPE_SECTION); MCSectionWasm *Result = new (WasmAllocator.Allocate()) MCSectionWasm(CachedName, Kind, GroupSym, UniqueID, Begin); Entry.second = Result; + + auto *F = new MCDataFragment(); + Result->getFragmentList().insert(Result->begin(), F); + F->setParent(Result); + Begin->setFragment(F); + return Result; } @@ -526,28 +535,61 @@ MCSubtargetInfo &MCContext::getSubtargetCopy(const MCSubtargetInfo &STI) { return *new (MCSubtargetAllocator.Allocate()) MCSubtargetInfo(STI); } +void MCContext::addDebugPrefixMapEntry(const std::string &From, + const std::string &To) { + DebugPrefixMap.insert(std::make_pair(From, To)); +} + +void MCContext::RemapDebugPaths() { + const auto &DebugPrefixMap = this->DebugPrefixMap; + const auto RemapDebugPath = [&DebugPrefixMap](std::string &Path) { + for (const auto &Entry : DebugPrefixMap) + if (StringRef(Path).startswith(Entry.first)) { + std::string RemappedPath = + (Twine(Entry.second) + Path.substr(Entry.first.size())).str(); + Path.swap(RemappedPath); + } + }; + + // Remap compilation directory. + std::string CompDir = CompilationDir.str(); + RemapDebugPath(CompDir); + CompilationDir = CompDir; + + // Remap MCDwarfDirs in all compilation units. + for (auto &CUIDTablePair : MCDwarfLineTablesCUMap) + for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs()) + RemapDebugPath(Dir); +} + //===----------------------------------------------------------------------===// // Dwarf Management //===----------------------------------------------------------------------===// -/// getDwarfFile - takes a file name an number to place in the dwarf file and +/// getDwarfFile - takes a file name and number to place in the dwarf file and /// directory tables. If the file number has already been allocated it is an /// error and zero is returned and the client reports the error, else the /// allocated file number is returned. The file numbers may be in any order. -unsigned MCContext::getDwarfFile(StringRef Directory, StringRef FileName, - unsigned FileNumber, unsigned CUID) { +Expected<unsigned> MCContext::getDwarfFile(StringRef Directory, + StringRef FileName, + unsigned FileNumber, + MD5::MD5Result *Checksum, + Optional<StringRef> Source, + unsigned CUID) { MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID]; - return Table.getFile(Directory, FileName, FileNumber); + return Table.tryGetFile(Directory, FileName, Checksum, Source, FileNumber); } /// isValidDwarfFileNumber - takes a dwarf file number and returns true if it /// currently is assigned and false otherwise. bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) { - const SmallVectorImpl<MCDwarfFile> &MCDwarfFiles = getMCDwarfFiles(CUID); - if (FileNumber == 0 || FileNumber >= MCDwarfFiles.size()) + const MCDwarfLineTable &LineTable = getMCDwarfLineTable(CUID); + if (FileNumber == 0) + return getDwarfVersion() >= 5 && LineTable.hasRootFile(); + if (FileNumber >= LineTable.getMCDwarfFiles().size()) return false; - return !MCDwarfFiles[FileNumber].Name.empty(); + return !LineTable.getMCDwarfFiles()[FileNumber].Name.empty(); } /// Remove empty sections from SectionStartEndSyms, to avoid generating @@ -563,6 +605,11 @@ CodeViewContext &MCContext::getCVContext() { return *CVContext.get(); } +void MCContext::clearCVLocSeen() { + if (CVContext) + CVContext->clearCVLocSeen(); +} + //===----------------------------------------------------------------------===// // Error Reporting //===----------------------------------------------------------------------===// |