~ubuntu-branches/ubuntu/trusty/llvm-toolchain-snapshot/trusty-201310232150

« back to all changes in this revision

Viewing changes to lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-27 15:01:57 UTC
  • mfrom: (0.10.1) (0.9.1) (0.8.1) (0.7.1) (0.6.1) (0.5.2)
  • Revision ID: package-import@ubuntu.com-20130527150157-tdkrsjpuvht7v0qx
Tags: 1:3.4~svn182733-1~exp1
* New snapshot release (3.4 release)
* Add a symlink of libLLVM-3.4.so.1 to usr/lib/llvm-3.4/lib/libLLVM-3.4.so
    to fix make the llvm-config-3.4 --libdir work (Closes: #708677)
  * Various packages rename to allow co installations:
    * libclang1 => libclang1-3.4
    * libclang1-dbg => libclang1-3.4-dbg
    * libclang-dev => libclang-3.4-dev
    * libclang-common-dev => libclang-common-3.4-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
151
151
 
152
152
namespace llvm {
153
153
 
 
154
StringRef RuntimeDyldELF::getEHFrameSection() {
 
155
  for (int i = 0, e = Sections.size(); i != e; ++i) {
 
156
    if (Sections[i].Name == ".eh_frame")
 
157
      return StringRef((const char*)Sections[i].Address, Sections[i].Size);
 
158
  }
 
159
  return StringRef();
 
160
}
 
161
 
154
162
ObjectImage *RuntimeDyldELF::createObjectImage(ObjectBuffer *Buffer) {
155
163
  if (Buffer->getBufferSize() < ELF::EI_NIDENT)
156
164
    llvm_unreachable("Unexpected ELF object size");
269
277
  }
270
278
}
271
279
 
 
280
void RuntimeDyldELF::resolveAArch64Relocation(const SectionEntry &Section,
 
281
                                              uint64_t Offset,
 
282
                                              uint64_t Value,
 
283
                                              uint32_t Type,
 
284
                                              int64_t Addend) {
 
285
  uint32_t *TargetPtr = reinterpret_cast<uint32_t*>(Section.Address + Offset);
 
286
  uint64_t FinalAddress = Section.LoadAddress + Offset;
 
287
 
 
288
  DEBUG(dbgs() << "resolveAArch64Relocation, LocalAddress: 0x"
 
289
               << format("%llx", Section.Address + Offset)
 
290
               << " FinalAddress: 0x" << format("%llx",FinalAddress)
 
291
               << " Value: 0x" << format("%llx",Value)
 
292
               << " Type: 0x" << format("%x",Type)
 
293
               << " Addend: 0x" << format("%llx",Addend)
 
294
               << "\n");
 
295
 
 
296
  switch (Type) {
 
297
  default:
 
298
    llvm_unreachable("Relocation type not implemented yet!");
 
299
    break;
 
300
  case ELF::R_AARCH64_ABS64: {
 
301
    uint64_t *TargetPtr = reinterpret_cast<uint64_t*>(Section.Address + Offset);
 
302
    *TargetPtr = Value + Addend;
 
303
    break;
 
304
  }
 
305
  case ELF::R_AARCH64_PREL32: {
 
306
    uint64_t Result = Value + Addend - FinalAddress;
 
307
    assert(static_cast<int64_t>(Result) >= INT32_MIN && 
 
308
           static_cast<int64_t>(Result) <= UINT32_MAX);
 
309
    *TargetPtr = static_cast<uint32_t>(Result & 0xffffffffU);
 
310
    break;
 
311
  }
 
312
  case ELF::R_AARCH64_CALL26: // fallthrough
 
313
  case ELF::R_AARCH64_JUMP26: {
 
314
    // Operation: S+A-P. Set Call or B immediate value to bits fff_fffc of the
 
315
    // calculation.
 
316
    uint64_t BranchImm = Value + Addend - FinalAddress;
 
317
 
 
318
    // "Check that -2^27 <= result < 2^27".
 
319
    assert(-(1LL << 27) <= static_cast<int64_t>(BranchImm) && 
 
320
           static_cast<int64_t>(BranchImm) < (1LL << 27));
 
321
 
 
322
    // AArch64 code is emitted with .rela relocations. The data already in any
 
323
    // bits affected by the relocation on entry is garbage.
 
324
    *TargetPtr &= 0xfc000000U;
 
325
    // Immediate goes in bits 25:0 of B and BL.
 
326
    *TargetPtr |= static_cast<uint32_t>(BranchImm & 0xffffffcU) >> 2;
 
327
    break;
 
328
  }
 
329
  case ELF::R_AARCH64_MOVW_UABS_G3: {
 
330
    uint64_t Result = Value + Addend;
 
331
 
 
332
    // AArch64 code is emitted with .rela relocations. The data already in any
 
333
    // bits affected by the relocation on entry is garbage.
 
334
    *TargetPtr &= 0xff80001fU;
 
335
    // Immediate goes in bits 20:5 of MOVZ/MOVK instruction
 
336
    *TargetPtr |= Result >> (48 - 5);
 
337
    // Shift is "lsl #48", in bits 22:21
 
338
    *TargetPtr |= 3 << 21;
 
339
    break;
 
340
  }
 
341
  case ELF::R_AARCH64_MOVW_UABS_G2_NC: {
 
342
    uint64_t Result = Value + Addend;
 
343
 
 
344
 
 
345
    // AArch64 code is emitted with .rela relocations. The data already in any
 
346
    // bits affected by the relocation on entry is garbage.
 
347
    *TargetPtr &= 0xff80001fU;
 
348
    // Immediate goes in bits 20:5 of MOVZ/MOVK instruction
 
349
    *TargetPtr |= ((Result & 0xffff00000000ULL) >> (32 - 5));
 
350
    // Shift is "lsl #32", in bits 22:21
 
351
    *TargetPtr |= 2 << 21;
 
352
    break;
 
353
  }
 
354
  case ELF::R_AARCH64_MOVW_UABS_G1_NC: {
 
355
    uint64_t Result = Value + Addend;
 
356
 
 
357
    // AArch64 code is emitted with .rela relocations. The data already in any
 
358
    // bits affected by the relocation on entry is garbage.
 
359
    *TargetPtr &= 0xff80001fU;
 
360
    // Immediate goes in bits 20:5 of MOVZ/MOVK instruction
 
361
    *TargetPtr |= ((Result & 0xffff0000U) >> (16 - 5));
 
362
    // Shift is "lsl #16", in bits 22:21
 
363
    *TargetPtr |= 1 << 21;
 
364
    break;
 
365
  }
 
366
  case ELF::R_AARCH64_MOVW_UABS_G0_NC: {
 
367
    uint64_t Result = Value + Addend;
 
368
 
 
369
    // AArch64 code is emitted with .rela relocations. The data already in any
 
370
    // bits affected by the relocation on entry is garbage.
 
371
    *TargetPtr &= 0xff80001fU;
 
372
    // Immediate goes in bits 20:5 of MOVZ/MOVK instruction
 
373
    *TargetPtr |= ((Result & 0xffffU) << 5);
 
374
    // Shift is "lsl #0", in bits 22:21. No action needed.
 
375
    break;
 
376
  }
 
377
  }
 
378
}
 
379
 
 
380
// FIXME: PR16013: this routine needs modification to handle repeated relocations.
272
381
void RuntimeDyldELF::resolveARMRelocation(const SectionEntry &Section,
273
382
                                          uint64_t Offset,
274
383
                                          uint32_t Value,
304
413
    // We are not expecting any other addend in the relocation address.
305
414
    // Using 0x000F0FFF because MOVW has its 16 bit immediate split into 2
306
415
    // non-contiguous fields.
307
 
    assert((*TargetPtr & 0x000F0FFF) == 0);
308
416
    Value = Value & 0xFFFF;
 
417
    *TargetPtr &= ~0x000F0FFF; // Not really right; see FIXME at top.
309
418
    *TargetPtr |= Value & 0xFFF;
310
419
    *TargetPtr |= ((Value >> 12) & 0xF) << 16;
311
420
    break;
315
424
  case ELF::R_ARM_MOVT_ABS :
316
425
    // We are not expecting any other addend in the relocation address.
317
426
    // Use 0x000F0FFF for the same reason as R_ARM_MOVW_ABS_NC.
318
 
    assert((*TargetPtr & 0x000F0FFF) == 0);
319
427
    Value = (Value >> 16) & 0xFFFF;
 
428
    *TargetPtr &= ~0x000F0FFF; // Not really right; see FIXME at top.
320
429
    *TargetPtr |= Value & 0xFFF;
321
430
    *TargetPtr |= ((Value >> 12) & 0xF) << 16;
322
431
    break;
432
541
 
433
542
      SymbolRef TargetSymbol;
434
543
      uint64_t TargetSymbolOffset;
435
 
      int64_t TargetAdditionalInfo;
436
544
      check(i->getSymbol(TargetSymbol));
437
545
      check(i->getOffset(TargetSymbolOffset));
438
 
      check(i->getAdditionalInfo(TargetAdditionalInfo));
 
546
      int64_t Addend;
 
547
      check(getELFRelocationAddend(*i, Addend));
439
548
 
440
549
      i = i.increment(err);
441
550
      if (i == e)
457
566
      section_iterator tsi(Obj.end_sections());
458
567
      check(TargetSymbol.getSection(tsi));
459
568
      Rel.SectionID = findOrEmitSection(Obj, (*tsi), true, LocalSections);
460
 
      Rel.Addend = (intptr_t)TargetAdditionalInfo;
 
569
      Rel.Addend = (intptr_t)Addend;
461
570
      return;
462
571
    }
463
572
  }
