aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/ELFObjectWriter.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-06-23 20:25:11 -0700
committerFangrui Song <i@maskray.me>2024-06-23 20:25:11 -0700
commit5997e7d748fdabe2abb7a19a5d9658622152e7d8 (patch)
tree0a24e69d1f6b64db50eee881fa57be3cd3dd3dab /llvm/lib/MC/ELFObjectWriter.cpp
parent4061354ab3157255238cf2664b9482bd6297dc83 (diff)
downloadllvm-5997e7d748fdabe2abb7a19a5d9658622152e7d8.zip
llvm-5997e7d748fdabe2abb7a19a5d9658622152e7d8.tar.gz
llvm-5997e7d748fdabe2abb7a19a5d9658622152e7d8.tar.bz2
Revert "[MC] Move ELFWriter::createMemtagRelocs to AArch64ELFStreamer::finishImpl"
This reverts commit 9d63506ddc6d60e220d967eb11779114075d401d. There is a heap-use-after-free.
Diffstat (limited to 'llvm/lib/MC/ELFObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 5724c5c..b8ef265 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -193,6 +193,8 @@ public:
MCSectionELF *createRelocationSection(MCContext &Ctx,
const MCSectionELF &Sec);
+ void createMemtagRelocs(MCAssembler &Asm);
+
void writeSectionHeader(const MCAsmLayout &Layout,
const SectionIndexMapTy &SectionIndexMap,
const SectionOffsetsTy &SectionOffsets);
@@ -614,6 +616,23 @@ bool ELFWriter::isInSymtab(const MCAsmLayout &Layout, const MCSymbolELF &Symbol,
return true;
}
+void ELFWriter::createMemtagRelocs(MCAssembler &Asm) {
+ MCSectionELF *MemtagRelocs = nullptr;
+ for (const MCSymbol &Sym : Asm.symbols()) {
+ const auto &SymE = cast<MCSymbolELF>(Sym);
+ if (!SymE.isMemtag())
+ continue;
+ if (MemtagRelocs == nullptr) {
+ MemtagRelocs = OWriter.TargetObjectWriter->getMemtagRelocsSection(Asm.getContext());
+ if (MemtagRelocs == nullptr)
+ report_fatal_error("Tagged globals are not available on this architecture.");
+ Asm.registerSection(*MemtagRelocs);
+ }
+ ELFRelocationEntry Rec(0, &SymE, ELF::R_AARCH64_NONE, 0, nullptr, 0);
+ OWriter.Relocations[MemtagRelocs].push_back(Rec);
+ }
+}
+
void ELFWriter::computeSymbolTable(
MCAssembler &Asm, const MCAsmLayout &Layout,
const SectionIndexMapTy &SectionIndexMap, const RevGroupMapTy &RevGroupMap,
@@ -1075,6 +1094,8 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
Ctx.getELFSection(".strtab", ELF::SHT_STRTAB, 0);
StringTableIndex = addToSectionTable(StrtabSection);
+ createMemtagRelocs(Asm);
+
RevGroupMapTy RevGroupMap;
SectionIndexMapTy SectionIndexMap;