1 //===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCExpr.h"
11 #include "llvm/MC/MCObjectWriter.h"
12 #include "llvm/MC/MCSymbol.h"
16 MCObjectWriter::~MCObjectWriter() {
19 /// Utility function to encode a SLEB128 value.
20 void MCObjectWriter::EncodeSLEB128(int64_t Value, raw_ostream &OS) {
23 uint8_t Byte = Value & 0x7f;
24 // NOTE: this assumes that this signed shift is an arithmetic right shift.
26 More = !((((Value == 0 ) && ((Byte & 0x40) == 0)) ||
27 ((Value == -1) && ((Byte & 0x40) != 0))));
29 Byte |= 0x80; // Mark this byte that that more bytes will follow.
34 /// Utility function to encode a ULEB128 value.
35 void MCObjectWriter::EncodeULEB128(uint64_t Value, raw_ostream &OS) {
37 uint8_t Byte = Value & 0x7f;
40 Byte |= 0x80; // Mark this byte that that more bytes will follow.
46 MCObjectWriter::IsSymbolRefDifferenceFullyResolved(const MCAssembler &Asm,
47 const MCSymbolRefExpr *A,
48 const MCSymbolRefExpr *B,
50 // Modified symbol references cannot be resolved.
51 if (A->getKind() != MCSymbolRefExpr::VK_None ||
52 B->getKind() != MCSymbolRefExpr::VK_None)
55 const MCSymbol &SA = A->getSymbol();
56 const MCSymbol &SB = B->getSymbol();
57 if (SA.isUndefined() || SB.isUndefined())
60 // On ELF and COFF A - B is absolute if A and B are in the same section.
61 return &SA.getSection() == &SB.getSection();