|
28 | 28 | #include "llvm/MC/MCExpr.h"
|
29 | 29 | #include "llvm/MC/MCInst.h"
|
30 | 30 | #include "llvm/MC/MCObjectWriter.h"
|
31 |
| -#include "llvm/MC/MCSection.h" |
| 31 | +#include "llvm/MC/MCSectionELF.h" |
32 | 32 | #include "llvm/MC/MCStreamer.h"
|
33 | 33 | #include "llvm/MC/MCSubtargetInfo.h"
|
34 | 34 | #include "llvm/MC/MCSymbolELF.h"
|
@@ -183,7 +183,7 @@ class AArch64ELFStreamer : public MCELFStreamer {
|
183 | 183 | std::move(Emitter)),
|
184 | 184 | MappingSymbolCounter(0), LastEMS(EMS_None) {}
|
185 | 185 |
|
186 |
| - void changeSection(MCSection *Section, uint32_t Subsection) override { |
| 186 | + void changeSection(MCSection *Section, uint32_t Subsection = 0) override { |
187 | 187 | // We have to keep track of the mapping symbol state of any sections we
|
188 | 188 | // use. Each one should start off as EMS_None, which is provided as the
|
189 | 189 | // default constructor by DenseMap::lookup.
|
@@ -248,6 +248,9 @@ class AArch64ELFStreamer : public MCELFStreamer {
|
248 | 248 | emitDataMappingSymbol();
|
249 | 249 | MCObjectStreamer::emitFill(NumBytes, FillValue, Loc);
|
250 | 250 | }
|
| 251 | + |
| 252 | + void finishImpl() override; |
| 253 | + |
251 | 254 | private:
|
252 | 255 | enum ElfMappingSymbol {
|
253 | 256 | EMS_None,
|
@@ -284,6 +287,27 @@ class AArch64ELFStreamer : public MCELFStreamer {
|
284 | 287 | ElfMappingSymbol LastEMS;
|
285 | 288 | };
|
286 | 289 |
|
| 290 | +void AArch64ELFStreamer::finishImpl() { |
| 291 | + MCContext &Ctx = getContext(); |
| 292 | + auto &Asm = getAssembler(); |
| 293 | + MCSectionELF *MemtagSec = nullptr; |
| 294 | + const auto *Zero = MCConstantExpr::create(0, Ctx); |
| 295 | + for (const MCSymbol &Symbol : Asm.symbols()) { |
| 296 | + const auto &Sym = cast<MCSymbolELF>(Symbol); |
| 297 | + if (!Sym.isMemtag()) |
| 298 | + continue; |
| 299 | + if (!MemtagSec) { |
| 300 | + MemtagSec = Ctx.getELFSection(".memtag.globals.static", |
| 301 | + ELF::SHT_AARCH64_MEMTAG_GLOBALS_STATIC, 0); |
| 302 | + switchSection(MemtagSec); |
| 303 | + } |
| 304 | + auto *SRE = MCSymbolRefExpr::create(&Sym, MCSymbolRefExpr::VK_None, Ctx); |
| 305 | + (void)MCObjectStreamer::emitRelocDirective( |
| 306 | + *Zero, "BFD_RELOC_NONE", SRE, SMLoc(), *Ctx.getSubtargetInfo()); |
| 307 | + } |
| 308 | + MCELFStreamer::finishImpl(); |
| 309 | +} |
| 310 | + |
287 | 311 | } // end anonymous namespace
|
288 | 312 |
|
289 | 313 | AArch64ELFStreamer &AArch64TargetELFStreamer::getStreamer() {
|
|
0 commit comments