1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 12:12:47 +01:00
llvm-mirror/include/llvm/MC/MCObjectFileInfo.h

445 lines
17 KiB
C
Raw Normal View History

//===-- llvm/MC/MCObjectFileInfo.h - Object File Info -----------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// This file describes common object file formats.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_MC_MCOBJECTFILEINFO_H
#define LLVM_MC_MCOBJECTFILEINFO_H
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Triple.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/VersionTuple.h"
namespace llvm {
class MCContext;
class MCSection;
class MCObjectFileInfo {
protected:
/// True if .comm supports alignment. This is a hack for as long as we
/// support 10.4 Tiger, whose assembler doesn't support alignment on comm.
bool CommDirectiveSupportsAlignment = false;
/// True if target object file supports a weak_definition of constant 0 for an
/// omitted EH frame.
bool SupportsWeakOmittedEHFrame = false;
/// True if the target object file supports emitting a compact unwind section
/// without an associated EH frame section.
bool SupportsCompactUnwindWithoutEHFrame = false;
/// OmitDwarfIfHaveCompactUnwind - True if the target object file
/// supports having some functions with compact unwind and other with
/// dwarf unwind.
bool OmitDwarfIfHaveCompactUnwind = false;
/// FDE CFI encoding. Controls the encoding of the begin label in the
/// .eh_frame section. Unlike the LSDA encoding, personality encoding, and
/// type encodings, this is something that the assembler just "knows" about
/// its target
unsigned FDECFIEncoding = 0;
/// Compact unwind encoding indicating that we should emit only an EH frame.
unsigned CompactUnwindDwarfEHFrameOnly = 0;
/// Section directive for standard text.
MCSection *TextSection = nullptr;
/// Section directive for standard data.
MCSection *DataSection = nullptr;
/// Section that is default initialized to zero.
MCSection *BSSSection = nullptr;
/// Section that is readonly and can contain arbitrary initialized data.
/// Targets are not required to have a readonly section. If they don't,
/// various bits of code will fall back to using the data section for
/// constants.
MCSection *ReadOnlySection = nullptr;
/// If exception handling is supported by the target, this is the section the
/// Language Specific Data Area information is emitted to.
MCSection *LSDASection = nullptr;
/// If exception handling is supported by the target and the target can
/// support a compact representation of the CIE and FDE, this is the section
/// to emit them into.
MCSection *CompactUnwindSection = nullptr;
// Dwarf sections for debug info. If a target supports debug info, these must
// be set.
MCSection *DwarfAbbrevSection = nullptr;
MCSection *DwarfInfoSection = nullptr;
MCSection *DwarfLineSection = nullptr;
MCSection *DwarfLineStrSection = nullptr;
MCSection *DwarfFrameSection = nullptr;
MCSection *DwarfPubTypesSection = nullptr;
const MCSection *DwarfDebugInlineSection = nullptr;
MCSection *DwarfStrSection = nullptr;
MCSection *DwarfLocSection = nullptr;
MCSection *DwarfARangesSection = nullptr;
MCSection *DwarfRangesSection = nullptr;
MCSection *DwarfMacinfoSection = nullptr;
MCSection *DwarfMacroSection = nullptr;
// The pubnames section is no longer generated by default. The generation
// can be enabled by a compiler flag.
MCSection *DwarfPubNamesSection = nullptr;
/// Accelerator table sections. DwarfDebugNamesSection is the DWARF v5
/// accelerator table, while DwarfAccelNamesSection, DwarfAccelObjCSection,
/// DwarfAccelNamespaceSection, DwarfAccelTypesSection are pre-DWARF v5
/// extensions.
MCSection *DwarfDebugNamesSection = nullptr;
MCSection *DwarfAccelNamesSection = nullptr;
MCSection *DwarfAccelObjCSection = nullptr;
MCSection *DwarfAccelNamespaceSection = nullptr;
MCSection *DwarfAccelTypesSection = nullptr;
// These are used for the Fission separate debug information files.
MCSection *DwarfInfoDWOSection = nullptr;
MCSection *DwarfTypesDWOSection = nullptr;
MCSection *DwarfAbbrevDWOSection = nullptr;
MCSection *DwarfStrDWOSection = nullptr;
MCSection *DwarfLineDWOSection = nullptr;
MCSection *DwarfLocDWOSection = nullptr;
MCSection *DwarfStrOffDWOSection = nullptr;
MCSection *DwarfMacinfoDWOSection = nullptr;
MCSection *DwarfMacroDWOSection = nullptr;
/// The DWARF v5 string offset and address table sections.
MCSection *DwarfStrOffSection = nullptr;
MCSection *DwarfAddrSection = nullptr;
/// The DWARF v5 range list section.
MCSection *DwarfRnglistsSection = nullptr;
/// The DWARF v5 locations list section.
MCSection *DwarfLoclistsSection = nullptr;
/// The DWARF v5 range and location list sections for fission.
MCSection *DwarfRnglistsDWOSection = nullptr;
MCSection *DwarfLoclistsDWOSection = nullptr;
// These are for Fission DWP files.
MCSection *DwarfCUIndexSection = nullptr;
MCSection *DwarfTUIndexSection = nullptr;
/// Section for newer gnu pubnames.
MCSection *DwarfGnuPubNamesSection = nullptr;
/// Section for newer gnu pubtypes.
MCSection *DwarfGnuPubTypesSection = nullptr;
// Section for Swift AST
MCSection *DwarfSwiftASTSection = nullptr;
MCSection *COFFDebugSymbolsSection = nullptr;
MCSection *COFFDebugTypesSection = nullptr;
MCSection *COFFGlobalTypeHashesSection = nullptr;
/// Extra TLS Variable Data section.
///
/// If the target needs to put additional information for a TLS variable,
/// it'll go here.
MCSection *TLSExtraDataSection = nullptr;
/// Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
MCSection *TLSDataSection = nullptr; // Defaults to ".tdata".
/// Section directive for Thread Local uninitialized data.
///
/// Null if this target doesn't support a BSS section. ELF and MachO only.
MCSection *TLSBSSSection = nullptr; // Defaults to ".tbss".
/// StackMap section.
MCSection *StackMapSection = nullptr;
/// FaultMap section.
MCSection *FaultMapSection = nullptr;
/// Remarks section.
MCSection *RemarksSection = nullptr;
/// EH frame section.
///
/// It is initialized on demand so it can be overwritten (with uniquing).
MCSection *EHFrameSection = nullptr;
/// Section containing metadata on function stack sizes.
MCSection *StackSizesSection = nullptr;
[CSSPGO] Pseudo probe encoding and emission. This change implements pseudo probe encoding and emission for CSSPGO. Please see RFC here for more context: https://groups.google.com/g/llvm-dev/c/1p1rdYbL93s Pseudo probes are in the form of intrinsic calls on IR/MIR but they do not turn into any machine instructions. Instead they are emitted into the binary as a piece of data in standalone sections. The probe-specific sections are not needed to be loaded into memory at execution time, thus they do not incur a runtime overhead.  **ELF object emission** The binary data to emit are organized as two ELF sections, i.e, the `.pseudo_probe_desc` section and the `.pseudo_probe` section. The `.pseudo_probe_desc` section stores a function descriptor for each function and the `.pseudo_probe` section stores the actual probes, each fo which corresponds to an IR basic block or an IR function callsite. A function descriptor is stored as a module-level metadata during the compilation and is serialized into the object file during object emission. Both the probe descriptors and pseudo probes can be emitted into a separate ELF section per function to leverage the linker for deduplication. A `.pseudo_probe` section shares the same COMDAT group with the function code so that when the function is dead, the probes are dead and disposed too. On the contrary, a `.pseudo_probe_desc` section has its own COMDAT group. This is because even if a function is dead, its probes may be inlined into other functions and its descriptor is still needed by the profile generation tool. The format of `.pseudo_probe_desc` section looks like: ``` .section .pseudo_probe_desc,"",@progbits .quad 6309742469962978389 // Func GUID .quad 4294967295 // Func Hash .byte 9 // Length of func name .ascii "_Z5funcAi" // Func name .quad 7102633082150537521 .quad 138828622701 .byte 12 .ascii "_Z8funcLeafi" .quad 446061515086924981 .quad 4294967295 .byte 9 .ascii "_Z5funcBi" .quad -2016976694713209516 .quad 72617220756 .byte 7 .ascii "_Z3fibi" ``` For each `.pseudoprobe` section, the encoded binary data consists of a single function record corresponding to an outlined function (i.e, a function with a code entry in the `.text` section). A function record has the following format : ``` FUNCTION BODY (one for each outlined function present in the text section) GUID (uint64) GUID of the function NPROBES (ULEB128) Number of probes originating from this function. NUM_INLINED_FUNCTIONS (ULEB128) Number of callees inlined into this function, aka number of first-level inlinees PROBE RECORDS A list of NPROBES entries. Each entry contains: INDEX (ULEB128) TYPE (uint4) 0 - block probe, 1 - indirect call, 2 - direct call ATTRIBUTE (uint3) reserved ADDRESS_TYPE (uint1) 0 - code address, 1 - address delta CODE_ADDRESS (uint64 or ULEB128) code address or address delta, depending on ADDRESS_TYPE INLINED FUNCTION RECORDS A list of NUM_INLINED_FUNCTIONS entries describing each of the inlined callees. Each record contains: INLINE SITE GUID of the inlinee (uint64) ID of the callsite probe (ULEB128) FUNCTION BODY A FUNCTION BODY entry describing the inlined function. ``` To support building a context-sensitive profile, probes from inlinees are grouped by their inline contexts. An inline context is logically a call path through which a callee function lands in a caller function. The probe emitter builds an inline tree based on the debug metadata for each outlined function in the form of a trie tree. A tree root is the outlined function. Each tree edge stands for a callsite where inlining happens. Pseudo probes originating from an inlinee function are stored in a tree node and the tree path starting from the root all the way down to the tree node is the inline context of the probes. The emission happens on the whole tree top-down recursively. Probes of a tree node will be emitted altogether with their direct parent edge. Since a pseudo probe corresponds to a real code address, for size savings, the address is encoded as a delta from the previous probe except for the first probe. Variant-sized integer encoding, aka LEB128, is used for address delta and probe index. **Assembling** Pseudo probes can be printed as assembly directives alternatively. This allows for good assembly code readability and also provides a view of how optimizations and pseudo probes affect each other, especially helpful for diff time assembly analysis. A pseudo probe directive has the following operands in order: function GUID, probe index, probe type, probe attributes and inline context. The directive is generated by the compiler and can be parsed by the assembler to form an encoded `.pseudoprobe` section in the object file. A example assembly looks like: ``` foo2: # @foo2 # %bb.0: # %bb0 pushq %rax testl %edi, %edi .pseudoprobe 837061429793323041 1 0 0 je .LBB1_1 # %bb.2: # %bb2 .pseudoprobe 837061429793323041 6 2 0 callq foo .pseudoprobe 837061429793323041 3 0 0 .pseudoprobe 837061429793323041 4 0 0 popq %rax retq .LBB1_1: # %bb1 .pseudoprobe 837061429793323041 5 1 0 callq *%rsi .pseudoprobe 837061429793323041 2 0 0 .pseudoprobe 837061429793323041 4 0 0 popq %rax retq # -- End function .section .pseudo_probe_desc,"",@progbits .quad 6699318081062747564 .quad 72617220756 .byte 3 .ascii "foo" .quad 837061429793323041 .quad 281547593931412 .byte 4 .ascii "foo2" ``` With inlining turned on, the assembly may look different around %bb2 with an inlined probe: ``` # %bb.2: # %bb2 .pseudoprobe 837061429793323041 3 0 .pseudoprobe 6699318081062747564 1 0 @ 837061429793323041:6 .pseudoprobe 837061429793323041 4 0 popq %rax retq ``` **Disassembling** We have a disassembling tool (llvm-profgen) that can display disassembly alongside with pseudo probes. So far it only supports ELF executable file. An example disassembly looks like: ``` 00000000002011a0 <foo2>: 2011a0: 50 push rax 2011a1: 85 ff test edi,edi [Probe]: FUNC: foo2 Index: 1 Type: Block 2011a3: 74 02 je 2011a7 <foo2+0x7> [Probe]: FUNC: foo2 Index: 3 Type: Block [Probe]: FUNC: foo2 Index: 4 Type: Block [Probe]: FUNC: foo Index: 1 Type: Block Inlined: @ foo2:6 2011a5: 58 pop rax 2011a6: c3 ret [Probe]: FUNC: foo2 Index: 2 Type: Block 2011a7: bf 01 00 00 00 mov edi,0x1 [Probe]: FUNC: foo2 Index: 5 Type: IndirectCall 2011ac: ff d6 call rsi [Probe]: FUNC: foo2 Index: 4 Type: Block 2011ae: 58 pop rax 2011af: c3 ret ``` Reviewed By: wmi Differential Revision: https://reviews.llvm.org/D91878
2020-12-09 00:37:32 +01:00
/// Section for pseudo probe information used by AutoFDO
MCSection *PseudoProbeSection = nullptr;
MCSection *PseudoProbeDescSection = nullptr;
// ELF specific sections.
MCSection *DataRelROSection = nullptr;
MCSection *MergeableConst4Section = nullptr;
MCSection *MergeableConst8Section = nullptr;
MCSection *MergeableConst16Section = nullptr;
MCSection *MergeableConst32Section = nullptr;
// MachO specific sections.
/// Section for thread local structure information.
///
/// Contains the source code name of the variable, visibility and a pointer to
/// the initial value (.tdata or .tbss).
MCSection *TLSTLVSection = nullptr; // Defaults to ".tlv".
/// Section for thread local data initialization functions.
// Defaults to ".thread_init_func".
const MCSection *TLSThreadInitSection = nullptr;
MCSection *CStringSection = nullptr;
MCSection *UStringSection = nullptr;
MCSection *TextCoalSection = nullptr;
MCSection *ConstTextCoalSection = nullptr;
MCSection *ConstDataSection = nullptr;
MCSection *DataCoalSection = nullptr;
MCSection *ConstDataCoalSection = nullptr;
MCSection *DataCommonSection = nullptr;
MCSection *DataBSSSection = nullptr;
MCSection *FourByteConstantSection = nullptr;
MCSection *EightByteConstantSection = nullptr;
MCSection *SixteenByteConstantSection = nullptr;
MCSection *LazySymbolPointerSection = nullptr;
MCSection *NonLazySymbolPointerSection = nullptr;
MCSection *ThreadLocalPointerSection = nullptr;
/// COFF specific sections.
MCSection *DrectveSection = nullptr;
MCSection *PDataSection = nullptr;
MCSection *XDataSection = nullptr;
MCSection *SXDataSection = nullptr;
MCSection *GEHContSection = nullptr;
MCSection *GFIDsSection = nullptr;
MCSection *GIATsSection = nullptr;
MCSection *GLJMPSection = nullptr;
// XCOFF specific sections
MCSection *TOCBaseSection = nullptr;
public:
void initMCObjectFileInfo(MCContext &MCCtx, bool PIC,
bool LargeCodeModel = false);
MCContext &getContext() const { return *Ctx; }
bool getSupportsWeakOmittedEHFrame() const {
return SupportsWeakOmittedEHFrame;
}
bool getSupportsCompactUnwindWithoutEHFrame() const {
return SupportsCompactUnwindWithoutEHFrame;
}
bool getOmitDwarfIfHaveCompactUnwind() const {
return OmitDwarfIfHaveCompactUnwind;
}
bool getCommDirectiveSupportsAlignment() const {
return CommDirectiveSupportsAlignment;
}
unsigned getFDEEncoding() const { return FDECFIEncoding; }
unsigned getCompactUnwindDwarfEHFrameOnly() const {
return CompactUnwindDwarfEHFrameOnly;
}
MCSection *getTextSection() const { return TextSection; }
MCSection *getDataSection() const { return DataSection; }
MCSection *getBSSSection() const { return BSSSection; }
MCSection *getReadOnlySection() const { return ReadOnlySection; }
MCSection *getLSDASection() const { return LSDASection; }
MCSection *getCompactUnwindSection() const { return CompactUnwindSection; }
MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
MCSection *getDwarfInfoSection(uint64_t Hash) const {
return getDwarfComdatSection(".debug_info", Hash);
}
MCSection *getDwarfLineSection() const { return DwarfLineSection; }
MCSection *getDwarfLineStrSection() const { return DwarfLineStrSection; }
MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
MCSection *getDwarfPubNamesSection() const { return DwarfPubNamesSection; }
MCSection *getDwarfPubTypesSection() const { return DwarfPubTypesSection; }
MCSection *getDwarfGnuPubNamesSection() const {
return DwarfGnuPubNamesSection;
}
MCSection *getDwarfGnuPubTypesSection() const {
return DwarfGnuPubTypesSection;
}
const MCSection *getDwarfDebugInlineSection() const {
return DwarfDebugInlineSection;
}
MCSection *getDwarfStrSection() const { return DwarfStrSection; }
MCSection *getDwarfLocSection() const { return DwarfLocSection; }
MCSection *getDwarfARangesSection() const { return DwarfARangesSection; }
MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
MCSection *getDwarfRnglistsSection() const { return DwarfRnglistsSection; }
MCSection *getDwarfLoclistsSection() const { return DwarfLoclistsSection; }
MCSection *getDwarfMacinfoSection() const { return DwarfMacinfoSection; }
MCSection *getDwarfMacroSection() const { return DwarfMacroSection; }
MCSection *getDwarfDebugNamesSection() const {
return DwarfDebugNamesSection;
}
MCSection *getDwarfAccelNamesSection() const {
return DwarfAccelNamesSection;
}
MCSection *getDwarfAccelObjCSection() const { return DwarfAccelObjCSection; }
MCSection *getDwarfAccelNamespaceSection() const {
return DwarfAccelNamespaceSection;
}
MCSection *getDwarfAccelTypesSection() const {
return DwarfAccelTypesSection;
}
MCSection *getDwarfInfoDWOSection() const { return DwarfInfoDWOSection; }
MCSection *getDwarfTypesSection(uint64_t Hash) const {
return getDwarfComdatSection(".debug_types", Hash);
}
MCSection *getDwarfTypesDWOSection() const { return DwarfTypesDWOSection; }
MCSection *getDwarfAbbrevDWOSection() const { return DwarfAbbrevDWOSection; }
MCSection *getDwarfStrDWOSection() const { return DwarfStrDWOSection; }
MCSection *getDwarfLineDWOSection() const { return DwarfLineDWOSection; }
MCSection *getDwarfLocDWOSection() const { return DwarfLocDWOSection; }
MCSection *getDwarfStrOffDWOSection() const { return DwarfStrOffDWOSection; }
MCSection *getDwarfStrOffSection() const { return DwarfStrOffSection; }
MCSection *getDwarfAddrSection() const { return DwarfAddrSection; }
MCSection *getDwarfRnglistsDWOSection() const {
return DwarfRnglistsDWOSection;
}
MCSection *getDwarfLoclistsDWOSection() const {
return DwarfLoclistsDWOSection;
}
MCSection *getDwarfMacroDWOSection() const { return DwarfMacroDWOSection; }
MCSection *getDwarfMacinfoDWOSection() const {
return DwarfMacinfoDWOSection;
}
MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; }
MCSection *getDwarfTUIndexSection() const { return DwarfTUIndexSection; }
MCSection *getDwarfSwiftASTSection() const { return DwarfSwiftASTSection; }
MCSection *getCOFFDebugSymbolsSection() const {
return COFFDebugSymbolsSection;
}
MCSection *getCOFFDebugTypesSection() const {
return COFFDebugTypesSection;
}
MCSection *getCOFFGlobalTypeHashesSection() const {
return COFFGlobalTypeHashesSection;
}
MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; }
const MCSection *getTLSDataSection() const { return TLSDataSection; }
MCSection *getTLSBSSSection() const { return TLSBSSSection; }
MCSection *getStackMapSection() const { return StackMapSection; }
MCSection *getFaultMapSection() const { return FaultMapSection; }
MCSection *getRemarksSection() const { return RemarksSection; }
MCSection *getStackSizesSection(const MCSection &TextSec) const;
MCSection *getBBAddrMapSection(const MCSection &TextSec) const;
[CSSPGO] Pseudo probe encoding and emission. This change implements pseudo probe encoding and emission for CSSPGO. Please see RFC here for more context: https://groups.google.com/g/llvm-dev/c/1p1rdYbL93s Pseudo probes are in the form of intrinsic calls on IR/MIR but they do not turn into any machine instructions. Instead they are emitted into the binary as a piece of data in standalone sections. The probe-specific sections are not needed to be loaded into memory at execution time, thus they do not incur a runtime overhead.  **ELF object emission** The binary data to emit are organized as two ELF sections, i.e, the `.pseudo_probe_desc` section and the `.pseudo_probe` section. The `.pseudo_probe_desc` section stores a function descriptor for each function and the `.pseudo_probe` section stores the actual probes, each fo which corresponds to an IR basic block or an IR function callsite. A function descriptor is stored as a module-level metadata during the compilation and is serialized into the object file during object emission. Both the probe descriptors and pseudo probes can be emitted into a separate ELF section per function to leverage the linker for deduplication. A `.pseudo_probe` section shares the same COMDAT group with the function code so that when the function is dead, the probes are dead and disposed too. On the contrary, a `.pseudo_probe_desc` section has its own COMDAT group. This is because even if a function is dead, its probes may be inlined into other functions and its descriptor is still needed by the profile generation tool. The format of `.pseudo_probe_desc` section looks like: ``` .section .pseudo_probe_desc,"",@progbits .quad 6309742469962978389 // Func GUID .quad 4294967295 // Func Hash .byte 9 // Length of func name .ascii "_Z5funcAi" // Func name .quad 7102633082150537521 .quad 138828622701 .byte 12 .ascii "_Z8funcLeafi" .quad 446061515086924981 .quad 4294967295 .byte 9 .ascii "_Z5funcBi" .quad -2016976694713209516 .quad 72617220756 .byte 7 .ascii "_Z3fibi" ``` For each `.pseudoprobe` section, the encoded binary data consists of a single function record corresponding to an outlined function (i.e, a function with a code entry in the `.text` section). A function record has the following format : ``` FUNCTION BODY (one for each outlined function present in the text section) GUID (uint64) GUID of the function NPROBES (ULEB128) Number of probes originating from this function. NUM_INLINED_FUNCTIONS (ULEB128) Number of callees inlined into this function, aka number of first-level inlinees PROBE RECORDS A list of NPROBES entries. Each entry contains: INDEX (ULEB128) TYPE (uint4) 0 - block probe, 1 - indirect call, 2 - direct call ATTRIBUTE (uint3) reserved ADDRESS_TYPE (uint1) 0 - code address, 1 - address delta CODE_ADDRESS (uint64 or ULEB128) code address or address delta, depending on ADDRESS_TYPE INLINED FUNCTION RECORDS A list of NUM_INLINED_FUNCTIONS entries describing each of the inlined callees. Each record contains: INLINE SITE GUID of the inlinee (uint64) ID of the callsite probe (ULEB128) FUNCTION BODY A FUNCTION BODY entry describing the inlined function. ``` To support building a context-sensitive profile, probes from inlinees are grouped by their inline contexts. An inline context is logically a call path through which a callee function lands in a caller function. The probe emitter builds an inline tree based on the debug metadata for each outlined function in the form of a trie tree. A tree root is the outlined function. Each tree edge stands for a callsite where inlining happens. Pseudo probes originating from an inlinee function are stored in a tree node and the tree path starting from the root all the way down to the tree node is the inline context of the probes. The emission happens on the whole tree top-down recursively. Probes of a tree node will be emitted altogether with their direct parent edge. Since a pseudo probe corresponds to a real code address, for size savings, the address is encoded as a delta from the previous probe except for the first probe. Variant-sized integer encoding, aka LEB128, is used for address delta and probe index. **Assembling** Pseudo probes can be printed as assembly directives alternatively. This allows for good assembly code readability and also provides a view of how optimizations and pseudo probes affect each other, especially helpful for diff time assembly analysis. A pseudo probe directive has the following operands in order: function GUID, probe index, probe type, probe attributes and inline context. The directive is generated by the compiler and can be parsed by the assembler to form an encoded `.pseudoprobe` section in the object file. A example assembly looks like: ``` foo2: # @foo2 # %bb.0: # %bb0 pushq %rax testl %edi, %edi .pseudoprobe 837061429793323041 1 0 0 je .LBB1_1 # %bb.2: # %bb2 .pseudoprobe 837061429793323041 6 2 0 callq foo .pseudoprobe 837061429793323041 3 0 0 .pseudoprobe 837061429793323041 4 0 0 popq %rax retq .LBB1_1: # %bb1 .pseudoprobe 837061429793323041 5 1 0 callq *%rsi .pseudoprobe 837061429793323041 2 0 0 .pseudoprobe 837061429793323041 4 0 0 popq %rax retq # -- End function .section .pseudo_probe_desc,"",@progbits .quad 6699318081062747564 .quad 72617220756 .byte 3 .ascii "foo" .quad 837061429793323041 .quad 281547593931412 .byte 4 .ascii "foo2" ``` With inlining turned on, the assembly may look different around %bb2 with an inlined probe: ``` # %bb.2: # %bb2 .pseudoprobe 837061429793323041 3 0 .pseudoprobe 6699318081062747564 1 0 @ 837061429793323041:6 .pseudoprobe 837061429793323041 4 0 popq %rax retq ``` **Disassembling** We have a disassembling tool (llvm-profgen) that can display disassembly alongside with pseudo probes. So far it only supports ELF executable file. An example disassembly looks like: ``` 00000000002011a0 <foo2>: 2011a0: 50 push rax 2011a1: 85 ff test edi,edi [Probe]: FUNC: foo2 Index: 1 Type: Block 2011a3: 74 02 je 2011a7 <foo2+0x7> [Probe]: FUNC: foo2 Index: 3 Type: Block [Probe]: FUNC: foo2 Index: 4 Type: Block [Probe]: FUNC: foo Index: 1 Type: Block Inlined: @ foo2:6 2011a5: 58 pop rax 2011a6: c3 ret [Probe]: FUNC: foo2 Index: 2 Type: Block 2011a7: bf 01 00 00 00 mov edi,0x1 [Probe]: FUNC: foo2 Index: 5 Type: IndirectCall 2011ac: ff d6 call rsi [Probe]: FUNC: foo2 Index: 4 Type: Block 2011ae: 58 pop rax 2011af: c3 ret ``` Reviewed By: wmi Differential Revision: https://reviews.llvm.org/D91878
2020-12-09 00:37:32 +01:00
MCSection *getPseudoProbeSection(const MCSection *TextSec) const;
MCSection *getPseudoProbeDescSection(StringRef FuncName) const;
// ELF specific sections.
MCSection *getDataRelROSection() const { return DataRelROSection; }
const MCSection *getMergeableConst4Section() const {
return MergeableConst4Section;
}
const MCSection *getMergeableConst8Section() const {
return MergeableConst8Section;
}
const MCSection *getMergeableConst16Section() const {
return MergeableConst16Section;
}
const MCSection *getMergeableConst32Section() const {
return MergeableConst32Section;
}
// MachO specific sections.
const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
const MCSection *getTLSThreadInitSection() const {
return TLSThreadInitSection;
}
const MCSection *getCStringSection() const { return CStringSection; }
const MCSection *getUStringSection() const { return UStringSection; }
MCSection *getTextCoalSection() const { return TextCoalSection; }
const MCSection *getConstTextCoalSection() const {
return ConstTextCoalSection;
}
const MCSection *getConstDataSection() const { return ConstDataSection; }
const MCSection *getDataCoalSection() const { return DataCoalSection; }
const MCSection *getConstDataCoalSection() const {
return ConstDataCoalSection;
}
const MCSection *getDataCommonSection() const { return DataCommonSection; }
MCSection *getDataBSSSection() const { return DataBSSSection; }
const MCSection *getFourByteConstantSection() const {
return FourByteConstantSection;
}
const MCSection *getEightByteConstantSection() const {
return EightByteConstantSection;
}
const MCSection *getSixteenByteConstantSection() const {
return SixteenByteConstantSection;
}
MCSection *getLazySymbolPointerSection() const {
return LazySymbolPointerSection;
}
MCSection *getNonLazySymbolPointerSection() const {
return NonLazySymbolPointerSection;
}
MCSection *getThreadLocalPointerSection() const {
return ThreadLocalPointerSection;
}
// COFF specific sections.
MCSection *getDrectveSection() const { return DrectveSection; }
MCSection *getPDataSection() const { return PDataSection; }
MCSection *getXDataSection() const { return XDataSection; }
MCSection *getSXDataSection() const { return SXDataSection; }
MCSection *getGEHContSection() const { return GEHContSection; }
MCSection *getGFIDsSection() const { return GFIDsSection; }
MCSection *getGIATsSection() const { return GIATsSection; }
MCSection *getGLJMPSection() const { return GLJMPSection; }
// XCOFF specific sections
MCSection *getTOCBaseSection() const { return TOCBaseSection; }
MCSection *getEHFrameSection() const { return EHFrameSection; }
bool isPositionIndependent() const { return PositionIndependent; }
private:
bool PositionIndependent = false;
MCContext *Ctx = nullptr;
VersionTuple SDKVersion;
void initMachOMCObjectFileInfo(const Triple &T);
void initELFMCObjectFileInfo(const Triple &T, bool Large);
void initCOFFMCObjectFileInfo(const Triple &T);
void initWasmMCObjectFileInfo(const Triple &T);
void initXCOFFMCObjectFileInfo(const Triple &T);
MCSection *getDwarfComdatSection(const char *Name, uint64_t Hash) const;
public:
void setSDKVersion(const VersionTuple &TheSDKVersion) {
SDKVersion = TheSDKVersion;
}
const VersionTuple &getSDKVersion() const { return SDKVersion; }
};
} // end namespace llvm
#endif