@@ -359,7 +359,7 @@ class X86MCCodeEmitter : public MCCodeEmitter {
359
359
unsigned getX86RegEncoding (const MCInst &MI, unsigned OpNum) const ;
360
360
361
361
void emitImmediate (const MCOperand &Disp, SMLoc Loc, unsigned ImmSize,
362
- MCFixupKind FixupKind, uint64_t StartByte,
362
+ unsigned FixupKind, uint64_t StartByte,
363
363
SmallVectorImpl<char > &CB,
364
364
SmallVectorImpl<MCFixup> &Fixups, int ImmOffset = 0 ) const ;
365
365
@@ -528,7 +528,7 @@ unsigned X86MCCodeEmitter::getX86RegEncoding(const MCInst &MI,
528
528
}
529
529
530
530
void X86MCCodeEmitter::emitImmediate (const MCOperand &DispOp, SMLoc Loc,
531
- unsigned Size, MCFixupKind FixupKind,
531
+ unsigned Size, unsigned FixupKind,
532
532
uint64_t StartByte,
533
533
SmallVectorImpl<char > &CB,
534
534
SmallVectorImpl<MCFixup> &Fixups,
@@ -549,65 +549,71 @@ void X86MCCodeEmitter::emitImmediate(const MCOperand &DispOp, SMLoc Loc,
549
549
550
550
// If we have an immoffset, add it to the expression.
551
551
if ((FixupKind == FK_Data_4 || FixupKind == FK_Data_8 ||
552
- FixupKind == MCFixupKind ( X86::reloc_signed_4byte) )) {
552
+ FixupKind == X86::reloc_signed_4byte)) {
553
553
GlobalOffsetTableExprKind Kind = startsWithGlobalOffsetTable (Expr);
554
554
if (Kind != GOT_None) {
555
555
assert (ImmOffset == 0 );
556
556
557
557
if (Size == 8 ) {
558
- FixupKind =
559
- MCFixupKind (FirstLiteralRelocationKind + ELF::R_X86_64_GOTPC64);
558
+ FixupKind = FirstLiteralRelocationKind + ELF::R_X86_64_GOTPC64;
560
559
} else {
561
560
assert (Size == 4 );
562
- FixupKind = MCFixupKind ( X86::reloc_global_offset_table) ;
561
+ FixupKind = X86::reloc_global_offset_table;
563
562
}
564
563
565
564
if (Kind == GOT_Normal)
566
565
ImmOffset = static_cast <int >(CB.size () - StartByte);
567
566
} else if (Expr->getKind () == MCExpr::SymbolRef) {
568
567
if (hasSecRelSymbolRef (Expr)) {
569
- FixupKind = MCFixupKind ( FK_SecRel_4) ;
568
+ FixupKind = FK_SecRel_4;
570
569
}
571
570
} else if (Expr->getKind () == MCExpr::Binary) {
572
571
const MCBinaryExpr *Bin = static_cast <const MCBinaryExpr *>(Expr);
573
572
if (hasSecRelSymbolRef (Bin->getLHS ()) ||
574
573
hasSecRelSymbolRef (Bin->getRHS ())) {
575
- FixupKind = MCFixupKind ( FK_SecRel_4) ;
574
+ FixupKind = FK_SecRel_4;
576
575
}
577
576
}
578
577
}
579
578
580
579
// If the fixup is pc-relative, we need to bias the value to be relative to
581
580
// the start of the field, not the end of the field.
582
- if (FixupKind == FK_PCRel_4 ||
583
- FixupKind == MCFixupKind (X86::reloc_riprel_4byte) ||
584
- FixupKind == MCFixupKind (X86::reloc_riprel_4byte_movq_load) ||
585
- FixupKind == MCFixupKind (X86::reloc_riprel_4byte_movq_load_rex2) ||
586
- FixupKind == MCFixupKind (X86::reloc_riprel_4byte_relax) ||
587
- FixupKind == MCFixupKind (X86::reloc_riprel_4byte_relax_rex) ||
588
- FixupKind == MCFixupKind (X86::reloc_riprel_4byte_relax_rex2) ||
589
- FixupKind == MCFixupKind (X86::reloc_branch_4byte_pcrel) ||
590
- FixupKind == MCFixupKind (X86::reloc_riprel_4byte_relax_evex)) {
581
+ bool PCRel = false ;
582
+ switch (FixupKind) {
583
+ case FK_PCRel_1:
584
+ PCRel = true ;
585
+ ImmOffset -= 1 ;
586
+ break ;
587
+ case FK_PCRel_2:
588
+ PCRel = true ;
589
+ ImmOffset -= 2 ;
590
+ break ;
591
+ case FK_PCRel_4:
592
+ case X86::reloc_riprel_4byte:
593
+ case X86::reloc_riprel_4byte_movq_load:
594
+ case X86::reloc_riprel_4byte_movq_load_rex2:
595
+ case X86::reloc_riprel_4byte_relax:
596
+ case X86::reloc_riprel_4byte_relax_rex:
597
+ case X86::reloc_riprel_4byte_relax_rex2:
598
+ case X86::reloc_branch_4byte_pcrel:
599
+ case X86::reloc_riprel_4byte_relax_evex:
600
+ PCRel = true ;
591
601
ImmOffset -= 4 ;
592
602
// If this is a pc-relative load off _GLOBAL_OFFSET_TABLE_:
593
603
// leaq _GLOBAL_OFFSET_TABLE_(%rip), %r15
594
604
// this needs to be a GOTPC32 relocation.
595
605
if (startsWithGlobalOffsetTable (Expr) != GOT_None)
596
- FixupKind = MCFixupKind (X86::reloc_global_offset_table);
606
+ FixupKind = X86::reloc_global_offset_table;
607
+ break ;
597
608
}
598
609
599
- if (FixupKind == FK_PCRel_2)
600
- ImmOffset -= 2 ;
601
- if (FixupKind == FK_PCRel_1)
602
- ImmOffset -= 1 ;
603
-
604
610
if (ImmOffset)
605
611
Expr = MCBinaryExpr::createAdd (Expr, MCConstantExpr::create (ImmOffset, Ctx),
606
612
Ctx, Expr->getLoc ());
607
613
608
614
// Emit a symbolic constant as a fixup and 4 zeros.
609
615
Fixups.push_back (MCFixup::create (static_cast <uint32_t >(CB.size () - StartByte),
610
- Expr, FixupKind));
616
+ Expr, FixupKind, PCRel ));
611
617
emitConstant (0 , Size, CB);
612
618
}
613
619
0 commit comments