llvm.org GIT mirror llvm / 3660a84
Behave like gnu as when a relocation crosses sections. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129850 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 9 years ago
2 changed file(s) with 41 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
646646
647647 COFFSection *coff_section = SectionMap[&SectionData->getSection()];
648648 COFFSymbol *coff_symbol = SymbolMap[&A_SD.getSymbol()];
649 const MCSymbolRefExpr *SymA = Target.getSymA();
650 const MCSymbolRefExpr *SymB = Target.getSymB();
651 const bool CrossSection = SymB &&
652 &SymA->getSymbol().getSection() != &SymB->getSymbol().getSection();
649653
650654 if (Target.getSymB()) {
651 if (&Target.getSymA()->getSymbol().getSection()
652 != &Target.getSymB()->getSymbol().getSection()) {
653 llvm_unreachable("Symbol relative relocations are only allowed between "
654 "symbols in the same section");
655 }
656655 const MCSymbol *B = &Target.getSymB()->getSymbol();
657656 MCSymbolData &B_SD = Asm.getSymbolData(*B);
658657
661660 // In the case where we have SymbA and SymB, we just need to store the delta
662661 // between the two symbols. Update FixedValue to account for the delta, and
663662 // skip recording the relocation.
664 return;
663 if (!CrossSection)
664 return;
665665 } else {
666666 FixedValue = Target.getConstant();
667667 }
672672 Reloc.Data.VirtualAddress = Layout.getFragmentOffset(Fragment);
673673
674674 // Turn relocations for temporary symbols into section relocations.
675 if (coff_symbol->MCData->getSymbol().isTemporary()) {
675 if (coff_symbol->MCData->getSymbol().isTemporary() || CrossSection) {
676676 Reloc.Symb = coff_symbol->Section->Symbol;
677677 FixedValue += Layout.getFragmentOffset(coff_symbol->MCData->Fragment)
678678 + coff_symbol->MCData->getOffset();
683683
684684 Reloc.Data.VirtualAddress += Fixup.getOffset();
685685
686 switch ((unsigned)Fixup.getKind()) {
686 unsigned FixupKind = Fixup.getKind();
687
688 if (CrossSection)
689 FixupKind = FK_PCRel_4;
690
691 switch (FixupKind) {
687692 case FK_PCRel_4:
688693 case X86::reloc_riprel_4byte:
689694 case X86::reloc_riprel_4byte_movq_load:
0 // RUN: llvm-mc -filetype=obj -triple i686-pc-mingw32 %s | coff-dump.py | FileCheck %s
1
2 .def _foobar;
3 .scl 2;
4 .type 32;
5 .endef
6 .text
7 .globl _foobar
8 .align 16, 0x90
9 _foobar: # @foobar
10 # BB#0:
11 ret
12
13 .data
14 .globl _rust_crate # @rust_crate
15 .align 4
16 _rust_crate:
17 .long _foobar-_rust_crate
18
19
20 // CHECK: Relocations = [
21 // CHECK-NEXT: 0 = {
22 // CHECK-NEXT: VirtualAddress = 0x0
23 // CHECK-NEXT: SymbolTableIndex =
24 // CHECK-NEXT: Type = IMAGE_REL_I386_REL32 (20)
25 // CHECK-NEXT: SymbolName = .text
26 // CHECK-NEXT: }
27 // CHECK-NEXT: ]