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

« back to all changes in this revision

Viewing changes to lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.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:
33
33
    virtual const MCSymbol *undefinedExplicitRelSym(const MCValue &Target,
34
34
                                                    const MCFixup &Fixup,
35
35
                                                    bool IsPCRel) const;
36
 
    virtual void adjustFixupOffset(const MCFixup &Fixup, uint64_t &RelocOffset);
37
 
 
38
 
    virtual void sortRelocs(const MCAssembler &Asm,
39
 
                            std::vector<ELFRelocationEntry> &Relocs);
40
 
  };
41
 
 
42
 
  class PPCELFRelocationEntry : public ELFRelocationEntry {
43
 
  public:
44
 
    PPCELFRelocationEntry(const ELFRelocationEntry &RE);
45
 
    bool operator<(const PPCELFRelocationEntry &RE) const {
46
 
      return (RE.r_offset < r_offset ||
47
 
              (RE.r_offset == r_offset && RE.Type > Type));
48
 
    }
49
36
  };
50
37
}
51
38
 
52
 
PPCELFRelocationEntry::PPCELFRelocationEntry(const ELFRelocationEntry &RE)
53
 
  : ELFRelocationEntry(RE.r_offset, RE.Index, RE.Type, RE.Symbol,
54
 
                       RE.r_addend, *RE.Fixup) {}
55
 
 
56
39
PPCELFObjectWriter::PPCELFObjectWriter(bool Is64Bit, uint8_t OSABI)
57
40
  : MCELFObjectTargetWriter(Is64Bit, OSABI,
58
41
                            Is64Bit ?  ELF::EM_PPC64 : ELF::EM_PPC,
77
60
    case PPC::fixup_ppc_br24:
78
61
      Type = ELF::R_PPC_REL24;
79
62
      break;
 
63
    case PPC::fixup_ppc_brcond14:
 
64
      Type = ELF::R_PPC_REL14;
 
65
      break;
80
66
    case FK_Data_4:
81
67
    case FK_PCRel_4:
82
68
      Type = ELF::R_PPC_REL32;
95
81
    case PPC::fixup_ppc_brcond14:
96
82
      Type = ELF::R_PPC_ADDR14; // XXX: or BRNTAKEN?_
97
83
      break;
98
 
    case PPC::fixup_ppc_ha16:
 
84
    case PPC::fixup_ppc_half16:
99
85
      switch (Modifier) {
100
86
      default: llvm_unreachable("Unsupported Modifier");
101
87
      case MCSymbolRefExpr::VK_PPC_TPREL16_HA:
104
90
      case MCSymbolRefExpr::VK_PPC_DTPREL16_HA:
105
91
        Type = ELF::R_PPC64_DTPREL16_HA;
106
92
        break;
107
 
      case MCSymbolRefExpr::VK_None:
 
93
      case MCSymbolRefExpr::VK_PPC_ADDR16_HA:
108
94
        Type = ELF::R_PPC_ADDR16_HA;
109
95
        break;
110
96
      case MCSymbolRefExpr::VK_PPC_TOC16_HA:
119
105
      case MCSymbolRefExpr::VK_PPC_GOT_TLSLD16_HA:
120
106
        Type = ELF::R_PPC64_GOT_TLSLD16_HA;
121
107
        break;
122
 
      }
123
 
      break;
124
 
    case PPC::fixup_ppc_lo16:
125
 
      switch (Modifier) {
126
 
      default: llvm_unreachable("Unsupported Modifier");
127
108
      case MCSymbolRefExpr::VK_PPC_TPREL16_LO:
128
109
        Type = ELF::R_PPC_TPREL16_LO;
129
110
        break;
131
112
        Type = ELF::R_PPC64_DTPREL16_LO;
132
113
        break;
133
114
      case MCSymbolRefExpr::VK_None:
 
115
        Type = ELF::R_PPC_ADDR16;
 
116
        break;
 
117
      case MCSymbolRefExpr::VK_PPC_ADDR16_LO:
134
118
        Type = ELF::R_PPC_ADDR16_LO;
135
119
        break;
136
120
      case MCSymbolRefExpr::VK_PPC_TOC_ENTRY:
147
131
        break;
148
132
      }
149
133
      break;
150
 
    case PPC::fixup_ppc_lo16_ds:
 
134
    case PPC::fixup_ppc_half16ds:
151
135
      switch (Modifier) {
152
136
      default: llvm_unreachable("Unsupported Modifier");
153
137
      case MCSymbolRefExpr::VK_None:
154
138
        Type = ELF::R_PPC64_ADDR16_DS;
155
139
        break;
 
140
      case MCSymbolRefExpr::VK_PPC_ADDR16_LO:
 
141
        Type = ELF::R_PPC64_ADDR16_LO_DS;
 
142
        break;
156
143
      case MCSymbolRefExpr::VK_PPC_TOC_ENTRY:
157
144
        Type = ELF::R_PPC64_TOC16_DS;
158
145
        break;
228
215
  return NULL;
229
216
}
230
217
 
231
 
void PPCELFObjectWriter::
232
 
adjustFixupOffset(const MCFixup &Fixup, uint64_t &RelocOffset) {
233
 
  switch ((unsigned)Fixup.getKind()) {
234
 
    case PPC::fixup_ppc_ha16:
235
 
    case PPC::fixup_ppc_lo16:
236
 
    case PPC::fixup_ppc_lo16_ds:
237
 
      RelocOffset += 2;
238
 
      break;
239
 
    default:
240
 
      break;
241
 
  }
242
 
}
243
 
 
244
 
// The standard sorter only sorts on the r_offset field, but PowerPC can
245
 
// have multiple relocations at the same offset.  Sort secondarily on the
246
 
// relocation type to avoid nondeterminism.
247
 
void PPCELFObjectWriter::sortRelocs(const MCAssembler &Asm,
248
 
                                    std::vector<ELFRelocationEntry> &Relocs) {
249
 
 
250
 
  // Copy to a temporary vector of relocation entries having a different
251
 
  // sort function.
252
 
  std::vector<PPCELFRelocationEntry> TmpRelocs;
253
 
  
254
 
  for (std::vector<ELFRelocationEntry>::iterator R = Relocs.begin();
255
 
       R != Relocs.end(); ++R) {
256
 
    TmpRelocs.push_back(PPCELFRelocationEntry(*R));
257
 
  }
258
 
 
259
 
  // Sort in place by ascending r_offset and descending r_type.
260
 
  array_pod_sort(TmpRelocs.begin(), TmpRelocs.end());
261
 
 
262
 
  // Copy back to the original vector.
263
 
  unsigned I = 0;
264
 
  for (std::vector<PPCELFRelocationEntry>::iterator R = TmpRelocs.begin();
265
 
       R != TmpRelocs.end(); ++R, ++I) {
266
 
    Relocs[I] = ELFRelocationEntry(R->r_offset, R->Index, R->Type,
267
 
                                   R->Symbol, R->r_addend, *R->Fixup);
268
 
  }
269
 
}
270
 
 
271
 
 
272
218
MCObjectWriter *llvm::createPPCELFObjectWriter(raw_ostream &OS,
273
219
                                               bool Is64Bit,
274
220
                                               uint8_t OSABI) {