mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-26 08:06:08 +00:00
MCAssembler: Move FileNames and CompilerVersion to MCObjectWriter
This commit is contained in:
parent
e7a2405383
commit
219d80bcb7
@ -52,6 +52,7 @@ class MCValue;
|
||||
|
||||
class MCAssembler {
|
||||
public:
|
||||
friend class MCObjectWriter;
|
||||
using SectionListType = SmallVector<MCSection *, 0>;
|
||||
using const_iterator = pointee_iterator<SectionListType::const_iterator>;
|
||||
|
||||
@ -73,11 +74,6 @@ private:
|
||||
/// The list of linker options to propagate into the object file.
|
||||
std::vector<std::vector<std::string>> LinkerOptions;
|
||||
|
||||
/// List of declared file names
|
||||
std::vector<std::pair<std::string, size_t>> FileNames;
|
||||
// Optional compiler version.
|
||||
std::string CompilerVersion;
|
||||
|
||||
MCDwarfLineTableParams LTParams;
|
||||
|
||||
/// The set of function symbols for which a .thumb_func directive has
|
||||
@ -261,20 +257,6 @@ public:
|
||||
bool registerSection(MCSection &Section);
|
||||
bool registerSymbol(const MCSymbol &Symbol);
|
||||
|
||||
MutableArrayRef<std::pair<std::string, size_t>> getFileNames() {
|
||||
return FileNames;
|
||||
}
|
||||
|
||||
void addFileName(StringRef FileName) {
|
||||
FileNames.emplace_back(std::string(FileName), Symbols.size());
|
||||
}
|
||||
|
||||
void setCompilerVersion(std::string CompilerVers) {
|
||||
if (CompilerVersion.empty())
|
||||
CompilerVersion = std::move(CompilerVers);
|
||||
}
|
||||
StringRef getCompilerVersion() { return CompilerVersion; }
|
||||
|
||||
/// Write the necessary bundle padding to \p OS.
|
||||
/// Expects a fragment \p F containing instructions and its size \p FSize.
|
||||
void writeFragmentPadding(raw_ostream &OS, const MCEncodedFragment &F,
|
||||
|
@ -32,6 +32,10 @@ class MCValue;
|
||||
/// should be emitted as part of writeObject().
|
||||
class MCObjectWriter {
|
||||
protected:
|
||||
/// List of declared file names
|
||||
SmallVector<std::pair<std::string, size_t>, 0> FileNames;
|
||||
// XCOFF specific: Optional compiler version.
|
||||
std::string CompilerVersion;
|
||||
std::vector<const MCSymbol *> AddrsigSyms;
|
||||
bool EmitAddrsigSection = false;
|
||||
|
||||
@ -43,7 +47,7 @@ public:
|
||||
virtual ~MCObjectWriter();
|
||||
|
||||
/// lifetime management
|
||||
virtual void reset() {}
|
||||
virtual void reset();
|
||||
|
||||
/// \name High-Level API
|
||||
/// @{
|
||||
@ -81,6 +85,14 @@ public:
|
||||
bool InSet,
|
||||
bool IsPCRel) const;
|
||||
|
||||
MutableArrayRef<std::pair<std::string, size_t>> getFileNames() {
|
||||
return FileNames;
|
||||
}
|
||||
void addFileName(MCAssembler &Asm, StringRef FileName);
|
||||
void setCompilerVersion(StringRef CompilerVers) {
|
||||
CompilerVersion = CompilerVers;
|
||||
}
|
||||
|
||||
/// Tell the object writer to emit an address-significance table during
|
||||
/// writeObject(). If this function is not called, all symbols are treated as
|
||||
/// address-significant.
|
||||
|
@ -560,7 +560,7 @@ void ELFWriter::computeSymbolTable(MCAssembler &Asm,
|
||||
std::vector<ELFSymbolData> LocalSymbolData;
|
||||
std::vector<ELFSymbolData> ExternalSymbolData;
|
||||
MutableArrayRef<std::pair<std::string, size_t>> FileNames =
|
||||
Asm.getFileNames();
|
||||
OWriter.getFileNames();
|
||||
for (const std::pair<std::string, size_t> &F : FileNames)
|
||||
StrTabBuilder.add(F.first);
|
||||
|
||||
|
@ -94,7 +94,6 @@ void MCAssembler::reset() {
|
||||
Sections.clear();
|
||||
Symbols.clear();
|
||||
LinkerOptions.clear();
|
||||
FileNames.clear();
|
||||
ThumbFuncs.clear();
|
||||
BundleAlignSize = 0;
|
||||
|
||||
|
@ -784,15 +784,18 @@ void MCObjectStreamer::emitNops(int64_t NumBytes, int64_t ControlledNopLength,
|
||||
}
|
||||
|
||||
void MCObjectStreamer::emitFileDirective(StringRef Filename) {
|
||||
getAssembler().addFileName(Filename);
|
||||
MCAssembler &Asm = getAssembler();
|
||||
Asm.getWriter().addFileName(Asm, Filename);
|
||||
}
|
||||
|
||||
void MCObjectStreamer::emitFileDirective(StringRef Filename,
|
||||
StringRef CompilerVersion,
|
||||
StringRef TimeStamp,
|
||||
StringRef Description) {
|
||||
getAssembler().addFileName(Filename);
|
||||
getAssembler().setCompilerVersion(CompilerVersion.str());
|
||||
MCObjectWriter &W = getAssembler().getWriter();
|
||||
W.addFileName(getAssembler(), Filename);
|
||||
if (CompilerVersion.size())
|
||||
W.setCompilerVersion(CompilerVersion);
|
||||
// TODO: add TimeStamp and Description to .file symbol table entry
|
||||
// with the integrated assembler.
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/MC/MCObjectWriter.h"
|
||||
#include "llvm/MC/MCAssembler.h"
|
||||
#include "llvm/MC/MCExpr.h"
|
||||
#include "llvm/MC/MCFragment.h"
|
||||
#include "llvm/MC/MCSymbol.h"
|
||||
@ -18,6 +19,8 @@ using namespace llvm;
|
||||
|
||||
MCObjectWriter::~MCObjectWriter() = default;
|
||||
|
||||
void MCObjectWriter::reset() { FileNames.clear(); }
|
||||
|
||||
bool MCObjectWriter::isSymbolRefDifferenceFullyResolved(
|
||||
const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B,
|
||||
bool InSet) const {
|
||||
@ -44,3 +47,7 @@ bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
|
||||
// On ELF and COFF A - B is absolute if A and B are in the same section.
|
||||
return &SecA == &SecB;
|
||||
}
|
||||
|
||||
void MCObjectWriter::addFileName(MCAssembler &Asm, StringRef FileName) {
|
||||
FileNames.emplace_back(std::string(FileName), Asm.Symbols.size());
|
||||
}
|
||||
|
@ -636,7 +636,7 @@ void WinCOFFWriter::writeSection(MCAssembler &Asm, const COFFSection &Sec) {
|
||||
|
||||
// Create .file symbols.
|
||||
void WinCOFFWriter::createFileSymbols(MCAssembler &Asm) {
|
||||
for (const std::pair<std::string, size_t> &It : Asm.getFileNames()) {
|
||||
for (const std::pair<std::string, size_t> &It : OWriter.getFileNames()) {
|
||||
// round up to calculate the number of auxiliary symbols required
|
||||
const std::string &Name = It.first;
|
||||
unsigned SymbolSize = UseBigObj ? COFF::Symbol32Size : COFF::Symbol16Size;
|
||||
|
@ -296,7 +296,6 @@ class XCOFFObjectWriter : public MCObjectWriter {
|
||||
uint64_t SymbolTableOffset = 0;
|
||||
uint16_t SectionCount = 0;
|
||||
uint32_t PaddingsBeforeDwarf = 0;
|
||||
std::vector<std::pair<std::string, size_t>> FileNames;
|
||||
bool HasVisibility = false;
|
||||
|
||||
support::endian::Writer W;
|
||||
@ -638,7 +637,6 @@ void XCOFFObjectWriter::executePostLayoutBinding(MCAssembler &Asm) {
|
||||
if (CISI && nameShouldBeInStringTable(CISI->Name))
|
||||
Strings.add(CISI->Name);
|
||||
|
||||
FileNames = Asm.getFileNames();
|
||||
// Emit ".file" as the source file name when there is no file name.
|
||||
if (FileNames.empty())
|
||||
FileNames.emplace_back(".file", 0);
|
||||
@ -651,7 +649,7 @@ void XCOFFObjectWriter::executePostLayoutBinding(MCAssembler &Asm) {
|
||||
// the AUX_FILE auxiliary entry.
|
||||
if (nameShouldBeInStringTable(".file"))
|
||||
Strings.add(".file");
|
||||
StringRef Vers = Asm.getCompilerVersion();
|
||||
StringRef Vers = CompilerVersion;
|
||||
if (auxFileSymNameShouldBeInStringTable(Vers))
|
||||
Strings.add(Vers);
|
||||
|
||||
@ -1161,7 +1159,7 @@ void XCOFFObjectWriter::writeRelocations() {
|
||||
|
||||
void XCOFFObjectWriter::writeSymbolTable(MCAssembler &Asm) {
|
||||
// Write C_FILE symbols.
|
||||
StringRef Vers = Asm.getCompilerVersion();
|
||||
StringRef Vers = CompilerVersion;
|
||||
|
||||
for (const std::pair<std::string, size_t> &F : FileNames) {
|
||||
// The n_name of a C_FILE symbol is the source file's name when no auxiliary
|
||||
@ -1417,7 +1415,7 @@ void XCOFFObjectWriter::assignAddressesAndIndices(MCAssembler &Asm) {
|
||||
// The symbol table starts with all the C_FILE symbols. Each C_FILE symbol
|
||||
// requires 1 or 2 auxiliary entries.
|
||||
uint32_t SymbolTableIndex =
|
||||
(2 + (Asm.getCompilerVersion().empty() ? 0 : 1)) * FileNames.size();
|
||||
(2 + (CompilerVersion.empty() ? 0 : 1)) * FileNames.size();
|
||||
|
||||
if (CInfoSymSection.Entry)
|
||||
SymbolTableIndex++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user