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,7 @@ class AArch64ELFStreamer : public MCELFStreamer {
248
248
emitDataMappingSymbol ();
249
249
MCObjectStreamer::emitFill (NumBytes, FillValue, Loc);
250
250
}
251
+
251
252
private:
252
253
enum ElfMappingSymbol {
253
254
EMS_None,
@@ -283,7 +284,6 @@ class AArch64ELFStreamer : public MCELFStreamer {
283
284
DenseMap<const MCSection *, ElfMappingSymbol> LastMappingSymbols;
284
285
ElfMappingSymbol LastEMS;
285
286
};
286
-
287
287
} // end anonymous namespace
288
288
289
289
AArch64ELFStreamer &AArch64TargetELFStreamer::getStreamer () {
@@ -299,6 +299,37 @@ void AArch64TargetELFStreamer::emitDirectiveVariantPCS(MCSymbol *Symbol) {
299
299
cast<MCSymbolELF>(Symbol)->setOther (ELF::STO_AARCH64_VARIANT_PCS);
300
300
}
301
301
302
+ void AArch64TargetELFStreamer::finish () {
303
+ AArch64TargetStreamer::finish ();
304
+ AArch64ELFStreamer &S = getStreamer ();
305
+ MCContext &Ctx = S.getContext ();
306
+ auto &Asm = S.getAssembler ();
307
+ MCSectionELF *MemtagSec = nullptr ;
308
+ for (const MCSymbol &Symbol : Asm.symbols ()) {
309
+ const auto &Sym = cast<MCSymbolELF>(Symbol);
310
+ if (Sym.isMemtag ()) {
311
+ MemtagSec = Ctx.getELFSection (" .memtag.globals.static" ,
312
+ ELF::SHT_AARCH64_MEMTAG_GLOBALS_STATIC, 0 );
313
+ break ;
314
+ }
315
+ }
316
+ if (!MemtagSec)
317
+ return ;
318
+
319
+ // switchSection registers the section symbol and invalidates symbols(). We
320
+ // need a separate symbols() loop.
321
+ S.switchSection (MemtagSec);
322
+ const auto *Zero = MCConstantExpr::create (0 , Ctx);
323
+ for (const MCSymbol &Symbol : Asm.symbols ()) {
324
+ const auto &Sym = cast<MCSymbolELF>(Symbol);
325
+ if (!Sym.isMemtag ())
326
+ continue ;
327
+ auto *SRE = MCSymbolRefExpr::create (&Sym, MCSymbolRefExpr::VK_None, Ctx);
328
+ (void )S.emitRelocDirective (*Zero, " BFD_RELOC_NONE" , SRE, SMLoc (),
329
+ *Ctx.getSubtargetInfo ());
330
+ }
331
+ }
332
+
302
333
MCTargetStreamer *
303
334
llvm::createAArch64AsmTargetStreamer (MCStreamer &S, formatted_raw_ostream &OS,
304
335
MCInstPrinter *InstPrint,
0 commit comments