541
650
      llvm_unreachable("Relocation R_PPC64_REL32 overflow");
542
651
    writeInt32BE(LocalAddress, delta);
543
652
  } break;
 
653
  case ELF::R_PPC64_REL64: {
 
654
    uint64_t FinalAddress = (Section.LoadAddress + Offset);
 
655
    uint64_t Delta = Value - FinalAddress + Addend;
 
656
    writeInt64BE(LocalAddress, Delta);
 
657
  } break;
544
658
  case ELF::R_PPC64_ADDR64 :
545
659
    writeInt64BE(LocalAddress, Value + Addend);
546
660
    break;
560
674
  }
561
675
}
562
676
 
 
677
void RuntimeDyldELF::resolveSystemZRelocation(const SectionEntry &Section,
 
678
                                              uint64_t Offset,
 
679
                                              uint64_t Value,
 
680
                                              uint32_t Type,
 
681
                                              int64_t Addend) {
 
682
  uint8_t *LocalAddress = Section.Address + Offset;
 
683
  switch (Type) {
 
684
  default:
 
685
    llvm_unreachable("Relocation type not implemented yet!");
 
686
    break;
 
687
  case ELF::R_390_PC16DBL:
 
688
  case ELF::R_390_PLT16DBL: {
 
689
    int64_t Delta = (Value + Addend) - (Section.LoadAddress + Offset);
 
690
    assert(int16_t(Delta / 2) * 2 == Delta && "R_390_PC16DBL overflow");
 
691
    writeInt16BE(LocalAddress, Delta / 2);
 
692
    break;
 
693
  }
 
694
  case ELF::R_390_PC32DBL:
 
695
  case ELF::R_390_PLT32DBL: {
 
696
    int64_t Delta = (Value + Addend) - (Section.LoadAddress + Offset);
 
697
    assert(int32_t(Delta / 2) * 2 == Delta && "R_390_PC32DBL overflow");
 
698
    writeInt32BE(LocalAddress, Delta / 2);
 
699
    break;
 
700
  }
 
701
  case ELF::R_390_PC32: {
 
702
    int64_t Delta = (Value + Addend) - (Section.LoadAddress + Offset);
 
703
    assert(int32_t(Delta) == Delta && "R_390_PC32 overflow");
 
704
    writeInt32BE(LocalAddress, Delta);
 
705
    break;
 
706
  }
 
707
  case ELF::R_390_64:
 
708
    writeInt64BE(LocalAddress, Value + Addend);
 
709
    break;
 
710
  }
 
711
}
 
