LLVM  8.0.0svn
MipsELFObjectWriter.cpp
Go to the documentation of this file.
1 //===-- MipsELFObjectWriter.cpp - Mips ELF Writer -------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
12 #include "llvm/ADT/STLExtras.h"
13 #include "llvm/BinaryFormat/ELF.h"
15 #include "llvm/MC/MCFixup.h"
16 #include "llvm/MC/MCObjectWriter.h"
17 #include "llvm/MC/MCSymbolELF.h"
18 #include "llvm/Support/Casting.h"
19 #include "llvm/Support/Compiler.h"
20 #include "llvm/Support/Debug.h"
24 #include <algorithm>
25 #include <cassert>
26 #include <cstdint>
27 #include <iterator>
28 #include <list>
29 #include <utility>
30 
31 #define DEBUG_TYPE "mips-elf-object-writer"
32 
33 using namespace llvm;
34 
35 namespace {
36 
37 /// Holds additional information needed by the relocation ordering algorithm.
38 struct MipsRelocationEntry {
39  const ELFRelocationEntry R; ///< The relocation.
40  bool Matched = false; ///< Is this relocation part of a match.
41 
42  MipsRelocationEntry(const ELFRelocationEntry &R) : R(R) {}
43 
44  void print(raw_ostream &Out) const {
45  R.print(Out);
46  Out << ", Matched=" << Matched;
47  }
48 };
49 
50 #ifndef NDEBUG
51 raw_ostream &operator<<(raw_ostream &OS, const MipsRelocationEntry &RHS) {
52  RHS.print(OS);
53  return OS;
54 }
55 #endif
56 
57 class MipsELFObjectWriter : public MCELFObjectTargetWriter {
58 public:
59  MipsELFObjectWriter(uint8_t OSABI, bool HasRelocationAddend, bool Is64);
60 
61  ~MipsELFObjectWriter() override = default;
62 
63  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
64  const MCFixup &Fixup, bool IsPCRel) const override;
65  bool needsRelocateWithSymbol(const MCSymbol &Sym,
66  unsigned Type) const override;
67  void sortRelocs(const MCAssembler &Asm,
68  std::vector<ELFRelocationEntry> &Relocs) override;
69 };
70 
71 /// The possible results of the Predicate function used by find_best.
73  FindBest_NoMatch = 0, ///< The current element is not a match.
74  FindBest_Match, ///< The current element is a match but better ones are
75  /// possible.
76  FindBest_PerfectMatch, ///< The current element is an unbeatable match.
77 };
78 
79 } // end anonymous namespace
80 
81 /// Copy elements in the range [First, Last) to d1 when the predicate is true or
82 /// d2 when the predicate is false. This is essentially both std::copy_if and
83 /// std::remove_copy_if combined into a single pass.
84 template <class InputIt, class OutputIt1, class OutputIt2, class UnaryPredicate>
85 static std::pair<OutputIt1, OutputIt2> copy_if_else(InputIt First, InputIt Last,
86  OutputIt1 d1, OutputIt2 d2,
87  UnaryPredicate Predicate) {
88  for (InputIt I = First; I != Last; ++I) {
89  if (Predicate(*I)) {
90  *d1 = *I;
91  d1++;
92  } else {
93  *d2 = *I;
94  d2++;
95  }
96  }
97 
98  return std::make_pair(d1, d2);
99 }
100 
101 /// Find the best match in the range [First, Last).
102 ///
103 /// An element matches when Predicate(X) returns FindBest_Match or
104 /// FindBest_PerfectMatch. A value of FindBest_PerfectMatch also terminates
105 /// the search. BetterThan(A, B) is a comparator that returns true when A is a
106 /// better match than B. The return value is the position of the best match.
107 ///
108 /// This is similar to std::find_if but finds the best of multiple possible
109 /// matches.
110 template <class InputIt, class UnaryPredicate, class Comparator>
111 static InputIt find_best(InputIt First, InputIt Last, UnaryPredicate Predicate,
112  Comparator BetterThan) {
113  InputIt Best = Last;
114 
115  for (InputIt I = First; I != Last; ++I) {
116  unsigned Matched = Predicate(*I);
117  if (Matched != FindBest_NoMatch) {
118  LLVM_DEBUG(dbgs() << std::distance(First, I) << " is a match (";
119  I->print(dbgs()); dbgs() << ")\n");
120  if (Best == Last || BetterThan(*I, *Best)) {
121  LLVM_DEBUG(dbgs() << ".. and it beats the last one\n");
122  Best = I;
123  }
124  }
125  if (Matched == FindBest_PerfectMatch) {
126  LLVM_DEBUG(dbgs() << ".. and it is unbeatable\n");
127  break;
128  }
129  }
130 
131  return Best;
132 }
133 
134 /// Determine the low relocation that matches the given relocation.
135 /// If the relocation does not need a low relocation then the return value
136 /// is ELF::R_MIPS_NONE.
137 ///
138 /// The relocations that need a matching low part are
139 /// R_(MIPS|MICROMIPS|MIPS16)_HI16 for all symbols and
140 /// R_(MIPS|MICROMIPS|MIPS16)_GOT16 for local symbols only.
141 static unsigned getMatchingLoType(const ELFRelocationEntry &Reloc) {
142  unsigned Type = Reloc.Type;
143  if (Type == ELF::R_MIPS_HI16)
144  return ELF::R_MIPS_LO16;
145  if (Type == ELF::R_MICROMIPS_HI16)
146  return ELF::R_MICROMIPS_LO16;
147  if (Type == ELF::R_MIPS16_HI16)
148  return ELF::R_MIPS16_LO16;
149 
150  if (Reloc.OriginalSymbol &&
152  return ELF::R_MIPS_NONE;
153 
154  if (Type == ELF::R_MIPS_GOT16)
155  return ELF::R_MIPS_LO16;
156  if (Type == ELF::R_MICROMIPS_GOT16)
157  return ELF::R_MICROMIPS_LO16;
158  if (Type == ELF::R_MIPS16_GOT16)
159  return ELF::R_MIPS16_LO16;
160 
161  return ELF::R_MIPS_NONE;
162 }
163 
164 /// Determine whether a relocation (X) matches the one given in R.
165 ///
166 /// A relocation matches if:
167 /// - It's type matches that of a corresponding low part. This is provided in
168 /// MatchingType for efficiency.
169 /// - It's based on the same symbol.
170 /// - It's offset of greater or equal to that of the one given in R.
171 /// It should be noted that this rule assumes the programmer does not use
172 /// offsets that exceed the alignment of the symbol. The carry-bit will be
173 /// incorrect if this is not true.
174 ///
175 /// A matching relocation is unbeatable if:
176 /// - It is not already involved in a match.
177 /// - It's offset is exactly that of the one given in R.
178 static FindBestPredicateResult isMatchingReloc(const MipsRelocationEntry &X,
179  const ELFRelocationEntry &R,
180  unsigned MatchingType) {
181  if (X.R.Type == MatchingType && X.R.OriginalSymbol == R.OriginalSymbol) {
182  if (!X.Matched &&
183  X.R.OriginalAddend == R.OriginalAddend)
184  return FindBest_PerfectMatch;
185  else if (X.R.OriginalAddend >= R.OriginalAddend)
186  return FindBest_Match;
187  }
188  return FindBest_NoMatch;
189 }
190 
191 /// Determine whether Candidate or PreviousBest is the better match.
192 /// The return value is true if Candidate is the better match.
193 ///
194 /// A matching relocation is a better match if:
195 /// - It has a smaller addend.
196 /// - It is not already involved in a match.
197 static bool compareMatchingRelocs(const MipsRelocationEntry &Candidate,
198  const MipsRelocationEntry &PreviousBest) {
199  if (Candidate.R.OriginalAddend != PreviousBest.R.OriginalAddend)
200  return Candidate.R.OriginalAddend < PreviousBest.R.OriginalAddend;
201  return PreviousBest.Matched && !Candidate.Matched;
202 }
203 
204 #ifndef NDEBUG
205 /// Print all the relocations.
206 template <class Container>
207 static void dumpRelocs(const char *Prefix, const Container &Relocs) {
208  for (const auto &R : Relocs)
209  dbgs() << Prefix << R << "\n";
210 }
211 #endif
212 
213 MipsELFObjectWriter::MipsELFObjectWriter(uint8_t OSABI,
214  bool HasRelocationAddend, bool Is64)
215  : MCELFObjectTargetWriter(Is64, OSABI, ELF::EM_MIPS, HasRelocationAddend) {}
216 
218  const MCValue &Target,
219  const MCFixup &Fixup,
220  bool IsPCRel) const {
221  // Determine the type of the relocation.
222  unsigned Kind = (unsigned)Fixup.getKind();
223 
224  switch (Kind) {
226  return ELF::R_MIPS_NONE;
227  case FK_Data_1:
228  report_fatal_error("MIPS does not support one byte relocations");
229  case Mips::fixup_Mips_16:
230  case FK_Data_2:
231  return IsPCRel ? ELF::R_MIPS_PC16 : ELF::R_MIPS_16;
232  case Mips::fixup_Mips_32:
233  case FK_Data_4:
234  return IsPCRel ? ELF::R_MIPS_PC32 : ELF::R_MIPS_32;
235  }
236 
237  if (IsPCRel) {
238  switch (Kind) {
241  return ELF::R_MIPS_PC16;
243  return ELF::R_MICROMIPS_PC7_S1;
245  return ELF::R_MICROMIPS_PC10_S1;
247  return ELF::R_MICROMIPS_PC16_S1;
249  return ELF::R_MICROMIPS_PC26_S1;
251  return ELF::R_MICROMIPS_PC19_S2;
253  return ELF::R_MICROMIPS_PC18_S3;
255  return ELF::R_MICROMIPS_PC21_S1;
257  return ELF::R_MIPS_PC19_S2;
259  return ELF::R_MIPS_PC18_S3;
261  return ELF::R_MIPS_PC21_S2;
263  return ELF::R_MIPS_PC26_S2;
265  return ELF::R_MIPS_PCHI16;
267  return ELF::R_MIPS_PCLO16;
268  }
269 
270  llvm_unreachable("invalid PC-relative fixup kind!");
271  }
272 
273  switch (Kind) {
274  case Mips::fixup_Mips_64:
275  case FK_Data_8:
276  return ELF::R_MIPS_64;
277  case FK_DTPRel_4:
278  return ELF::R_MIPS_TLS_DTPREL32;
279  case FK_DTPRel_8:
280  return ELF::R_MIPS_TLS_DTPREL64;
281  case FK_TPRel_4:
282  return ELF::R_MIPS_TLS_TPREL32;
283  case FK_TPRel_8:
284  return ELF::R_MIPS_TLS_TPREL64;
285  case FK_GPRel_4:
286  if (is64Bit()) {
287  unsigned Type = (unsigned)ELF::R_MIPS_NONE;
288  Type = setRType((unsigned)ELF::R_MIPS_GPREL32, Type);
289  Type = setRType2((unsigned)ELF::R_MIPS_64, Type);
290  Type = setRType3((unsigned)ELF::R_MIPS_NONE, Type);
291  return Type;
292  }
293  return ELF::R_MIPS_GPREL32;
295  return ELF::R_MIPS_GPREL16;
296  case Mips::fixup_Mips_26:
297  return ELF::R_MIPS_26;
299  return ELF::R_MIPS_CALL16;
301  return ELF::R_MIPS_GOT16;
303  return ELF::R_MIPS_HI16;
305  return ELF::R_MIPS_LO16;
307  return ELF::R_MIPS_TLS_GD;
309  return ELF::R_MIPS_TLS_GOTTPREL;
311  return ELF::R_MIPS_TLS_TPREL_HI16;
313  return ELF::R_MIPS_TLS_TPREL_LO16;
315  return ELF::R_MIPS_TLS_LDM;
317  return ELF::R_MIPS_TLS_DTPREL_HI16;
319  return ELF::R_MIPS_TLS_DTPREL_LO16;
321  return ELF::R_MIPS_GOT_PAGE;
323  return ELF::R_MIPS_GOT_OFST;
325  return ELF::R_MIPS_GOT_DISP;
327  unsigned Type = (unsigned)ELF::R_MIPS_NONE;
328  Type = setRType((unsigned)ELF::R_MIPS_GPREL16, Type);
329  Type = setRType2((unsigned)ELF::R_MIPS_SUB, Type);
330  Type = setRType3((unsigned)ELF::R_MIPS_HI16, Type);
331  return Type;
332  }
334  unsigned Type = (unsigned)ELF::R_MIPS_NONE;
335  Type = setRType((unsigned)ELF::R_MICROMIPS_GPREL16, Type);
336  Type = setRType2((unsigned)ELF::R_MICROMIPS_SUB, Type);
337  Type = setRType3((unsigned)ELF::R_MICROMIPS_HI16, Type);
338  return Type;
339  }
341  unsigned Type = (unsigned)ELF::R_MIPS_NONE;
342  Type = setRType((unsigned)ELF::R_MIPS_GPREL16, Type);
343  Type = setRType2((unsigned)ELF::R_MIPS_SUB, Type);
344  Type = setRType3((unsigned)ELF::R_MIPS_LO16, Type);
345  return Type;
346  }
348  unsigned Type = (unsigned)ELF::R_MIPS_NONE;
349  Type = setRType((unsigned)ELF::R_MICROMIPS_GPREL16, Type);
350  Type = setRType2((unsigned)ELF::R_MICROMIPS_SUB, Type);
351  Type = setRType3((unsigned)ELF::R_MICROMIPS_LO16, Type);
352  return Type;
353  }
355  return ELF::R_MIPS_HIGHER;
357  return ELF::R_MIPS_HIGHEST;
359  return ELF::R_MIPS_SUB;
361  return ELF::R_MIPS_GOT_HI16;
363  return ELF::R_MIPS_GOT_LO16;
365  return ELF::R_MIPS_CALL_HI16;
367  return ELF::R_MIPS_CALL_LO16;
369  return ELF::R_MICROMIPS_26_S1;
371  return ELF::R_MICROMIPS_HI16;
373  return ELF::R_MICROMIPS_LO16;
375  return ELF::R_MICROMIPS_GOT16;
377  return ELF::R_MICROMIPS_CALL16;
379  return ELF::R_MICROMIPS_GOT_DISP;
381  return ELF::R_MICROMIPS_GOT_PAGE;
383  return ELF::R_MICROMIPS_GOT_OFST;
385  return ELF::R_MICROMIPS_TLS_GD;
387  return ELF::R_MICROMIPS_TLS_LDM;
389  return ELF::R_MICROMIPS_TLS_DTPREL_HI16;
391  return ELF::R_MICROMIPS_TLS_DTPREL_LO16;
393  return ELF::R_MICROMIPS_TLS_GOTTPREL;
395  return ELF::R_MICROMIPS_TLS_TPREL_HI16;
397  return ELF::R_MICROMIPS_TLS_TPREL_LO16;
399  return ELF::R_MICROMIPS_SUB;
401  return ELF::R_MICROMIPS_HIGHER;
403  return ELF::R_MICROMIPS_HIGHEST;
405  return ELF::R_MIPS_JALR;
407  return ELF::R_MICROMIPS_JALR;
408  }
409 
410  llvm_unreachable("invalid fixup kind!");
411 }
412 
413 /// Sort relocation table entries by offset except where another order is
414 /// required by the MIPS ABI.
415 ///
416 /// MIPS has a few relocations that have an AHL component in the expression used
417 /// to evaluate them. This AHL component is an addend with the same number of
418 /// bits as a symbol value but not all of our ABI's are able to supply a
419 /// sufficiently sized addend in a single relocation.
420 ///
421 /// The O32 ABI for example, uses REL relocations which store the addend in the
422 /// section data. All the relocations with AHL components affect 16-bit fields
423 /// so the addend for a single relocation is limited to 16-bit. This ABI
424 /// resolves the limitation by linking relocations (e.g. R_MIPS_HI16 and
425 /// R_MIPS_LO16) and distributing the addend between the linked relocations. The
426 /// ABI mandates that such relocations must be next to each other in a
427 /// particular order (e.g. R_MIPS_HI16 must be immediately followed by a
428 /// matching R_MIPS_LO16) but the rule is less strict in practice.
429 ///
430 /// The de facto standard is lenient in the following ways:
431 /// - 'Immediately following' does not refer to the next relocation entry but
432 /// the next matching relocation.
433 /// - There may be multiple high parts relocations for one low part relocation.
434 /// - There may be multiple low part relocations for one high part relocation.
435 /// - The AHL addend in each part does not have to be exactly equal as long as
436 /// the difference does not affect the carry bit from bit 15 into 16. This is
437 /// to allow, for example, the use of %lo(foo) and %lo(foo+4) when loading
438 /// both halves of a long long.
439 ///
440 /// See getMatchingLoType() for a description of which high part relocations
441 /// match which low part relocations. One particular thing to note is that
442 /// R_MIPS_GOT16 and similar only have AHL addends if they refer to local
443 /// symbols.
444 ///
445 /// It should also be noted that this function is not affected by whether
446 /// the symbol was kept or rewritten into a section-relative equivalent. We
447 /// always match using the expressions from the source.
448 void MipsELFObjectWriter::sortRelocs(const MCAssembler &Asm,
449  std::vector<ELFRelocationEntry> &Relocs) {
450  // We do not need to sort the relocation table for RELA relocations which
451  // N32/N64 uses as the relocation addend contains the value we require,
452  // rather than it being split across a pair of relocations.
453  if (hasRelocationAddend())
454  return;
455 
456  if (Relocs.size() < 2)
457  return;
458 
459  // Sort relocations by the address they are applied to.
460  llvm::sort(Relocs,
461  [](const ELFRelocationEntry &A, const ELFRelocationEntry &B) {
462  return A.Offset < B.Offset;
463  });
464 
465  std::list<MipsRelocationEntry> Sorted;
466  std::list<ELFRelocationEntry> Remainder;
467 
468  LLVM_DEBUG(dumpRelocs("R: ", Relocs));
469 
470  // Separate the movable relocations (AHL relocations using the high bits) from
471  // the immobile relocations (everything else). This does not preserve high/low
472  // matches that already existed in the input.
473  copy_if_else(Relocs.begin(), Relocs.end(), std::back_inserter(Remainder),
474  std::back_inserter(Sorted), [](const ELFRelocationEntry &Reloc) {
475  return getMatchingLoType(Reloc) != ELF::R_MIPS_NONE;
476  });
477 
478  for (auto &R : Remainder) {
479  LLVM_DEBUG(dbgs() << "Matching: " << R << "\n");
480 
481  unsigned MatchingType = getMatchingLoType(R);
482  assert(MatchingType != ELF::R_MIPS_NONE &&
483  "Wrong list for reloc that doesn't need a match");
484 
485  // Find the best matching relocation for the current high part.
486  // See isMatchingReloc for a description of a matching relocation and
487  // compareMatchingRelocs for a description of what 'best' means.
488  auto InsertionPoint =
489  find_best(Sorted.begin(), Sorted.end(),
490  [&R, &MatchingType](const MipsRelocationEntry &X) {
491  return isMatchingReloc(X, R, MatchingType);
492  },
494 
495  // If we matched then insert the high part in front of the match and mark
496  // both relocations as being involved in a match. We only mark the high
497  // part for cosmetic reasons in the debug output.
498  //
499  // If we failed to find a match then the high part is orphaned. This is not
500  // permitted since the relocation cannot be evaluated without knowing the
501  // carry-in. We can sometimes handle this using a matching low part that is
502  // already used in a match but we already cover that case in
503  // isMatchingReloc and compareMatchingRelocs. For the remaining cases we
504  // should insert the high part at the end of the list. This will cause the
505  // linker to fail but the alternative is to cause the linker to bind the
506  // high part to a semi-matching low part and silently calculate the wrong
507  // value. Unfortunately we have no means to warn the user that we did this
508  // so leave it up to the linker to complain about it.
509  if (InsertionPoint != Sorted.end())
510  InsertionPoint->Matched = true;
511  Sorted.insert(InsertionPoint, R)->Matched = true;
512  }
513 
514  LLVM_DEBUG(dumpRelocs("S: ", Sorted));
515 
516  assert(Relocs.size() == Sorted.size() && "Some relocs were not consumed");
517 
518  // Overwrite the original vector with the sorted elements. The caller expects
519  // them in reverse order.
520  unsigned CopyTo = 0;
521  for (const auto &R : reverse(Sorted))
522  Relocs[CopyTo++] = R.R;
523 }
524 
525 bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCSymbol &Sym,
526  unsigned Type) const {
527  // If it's a compound relocation for N64 then we need the relocation if any
528  // sub-relocation needs it.
529  if (!isUInt<8>(Type))
530  return needsRelocateWithSymbol(Sym, Type & 0xff) ||
531  needsRelocateWithSymbol(Sym, (Type >> 8) & 0xff) ||
532  needsRelocateWithSymbol(Sym, (Type >> 16) & 0xff);
533 
534  switch (Type) {
535  default:
536  errs() << Type << "\n";
537  llvm_unreachable("Unexpected relocation");
538  return true;
539 
540  // This relocation doesn't affect the section data.
541  case ELF::R_MIPS_NONE:
542  return false;
543 
544  // On REL ABI's (e.g. O32), these relocations form pairs. The pairing is done
545  // by the static linker by matching the symbol and offset.
546  // We only see one relocation at a time but it's still safe to relocate with
547  // the section so long as both relocations make the same decision.
548  //
549  // Some older linkers may require the symbol for particular cases. Such cases
550  // are not supported yet but can be added as required.
551  case ELF::R_MIPS_GOT16:
552  case ELF::R_MIPS16_GOT16:
553  case ELF::R_MICROMIPS_GOT16:
554  case ELF::R_MIPS_HIGHER:
555  case ELF::R_MIPS_HIGHEST:
556  case ELF::R_MIPS_HI16:
557  case ELF::R_MIPS16_HI16:
558  case ELF::R_MICROMIPS_HI16:
559  case ELF::R_MIPS_LO16:
560  case ELF::R_MIPS16_LO16:
561  case ELF::R_MICROMIPS_LO16:
562  // FIXME: It should be safe to return false for the STO_MIPS_MICROMIPS but
563  // we neglect to handle the adjustment to the LSB of the addend that
564  // it causes in applyFixup() and similar.
565  if (cast<MCSymbolELF>(Sym).getOther() & ELF::STO_MIPS_MICROMIPS)
566  return true;
567  return false;
568 
569  case ELF::R_MIPS_GOT_PAGE:
570  case ELF::R_MICROMIPS_GOT_PAGE:
571  case ELF::R_MIPS_GOT_OFST:
572  case ELF::R_MICROMIPS_GOT_OFST:
573  case ELF::R_MIPS_16:
574  case ELF::R_MIPS_32:
575  case ELF::R_MIPS_GPREL32:
576  if (cast<MCSymbolELF>(Sym).getOther() & ELF::STO_MIPS_MICROMIPS)
577  return true;
579  case ELF::R_MIPS_26:
580  case ELF::R_MIPS_64:
581  case ELF::R_MIPS_GPREL16:
582  case ELF::R_MIPS_PC16:
583  case ELF::R_MIPS_SUB:
584  return false;
585 
586  // FIXME: Many of these relocations should probably return false but this
587  // hasn't been confirmed to be safe yet.
588  case ELF::R_MIPS_REL32:
589  case ELF::R_MIPS_LITERAL:
590  case ELF::R_MIPS_CALL16:
591  case ELF::R_MIPS_SHIFT5:
592  case ELF::R_MIPS_SHIFT6:
593  case ELF::R_MIPS_GOT_DISP:
594  case ELF::R_MIPS_GOT_HI16:
595  case ELF::R_MIPS_GOT_LO16:
596  case ELF::R_MIPS_INSERT_A:
597  case ELF::R_MIPS_INSERT_B:
598  case ELF::R_MIPS_DELETE:
599  case ELF::R_MIPS_CALL_HI16:
600  case ELF::R_MIPS_CALL_LO16:
601  case ELF::R_MIPS_SCN_DISP:
602  case ELF::R_MIPS_REL16:
603  case ELF::R_MIPS_ADD_IMMEDIATE:
604  case ELF::R_MIPS_PJUMP:
605  case ELF::R_MIPS_RELGOT:
606  case ELF::R_MIPS_JALR:
607  case ELF::R_MIPS_TLS_DTPMOD32:
608  case ELF::R_MIPS_TLS_DTPREL32:
609  case ELF::R_MIPS_TLS_DTPMOD64:
610  case ELF::R_MIPS_TLS_DTPREL64:
611  case ELF::R_MIPS_TLS_GD:
612  case ELF::R_MIPS_TLS_LDM:
613  case ELF::R_MIPS_TLS_DTPREL_HI16:
614  case ELF::R_MIPS_TLS_DTPREL_LO16:
615  case ELF::R_MIPS_TLS_GOTTPREL:
616  case ELF::R_MIPS_TLS_TPREL32:
617  case ELF::R_MIPS_TLS_TPREL64:
618  case ELF::R_MIPS_TLS_TPREL_HI16:
619  case ELF::R_MIPS_TLS_TPREL_LO16:
620  case ELF::R_MIPS_GLOB_DAT:
621  case ELF::R_MIPS_PC21_S2:
622  case ELF::R_MIPS_PC26_S2:
623  case ELF::R_MIPS_PC18_S3:
624  case ELF::R_MIPS_PC19_S2:
625  case ELF::R_MIPS_PCHI16:
626  case ELF::R_MIPS_PCLO16:
627  case ELF::R_MIPS_COPY:
628  case ELF::R_MIPS_JUMP_SLOT:
629  case ELF::R_MIPS_NUM:
630  case ELF::R_MIPS_PC32:
631  case ELF::R_MIPS_EH:
632  case ELF::R_MICROMIPS_26_S1:
633  case ELF::R_MICROMIPS_GPREL16:
634  case ELF::R_MICROMIPS_LITERAL:
635  case ELF::R_MICROMIPS_PC7_S1:
636  case ELF::R_MICROMIPS_PC10_S1:
637  case ELF::R_MICROMIPS_PC16_S1:
638  case ELF::R_MICROMIPS_CALL16:
639  case ELF::R_MICROMIPS_GOT_DISP:
640  case ELF::R_MICROMIPS_GOT_HI16:
641  case ELF::R_MICROMIPS_GOT_LO16:
642  case ELF::R_MICROMIPS_SUB:
643  case ELF::R_MICROMIPS_HIGHER:
644  case ELF::R_MICROMIPS_HIGHEST:
645  case ELF::R_MICROMIPS_CALL_HI16:
646  case ELF::R_MICROMIPS_CALL_LO16:
647  case ELF::R_MICROMIPS_SCN_DISP:
648  case ELF::R_MICROMIPS_JALR:
649  case ELF::R_MICROMIPS_HI0_LO16:
650  case ELF::R_MICROMIPS_TLS_GD:
651  case ELF::R_MICROMIPS_TLS_LDM:
652  case ELF::R_MICROMIPS_TLS_DTPREL_HI16:
653  case ELF::R_MICROMIPS_TLS_DTPREL_LO16:
654  case ELF::R_MICROMIPS_TLS_GOTTPREL:
655  case ELF::R_MICROMIPS_TLS_TPREL_HI16:
656  case ELF::R_MICROMIPS_TLS_TPREL_LO16:
657  case ELF::R_MICROMIPS_GPREL7_S2:
658  case ELF::R_MICROMIPS_PC23_S2:
659  case ELF::R_MICROMIPS_PC21_S1:
660  case ELF::R_MICROMIPS_PC26_S1:
661  case ELF::R_MICROMIPS_PC18_S3:
662  case ELF::R_MICROMIPS_PC19_S2:
663  return true;
664 
665  // FIXME: Many of these should probably return false but MIPS16 isn't
666  // supported by the integrated assembler.
667  case ELF::R_MIPS16_26:
668  case ELF::R_MIPS16_GPREL:
669  case ELF::R_MIPS16_CALL16:
670  case ELF::R_MIPS16_TLS_GD:
671  case ELF::R_MIPS16_TLS_LDM:
672  case ELF::R_MIPS16_TLS_DTPREL_HI16:
673  case ELF::R_MIPS16_TLS_DTPREL_LO16:
674  case ELF::R_MIPS16_TLS_GOTTPREL:
675  case ELF::R_MIPS16_TLS_TPREL_HI16:
676  case ELF::R_MIPS16_TLS_TPREL_LO16:
677  llvm_unreachable("Unsupported MIPS16 relocation");
678  return true;
679  }
680 }
681 
682 std::unique_ptr<MCObjectTargetWriter>
683 llvm::createMipsELFObjectWriter(const Triple &TT, bool IsN32) {
684  uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TT.getOS());
685  bool IsN64 = TT.isArch64Bit() && !IsN32;
686  bool HasRelocationAddend = TT.isArch64Bit();
687  return llvm::make_unique<MipsELFObjectWriter>(OSABI, HasRelocationAddend,
688  IsN64);
689 }
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
A eight-byte dtp relative fixup.
Definition: MCFixup.h:37
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:139
This class represents lattice values for constants.
Definition: AllocatorList.h:24
This represents an "assembler immediate".
Definition: MCValue.h:40
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
#define LLVM_FALLTHROUGH
Definition: Compiler.h:86
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
Definition: Triple.h:299
std::unique_ptr< MCObjectTargetWriter > createMipsELFObjectWriter(const Triple &TT, bool IsN32)
unsigned getBinding() const
Definition: MCSymbolELF.cpp:67
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:74
A four-byte tp relative fixup.
Definition: MCFixup.h:38
static unsigned getRelocType(const MCValue &Target, const MCFixupKind FixupKind, const bool IsPCRel)
Translates generic PPC fixup kind to Mach-O/PPC relocation type enum.
A four-byte fixup.
Definition: MCFixup.h:26
Context object for machine code objects.
Definition: MCContext.h:63
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
Definition: STLExtras.h:261
A four-byte gp relative fixup.
Definition: MCFixup.h:34
static std::pair< OutputIt1, OutputIt2 > copy_if_else(InputIt First, InputIt Last, OutputIt1 d1, OutputIt2 d2, UnaryPredicate Predicate)
Copy elements in the range [First, Last) to d1 when the predicate is true or d2 when the predicate is...
static FindBestPredicateResult isMatchingReloc(const MipsRelocationEntry &X, const ELFRelocationEntry &R, unsigned MatchingType)
Determine whether a relocation (X) matches the one given in R.
static InputIt find_best(InputIt First, InputIt Last, UnaryPredicate Predicate, Comparator BetterThan)
Find the best match in the range [First, Last).
A four-byte dtp relative fixup.
Definition: MCFixup.h:36
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
constexpr bool isUInt< 8 >(uint64_t x)
Definition: MathExtras.h:343
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
static void dumpRelocs(const char *Prefix, const Container &Relocs)
Print all the relocations.
static bool is64Bit(const char *name)
static bool compareMatchingRelocs(const MipsRelocationEntry &Candidate, const MipsRelocationEntry &PreviousBest)
Determine whether Candidate or PreviousBest is the better match.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
A eight-byte tp relative fixup.
Definition: MCFixup.h:39
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A one-byte fixup.
Definition: MCFixup.h:24
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1110
PowerPC TLS Dynamic Call Fixup
FindBestPredicateResult
The possible results of the Predicate function used by find_best.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
Definition: PPCPredicates.h:27
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:133
Target - Wrapper for Target specific information.
bool isArch64Bit() const
Test whether the architecture is 64-bit.
Definition: Triple.cpp:1274
void print(raw_ostream &Out) const
#define I(x, y, z)
Definition: MD5.cpp:58
A eight-byte fixup.
Definition: MCFixup.h:27
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:2039
const MCSymbolELF * OriginalSymbol
const unsigned Kind
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
static unsigned getMatchingLoType(const ELFRelocationEntry &Reloc)
Determine the low relocation that matches the given relocation.
#define LLVM_DEBUG(X)
Definition: Debug.h:123
A two-byte fixup.
Definition: MCFixup.h:25
MCFixupKind getKind() const
Definition: MCFixup.h:123