[PATCH] D105217: [LLD] Adding support for RELA for CG Profile.
Alexander Yermolovich via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 30 11:28:03 PDT 2021
ayermolo created this revision.
ayermolo added a reviewer: MaskRay.
Herald added subscribers: hoy, modimo, wenlei, arichardson, emaste.
ayermolo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Looks like if we run strip -S it changes rel to rela. Changed so that LLD supports both REL and RELA for CG Profile.
This is follow up to https://reviews.llvm.org/D104080.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D105217
Files:
lld/ELF/Driver.cpp
lld/ELF/InputFiles.cpp
lld/ELF/InputFiles.h
Index: lld/ELF/InputFiles.h
===================================================================
--- lld/ELF/InputFiles.h
+++ lld/ELF/InputFiles.h
@@ -253,6 +253,8 @@
ArrayRef<Elf_CGProfile> cgProfile;
// SHT_LLVM_CALL_GRAPH_PROFILE relocations, always in the REL format.
ArrayRef<Elf_Rel> cgProfileRel;
+ // SHT_LLVM_CALL_GRAPH_PROFILE relocations, always in the RELA format.
+ ArrayRef<Elf_Rela> cgProfileRela;
// Get cached DWARF information.
DWARFCache *getDwarf();
Index: lld/ELF/InputFiles.cpp
===================================================================
--- lld/ELF/InputFiles.cpp
+++ lld/ELF/InputFiles.cpp
@@ -674,6 +674,8 @@
if (cgProfileSectionIndex && sec.sh_info == cgProfileSectionIndex) {
if (sec.sh_type == SHT_REL)
cgProfileRel = CHECK(getObj().rels(sec), this);
+ else
+ cgProfileRela = CHECK(getObj().relas(sec), this);
}
}
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -60,6 +60,7 @@
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/raw_ostream.h"
+#include <cstdint>
#include <cstdlib>
#include <utility>
@@ -855,22 +856,34 @@
}
}
+/// Retrieves symbol indices either from REL or RELA section.
+template <class ELFTRel>
+static void getIndices(SmallVector<uint32_t, 128> &symbolIndices,
+ ArrayRef<ELFTRel> cgProfileRel) {
+ for (const ELFTRel &rel : cgProfileRel) {
+ symbolIndices.push_back(rel.getSymbol(config->isMips64EL));
+ }
+}
+
template <class ELFT> static void readCallGraphsFromObjectFiles() {
- auto getIndex = [&](ObjFile<ELFT> *obj, uint32_t index) {
- const Elf_Rel_Impl<ELFT, false> &rel = obj->cgProfileRel[index];
- return rel.getSymbol(config->isMips64EL);
- };
+ SmallVector<uint32_t, 128> symbolIndices;
for (auto file : objectFiles) {
auto *obj = cast<ObjFile<ELFT>>(file);
- if (obj->cgProfileRel.empty())
+ if (obj->cgProfileRel.empty() && obj->cgProfileRela.empty())
continue;
- if (obj->cgProfileRel.size() != obj->cgProfile.size() * 2)
+ symbolIndices.clear();
+ if (!obj->cgProfileRel.empty())
+ getIndices(symbolIndices, obj->cgProfileRel);
+ else
+ getIndices(symbolIndices, obj->cgProfileRela);
+
+ if (symbolIndices.size() != obj->cgProfile.size() * 2)
fatal("number of relocations doesn't match Weights");
for (uint32_t i = 0, size = obj->cgProfile.size(); i < size; ++i) {
const Elf_CGProfile_Impl<ELFT> &cgpe = obj->cgProfile[i];
- uint32_t fromIndex = getIndex(obj, i * 2);
- uint32_t toIndex = getIndex(obj, i * 2 + 1);
+ uint32_t fromIndex = symbolIndices[i * 2];
+ uint32_t toIndex = symbolIndices[i * 2 + 1];
auto *fromSym = dyn_cast<Defined>(&obj->getSymbol(fromIndex));
auto *toSym = dyn_cast<Defined>(&obj->getSymbol(toIndex));
if (!fromSym || !toSym)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105217.355641.patch
Type: text/x-patch
Size: 3006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210630/9c345701/attachment.bin>
More information about the llvm-commits
mailing list