712
 
 
713
void RuntimeDyldELF::resolveRelocation(const RelocationEntry &RE,
 
714
                                       uint64_t Value) {
 
715
  const SectionEntry &Section = Sections[RE.SectionID];
 
716
  return resolveRelocation(Section, RE.Offset, Value, RE.RelType, RE.Addend);
 
717
}
 
718
 
563
719
void RuntimeDyldELF::resolveRelocation(const SectionEntry &Section,
564
720
                                       uint64_t Offset,
565
721
                                       uint64_t Value,
574
730
                         (uint32_t)(Value & 0xffffffffL), Type,
575
731
                         (uint32_t)(Addend & 0xffffffffL));
576
732
    break;
 
733
  case Triple::aarch64:
 
734
    resolveAArch64Relocation(Section, Offset, Value, Type, Addend);
 
735
    break;
577
736
  case Triple::arm:    // Fall through.
578
737
  case Triple::thumb:
579
738
    resolveARMRelocation(Section, Offset,
589
748
  case Triple::ppc64:
590
749
    resolvePPC64Relocation(Section, Offset, Value, Type, Addend);
591
750
    break;
 
751
  case Triple::systemz:
 
752
    resolveSystemZRelocation(Section, Offset, Value, Type, Addend);
 
753
    break;
592
754
  default: llvm_unreachable("Unsupported CPU type!");
593
755
  }
