Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add section type to support CFI jump table relaxation.#149259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

pcc
Copy link
Contributor

@pccpcc commentedJul 17, 2025

For context see main pull request:#147424.

Created using spr 1.3.6-beta.1
@llvmbotllvmbot added mcMachine (object) code llvm:binary-utilities labelsJul 17, 2025
@llvmbot
Copy link
Member

@llvm/pr-subscribers-mc

Author: Peter Collingbourne (pcc)

Changes

For context see main pull request: #147424.


Full diff:https://github.com/llvm/llvm-project/pull/149259.diff

5 Files Affected:

  • (modified) llvm/docs/Extensions.rst (+20)
  • (modified) llvm/include/llvm/BinaryFormat/ELF.h (+1)
  • (modified) llvm/lib/MC/MCParser/ELFAsmParser.cpp (+3-1)
  • (modified) llvm/lib/Object/ELF.cpp (+1)
  • (modified) llvm/test/MC/AsmParser/llvm_section_types.s (+5)
diff --git a/llvm/docs/Extensions.rst b/llvm/docs/Extensions.rstindex bad72c6ca8295..d8fb87b6998ad 100644--- a/llvm/docs/Extensions.rst+++ b/llvm/docs/Extensions.rst@@ -581,6 +581,26 @@ This section stores pairs of (jump table address, number of entries). This information is useful for tools that need to statically reconstruct the control flow of executables.+``SHT_LLVM_CFI_JUMP_TABLE`` Section (CFI jump table)+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^+This section contains the instructions that make up a `CFI jump table`_.+It is expected to be ``SHF_ALLOC`` and may be laid out like a normal+section. The ``SHT_LLVM_CFI_JUMP_TABLE`` section type gives the linker+permission to modify the section in ways that would not normally be+permitted, in order to optimize calls via the jump table.++Each ``sh_entsize`` sized slice of a section of this type containing+exactly one relocation may be considered to be a jump table entry+that branches to the target of the relocation. This allows the linker+to replace the jump table entry with the function body if it is small+enough, or if the function is the last function in the jump table.++A section of this type does not have to be placed according to its+name. The linker may place the section in whichever output section it+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+ CodeView-Dependent ------------------diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.hindex ebb257ab33821..b9e38801d880f 100644--- a/llvm/include/llvm/BinaryFormat/ELF.h+++ b/llvm/include/llvm/BinaryFormat/ELF.h@@ -1159,6 +1159,7 @@ enum : unsigned {   SHT_LLVM_OFFLOADING = 0x6fff4c0b,         // LLVM device offloading data.   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.   // 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.diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cppindex ec8b40261a6ca..c7c3df330fc94 100644--- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp+++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp@@ -571,7 +571,7 @@ bool ELFAsmParser::parseSectionArguments(bool IsPush, SMLoc loc) {         return TokError("expected end of directive");     }-    if (Mergeable)+    if (Mergeable || TypeName == "llvm_cfi_jump_table")       if (parseMergeSize(Size))         return true;     if (Flags & ELF::SHF_LINK_ORDER)@@ -637,6 +637,8 @@ bool ELFAsmParser::parseSectionArguments(bool IsPush, SMLoc loc) {       Type = ELF::SHT_LLVM_LTO;     else if (TypeName == "llvm_jt_sizes")       Type = ELF::SHT_LLVM_JT_SIZES;+    else if (TypeName == "llvm_cfi_jump_table")+      Type = ELF::SHT_LLVM_CFI_JUMP_TABLE;     else if (TypeName.getAsInteger(0, Type))       return TokError("unknown section type");   }diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cppindex ff99dc25abe07..28a7040ea8d56 100644--- a/llvm/lib/Object/ELF.cpp+++ b/llvm/lib/Object/ELF.cpp@@ -321,6 +321,7 @@ StringRef llvm::object::getELFSectionTypeName(uint32_t Machine, unsigned Type) {     STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_OFFLOADING);     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_GNU_ATTRIBUTES);     STRINGIFY_ENUM_CASE(ELF, SHT_GNU_HASH);     STRINGIFY_ENUM_CASE(ELF, SHT_GNU_verdef);diff --git a/llvm/test/MC/AsmParser/llvm_section_types.s b/llvm/test/MC/AsmParser/llvm_section_types.sindex 147b1499d2b88..1e644ced853b3 100644--- a/llvm/test/MC/AsmParser/llvm_section_types.s+++ b/llvm/test/MC/AsmParser/llvm_section_types.s@@ -17,6 +17,8 @@ .byte 1 .section    .section8,"",@llvm_lto .byte 1+.section    .section9,"",@llvm_cfi_jump_table,1+.byte 1  # CHECK:        Name: .section1 # CHECK-NEXT:   Type: SHT_LLVM_BB_ADDR_MAP@@ -34,3 +36,6 @@ # CHECK-NEXT:   Type: SHT_LLVM_OFFLOADING # CHECK:        Name: .section8 # CHECK-NEXT:   Type: SHT_LLVM_LTO+# CHECK:        Name: .section9+# CHECK-NEXT:   Type: SHT_LLVM_CFI_JUMP_TABLE+# CHECK:        EntrySize: 1

@llvmbot
Copy link
Member

@llvm/pr-subscribers-llvm-binary-utilities

Author: Peter Collingbourne (pcc)

Changes

For context see main pull request: #147424.


Full diff:https://github.com/llvm/llvm-project/pull/149259.diff

5 Files Affected:

  • (modified) llvm/docs/Extensions.rst (+20)
  • (modified) llvm/include/llvm/BinaryFormat/ELF.h (+1)
  • (modified) llvm/lib/MC/MCParser/ELFAsmParser.cpp (+3-1)
  • (modified) llvm/lib/Object/ELF.cpp (+1)
  • (modified) llvm/test/MC/AsmParser/llvm_section_types.s (+5)
diff --git a/llvm/docs/Extensions.rst b/llvm/docs/Extensions.rstindex bad72c6ca8295..d8fb87b6998ad 100644--- a/llvm/docs/Extensions.rst+++ b/llvm/docs/Extensions.rst@@ -581,6 +581,26 @@ This section stores pairs of (jump table address, number of entries). This information is useful for tools that need to statically reconstruct the control flow of executables.+``SHT_LLVM_CFI_JUMP_TABLE`` Section (CFI jump table)+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^+This section contains the instructions that make up a `CFI jump table`_.+It is expected to be ``SHF_ALLOC`` and may be laid out like a normal+section. The ``SHT_LLVM_CFI_JUMP_TABLE`` section type gives the linker+permission to modify the section in ways that would not normally be+permitted, in order to optimize calls via the jump table.++Each ``sh_entsize`` sized slice of a section of this type containing+exactly one relocation may be considered to be a jump table entry+that branches to the target of the relocation. This allows the linker+to replace the jump table entry with the function body if it is small+enough, or if the function is the last function in the jump table.++A section of this type does not have to be placed according to its+name. The linker may place the section in whichever output section it+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+ CodeView-Dependent ------------------diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.hindex ebb257ab33821..b9e38801d880f 100644--- a/llvm/include/llvm/BinaryFormat/ELF.h+++ b/llvm/include/llvm/BinaryFormat/ELF.h@@ -1159,6 +1159,7 @@ enum : unsigned {   SHT_LLVM_OFFLOADING = 0x6fff4c0b,         // LLVM device offloading data.   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.   // 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.diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cppindex ec8b40261a6ca..c7c3df330fc94 100644--- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp+++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp@@ -571,7 +571,7 @@ bool ELFAsmParser::parseSectionArguments(bool IsPush, SMLoc loc) {         return TokError("expected end of directive");     }-    if (Mergeable)+    if (Mergeable || TypeName == "llvm_cfi_jump_table")       if (parseMergeSize(Size))         return true;     if (Flags & ELF::SHF_LINK_ORDER)@@ -637,6 +637,8 @@ bool ELFAsmParser::parseSectionArguments(bool IsPush, SMLoc loc) {       Type = ELF::SHT_LLVM_LTO;     else if (TypeName == "llvm_jt_sizes")       Type = ELF::SHT_LLVM_JT_SIZES;+    else if (TypeName == "llvm_cfi_jump_table")+      Type = ELF::SHT_LLVM_CFI_JUMP_TABLE;     else if (TypeName.getAsInteger(0, Type))       return TokError("unknown section type");   }diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cppindex ff99dc25abe07..28a7040ea8d56 100644--- a/llvm/lib/Object/ELF.cpp+++ b/llvm/lib/Object/ELF.cpp@@ -321,6 +321,7 @@ StringRef llvm::object::getELFSectionTypeName(uint32_t Machine, unsigned Type) {     STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_OFFLOADING);     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_GNU_ATTRIBUTES);     STRINGIFY_ENUM_CASE(ELF, SHT_GNU_HASH);     STRINGIFY_ENUM_CASE(ELF, SHT_GNU_verdef);diff --git a/llvm/test/MC/AsmParser/llvm_section_types.s b/llvm/test/MC/AsmParser/llvm_section_types.sindex 147b1499d2b88..1e644ced853b3 100644--- a/llvm/test/MC/AsmParser/llvm_section_types.s+++ b/llvm/test/MC/AsmParser/llvm_section_types.s@@ -17,6 +17,8 @@ .byte 1 .section    .section8,"",@llvm_lto .byte 1+.section    .section9,"",@llvm_cfi_jump_table,1+.byte 1  # CHECK:        Name: .section1 # CHECK-NEXT:   Type: SHT_LLVM_BB_ADDR_MAP@@ -34,3 +36,6 @@ # CHECK-NEXT:   Type: SHT_LLVM_OFFLOADING # CHECK:        Name: .section8 # CHECK-NEXT:   Type: SHT_LLVM_LTO+# CHECK:        Name: .section9+# CHECK-NEXT:   Type: SHT_LLVM_CFI_JUMP_TABLE+# CHECK:        EntrySize: 1

@pccpcc requested a review fromMaskRayJuly 17, 2025 06:12
Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1
@pccpcc merged commitb5e71d7 intomainJul 18, 2025
3 checks passed
@pccpcc deleted the users/pcc/spr/add-section-type-to-support-cfi-jump-table-relaxation branchJuly 18, 2025 17:48
llvm-syncbot pushed a commit to arm/arm-toolchain that referenced this pull requestJul 18, 2025
For context see main pull request: #147424.Reviewers: MaskRayReviewed By: MaskRayPull Request:llvm/llvm-project#149259
mdfazlay pushed a commit to mdfazlay/llvm-project that referenced this pull requestJul 18, 2025
For context see main pull request:llvm#147424.Reviewers: MaskRayReviewed By: MaskRayPull Request:llvm#149259
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@MaskRayMaskRayMaskRay approved these changes

Assignees
No one assigned
Labels
llvm:binary-utilitiesmcMachine (object) code
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@pcc@llvmbot@MaskRay

[8]ページ先頭

©2009-2025 Movatter.jp