Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions llvm/docs/Extensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,35 @@ sees fit (generally the section that would provide the best locality).

.. _CFI jump table: https://clang.llvm.org/docs/ControlFlowIntegrityDesign.html#forward-edge-cfi-for-indirect-function-calls

``SHT_LLVM_CALL_GRAPH`` Section (Call Graph)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This section is used to store the call graph. It has a type of
``SHT_LLVM_CALL_GRAPH`` (0x6fff4c0f). Details of call graph section layout
are described in :doc:`CallGraphSection`.

For example:

.. code-block:: gas

.section ".llvm.callgraph","",@llvm_call_graph
.byte 0
.byte 7
.quad .Lball
.quad 0
.byte 3
.quad foo
.quad bar
.quad baz
.byte 3
.quad 4524972987496481828
.quad 3498816979441845844
.quad 8646233951371320954

This indicates that ``ball`` calls ``foo``, ``bar`` and ``baz`` directly;
``ball`` indirectly calls functions whose types are ``4524972987496481828``,
``3498816979441845844`` and ``8646233951371320954``.

CodeView-Dependent
------------------

Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/BinaryFormat/ELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,7 @@ enum : unsigned {
SHT_LLVM_LTO = 0x6fff4c0c, // .llvm.lto for fat LTO.
SHT_LLVM_JT_SIZES = 0x6fff4c0d, // LLVM jump tables sizes.
SHT_LLVM_CFI_JUMP_TABLE = 0x6fff4c0e, // LLVM CFI jump table.
SHT_LLVM_CALL_GRAPH = 0x6fff4c0f, // LLVM Call Graph Section.
// Android's experimental support for SHT_RELR sections.
// https://android.googlesource.com/platform/bionic/+/b7feec74547f84559a1467aca02708ff61346d2a/libc/include/elf.h#512
SHT_ANDROID_RELR = 0x6fffff00, // Relocation entries; only offsets.
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/MC/MCAsmInfoELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ void MCAsmInfoELF::printSwitchToSection(const MCSection &Section,
OS << "llvm_jt_sizes";
else if (Sec.Type == ELF::SHT_LLVM_CFI_JUMP_TABLE)
OS << "llvm_cfi_jump_table";
else if (Sec.Type == ELF::SHT_LLVM_CALL_GRAPH)
OS << "llvm_call_graph";
else
OS << "0x" << Twine::utohexstr(Sec.Type);

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/MC/MCObjectFileInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
Ctx->getELFSection(".sframe", ELF::SHT_GNU_SFRAME, ELF::SHF_ALLOC);

CallGraphSection =
Ctx->getELFSection(".llvm.callgraph", ELF::SHT_PROGBITS, 0);
Ctx->getELFSection(".llvm.callgraph", ELF::SHT_LLVM_CALL_GRAPH, 0);

StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);

Expand Down Expand Up @@ -1172,7 +1172,7 @@ MCObjectFileInfo::getCallGraphSection(const MCSection &TextSec) const {
}

return Ctx->getELFSection(
".llvm.callgraph", ELF::SHT_PROGBITS, Flags, 0, GroupName,
".llvm.callgraph", ELF::SHT_LLVM_CALL_GRAPH, Flags, 0, GroupName,
/*IsComdat=*/true, ElfSec.getUniqueID(),
static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol()));
}
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/MC/MCParser/ELFAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,8 @@ bool ELFAsmParser::parseSectionArguments(bool IsPush, SMLoc loc) {
Type = ELF::SHT_LLVM_JT_SIZES;
else if (TypeName == "llvm_cfi_jump_table")
Type = ELF::SHT_LLVM_CFI_JUMP_TABLE;
else if (TypeName == "llvm_call_graph")
Type = ELF::SHT_LLVM_CALL_GRAPH;
else if (TypeName.getAsInteger(0, Type))
return TokError("unknown section type");
}
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Object/ELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ StringRef llvm::object::getELFSectionTypeName(uint32_t Machine, unsigned Type) {
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_LTO);
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_JT_SIZES)
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_CFI_JUMP_TABLE)
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_CALL_GRAPH);
STRINGIFY_ENUM_CASE(ELF, SHT_GNU_SFRAME);
STRINGIFY_ENUM_CASE(ELF, SHT_GNU_ATTRIBUTES);
STRINGIFY_ENUM_CASE(ELF, SHT_GNU_HASH);
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/ObjectYAML/ELFYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration(
ECase(SHT_LLVM_BB_ADDR_MAP);
ECase(SHT_LLVM_OFFLOADING);
ECase(SHT_LLVM_LTO);
ECase(SHT_LLVM_CALL_GRAPH);
ECase(SHT_GNU_SFRAME);
ECase(SHT_GNU_ATTRIBUTES);
ECase(SHT_GNU_HASH);
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/ARM/call-graph-section-addrtaken.ll
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ entry:
!1 = !{i64 0, !"_ZTSFivE.generalized"}
!2 = !{i64 0, !"_ZTSFviE.generalized"}

; CHECK: .section .llvm.callgraph,"o",%progbits,.text
; CHECK: .section .llvm.callgraph,"o",%llvm_call_graph,.text
;; Version
; CHECK-NEXT: .byte 0
;; Flags -- Potential indirect target so LSB is set to 1. Other bits are 0.
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/ARM/call-graph-section-assembly.ll
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ entry:
!4 = !{!5}
!5 = !{i64 0, !"_ZTSFPvS_E.generalized"}

; CHECK: .section .llvm.callgraph,"o",%progbits,.text
; CHECK: .section .llvm.callgraph,"o",%llvm_call_graph,.text
;; Version
; CHECK-NEXT: .byte 0
;; Flags
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/X86/call-graph-section-addrtaken.ll
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ entry:
!1 = !{i64 0, !"_ZTSFivE.generalized"}
!2 = !{i64 0, !"_ZTSFviE.generalized"}

; CHECK: .section .llvm.callgraph,"o",@progbits,.text
; CHECK: .section .llvm.callgraph,"o",@llvm_call_graph,.text
;; Version
; CHECK-NEXT: .byte 0
;; Flags -- Potential indirect target so LSB is set to 1. Other bits are 0.
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/X86/call-graph-section-assembly.ll
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ entry:
!4 = !{!5}
!5 = !{i64 0, !"_ZTSFPvS_E.generalized"}

; CHECK: .section .llvm.callgraph,"o",@progbits,.text
; CHECK: .section .llvm.callgraph,"o",@llvm_call_graph,.text
;; Version
; CHECK-NEXT: .byte 0
;; Flags
Expand Down
5 changes: 5 additions & 0 deletions llvm/test/tools/llvm-readobj/ELF/section-types.test
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
# LLVM: Type: SHT_LLVM_PART_PHDR
# LLVM: Name: .llvm.lto
# LLVM: Type: SHT_LLVM_LTO
# LLVM: Name: .llvm.callgraph
# LLVM: Type: SHT_LLVM_CALL_GRAPH
# LLVM: Name: gnu_sframe
# LLVM: Type: SHT_GNU_SFRAME
# LLVM: Name: gnu_attributes
Expand Down Expand Up @@ -127,6 +129,7 @@
# GNU-NEXT: part1 LLVM_PART_EHDR
# GNU-NEXT: .phdrs LLVM_PART_PHDR
# GNU-NEXT: .llvm.lto LLVM_LTO
# GNU-NEXT: .llvm.callgraph LLVM_CALL_GRAPH
# GNU-NEXT: gnu_sframe SFRAME
# GNU-NEXT: gnu_attributes ATTRIBUTES
# GNU-NEXT: gnu_hash GNU_HASH
Expand Down Expand Up @@ -218,6 +221,8 @@ Sections:
Type: SHT_LLVM_PART_PHDR
- Name: .llvm.lto
Type: SHT_LLVM_LTO
- Name: .llvm.callgraph
Type: SHT_LLVM_CALL_GRAPH
- Name: gnu_sframe
Type: SHT_GNU_SFRAME
- Name: gnu_attributes
Expand Down