blob: 44da29f09214f0c478580609f784229b7218b7b0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
//===- lib/ReaderWriter/ELF/MipsAbiInfoHandler.h --------------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLD_READER_WRITER_ELF_MIPS_MIPS_ABI_INFO_HANDLER_H
#define LLD_READER_WRITER_ELF_MIPS_MIPS_ABI_INFO_HANDLER_H
#include "llvm/ADT/Optional.h"
#include "llvm/Object/ELFTypes.h"
#include "llvm/Support/ErrorOr.h"
#include <mutex>
#include <system_error>
namespace lld {
namespace elf {
enum class MipsAbi { O32, N32, N64 };
struct MipsAbiFlags {
unsigned _isa = 0;
unsigned _fpAbi = 0;
unsigned _ases = 0;
unsigned _flags1 = 0;
unsigned _gprSize = 0;
unsigned _cpr1Size = 0;
unsigned _cpr2Size = 0;
unsigned _abi = 0;
bool _isPic = false;
bool _isCPic = false;
bool _isNoReorder = false;
bool _is32BitMode = false;
bool _isNan2008 = false;
};
template <class ELFT> class MipsAbiInfoHandler {
public:
typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
typedef llvm::object::Elf_Mips_ABIFlags<ELFT> Elf_Mips_ABIFlags;
MipsAbiInfoHandler() = default;
bool hasMipsAbiSection() const { return _hasAbiSection; }
bool isMicroMips() const;
bool isMipsR6() const;
bool isFp64() const;
bool isCPicOnly() const;
uint32_t getFlags() const;
llvm::Optional<Elf_Mips_RegInfo> getRegistersMask() const;
llvm::Optional<Elf_Mips_ABIFlags> getAbiFlags() const;
MipsAbi getAbi() const;
/// \brief Merge saved ELF header flags and the new set of flags.
std::error_code mergeFlags(uint32_t newFlags,
const Elf_Mips_ABIFlags *newAbi);
/// \brief Merge saved and new sets of registers usage masks.
void mergeRegistersMask(const Elf_Mips_RegInfo &info);
private:
mutable std::mutex _mutex;
bool _hasAbiSection = false;
llvm::Optional<MipsAbiFlags> _abiFlags;
llvm::Optional<Elf_Mips_RegInfo> _regMask;
llvm::ErrorOr<MipsAbiFlags> createAbiFlags(uint32_t flags,
const Elf_Mips_ABIFlags *sec);
static llvm::ErrorOr<MipsAbiFlags> createAbiFromHeaderFlags(uint32_t flags);
static llvm::ErrorOr<MipsAbiFlags>
createAbiFromSection(const Elf_Mips_ABIFlags &sec);
};
} // namespace elf
} // namespace lld
#endif
|