2017-02-08 23:23:19 +01:00
|
|
|
//===- llvm/MC/MCObjectWriter.h - Object File Writer Interface --*- C++ -*-===//
|
2010-03-19 10:28:59 +01:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// 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
|
2010-03-19 10:28:59 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_MC_MCOBJECTWRITER_H
|
|
|
|
#define LLVM_MC_MCOBJECTWRITER_H
|
|
|
|
|
2018-05-21 21:20:29 +02:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2017-02-08 23:23:19 +01:00
|
|
|
#include <cstdint>
|
2010-03-19 10:28:59 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-02-08 23:23:19 +01:00
|
|
|
|
2010-03-24 04:43:40 +01:00
|
|
|
class MCAsmLayout;
|
2010-03-19 10:28:59 +01:00
|
|
|
class MCAssembler;
|
2010-05-26 17:18:56 +02:00
|
|
|
class MCFixup;
|
2010-03-22 21:35:50 +01:00
|
|
|
class MCFragment;
|
2016-01-27 11:01:28 +01:00
|
|
|
class MCSymbol;
|
2010-12-17 05:54:54 +01:00
|
|
|
class MCSymbolRefExpr;
|
2010-03-19 10:28:59 +01:00
|
|
|
class MCValue;
|
|
|
|
|
2015-06-05 00:24:29 +02:00
|
|
|
/// Defines the object file and target independent interfaces used by the
|
|
|
|
/// assembler backend to write native file format object files.
|
2010-03-19 10:28:59 +01:00
|
|
|
///
|
|
|
|
/// The object writer contains a few callbacks used by the assembler to allow
|
|
|
|
/// the object writer to modify the assembler data structures at appropriate
|
|
|
|
/// points. Once assembly is complete, the object writer is given the
|
|
|
|
/// MCAssembler instance, which contains all the symbol and section data which
|
2015-06-05 00:24:41 +02:00
|
|
|
/// should be emitted as part of writeObject().
|
2010-03-19 10:28:59 +01:00
|
|
|
class MCObjectWriter {
|
2015-09-01 18:19:03 +02:00
|
|
|
protected:
|
2018-05-21 20:28:57 +02:00
|
|
|
MCObjectWriter() = default;
|
2015-11-18 16:24:17 +01:00
|
|
|
|
2010-03-19 10:28:59 +01:00
|
|
|
public:
|
2017-02-08 23:23:19 +01:00
|
|
|
MCObjectWriter(const MCObjectWriter &) = delete;
|
|
|
|
MCObjectWriter &operator=(const MCObjectWriter &) = delete;
|
2010-03-19 10:28:59 +01:00
|
|
|
virtual ~MCObjectWriter();
|
|
|
|
|
2012-12-14 19:52:11 +01:00
|
|
|
/// lifetime management
|
2015-06-05 00:24:29 +02:00
|
|
|
virtual void reset() {}
|
2012-12-14 19:52:11 +01:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \name High-Level API
|
2010-03-19 10:28:59 +01:00
|
|
|
/// @{
|
|
|
|
|
2015-06-05 00:24:29 +02:00
|
|
|
/// Perform any late binding of symbols (for example, to assign symbol
|
2013-02-05 18:10:07 +01:00
|
|
|
/// indices for use when generating relocations).
|
2010-03-19 10:28:59 +01:00
|
|
|
///
|
|
|
|
/// This routine is called by the assembler after layout and relaxation is
|
|
|
|
/// complete.
|
2015-06-05 01:25:54 +02:00
|
|
|
virtual void executePostLayoutBinding(MCAssembler &Asm,
|
2010-12-07 01:27:36 +01:00
|
|
|
const MCAsmLayout &Layout) = 0;
|
2010-03-19 10:28:59 +01:00
|
|
|
|
2015-06-05 00:24:29 +02:00
|
|
|
/// Record a relocation entry.
|
2010-03-19 10:28:59 +01:00
|
|
|
///
|
|
|
|
/// This routine is called by the assembler after layout and relaxation, and
|
|
|
|
/// post layout binding. The implementation is responsible for storing
|
|
|
|
/// information about the relocation so that it can be emitted during
|
2015-06-05 00:24:41 +02:00
|
|
|
/// writeObject().
|
|
|
|
virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
|
2010-03-22 21:35:50 +01:00
|
|
|
const MCFragment *Fragment,
|
2010-05-26 17:18:56 +02:00
|
|
|
const MCFixup &Fixup, MCValue Target,
|
2017-07-12 01:56:10 +02:00
|
|
|
uint64_t &FixedValue) = 0;
|
2010-03-19 10:28:59 +01:00
|
|
|
|
2015-06-05 00:24:29 +02:00
|
|
|
/// Check whether the difference (A - B) between two symbol references is
|
|
|
|
/// fully resolved.
|
2010-12-17 05:54:54 +01:00
|
|
|
///
|
|
|
|
/// Clients are not required to answer precisely and may conservatively return
|
|
|
|
/// false, even when a difference is fully resolved.
|
2015-06-05 00:24:41 +02:00
|
|
|
bool isSymbolRefDifferenceFullyResolved(const MCAssembler &Asm,
|
2015-03-25 20:24:39 +01:00
|
|
|
const MCSymbolRefExpr *A,
|
|
|
|
const MCSymbolRefExpr *B,
|
|
|
|
bool InSet) const;
|
2010-12-17 05:54:54 +01:00
|
|
|
|
2015-10-05 14:07:05 +02:00
|
|
|
virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
|
|
|
|
const MCSymbol &A,
|
|
|
|
const MCSymbol &B,
|
|
|
|
bool InSet) const;
|
|
|
|
|
2015-06-05 00:24:41 +02:00
|
|
|
virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
|
2015-05-16 03:01:55 +02:00
|
|
|
const MCSymbol &SymA,
|
2015-04-06 17:27:57 +02:00
|
|
|
const MCFragment &FB,
|
|
|
|
bool InSet,
|
|
|
|
bool IsPCRel) const;
|
2010-12-24 22:22:02 +01:00
|
|
|
|
2021-03-09 18:59:47 +01:00
|
|
|
/// ELF only. Mark that we have seen GNU ABI usage (e.g. SHF_GNU_RETAIN).
|
|
|
|
virtual void markGnuAbi() {}
|
|
|
|
|
2018-07-18 00:17:18 +02:00
|
|
|
/// 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.
|
|
|
|
virtual void emitAddrsigSection() {}
|
|
|
|
|
|
|
|
/// Record the given symbol in the address-significance table to be written
|
|
|
|
/// diring writeObject().
|
|
|
|
virtual void addAddrsigSymbol(const MCSymbol *Sym) {}
|
|
|
|
|
2018-05-21 20:23:50 +02:00
|
|
|
/// Write the object file and returns the number of bytes written.
|
2010-03-19 10:28:59 +01:00
|
|
|
///
|
|
|
|
/// This routine is called by the assembler after layout and relaxation is
|
2010-05-14 03:02:48 +02:00
|
|
|
/// complete, fixups have been evaluated and applied, and relocations
|
2010-03-19 10:28:59 +01:00
|
|
|
/// generated.
|
2018-05-21 20:23:50 +02:00
|
|
|
virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) = 0;
|
2010-03-19 10:28:59 +01:00
|
|
|
|
|
|
|
/// @}
|
|
|
|
};
|
|
|
|
|
2018-05-21 21:20:29 +02:00
|
|
|
/// Base class for classes that define behaviour that is specific to both the
|
|
|
|
/// target and the object format.
|
|
|
|
class MCObjectTargetWriter {
|
|
|
|
public:
|
|
|
|
virtual ~MCObjectTargetWriter() = default;
|
|
|
|
virtual Triple::ObjectFormatType getFormat() const = 0;
|
|
|
|
};
|
|
|
|
|
2017-02-08 23:23:19 +01:00
|
|
|
} // end namespace llvm
|
2010-03-19 10:28:59 +01:00
|
|
|
|
2017-02-08 23:23:19 +01:00
|
|
|
#endif // LLVM_MC_MCOBJECTWRITER_H
|