[lld] 0766a59 - [ELF] .llvm.call-graph-profile: support CREL
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 8 00:57:47 PDT 2024
Author: Fangrui Song
Date: 2024-08-08T00:57:43-07:00
New Revision: 0766a59be3256e83a454a089f01215d6c7f94a48
URL: https://github.com/llvm/llvm-project/commit/0766a59be3256e83a454a089f01215d6c7f94a48
DIFF: https://github.com/llvm/llvm-project/commit/0766a59be3256e83a454a089f01215d6c7f94a48.diff
LOG: [ELF] .llvm.call-graph-profile: support CREL
https://reviews.llvm.org/D105217 added RELA support. This patch adds
CREL support.
Added:
Modified:
lld/ELF/Driver.cpp
lld/test/ELF/cgprofile-rela.test
Removed:
################################################################################
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index aeb8dcaa851b44..8aa2380ba3a177 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1003,6 +1003,15 @@ processCallGraphRelocations(SmallVector<uint32_t, 32> &symbolIndices,
for (size_t i = 0, e = objSections.size(); i < e; ++i) {
const Elf_Shdr_Impl<ELFT> &sec = objSections[i];
if (sec.sh_info == inputObj->cgProfileSectionIndex) {
+ if (sec.sh_type == SHT_CREL) {
+ auto crels =
+ CHECK(obj.crels(sec), "could not retrieve cg profile rela section");
+ for (const auto &rel : crels.first)
+ symbolIndices.push_back(rel.getSymbol(false));
+ for (const auto &rel : crels.second)
+ symbolIndices.push_back(rel.getSymbol(false));
+ break;
+ }
if (sec.sh_type == SHT_RELA) {
ArrayRef<typename ELFT::Rela> relas =
CHECK(obj.relas(sec), "could not retrieve cg profile rela section");
diff --git a/lld/test/ELF/cgprofile-rela.test b/lld/test/ELF/cgprofile-rela.test
index 141dfd4c65b1ea..87dad02940b98b 100644
--- a/lld/test/ELF/cgprofile-rela.test
+++ b/lld/test/ELF/cgprofile-rela.test
@@ -8,6 +8,10 @@
# RUN: ld.lld --no-call-graph-profile-sort %t.o -o %t
# RUN: llvm-nm --no-sort %t | FileCheck %s --check-prefix=NO-CG
+# RUN: yaml2obj -DTYPE=SHT_CREL %s -o %tcrel.o
+# RUN: ld.lld --call-graph-profile-sort=hfsort %tcrel.o -o %t
+# RUN: llvm-nm --no-sort %t | FileCheck %s
+
# CHECK: 0000000000201124 t D
# CHECK: 0000000000201122 t C
# CHECK: 0000000000201128 t B
@@ -60,7 +64,7 @@ Sections:
- Weight: 30
- Weight: 90
- Name: .rela.llvm.call-graph-profile
- Type: SHT_RELA
+ Type: [[TYPE=SHT_RELA]]
Info: .llvm.call-graph-profile
Relocations:
- Offset: 0x0
More information about the llvm-commits
mailing list