LLVM: include/llvm/MC/MCELFExtras.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_MC_MCELFEXTRAS_H

10#define LLVM_MC_MCELFEXTRAS_H

11

17

18#include

19#include <type_traits>

20

22

23

24template <bool Is64, class RelocsTy, class F>

26 using uint = std::conditional_t<Is64, uint64_t, uint32_t>;

27 uint OffsetMask = 8, Offset = 0, Addend = 0;

29 for (const auto &R : Relocs)

30 OffsetMask |= ToCrel(R).r_offset;

33 for (const auto &R : Relocs) {

34 auto CR = ToCrel(R);

35 auto DeltaOffset = static_cast<uint>((CR.r_offset - Offset) >> Shift);

37 uint8_t B = (DeltaOffset << 3) + (SymIdx != CR.r_symidx) +

38 (Type != CR.r_type ? 2 : 0) +

39 (Addend != uint(CR.r_addend) ? 4 : 0);

40 if (DeltaOffset < 0x10) {

42 } else {

43 OS << char(B | 0x80);

45 }

46

47 if (B & 1) {

48 encodeSLEB128(static_cast<int32_t>(CR.r_symidx - SymIdx), OS);

49 SymIdx = CR.r_symidx;

50 }

51 if (B & 2) {

53 Type = CR.r_type;

54 }

55 if (B & 4) {

56 encodeSLEB128(std::make_signed_t(CR.r_addend - Addend), OS);

57 Addend = CR.r_addend;

58 }

59 }

60}

61}

62

63#endif

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

This file implements the C++20 header.

The instances of the Type class are immutable: once they are created, they are never changed.

This class implements an extremely fast bulk output stream that can only output to a stream.

void encodeCrel(raw_ostream &OS, RelocsTy Relocs, F ToCrel)

Definition MCELFExtras.h:25

constexpr unsigned CREL_HDR_ADDEND

int countr_zero(T Val)

Count number of 0's from the least significant bit to the most stopping at the first 1.

unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)

Utility function to encode a SLEB128 value to an output stream.

unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)

Utility function to encode a ULEB128 value to an output stream.