1218885Sdim//===-- MCELFObjectTargetWriter.cpp - ELF Target Writer Subclass ----------===// 2218885Sdim// 3218885Sdim// The LLVM Compiler Infrastructure 4218885Sdim// 5218885Sdim// This file is distributed under the University of Illinois Open Source 6218885Sdim// License. See LICENSE.TXT for details. 7218885Sdim// 8218885Sdim//===----------------------------------------------------------------------===// 9218885Sdim 10234353Sdim#include "llvm/ADT/STLExtras.h" 11218885Sdim#include "llvm/MC/MCELFObjectWriter.h" 12243830Sdim#include "llvm/MC/MCExpr.h" 13243830Sdim#include "llvm/MC/MCValue.h" 14218885Sdim 15218885Sdimusing namespace llvm; 16218885Sdim 17218885SdimMCELFObjectTargetWriter::MCELFObjectTargetWriter(bool Is64Bit_, 18234353Sdim uint8_t OSABI_, 19218885Sdim uint16_t EMachine_, 20239462Sdim bool HasRelocationAddend_, 21239462Sdim bool IsN64_) 22234353Sdim : OSABI(OSABI_), EMachine(EMachine_), 23239462Sdim HasRelocationAddend(HasRelocationAddend_), Is64Bit(Is64Bit_), 24239462Sdim IsN64(IsN64_){ 25218885Sdim} 26218885Sdim 27234353Sdimconst MCSymbol *MCELFObjectTargetWriter::ExplicitRelSym(const MCAssembler &Asm, 28234353Sdim const MCValue &Target, 29234353Sdim const MCFragment &F, 30234353Sdim const MCFixup &Fixup, 31234353Sdim bool IsPCRel) const { 32234353Sdim return NULL; 33234353Sdim} 34234353Sdim 35243830Sdimconst MCSymbol *MCELFObjectTargetWriter::undefinedExplicitRelSym(const MCValue &Target, 36243830Sdim const MCFixup &Fixup, 37243830Sdim bool IsPCRel) const { 38243830Sdim const MCSymbol &Symbol = Target.getSymA()->getSymbol(); 39243830Sdim return &Symbol.AliasedSymbol(); 40243830Sdim} 41234353Sdim 42263508Sdim// ELF doesn't require relocations to be in any order. We sort by the r_offset, 43263508Sdim// just to match gnu as for easier comparison. The use type and index is an 44263508Sdim// arbitrary way of making the sort deterministic. 45263508Sdimstatic int cmpRel(const ELFRelocationEntry *AP, const ELFRelocationEntry *BP) { 46263508Sdim const ELFRelocationEntry &A = *AP; 47263508Sdim const ELFRelocationEntry &B = *BP; 48263508Sdim if (A.r_offset != B.r_offset) 49263508Sdim return B.r_offset - A.r_offset; 50263508Sdim if (B.Type != A.Type) 51263508Sdim return A.Type - B.Type; 52263508Sdim if (B.Index != A.Index) 53263508Sdim return B.Index - A.Index; 54263508Sdim llvm_unreachable("ELFRelocs might be unstable!"); 55234353Sdim} 56234353Sdim 57234353Sdimvoid 58234353SdimMCELFObjectTargetWriter::sortRelocs(const MCAssembler &Asm, 59234353Sdim std::vector<ELFRelocationEntry> &Relocs) { 60263508Sdim array_pod_sort(Relocs.begin(), Relocs.end(), cmpRel); 61234353Sdim} 62