aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm/lib/MC/MCContext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/lib/MC/MCContext.cpp')
-rw-r--r--contrib/llvm/lib/MC/MCContext.cpp97
1 files changed, 82 insertions, 15 deletions
diff --git a/contrib/llvm/lib/MC/MCContext.cpp b/contrib/llvm/lib/MC/MCContext.cpp
index fab517075c5a..0dc2e2d37caf 100644
--- a/contrib/llvm/lib/MC/MCContext.cpp
+++ b/contrib/llvm/lib/MC/MCContext.cpp
@@ -1,9 +1,8 @@
//===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// 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
//
//===----------------------------------------------------------------------===//
@@ -27,17 +26,20 @@
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCSectionWasm.h"
+#include "llvm/MC/MCSectionXCOFF.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCSymbolCOFF.h"
#include "llvm/MC/MCSymbolELF.h"
#include "llvm/MC/MCSymbolMachO.h"
#include "llvm/MC/MCSymbolWasm.h"
+#include "llvm/MC/MCSymbolXCOFF.h"
#include "llvm/MC/SectionKind.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
@@ -85,6 +87,7 @@ void MCContext::reset() {
COFFAllocator.DestroyAll();
ELFAllocator.DestroyAll();
MachOAllocator.DestroyAll();
+ XCOFFAllocator.DestroyAll();
MCSubtargetAllocator.DestroyAll();
UsedNames.clear();
@@ -106,6 +109,7 @@ void MCContext::reset() {
ELFUniquingMap.clear();
COFFUniquingMap.clear();
WasmUniquingMap.clear();
+ XCOFFUniquingMap.clear();
NextID.clear();
AllowTemporaryLabels = true;
@@ -161,6 +165,8 @@ MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
return new (Name, *this) MCSymbolMachO(Name, IsTemporary);
case MCObjectFileInfo::IsWasm:
return new (Name, *this) MCSymbolWasm(Name, IsTemporary);
+ case MCObjectFileInfo::IsXCOFF:
+ return new (Name, *this) MCSymbolXCOFF(Name, IsTemporary);
}
}
return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name,
@@ -459,14 +465,6 @@ MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
BeginSymName);
}
-MCSectionCOFF *MCContext::getCOFFSection(StringRef Section) {
- COFFSectionKey T{Section, "", 0, GenericSectionID};
- auto Iter = COFFUniquingMap.find(T);
- if (Iter == COFFUniquingMap.end())
- return nullptr;
- return Iter->second;
-}
-
MCSectionCOFF *MCContext::getAssociativeCOFFSection(MCSectionCOFF *Sec,
const MCSymbol *KeySym,
unsigned UniqueID) {
@@ -531,6 +529,38 @@ MCSectionWasm *MCContext::getWasmSection(const Twine &Section, SectionKind Kind,
return Result;
}
+MCSectionXCOFF *MCContext::getXCOFFSection(StringRef Section,
+ XCOFF::StorageMappingClass SMC,
+ SectionKind Kind,
+ const char *BeginSymName) {
+ // Do the lookup. If we have a hit, return it.
+ auto IterBool = XCOFFUniquingMap.insert(
+ std::make_pair(XCOFFSectionKey{Section.str(), SMC}, nullptr));
+ auto &Entry = *IterBool.first;
+ if (!IterBool.second)
+ return Entry.second;
+
+ // Otherwise, return a new section.
+ StringRef CachedName = Entry.first.SectionName;
+
+ MCSymbol *Begin = nullptr;
+ if (BeginSymName)
+ Begin = createTempSymbol(BeginSymName, false);
+
+ MCSectionXCOFF *Result = new (XCOFFAllocator.Allocate())
+ MCSectionXCOFF(CachedName, SMC, Kind, Begin);
+ Entry.second = Result;
+
+ auto *F = new MCDataFragment();
+ Result->getFragmentList().insert(Result->begin(), F);
+ F->setParent(Result);
+
+ if (Begin)
+ Begin->setFragment(F);
+
+ return Result;
+}
+
MCSubtargetInfo &MCContext::getSubtargetCopy(const MCSubtargetInfo &STI) {
return *new (MCSubtargetAllocator.Allocate()) MCSubtargetInfo(STI);
}
@@ -566,6 +596,42 @@ void MCContext::RemapDebugPaths() {
// Dwarf Management
//===----------------------------------------------------------------------===//
+void MCContext::setGenDwarfRootFile(StringRef InputFileName, StringRef Buffer) {
+ // MCDwarf needs the root file as well as the compilation directory.
+ // If we find a '.file 0' directive that will supersede these values.
+ Optional<MD5::MD5Result> Cksum;
+ if (getDwarfVersion() >= 5) {
+ MD5 Hash;
+ MD5::MD5Result Sum;
+ Hash.update(Buffer);
+ Hash.final(Sum);
+ Cksum = Sum;
+ }
+ // Canonicalize the root filename. It cannot be empty, and should not
+ // repeat the compilation dir.
+ // The MCContext ctor initializes MainFileName to the name associated with
+ // the SrcMgr's main file ID, which might be the same as InputFileName (and
+ // possibly include directory components).
+ // Or, MainFileName might have been overridden by a -main-file-name option,
+ // which is supposed to be just a base filename with no directory component.
+ // So, if the InputFileName and MainFileName are not equal, assume
+ // MainFileName is a substitute basename and replace the last component.
+ SmallString<1024> FileNameBuf = InputFileName;
+ if (FileNameBuf.empty() || FileNameBuf == "-")
+ FileNameBuf = "<stdin>";
+ if (!getMainFileName().empty() && FileNameBuf != getMainFileName()) {
+ llvm::sys::path::remove_filename(FileNameBuf);
+ llvm::sys::path::append(FileNameBuf, getMainFileName());
+ }
+ StringRef FileName = FileNameBuf;
+ if (FileName.consume_front(getCompilationDir()))
+ if (llvm::sys::path::is_separator(FileName.front()))
+ FileName = FileName.drop_front();
+ assert(!FileName.empty());
+ setMCLineTableRootFile(
+ /*CUID=*/0, getCompilationDir(), FileName, Cksum, None);
+}
+
/// 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
@@ -573,11 +639,12 @@ void MCContext::RemapDebugPaths() {
Expected<unsigned> MCContext::getDwarfFile(StringRef Directory,
StringRef FileName,
unsigned FileNumber,
- MD5::MD5Result *Checksum,
+ Optional<MD5::MD5Result> Checksum,
Optional<StringRef> Source,
unsigned CUID) {
MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
- return Table.tryGetFile(Directory, FileName, Checksum, Source, FileNumber);
+ return Table.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
+ FileNumber);
}
/// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
@@ -585,7 +652,7 @@ Expected<unsigned> MCContext::getDwarfFile(StringRef Directory,
bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
const MCDwarfLineTable &LineTable = getMCDwarfLineTable(CUID);
if (FileNumber == 0)
- return getDwarfVersion() >= 5 && LineTable.hasRootFile();
+ return getDwarfVersion() >= 5;
if (FileNumber >= LineTable.getMCDwarfFiles().size())
return false;