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/MCAssembler.h"
11 #include "llvm/MC/MCExpr.h"
12 #include "llvm/MC/MCObjectWriter.h"
13 #include "llvm/MC/MCSymbol.h"
17 MCObjectWriter::~MCObjectWriter() {
20 /// Utility function to encode a SLEB128 value.
21 void MCObjectWriter::EncodeSLEB128(int64_t Value
, raw_ostream
&OS
) {
24 uint8_t Byte
= Value
& 0x7f;
25 // NOTE: this assumes that this signed shift is an arithmetic right shift.
27 More
= !((((Value
== 0 ) && ((Byte
& 0x40) == 0)) ||
28 ((Value
== -1) && ((Byte
& 0x40) != 0))));
30 Byte
|= 0x80; // Mark this byte that that more bytes will follow.
35 /// Utility function to encode a ULEB128 value.
36 void MCObjectWriter::EncodeULEB128(uint64_t Value
, raw_ostream
&OS
) {
38 uint8_t Byte
= Value
& 0x7f;
41 Byte
|= 0x80; // Mark this byte that that more bytes will follow.
47 MCObjectWriter::IsSymbolRefDifferenceFullyResolved(const MCAssembler
&Asm
,
48 const MCSymbolRefExpr
*A
,
49 const MCSymbolRefExpr
*B
,
51 // Modified symbol references cannot be resolved.
52 if (A
->getKind() != MCSymbolRefExpr::VK_None
||
53 B
->getKind() != MCSymbolRefExpr::VK_None
)
56 const MCSymbol
&SA
= A
->getSymbol();
57 const MCSymbol
&SB
= B
->getSymbol();
58 if (SA
.AliasedSymbol().isUndefined() || SB
.AliasedSymbol().isUndefined())
61 const MCSymbolData
&DataA
= Asm
.getSymbolData(SA
);
62 const MCSymbolData
&DataB
= Asm
.getSymbolData(SB
);
64 return IsSymbolRefDifferenceFullyResolvedImpl(Asm
, DataA
,
71 MCObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler
&Asm
,
72 const MCSymbolData
&DataA
,
76 const MCSection
&SecA
= DataA
.getSymbol().AliasedSymbol().getSection();
77 const MCSection
&SecB
= FB
.getParent()->getSection();
78 // On ELF and COFF A - B is absolute if A and B are in the same section.
79 return &SecA
== &SecB
;