594
756
}
595
757
 
596
 
void RuntimeDyldELF::processRelocationRef(const ObjRelocationInfo &Rel,
 
758
void RuntimeDyldELF::processRelocationRef(unsigned SectionID,
 
759
                                          RelocationRef RelI,
597
760
                                          ObjectImage &Obj,
598
761
                                          ObjSectionToIDMap &ObjSectionToID,
599
762
                                          const SymbolTableMap &Symbols,
600
763
                                          StubMap &Stubs) {
601
 
 
602
 
  uint32_t RelType = (uint32_t)(Rel.Type & 0xffffffffL);
603
 
  intptr_t Addend = (intptr_t)Rel.AdditionalInfo;
604
 
  const SymbolRef &Symbol = Rel.Symbol;
 
764
  uint64_t RelType;
 
765
  Check(RelI.getType(RelType));
 
766
  int64_t Addend;
 
767
  Check(getELFRelocationAddend(RelI, Addend));
 
768
  SymbolRef Symbol;
 
769
  Check(RelI.getSymbol(Symbol));
605
770
 
606
771
  // Obtain the symbol name which is referenced in the relocation
607
772
  StringRef TargetName;
657
822
      }
658
823
    }
659
824
  }
660
 
  DEBUG(dbgs() << "\t\tRel.SectionID: " << Rel.SectionID
661
 
               << " Rel.Offset: " << Rel.Offset
 
825
  uint64_t Offset;
 
826
  Check(RelI.getOffset(Offset));
 
827
 
 
828
  DEBUG(dbgs() << "\t\tSectionID: " << SectionID
 
829
               << " Offset: " << Offset
662
830
               << "\n");
663
 
  if (Arch == Triple::arm &&
 
831
  if (Arch == Triple::aarch64 &&
 
832
      (RelType == ELF::R_AARCH64_CALL26 ||
 
833
       RelType == ELF::R_AARCH64_JUMP26)) {
 
834
    // This is an AArch64 branch relocation, need to use a stub function.
 
835
    DEBUG(dbgs() << "\t\tThis is an AArch64 branch relocation.");
 
836
    SectionEntry &Section = Sections[SectionID];
 
837
 
 
838
    // Look for an existing stub.
 
839
    StubMap::const_iterator i = Stubs.find(Value);
 
840
    if (i != Stubs.end()) {
 
841
        resolveRelocation(Section, Offset,
 
842
                          (uint64_t)Section.Address + i->second, RelType, 0);
 
843
      DEBUG(dbgs() << " Stub function found\n");
 
844
    } else {
 
845
      // Create a new stub function.
 
846
      DEBUG(dbgs() << " Create a new stub function\n");
 
847
      Stubs[Value] = Section.StubOffset;
 
848
      uint8_t *StubTargetAddr = createStubFunction(Section.Address +
 
849
                                                   Section.StubOffset);
 
850
 
 
851
      RelocationEntry REmovz_g3(SectionID,
 
852
                                StubTargetAddr - Section.Address,
 
853
                                ELF::R_AARCH64_MOVW_UABS_G3, Value.Addend);
 
854
      RelocationEntry REmovk_g2(SectionID,
 
855
                                StubTargetAddr - Section.Address + 4,
 
856
                                ELF::R_AARCH64_MOVW_UABS_G2_NC, Value.Addend);
 
857
      RelocationEntry REmovk_g1(SectionID,
 
858
                                StubTargetAddr - Section.Address + 8,
 
859
                                ELF::R_AARCH64_MOVW_UABS_G1_NC, Value.Addend);
 
860
      RelocationEntry REmovk_g0(SectionID,
 
861
                                StubTargetAddr - Section.Address + 12,
 
862
                                ELF::R_AARCH64_MOVW_UABS_G0_NC, Value.Addend);
 
863
 
 
864
      if (Value.SymbolName) {
 
865
        addRelocationForSymbol(REmovz_g3, Value.SymbolName);
 
866
        addRelocationForSymbol(REmovk_g2, Value.SymbolName);
 
867
        addRelocationForSymbol(REmovk_g1, Value.SymbolName);
 
868
        addRelocationForSymbol(REmovk_g0, Value.SymbolName);
 
869
      } else {
 
870
        addRelocationForSection(REmovz_g3, Value.SectionID);
 
871
        addRelocationForSection(REmovk_g2, Value.SectionID);
 
872
        addRelocationForSection(REmovk_g1, Value.SectionID);
 
873
        addRelocationForSection(REmovk_g0, Value.SectionID);
 
874
      }
 
875
      resolveRelocation(Section, Offset,
 
876
                        (uint64_t)Section.Address + Section.StubOffset,
 
877
                        RelType, 0);
 
878
      Section.StubOffset += getMaxStubSize();
 
879
    }
 
880
  } else if (Arch == Triple::arm &&
664
881
      (RelType == ELF::R_ARM_PC24 ||
665
882
       RelType == ELF::R_ARM_CALL ||
666
883
       RelType == ELF::R_ARM_JUMP24)) {
667
884
    // This is an ARM branch relocation, need to use a stub function.
668
885
    DEBUG(dbgs() << "\t\tThis is an ARM branch relocation.");
669
 
    SectionEntry &Section = Sections[Rel.SectionID];
 
886
    SectionEntry &Section = Sections[SectionID];
670
887
 
671
888
    // Look for an existing stub.
672
889
    StubMap::const_iterator i = Stubs.find(Value);
673
890
    if (i != Stubs.end()) {
674
 
        resolveRelocation(Section, Rel.Offset,
 
891
        resolveRelocation(Section, Offset,
675
892
                          (uint64_t)Section.Address + i->second, RelType, 0);
676
893
      DEBUG(dbgs() << " Stub function found\n");
677
894
    } else {
680
897
      Stubs[Value] = Section.StubOffset;
681
898
      uint8_t *StubTargetAddr = createStubFunction(Section.Address +
682
899
                                                   Section.StubOffset);
683
 
      RelocationEntry RE(Rel.SectionID, StubTargetAddr - Section.Address,
 
900
      RelocationEntry RE(SectionID, StubTargetAddr - Section.Address,
684
901
                         ELF::R_ARM_ABS32, Value.Addend);
685
902
      if (Value.SymbolName)
686
903
        addRelocationForSymbol(RE, Value.SymbolName);
687
904
      else
688
905
        addRelocationForSection(RE, Value.SectionID);
689
906
 
690
 
      resolveRelocation(Section, Rel.Offset,
 
907
      resolveRelocation(Section, Offset,
691
908
                        (uint64_t)Section.Address + Section.StubOffset,
692
909
                        RelType, 0);
693
910
      Section.StubOffset += getMaxStubSize();
696
913
             RelType == ELF::R_MIPS_26) {
697
914
    // This is an Mips branch relocation, need to use a stub function.
698
915
    DEBUG(dbgs() << "\t\tThis is a Mips branch relocation.");
699
 
    SectionEntry &Section = Sections[Rel.SectionID];
700
 
    uint8_t *Target = Section.Address + Rel.Offset;
 
916
    SectionEntry &Section = Sections[SectionID];
 
917
    uint8_t *Target = Section.Address + Offset;
701
918
    uint32_t *TargetAddress = (uint32_t *)Target;
702
919
 
703
920
    // Extract the addend from the instruction.
708
925
    //  Look up for existing stub.
709
926
    StubMap::const_iterator i = Stubs.find(Value);
710
927
    if (i != Stubs.end()) {
711
 
      resolveRelocation(Section, Rel.Offset,
 
928
      resolveRelocation(Section, Offset,
712
929
                        (uint64_t)Section.Address + i->second, RelType, 0);
713
930
      DEBUG(dbgs() << " Stub function found\n");
714
931
    } else {
719
936
                                                   Section.StubOffset);
720
937
 
721
938
      // Creating Hi and Lo relocations for the filled stub instructions.
722
 
      RelocationEntry REHi(Rel.SectionID,
 
939
      RelocationEntry REHi(SectionID,
723
940
                           StubTargetAddr - Section.Address,
724
941
                           ELF::R_MIPS_HI16, Value.Addend);
725
 
      RelocationEntry RELo(Rel.SectionID,
 
942
      RelocationEntry RELo(SectionID,
726
943
                           StubTargetAddr - Section.Address + 4,
727
944
                           ELF::R_MIPS_LO16, Value.Addend);
728
945
 
734
951
        addRelocationForSection(RELo, Value.SectionID);
735
952
      }
736
953
 
737
 
      resolveRelocation(Section, Rel.Offset,
 
954
      resolveRelocation(Section, Offset,
738
955
                        (uint64_t)Section.Address + Section.StubOffset,
739
956
                        RelType, 0);
740
957
      Section.StubOffset += getMaxStubSize();
744
961
      // A PPC branch relocation will need a stub function if the target is
745
962
      // an external symbol (Symbol::ST_Unknown) or if the target address
746
963
      // is not within the signed 24-bits branch address.
747
 
      SectionEntry &Section = Sections[Rel.SectionID];
748
 
      uint8_t *Target = Section.Address + Rel.Offset;
 
964
      SectionEntry &Section = Sections[SectionID];
 
965
      uint8_t *Target = Section.Address + Offset;
749
966
      bool RangeOverflow = false;
750
967
      if (SymType != SymbolRef::ST_Unknown) {
751
968
        // A function call may points to the .opd entry, so the final symbol value
755
972
        int32_t delta = static_cast<int32_t>(Target - RelocTarget);
756
973
        // If it is within 24-bits branch range, just set the branch target
757
974
        if (SignExtend32<24>(delta) == delta) {
758
 
          RelocationEntry RE(Rel.SectionID, Rel.Offset, RelType, Value.Addend);
 
975
          RelocationEntry RE(SectionID, Offset, RelType, Value.Addend);
759
976
          if (Value.SymbolName)
760
977
            addRelocationForSymbol(RE, Value.SymbolName);
761
978
          else
770
987
        StubMap::const_iterator i = Stubs.find(Value);
771
988
        if (i != Stubs.end()) {
772
989
          // Symbol function stub already created, just relocate to it
773
 
          resolveRelocation(Section, Rel.Offset,
 
990
          resolveRelocation(Section, Offset,
774
991
                            (uint64_t)Section.Address + i->second, RelType, 0);
775
992
          DEBUG(dbgs() << " Stub function found\n");
776
993
        } else {
779
996
          Stubs[Value] = Section.StubOffset;
780
997
          uint8_t *StubTargetAddr = createStubFunction(Section.Address +
781
998
                                                       Section.StubOffset);
782
 
          RelocationEntry RE(Rel.SectionID, StubTargetAddr - Section.Address,
 
999
          RelocationEntry RE(SectionID, StubTargetAddr - Section.Address,
783
1000
                             ELF::R_PPC64_ADDR64, Value.Addend);
784
1001
 
785
1002
          // Generates the 64-bits address loads as exemplified in section
786
1003
          // 4.5.1 in PPC64 ELF ABI.
787
 
          RelocationEntry REhst(Rel.SectionID,
 
1004
          RelocationEntry REhst(SectionID,
788
1005
                                StubTargetAddr - Section.Address + 2,
789
1006
                                ELF::R_PPC64_ADDR16_HIGHEST, Value.Addend);
790
 
          RelocationEntry REhr(Rel.SectionID,
 
1007
          RelocationEntry REhr(SectionID,
791
1008
                               StubTargetAddr - Section.Address + 6,
792
1009
                               ELF::R_PPC64_ADDR16_HIGHER, Value.Addend);
793
 
          RelocationEntry REh(Rel.SectionID,
 
1010
          RelocationEntry REh(SectionID,
794
1011
                              StubTargetAddr - Section.Address + 14,
795
1012
                              ELF::R_PPC64_ADDR16_HI, Value.Addend);
796
 
          RelocationEntry REl(Rel.SectionID,
 
1013
          RelocationEntry REl(SectionID,
797
1014
                              StubTargetAddr - Section.Address + 18,
798
1015
                              ELF::R_PPC64_ADDR16_LO, Value.Addend);
799
1016
 
809
1026
            addRelocationForSection(REl,   Value.SectionID);
810
1027
          }
811
1028
 
812
 
          resolveRelocation(Section, Rel.Offset,
 
1029
          resolveRelocation(Section, Offset,
813
1030
                            (uint64_t)Section.Address + Section.StubOffset,
814
1031
                            RelType, 0);
815
1032
          if (SymType == SymbolRef::ST_Unknown)
819
1036
        }
820
1037
      }
821
1038
    } else {
822
 
      RelocationEntry RE(Rel.SectionID, Rel.Offset, RelType, Value.Addend);
 
1039
      RelocationEntry RE(SectionID, Offset, RelType, Value.Addend);
823
1040
      // Extra check to avoid relocation againt empty symbols (usually
824
1041
      // the R_PPC64_TOC).
825
1042
      if (Value.SymbolName && !TargetName.empty())
827
1044
      else
828
1045
        addRelocationForSection(RE, Value.SectionID);
829
1046
    }
 
1047
  } else if (Arch == Triple::systemz &&
 
1048
             (RelType == ELF::R_390_PLT32DBL ||
 
1049
              RelType == ELF::R_390_GOTENT)) {
 
1050
    // Create function stubs for both PLT and GOT references, regardless of
 
1051
    // whether the GOT reference is to data or code.  The stub contains the
 
1052
    // full address of the symbol, as needed by GOT references, and the
 
1053
    // executable part only adds an overhead of 8 bytes.
 
1054
    //
 
1055
    // We could try to conserve space by allocating the code and data
 
1056
    // parts of the stub separately.  However, as things stand, we allocate
 
1057
    // a stub for every relocation, so using a GOT in JIT code should be
 
1058
    // no less space efficient than using an explicit constant pool.
 
1059
    DEBUG(dbgs() << "\t\tThis is a SystemZ indirect relocation.");
 
1060
    SectionEntry &Section = Sections[SectionID];
 
1061
 
 
1062
    // Look for an existing stub.
 
1063
    StubMap::const_iterator i = Stubs.find(Value);
 
1064
    uintptr_t StubAddress;
 
1065
    if (i != Stubs.end()) {
 
1066
      StubAddress = uintptr_t(Section.Address) + i->second;
 
1067
      DEBUG(dbgs() << " Stub function found\n");
 
1068
    } else {
 
1069
      // Create a new stub function.
 
1070
      DEBUG(dbgs() << " Create a new stub function\n");
 
1071
 
 
1072
      uintptr_t BaseAddress = uintptr_t(Section.Address);
 
1073
      uintptr_t StubAlignment = getStubAlignment();
 
1074
      StubAddress = (BaseAddress + Section.StubOffset +
 
1075
                     StubAlignment - 1) & -StubAlignment;
 
1076
      unsigned StubOffset = StubAddress - BaseAddress;
 
1077
 
 
1078
      Stubs[Value] = StubOffset;
 
1079
      createStubFunction((uint8_t *)StubAddress);
 
1080
      RelocationEntry RE(SectionID, StubOffset + 8,
 
1081
                         ELF::R_390_64, Value.Addend - Addend);
 
1082
      if (Value.SymbolName)
 
1083
        addRelocationForSymbol(RE, Value.SymbolName);
 
1084
      else
 
1085
        addRelocationForSection(RE, Value.SectionID);
 
1086
      Section.StubOffset = StubOffset + getMaxStubSize();
 
1087
    }
 
1088
 
 
1089
    if (RelType == ELF::R_390_GOTENT)
 
1090
      resolveRelocation(Section, Offset, StubAddress + 8,
 
1091
                        ELF::R_390_PC32DBL, Addend);
 
1092
    else
 
1093
      resolveRelocation(Section, Offset, StubAddress, RelType, Addend);
830
1094
  } else {
831
 
    RelocationEntry RE(Rel.SectionID, Rel.Offset, RelType, Value.Addend);
 
1095
    RelocationEntry RE(SectionID, Offset, RelType, Value.Addend);
832
1096
    if (Value.SymbolName)
833
1097
      addRelocationForSymbol(RE, Value.SymbolName);
834
1098
    else
836
1100
  }
837
1101
}
838
1102
 
839
 
unsigned RuntimeDyldELF::getCommonSymbolAlignment(const SymbolRef &Sym) {
840
 
  // In ELF, the value of an SHN_COMMON symbol is its alignment requirement.
841
 
  uint64_t Align;
842
 
  Check(Sym.getValue(Align));
843
 
  return Align;
844
 
}
845
 
 
846
1103
bool RuntimeDyldELF::isCompatibleFormat(const ObjectBuffer *Buffer) const {
847
1104
  if (Buffer->getBufferSize() < strlen(ELF::ElfMagic))
848
1105
    return false;