2018-03-24 00:58:19 +01:00
|
|
|
//===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
|
2009-07-28 05:13:23 +02: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
|
2009-07-28 05:13:23 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements classes used to handle lowerings specific to common
|
|
|
|
// object file formats.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-11-17 02:07:10 +01:00
|
|
|
#ifndef LLVM_CODEGEN_TARGETLOWERINGOBJECTFILE_H
|
|
|
|
#define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILE_H
|
2009-07-28 05:13:23 +02:00
|
|
|
|
2012-12-03 18:02:12 +01:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2017-01-18 01:57:48 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/Module.h"
|
2011-07-20 07:58:47 +02:00
|
|
|
#include "llvm/MC/MCObjectFileInfo.h"
|
2009-08-01 23:30:49 +02:00
|
|
|
#include "llvm/MC/SectionKind.h"
|
2017-01-18 01:57:48 +01:00
|
|
|
#include <cstdint>
|
2009-07-28 05:13:23 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-01-18 01:57:48 +01:00
|
|
|
|
|
|
|
class GlobalValue;
|
|
|
|
class MachineModuleInfo;
|
|
|
|
class Mangler;
|
|
|
|
class MCContext;
|
|
|
|
class MCExpr;
|
|
|
|
class MCSection;
|
|
|
|
class MCSymbol;
|
|
|
|
class MCSymbolRefExpr;
|
|
|
|
class MCStreamer;
|
|
|
|
class MCValue;
|
|
|
|
class TargetMachine;
|
2014-02-07 23:33:56 +01:00
|
|
|
|
2011-07-20 07:58:47 +02:00
|
|
|
class TargetLoweringObjectFile : public MCObjectFileInfo {
|
2017-01-18 01:57:48 +01:00
|
|
|
MCContext *Ctx = nullptr;
|
2012-09-17 08:59:23 +02:00
|
|
|
|
2016-09-16 09:33:15 +02:00
|
|
|
/// Name-mangler for global names.
|
2016-09-16 13:50:57 +02:00
|
|
|
Mangler *Mang = nullptr;
|
2016-09-16 09:33:15 +02:00
|
|
|
|
2015-02-23 22:26:18 +01:00
|
|
|
protected:
|
2017-01-18 01:57:48 +01:00
|
|
|
bool SupportIndirectSymViaGOTPCRel = false;
|
|
|
|
bool SupportGOTPCRelWithOffset = true;
|
2018-08-02 01:46:49 +02:00
|
|
|
bool SupportDebugThreadLocalLocation = true;
|
2015-02-23 22:26:18 +01:00
|
|
|
|
[MC] Move EH DWARF encodings from MC to CodeGen, NFC
Summary:
The TType encoding, LSDA encoding, and personality encoding are all
passed explicitly by CodeGen to the assembler through .cfi_* directives,
so only the AsmPrinter needs to know about them.
The FDE CFI encoding however, controls the encoding of the label
implicitly created by the .cfi_startproc directive. That directive seems
to be special in that it doesn't take an encoding, so the assembler just
has to know how to encode one DSO-local label reference from .eh_frame
to .text.
As a result, it looks like MC will continue to have to know when the
large code model is in use. Perhaps we could invent a '.cfi_startproc
[large]' flag so that this knowledge doesn't need to pollute the
assembler.
Reviewers: davide, lliu0, JDevlieghere
Subscribers: hiraditya, fedor.sergeev, llvm-commits
Differential Revision: https://reviews.llvm.org/D50533
llvm-svn: 339397
2018-08-10 00:24:04 +02:00
|
|
|
/// PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values
|
|
|
|
/// for EH.
|
|
|
|
unsigned PersonalityEncoding = 0;
|
|
|
|
unsigned LSDAEncoding = 0;
|
|
|
|
unsigned TTypeEncoding = 0;
|
2019-07-17 16:00:35 +02:00
|
|
|
unsigned CallSiteEncoding = 0;
|
[MC] Move EH DWARF encodings from MC to CodeGen, NFC
Summary:
The TType encoding, LSDA encoding, and personality encoding are all
passed explicitly by CodeGen to the assembler through .cfi_* directives,
so only the AsmPrinter needs to know about them.
The FDE CFI encoding however, controls the encoding of the label
implicitly created by the .cfi_startproc directive. That directive seems
to be special in that it doesn't take an encoding, so the assembler just
has to know how to encode one DSO-local label reference from .eh_frame
to .text.
As a result, it looks like MC will continue to have to know when the
large code model is in use. Perhaps we could invent a '.cfi_startproc
[large]' flag so that this knowledge doesn't need to pollute the
assembler.
Reviewers: davide, lliu0, JDevlieghere
Subscribers: hiraditya, fedor.sergeev, llvm-commits
Differential Revision: https://reviews.llvm.org/D50533
llvm-svn: 339397
2018-08-10 00:24:04 +02:00
|
|
|
|
2016-08-29 14:33:42 +02:00
|
|
|
/// This section contains the static constructor pointer list.
|
2017-09-12 20:31:24 +02:00
|
|
|
MCSection *StaticCtorSection = nullptr;
|
2016-08-29 14:33:42 +02:00
|
|
|
|
|
|
|
/// This section contains the static destructor pointer list.
|
2017-09-12 20:31:24 +02:00
|
|
|
MCSection *StaticDtorSection = nullptr;
|
2016-08-29 14:33:42 +02:00
|
|
|
|
2009-07-28 05:13:23 +02:00
|
|
|
public:
|
2017-01-18 01:57:48 +01:00
|
|
|
TargetLoweringObjectFile() = default;
|
|
|
|
TargetLoweringObjectFile(const TargetLoweringObjectFile &) = delete;
|
|
|
|
TargetLoweringObjectFile &
|
|
|
|
operator=(const TargetLoweringObjectFile &) = delete;
|
|
|
|
virtual ~TargetLoweringObjectFile();
|
|
|
|
|
2009-08-08 22:14:13 +02:00
|
|
|
MCContext &getContext() const { return *Ctx; }
|
2016-09-16 09:33:15 +02:00
|
|
|
Mangler &getMangler() const { return *Mang; }
|
2011-07-20 07:58:47 +02:00
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
/// This method must be called before any actual lowering is done. This
|
|
|
|
/// specifies the current context for codegen, and gives the lowering
|
|
|
|
/// implementations a chance to set up their default sections.
|
2011-07-20 07:58:47 +02:00
|
|
|
virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
|
2014-02-07 23:33:56 +01:00
|
|
|
|
2015-07-16 08:04:17 +02:00
|
|
|
virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
|
2011-04-16 05:51:21 +02:00
|
|
|
const MCSymbol *Sym) const;
|
2012-02-14 22:28:13 +01:00
|
|
|
|
2017-06-12 22:10:48 +02:00
|
|
|
/// Emit the module-level metadata that the platform cares about.
|
2018-04-20 21:07:57 +02:00
|
|
|
virtual void emitModuleMetadata(MCStreamer &Streamer, Module &M) const {}
|
2012-02-14 22:28:13 +01:00
|
|
|
|
2019-04-11 06:59:13 +02:00
|
|
|
/// Get the module-level metadata that the platform cares about.
|
|
|
|
virtual void getModuleMetadata(Module &M) {}
|
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
/// Given a constant with the SectionKind, return a section that it should be
|
|
|
|
/// placed in.
|
2015-07-16 08:04:17 +02:00
|
|
|
virtual MCSection *getSectionForConstant(const DataLayout &DL,
|
|
|
|
SectionKind Kind,
|
2016-02-21 02:30:30 +01:00
|
|
|
const Constant *C,
|
|
|
|
unsigned &Align) const;
|
2014-02-07 23:33:56 +01:00
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
/// Classify the specified global variable into a set of target independent
|
|
|
|
/// categories embodied in SectionKind.
|
2016-10-24 21:23:39 +02:00
|
|
|
static SectionKind getKindForGlobal(const GlobalObject *GO,
|
2009-08-05 06:25:40 +02:00
|
|
|
const TargetMachine &TM);
|
2014-02-07 23:33:56 +01:00
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
/// This method computes the appropriate section to emit the specified global
|
|
|
|
/// variable or function definition. This should not be passed external (or
|
|
|
|
/// available externally) globals.
|
2016-10-24 21:23:39 +02:00
|
|
|
MCSection *SectionForGlobal(const GlobalObject *GO, SectionKind Kind,
|
2016-09-16 09:33:15 +02:00
|
|
|
const TargetMachine &TM) const;
|
2014-02-07 23:33:56 +01:00
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
/// This method computes the appropriate section to emit the specified global
|
|
|
|
/// variable or function definition. This should not be passed external (or
|
|
|
|
/// available externally) globals.
|
2016-10-24 21:23:39 +02:00
|
|
|
MCSection *SectionForGlobal(const GlobalObject *GO,
|
2015-05-21 21:20:38 +02:00
|
|
|
const TargetMachine &TM) const {
|
2016-10-24 21:23:39 +02:00
|
|
|
return SectionForGlobal(GO, getKindForGlobal(GO, TM), TM);
|
2009-08-05 06:25:40 +02:00
|
|
|
}
|
2012-02-14 22:28:13 +01:00
|
|
|
|
2015-03-18 00:54:51 +01:00
|
|
|
virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
|
2016-09-16 09:33:15 +02:00
|
|
|
const GlobalValue *GV,
|
2015-03-18 00:54:51 +01:00
|
|
|
const TargetMachine &TM) const;
|
|
|
|
|
2016-09-16 09:33:15 +02:00
|
|
|
virtual MCSection *getSectionForJumpTable(const Function &F,
|
2015-05-21 21:20:38 +02:00
|
|
|
const TargetMachine &TM) const;
|
2015-02-12 18:16:46 +01:00
|
|
|
|
2015-02-18 00:34:51 +01:00
|
|
|
virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
|
|
|
|
const Function &F) const;
|
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
/// Targets should implement this method to assign a section to globals with
|
|
|
|
/// an explicit section specfied. The implementation of this method can
|
2016-10-24 21:23:39 +02:00
|
|
|
/// assume that GO->hasSection() is true.
|
2015-05-21 21:20:38 +02:00
|
|
|
virtual MCSection *
|
2016-10-24 21:23:39 +02:00
|
|
|
getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
|
2016-09-16 09:33:15 +02:00
|
|
|
const TargetMachine &TM) const = 0;
|
2014-02-07 23:33:56 +01:00
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
/// Return an MCExpr to use for a reference to the specified global variable
|
|
|
|
/// from exception handling information.
|
2016-09-16 09:33:15 +02:00
|
|
|
virtual const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
|
|
|
|
unsigned Encoding,
|
|
|
|
const TargetMachine &TM,
|
|
|
|
MachineModuleInfo *MMI,
|
|
|
|
MCStreamer &Streamer) const;
|
2013-10-29 18:28:26 +01:00
|
|
|
|
2013-12-02 17:25:47 +01:00
|
|
|
/// Return the MCSymbol for a private symbol with global value name as its
|
|
|
|
/// base, with the specified suffix.
|
2014-02-09 15:50:44 +01:00
|
|
|
MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
|
2016-09-16 09:33:15 +02:00
|
|
|
StringRef Suffix,
|
2014-02-19 18:23:20 +01:00
|
|
|
const TargetMachine &TM) const;
|
2013-12-02 17:25:47 +01:00
|
|
|
|
2014-02-07 23:39:17 +01:00
|
|
|
// The symbol that gets passed to .cfi_personality.
|
2014-02-19 18:23:20 +01:00
|
|
|
virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
|
|
|
|
const TargetMachine &TM,
|
|
|
|
MachineModuleInfo *MMI) const;
|
2011-04-28 01:08:15 +02:00
|
|
|
|
[MC] Move EH DWARF encodings from MC to CodeGen, NFC
Summary:
The TType encoding, LSDA encoding, and personality encoding are all
passed explicitly by CodeGen to the assembler through .cfi_* directives,
so only the AsmPrinter needs to know about them.
The FDE CFI encoding however, controls the encoding of the label
implicitly created by the .cfi_startproc directive. That directive seems
to be special in that it doesn't take an encoding, so the assembler just
has to know how to encode one DSO-local label reference from .eh_frame
to .text.
As a result, it looks like MC will continue to have to know when the
large code model is in use. Perhaps we could invent a '.cfi_startproc
[large]' flag so that this knowledge doesn't need to pollute the
assembler.
Reviewers: davide, lliu0, JDevlieghere
Subscribers: hiraditya, fedor.sergeev, llvm-commits
Differential Revision: https://reviews.llvm.org/D50533
llvm-svn: 339397
2018-08-10 00:24:04 +02:00
|
|
|
unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
|
|
|
|
unsigned getLSDAEncoding() const { return LSDAEncoding; }
|
|
|
|
unsigned getTTypeEncoding() const { return TTypeEncoding; }
|
2019-07-17 16:00:35 +02:00
|
|
|
unsigned getCallSiteEncoding() const { return CallSiteEncoding; }
|
[MC] Move EH DWARF encodings from MC to CodeGen, NFC
Summary:
The TType encoding, LSDA encoding, and personality encoding are all
passed explicitly by CodeGen to the assembler through .cfi_* directives,
so only the AsmPrinter needs to know about them.
The FDE CFI encoding however, controls the encoding of the label
implicitly created by the .cfi_startproc directive. That directive seems
to be special in that it doesn't take an encoding, so the assembler just
has to know how to encode one DSO-local label reference from .eh_frame
to .text.
As a result, it looks like MC will continue to have to know when the
large code model is in use. Perhaps we could invent a '.cfi_startproc
[large]' flag so that this knowledge doesn't need to pollute the
assembler.
Reviewers: davide, lliu0, JDevlieghere
Subscribers: hiraditya, fedor.sergeev, llvm-commits
Differential Revision: https://reviews.llvm.org/D50533
llvm-svn: 339397
2018-08-10 00:24:04 +02:00
|
|
|
|
2016-09-16 09:33:15 +02:00
|
|
|
const MCExpr *getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
|
|
|
|
MCStreamer &Streamer) const;
|
2012-01-25 23:24:19 +01:00
|
|
|
|
2015-05-21 21:20:38 +02:00
|
|
|
virtual MCSection *getStaticCtorSection(unsigned Priority,
|
|
|
|
const MCSymbol *KeySym) const {
|
2012-01-25 23:24:19 +01:00
|
|
|
return StaticCtorSection;
|
|
|
|
}
|
2014-05-16 22:39:27 +02:00
|
|
|
|
2015-05-21 21:20:38 +02:00
|
|
|
virtual MCSection *getStaticDtorSection(unsigned Priority,
|
|
|
|
const MCSymbol *KeySym) const {
|
2012-01-25 23:24:19 +01:00
|
|
|
return StaticDtorSection;
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Create a symbol reference to describe the given TLS variable when
|
2013-06-28 22:05:11 +02:00
|
|
|
/// emitting the address in debug info.
|
2013-07-02 20:47:09 +02:00
|
|
|
virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
|
2013-06-28 22:05:11 +02:00
|
|
|
|
2016-09-16 09:33:15 +02:00
|
|
|
virtual const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
|
|
|
|
const GlobalValue *RHS,
|
|
|
|
const TargetMachine &TM) const {
|
2014-04-14 02:51:57 +02:00
|
|
|
return nullptr;
|
2014-01-15 10:16:42 +01:00
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Target supports replacing a data "PC"-relative access to a symbol
|
2015-02-23 22:26:18 +01:00
|
|
|
/// through another symbol, by accessing the later via a GOT entry instead?
|
|
|
|
bool supportIndirectSymViaGOTPCRel() const {
|
|
|
|
return SupportIndirectSymViaGOTPCRel;
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Target GOT "PC"-relative relocation supports encoding an additional
|
2015-03-06 14:48:45 +01:00
|
|
|
/// binary expression with an offset?
|
|
|
|
bool supportGOTPCRelWithOffset() const {
|
|
|
|
return SupportGOTPCRelWithOffset;
|
|
|
|
}
|
|
|
|
|
2018-08-02 01:46:49 +02:00
|
|
|
/// Target supports TLS offset relocation in debug section?
|
|
|
|
bool supportDebugThreadLocalLocation() const {
|
|
|
|
return SupportDebugThreadLocalLocation;
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Get the target specific PC relative GOT entry relocation
|
2019-08-22 18:59:00 +02:00
|
|
|
virtual const MCExpr *getIndirectSymViaGOTPCRel(const GlobalValue *GV,
|
|
|
|
const MCSymbol *Sym,
|
2015-03-06 14:49:05 +01:00
|
|
|
const MCValue &MV,
|
2015-03-06 14:48:45 +01:00
|
|
|
int64_t Offset,
|
2015-03-06 14:49:05 +01:00
|
|
|
MachineModuleInfo *MMI,
|
2015-03-06 14:48:45 +01:00
|
|
|
MCStreamer &Streamer) const {
|
2015-02-23 22:26:18 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-09-16 09:33:15 +02:00
|
|
|
virtual void emitLinkerFlagsForGlobal(raw_ostream &OS,
|
|
|
|
const GlobalValue *GV) const {}
|
2015-06-30 00:04:09 +02:00
|
|
|
|
2018-01-20 01:28:02 +01:00
|
|
|
virtual void emitLinkerFlagsForUsed(raw_ostream &OS,
|
|
|
|
const GlobalValue *GV) const {}
|
|
|
|
|
2018-12-14 16:38:15 +01:00
|
|
|
/// If supported, return the section to use for the llvm.commandline
|
|
|
|
/// metadata. Otherwise, return nullptr.
|
|
|
|
virtual MCSection *getSectionForCommandLines() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2009-07-28 05:13:23 +02:00
|
|
|
protected:
|
2016-10-24 21:23:39 +02:00
|
|
|
virtual MCSection *SelectSectionForGlobal(const GlobalObject *GO,
|
2016-09-16 09:33:15 +02:00
|
|
|
SectionKind Kind,
|
2015-05-21 21:20:38 +02:00
|
|
|
const TargetMachine &TM) const = 0;
|
2009-07-28 05:13:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
2017-11-17 02:07:10 +01:00
|
|
|
#endif // LLVM_CODEGEN_TARGETLOWERINGOBJECTFILE_H
|