Bug Summary

File:tools/llvm-readobj/ELFDumper.cpp
Warning:line 2983, column 25
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ELFDumper.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/llvm-readobj -I /build/llvm-toolchain-snapshot-7~svn329677/tools/llvm-readobj -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn329677/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/llvm-readobj -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-04-11-031539-24776-1 -x c++ /build/llvm-toolchain-snapshot-7~svn329677/tools/llvm-readobj/ELFDumper.cpp
1//===- ELFDumper.cpp - ELF-specific dumper --------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief This file implements the ELF-specific dumper for llvm-readobj.
12///
13//===----------------------------------------------------------------------===//
14
15#include "ARMEHABIPrinter.h"
16#include "DwarfCFIEHPrinter.h"
17#include "Error.h"
18#include "ObjDumper.h"
19#include "StackMapPrinter.h"
20#include "llvm-readobj.h"
21#include "llvm/ADT/ArrayRef.h"
22#include "llvm/ADT/DenseMap.h"
23#include "llvm/ADT/Optional.h"
24#include "llvm/ADT/PointerIntPair.h"
25#include "llvm/ADT/SmallString.h"
26#include "llvm/ADT/SmallVector.h"
27#include "llvm/ADT/STLExtras.h"
28#include "llvm/ADT/StringExtras.h"
29#include "llvm/ADT/StringRef.h"
30#include "llvm/ADT/Twine.h"
31#include "llvm/BinaryFormat/ELF.h"
32#include "llvm/Object/ELF.h"
33#include "llvm/Object/ELFObjectFile.h"
34#include "llvm/Object/ELFTypes.h"
35#include "llvm/Object/Error.h"
36#include "llvm/Object/ObjectFile.h"
37#include "llvm/Object/StackMapParser.h"
38#include "llvm/Support/AMDGPUMetadata.h"
39#include "llvm/Support/ARMAttributeParser.h"
40#include "llvm/Support/ARMBuildAttributes.h"
41#include "llvm/Support/Casting.h"
42#include "llvm/Support/Compiler.h"
43#include "llvm/Support/Endian.h"
44#include "llvm/Support/ErrorHandling.h"
45#include "llvm/Support/Format.h"
46#include "llvm/Support/FormattedStream.h"
47#include "llvm/Support/MathExtras.h"
48#include "llvm/Support/MipsABIFlags.h"
49#include "llvm/Support/ScopedPrinter.h"
50#include "llvm/Support/raw_ostream.h"
51#include <algorithm>
52#include <cinttypes>
53#include <cstddef>
54#include <cstdint>
55#include <cstdlib>
56#include <iterator>
57#include <memory>
58#include <string>
59#include <system_error>
60#include <vector>
61
62using namespace llvm;
63using namespace llvm::object;
64using namespace ELF;
65
66#define LLVM_READOBJ_ENUM_CASE(ns, enum)case ns::enum: return "enum"; \
67 case ns::enum: return #enum;
68
69#define ENUM_ENT(enum, altName){ "enum", altName, ELF::enum } \
70 { #enum, altName, ELF::enum }
71
72#define ENUM_ENT_1(enum){ "enum", "enum", ELF::enum } \
73 { #enum, #enum, ELF::enum }
74
75#define LLVM_READOBJ_PHDR_ENUM(ns, enum)case ns::enum: return std::string("enum").substr(3); \
76 case ns::enum: \
77 return std::string(#enum).substr(3);
78
79#define TYPEDEF_ELF_TYPES(ELFT)using ELFO = ELFFile<ELFT>; using Elf_Addr = typename ELFT
::Addr; using Elf_Shdr = typename ELFT::Shdr; using Elf_Sym =
typename ELFT::Sym; using Elf_Dyn = typename ELFT::Dyn; using
Elf_Dyn_Range = typename ELFT::DynRange; using Elf_Rel = typename
ELFT::Rel; using Elf_Rela = typename ELFT::Rela; using Elf_Rel_Range
= typename ELFT::RelRange; using Elf_Rela_Range = typename ELFT
::RelaRange; using Elf_Phdr = typename ELFT::Phdr; using Elf_Half
= typename ELFT::Half; using Elf_Ehdr = typename ELFT::Ehdr;
using Elf_Word = typename ELFT::Word; using Elf_Hash = typename
ELFT::Hash; using Elf_GnuHash = typename ELFT::GnuHash; using
Elf_Note = typename ELFT::Note; using Elf_Sym_Range = typename
ELFT::SymRange; using Elf_Versym = typename ELFT::Versym; using
Elf_Verneed = typename ELFT::Verneed; using Elf_Vernaux = typename
ELFT::Vernaux; using Elf_Verdef = typename ELFT::Verdef; using
Elf_Verdaux = typename ELFT::Verdaux; using uintX_t = typename
ELFT::uint;
\
80 using ELFO = ELFFile<ELFT>; \
81 using Elf_Addr = typename ELFT::Addr; \
82 using Elf_Shdr = typename ELFT::Shdr; \
83 using Elf_Sym = typename ELFT::Sym; \
84 using Elf_Dyn = typename ELFT::Dyn; \
85 using Elf_Dyn_Range = typename ELFT::DynRange; \
86 using Elf_Rel = typename ELFT::Rel; \
87 using Elf_Rela = typename ELFT::Rela; \
88 using Elf_Rel_Range = typename ELFT::RelRange; \
89 using Elf_Rela_Range = typename ELFT::RelaRange; \
90 using Elf_Phdr = typename ELFT::Phdr; \
91 using Elf_Half = typename ELFT::Half; \
92 using Elf_Ehdr = typename ELFT::Ehdr; \
93 using Elf_Word = typename ELFT::Word; \
94 using Elf_Hash = typename ELFT::Hash; \
95 using Elf_GnuHash = typename ELFT::GnuHash; \
96 using Elf_Note = typename ELFT::Note; \
97 using Elf_Sym_Range = typename ELFT::SymRange; \
98 using Elf_Versym = typename ELFT::Versym; \
99 using Elf_Verneed = typename ELFT::Verneed; \
100 using Elf_Vernaux = typename ELFT::Vernaux; \
101 using Elf_Verdef = typename ELFT::Verdef; \
102 using Elf_Verdaux = typename ELFT::Verdaux; \
103 using uintX_t = typename ELFT::uint;
104
105namespace {
106
107template <class ELFT> class DumpStyle;
108
109/// Represents a contiguous uniform range in the file. We cannot just create a
110/// range directly because when creating one of these from the .dynamic table
111/// the size, entity size and virtual address are different entries in arbitrary
112/// order (DT_REL, DT_RELSZ, DT_RELENT for example).
113struct DynRegionInfo {
114 DynRegionInfo() = default;
115 DynRegionInfo(const void *A, uint64_t S, uint64_t ES)
116 : Addr(A), Size(S), EntSize(ES) {}
117
118 /// \brief Address in current address space.
119 const void *Addr = nullptr;
120 /// \brief Size in bytes of the region.
121 uint64_t Size = 0;
122 /// \brief Size of each entity in the region.
123 uint64_t EntSize = 0;
124
125 template <typename Type> ArrayRef<Type> getAsArrayRef() const {
126 const Type *Start = reinterpret_cast<const Type *>(Addr);
127 if (!Start)
128 return {Start, Start};
129 if (EntSize != sizeof(Type) || Size % EntSize)
130 reportError("Invalid entity size");
131 return {Start, Start + (Size / EntSize)};
132 }
133};
134
135template<typename ELFT>
136class ELFDumper : public ObjDumper {
137public:
138 ELFDumper(const ELFFile<ELFT> *Obj, ScopedPrinter &Writer);
139
140 void printFileHeaders() override;
141 void printSections() override;
142 void printRelocations() override;
143 void printDynamicRelocations() override;
144 void printSymbols() override;
145 void printDynamicSymbols() override;
146 void printUnwindInfo() override;
147
148 void printDynamicTable() override;
149 void printNeededLibraries() override;
150 void printProgramHeaders() override;
151 void printHashTable() override;
152 void printGnuHashTable() override;
153 void printLoadName() override;
154 void printVersionInfo() override;
155 void printGroupSections() override;
156
157 void printAttributes() override;
158 void printMipsPLTGOT() override;
159 void printMipsABIFlags() override;
160 void printMipsReginfo() override;
161 void printMipsOptions() override;
162
163 void printStackMap() const override;
164
165 void printHashHistogram() override;
166
167 void printNotes() override;
168
169 void printELFLinkerOptions() override;
170
171private:
172 std::unique_ptr<DumpStyle<ELFT>> ELFDumperStyle;
173
174 TYPEDEF_ELF_TYPES(ELFT)using ELFO = ELFFile<ELFT>; using Elf_Addr = typename ELFT
::Addr; using Elf_Shdr = typename ELFT::Shdr; using Elf_Sym =
typename ELFT::Sym; using Elf_Dyn = typename ELFT::Dyn; using
Elf_Dyn_Range = typename ELFT::DynRange; using Elf_Rel = typename
ELFT::Rel; using Elf_Rela = typename ELFT::Rela; using Elf_Rel_Range
= typename ELFT::RelRange; using Elf_Rela_Range = typename ELFT
::RelaRange; using Elf_Phdr = typename ELFT::Phdr; using Elf_Half
= typename ELFT::Half; using Elf_Ehdr = typename ELFT::Ehdr;
using Elf_Word = typename ELFT::Word; using Elf_Hash = typename
ELFT::Hash; using Elf_GnuHash = typename ELFT::GnuHash; using
Elf_Note = typename ELFT::Note; using Elf_Sym_Range = typename
ELFT::SymRange; using Elf_Versym = typename ELFT::Versym; using
Elf_Verneed = typename ELFT::Verneed; using Elf_Vernaux = typename
ELFT::Vernaux; using Elf_Verdef = typename ELFT::Verdef; using
Elf_Verdaux = typename ELFT::Verdaux; using uintX_t = typename
ELFT::uint;
175
176 DynRegionInfo checkDRI(DynRegionInfo DRI) {
177 if (DRI.Addr < Obj->base() ||
178 (const uint8_t *)DRI.Addr + DRI.Size > Obj->base() + Obj->getBufSize())
179 error(llvm::object::object_error::parse_failed);
180 return DRI;
181 }
182
183 DynRegionInfo createDRIFrom(const Elf_Phdr *P, uintX_t EntSize) {
184 return checkDRI({Obj->base() + P->p_offset, P->p_filesz, EntSize});
185 }
186
187 DynRegionInfo createDRIFrom(const Elf_Shdr *S) {
188 return checkDRI({Obj->base() + S->sh_offset, S->sh_size, S->sh_entsize});
189 }
190
191 void parseDynamicTable(ArrayRef<const Elf_Phdr *> LoadSegments);
192
193 void printValue(uint64_t Type, uint64_t Value);
194
195 StringRef getDynamicString(uint64_t Offset) const;
196 StringRef getSymbolVersion(StringRef StrTab, const Elf_Sym *symb,
197 bool &IsDefault) const;
198 void LoadVersionMap() const;
199 void LoadVersionNeeds(const Elf_Shdr *ec) const;
200 void LoadVersionDefs(const Elf_Shdr *sec) const;
201
202 const ELFO *Obj;
203 DynRegionInfo DynRelRegion;
204 DynRegionInfo DynRelaRegion;
205 DynRegionInfo DynPLTRelRegion;
206 DynRegionInfo DynSymRegion;
207 DynRegionInfo DynamicTable;
208 StringRef DynamicStringTable;
209 StringRef SOName;
210 const Elf_Hash *HashTable = nullptr;
211 const Elf_GnuHash *GnuHashTable = nullptr;
212 const Elf_Shdr *DotSymtabSec = nullptr;
213 StringRef DynSymtabName;
214 ArrayRef<Elf_Word> ShndxTable;
215
216 const Elf_Shdr *dot_gnu_version_sec = nullptr; // .gnu.version
217 const Elf_Shdr *dot_gnu_version_r_sec = nullptr; // .gnu.version_r
218 const Elf_Shdr *dot_gnu_version_d_sec = nullptr; // .gnu.version_d
219
220 // Records for each version index the corresponding Verdef or Vernaux entry.
221 // This is filled the first time LoadVersionMap() is called.
222 class VersionMapEntry : public PointerIntPair<const void *, 1> {
223 public:
224 // If the integer is 0, this is an Elf_Verdef*.
225 // If the integer is 1, this is an Elf_Vernaux*.
226 VersionMapEntry() : PointerIntPair<const void *, 1>(nullptr, 0) {}
227 VersionMapEntry(const Elf_Verdef *verdef)
228 : PointerIntPair<const void *, 1>(verdef, 0) {}
229 VersionMapEntry(const Elf_Vernaux *vernaux)
230 : PointerIntPair<const void *, 1>(vernaux, 1) {}
231
232 bool isNull() const { return getPointer() == nullptr; }
233 bool isVerdef() const { return !isNull() && getInt() == 0; }
234 bool isVernaux() const { return !isNull() && getInt() == 1; }
235 const Elf_Verdef *getVerdef() const {
236 return isVerdef() ? (const Elf_Verdef *)getPointer() : nullptr;
237 }
238 const Elf_Vernaux *getVernaux() const {
239 return isVernaux() ? (const Elf_Vernaux *)getPointer() : nullptr;
240 }
241 };
242 mutable SmallVector<VersionMapEntry, 16> VersionMap;
243
244public:
245 Elf_Dyn_Range dynamic_table() const {
246 return DynamicTable.getAsArrayRef<Elf_Dyn>();
247 }
248
249 Elf_Sym_Range dynamic_symbols() const {
250 return DynSymRegion.getAsArrayRef<Elf_Sym>();
251 }
252
253 Elf_Rel_Range dyn_rels() const;
254 Elf_Rela_Range dyn_relas() const;
255 std::string getFullSymbolName(const Elf_Sym *Symbol, StringRef StrTable,
256 bool IsDynamic) const;
257 void getSectionNameIndex(const Elf_Sym *Symbol, const Elf_Sym *FirstSym,
258 StringRef &SectionName,
259 unsigned &SectionIndex) const;
260
261 void printSymbolsHelper(bool IsDynamic) const;
262 const Elf_Shdr *getDotSymtabSec() const { return DotSymtabSec; }
263 ArrayRef<Elf_Word> getShndxTable() const { return ShndxTable; }
264 StringRef getDynamicStringTable() const { return DynamicStringTable; }
265 const DynRegionInfo &getDynRelRegion() const { return DynRelRegion; }
266 const DynRegionInfo &getDynRelaRegion() const { return DynRelaRegion; }
267 const DynRegionInfo &getDynPLTRelRegion() const { return DynPLTRelRegion; }
268 const Elf_Hash *getHashTable() const { return HashTable; }
269 const Elf_GnuHash *getGnuHashTable() const { return GnuHashTable; }
270};
271
272template <class ELFT>
273void ELFDumper<ELFT>::printSymbolsHelper(bool IsDynamic) const {
274 StringRef StrTable, SymtabName;
275 size_t Entries = 0;
276 Elf_Sym_Range Syms(nullptr, nullptr);
277 if (IsDynamic) {
278 StrTable = DynamicStringTable;
279 Syms = dynamic_symbols();
280 SymtabName = DynSymtabName;
281 if (DynSymRegion.Addr)
282 Entries = DynSymRegion.Size / DynSymRegion.EntSize;
283 } else {
284 if (!DotSymtabSec)
285 return;
286 StrTable = unwrapOrError(Obj->getStringTableForSymtab(*DotSymtabSec));
287 Syms = unwrapOrError(Obj->symbols(DotSymtabSec));
288 SymtabName = unwrapOrError(Obj->getSectionName(DotSymtabSec));
289 Entries = DotSymtabSec->getEntityCount();
290 }
291 if (Syms.begin() == Syms.end())
292 return;
293 ELFDumperStyle->printSymtabMessage(Obj, SymtabName, Entries);
294 for (const auto &Sym : Syms)
295 ELFDumperStyle->printSymbol(Obj, &Sym, Syms.begin(), StrTable, IsDynamic);
296}
297
298template <class ELFT> class MipsGOTParser;
299
300template <typename ELFT> class DumpStyle {
301public:
302 using Elf_Shdr = typename ELFT::Shdr;
303 using Elf_Sym = typename ELFT::Sym;
304
305 DumpStyle(ELFDumper<ELFT> *Dumper) : Dumper(Dumper) {}
306 virtual ~DumpStyle() = default;
307
308 virtual void printFileHeaders(const ELFFile<ELFT> *Obj) = 0;
309 virtual void printGroupSections(const ELFFile<ELFT> *Obj) = 0;
310 virtual void printRelocations(const ELFFile<ELFT> *Obj) = 0;
311 virtual void printSections(const ELFFile<ELFT> *Obj) = 0;
312 virtual void printSymbols(const ELFFile<ELFT> *Obj) = 0;
313 virtual void printDynamicSymbols(const ELFFile<ELFT> *Obj) = 0;
314 virtual void printDynamicRelocations(const ELFFile<ELFT> *Obj) = 0;
315 virtual void printSymtabMessage(const ELFFile<ELFT> *obj, StringRef Name,
316 size_t Offset) {}
317 virtual void printSymbol(const ELFFile<ELFT> *Obj, const Elf_Sym *Symbol,
318 const Elf_Sym *FirstSym, StringRef StrTable,
319 bool IsDynamic) = 0;
320 virtual void printProgramHeaders(const ELFFile<ELFT> *Obj) = 0;
321 virtual void printHashHistogram(const ELFFile<ELFT> *Obj) = 0;
322 virtual void printNotes(const ELFFile<ELFT> *Obj) = 0;
323 virtual void printELFLinkerOptions(const ELFFile<ELFT> *Obj) = 0;
324 virtual void printMipsGOT(const MipsGOTParser<ELFT> &Parser) = 0;
325 virtual void printMipsPLT(const MipsGOTParser<ELFT> &Parser) = 0;
326 const ELFDumper<ELFT> *dumper() const { return Dumper; }
327
328private:
329 const ELFDumper<ELFT> *Dumper;
330};
331
332template <typename ELFT> class GNUStyle : public DumpStyle<ELFT> {
333 formatted_raw_ostream OS;
334
335public:
336 TYPEDEF_ELF_TYPES(ELFT)using ELFO = ELFFile<ELFT>; using Elf_Addr = typename ELFT
::Addr; using Elf_Shdr = typename ELFT::Shdr; using Elf_Sym =
typename ELFT::Sym; using Elf_Dyn = typename ELFT::Dyn; using
Elf_Dyn_Range = typename ELFT::DynRange; using Elf_Rel = typename
ELFT::Rel; using Elf_Rela = typename ELFT::Rela; using Elf_Rel_Range
= typename ELFT::RelRange; using Elf_Rela_Range = typename ELFT
::RelaRange; using Elf_Phdr = typename ELFT::Phdr; using Elf_Half
= typename ELFT::Half; using Elf_Ehdr = typename ELFT::Ehdr;
using Elf_Word = typename ELFT::Word; using Elf_Hash = typename
ELFT::Hash; using Elf_GnuHash = typename ELFT::GnuHash; using
Elf_Note = typename ELFT::Note; using Elf_Sym_Range = typename
ELFT::SymRange; using Elf_Versym = typename ELFT::Versym; using
Elf_Verneed = typename ELFT::Verneed; using Elf_Vernaux = typename
ELFT::Vernaux; using Elf_Verdef = typename ELFT::Verdef; using
Elf_Verdaux = typename ELFT::Verdaux; using uintX_t = typename
ELFT::uint;
337
338 GNUStyle(ScopedPrinter &W, ELFDumper<ELFT> *Dumper)
339 : DumpStyle<ELFT>(Dumper), OS(W.getOStream()) {}
340
341 void printFileHeaders(const ELFO *Obj) override;
342 void printGroupSections(const ELFFile<ELFT> *Obj) override;
343 void printRelocations(const ELFO *Obj) override;
344 void printSections(const ELFO *Obj) override;
345 void printSymbols(const ELFO *Obj) override;
346 void printDynamicSymbols(const ELFO *Obj) override;
347 void printDynamicRelocations(const ELFO *Obj) override;
348 void printSymtabMessage(const ELFO *Obj, StringRef Name,
349 size_t Offset) override;
350 void printProgramHeaders(const ELFO *Obj) override;
351 void printHashHistogram(const ELFFile<ELFT> *Obj) override;
352 void printNotes(const ELFFile<ELFT> *Obj) override;
353 void printELFLinkerOptions(const ELFFile<ELFT> *Obj) override;
354 void printMipsGOT(const MipsGOTParser<ELFT> &Parser) override;
355 void printMipsPLT(const MipsGOTParser<ELFT> &Parser) override;
356
357private:
358 struct Field {
359 StringRef Str;
360 unsigned Column;
361
362 Field(StringRef S, unsigned Col) : Str(S), Column(Col) {}
363 Field(unsigned Col) : Str(""), Column(Col) {}
364 };
365
366 template <typename T, typename TEnum>
367 std::string printEnum(T Value, ArrayRef<EnumEntry<TEnum>> EnumValues) {
368 for (const auto &EnumItem : EnumValues)
369 if (EnumItem.Value == Value)
370 return EnumItem.AltName;
371 return to_hexString(Value, false);
372 }
373
374 formatted_raw_ostream &printField(struct Field F) {
375 if (F.Column != 0)
376 OS.PadToColumn(F.Column);
377 OS << F.Str;
378 OS.flush();
379 return OS;
380 }
381 void printHashedSymbol(const ELFO *Obj, const Elf_Sym *FirstSym, uint32_t Sym,
382 StringRef StrTable, uint32_t Bucket);
383 void printRelocation(const ELFO *Obj, const Elf_Shdr *SymTab,
384 const Elf_Rela &R, bool IsRela);
385 void printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, const Elf_Sym *First,
386 StringRef StrTable, bool IsDynamic) override;
387 std::string getSymbolSectionNdx(const ELFO *Obj, const Elf_Sym *Symbol,
388 const Elf_Sym *FirstSym);
389 void printDynamicRelocation(const ELFO *Obj, Elf_Rela R, bool IsRela);
390 bool checkTLSSections(const Elf_Phdr &Phdr, const Elf_Shdr &Sec);
391 bool checkoffsets(const Elf_Phdr &Phdr, const Elf_Shdr &Sec);
392 bool checkVMA(const Elf_Phdr &Phdr, const Elf_Shdr &Sec);
393 bool checkPTDynamic(const Elf_Phdr &Phdr, const Elf_Shdr &Sec);
394};
395
396template <typename ELFT> class LLVMStyle : public DumpStyle<ELFT> {
397public:
398 TYPEDEF_ELF_TYPES(ELFT)using ELFO = ELFFile<ELFT>; using Elf_Addr = typename ELFT
::Addr; using Elf_Shdr = typename ELFT::Shdr; using Elf_Sym =
typename ELFT::Sym; using Elf_Dyn = typename ELFT::Dyn; using
Elf_Dyn_Range = typename ELFT::DynRange; using Elf_Rel = typename
ELFT::Rel; using Elf_Rela = typename ELFT::Rela; using Elf_Rel_Range
= typename ELFT::RelRange; using Elf_Rela_Range = typename ELFT
::RelaRange; using Elf_Phdr = typename ELFT::Phdr; using Elf_Half
= typename ELFT::Half; using Elf_Ehdr = typename ELFT::Ehdr;
using Elf_Word = typename ELFT::Word; using Elf_Hash = typename
ELFT::Hash; using Elf_GnuHash = typename ELFT::GnuHash; using
Elf_Note = typename ELFT::Note; using Elf_Sym_Range = typename
ELFT::SymRange; using Elf_Versym = typename ELFT::Versym; using
Elf_Verneed = typename ELFT::Verneed; using Elf_Vernaux = typename
ELFT::Vernaux; using Elf_Verdef = typename ELFT::Verdef; using
Elf_Verdaux = typename ELFT::Verdaux; using uintX_t = typename
ELFT::uint;
399
400 LLVMStyle(ScopedPrinter &W, ELFDumper<ELFT> *Dumper)
401 : DumpStyle<ELFT>(Dumper), W(W) {}
402
403 void printFileHeaders(const ELFO *Obj) override;
404 void printGroupSections(const ELFFile<ELFT> *Obj) override;
405 void printRelocations(const ELFO *Obj) override;
406 void printRelocations(const Elf_Shdr *Sec, const ELFO *Obj);
407 void printSections(const ELFO *Obj) override;
408 void printSymbols(const ELFO *Obj) override;
409 void printDynamicSymbols(const ELFO *Obj) override;
410 void printDynamicRelocations(const ELFO *Obj) override;
411 void printProgramHeaders(const ELFO *Obj) override;
412 void printHashHistogram(const ELFFile<ELFT> *Obj) override;
413 void printNotes(const ELFFile<ELFT> *Obj) override;
414 void printELFLinkerOptions(const ELFFile<ELFT> *Obj) override;
415 void printMipsGOT(const MipsGOTParser<ELFT> &Parser) override;
416 void printMipsPLT(const MipsGOTParser<ELFT> &Parser) override;
417
418private:
419 void printRelocation(const ELFO *Obj, Elf_Rela Rel, const Elf_Shdr *SymTab);
420 void printDynamicRelocation(const ELFO *Obj, Elf_Rela Rel);
421 void printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, const Elf_Sym *First,
422 StringRef StrTable, bool IsDynamic) override;
423
424 ScopedPrinter &W;
425};
426
427} // end anonymous namespace
428
429namespace llvm {
430
431template <class ELFT>
432static std::error_code createELFDumper(const ELFFile<ELFT> *Obj,
433 ScopedPrinter &Writer,
434 std::unique_ptr<ObjDumper> &Result) {
435 Result.reset(new ELFDumper<ELFT>(Obj, Writer));
436 return readobj_error::success;
437}
438
439std::error_code createELFDumper(const object::ObjectFile *Obj,
440 ScopedPrinter &Writer,
441 std::unique_ptr<ObjDumper> &Result) {
442 // Little-endian 32-bit
443 if (const ELF32LEObjectFile *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj))
444 return createELFDumper(ELFObj->getELFFile(), Writer, Result);
445
446 // Big-endian 32-bit
447 if (const ELF32BEObjectFile *ELFObj = dyn_cast<ELF32BEObjectFile>(Obj))
448 return createELFDumper(ELFObj->getELFFile(), Writer, Result);
449
450 // Little-endian 64-bit
451 if (const ELF64LEObjectFile *ELFObj = dyn_cast<ELF64LEObjectFile>(Obj))
452 return createELFDumper(ELFObj->getELFFile(), Writer, Result);
453
454 // Big-endian 64-bit
455 if (const ELF64BEObjectFile *ELFObj = dyn_cast<ELF64BEObjectFile>(Obj))
456 return createELFDumper(ELFObj->getELFFile(), Writer, Result);
457
458 return readobj_error::unsupported_obj_file_format;
459}
460
461} // end namespace llvm
462
463// Iterate through the versions needed section, and place each Elf_Vernaux
464// in the VersionMap according to its index.
465template <class ELFT>
466void ELFDumper<ELFT>::LoadVersionNeeds(const Elf_Shdr *sec) const {
467 unsigned vn_size = sec->sh_size; // Size of section in bytes
468 unsigned vn_count = sec->sh_info; // Number of Verneed entries
469 const char *sec_start = (const char *)Obj->base() + sec->sh_offset;
470 const char *sec_end = sec_start + vn_size;
471 // The first Verneed entry is at the start of the section.
472 const char *p = sec_start;
473 for (unsigned i = 0; i < vn_count; i++) {
474 if (p + sizeof(Elf_Verneed) > sec_end)
475 report_fatal_error("Section ended unexpectedly while scanning "
476 "version needed records.");
477 const Elf_Verneed *vn = reinterpret_cast<const Elf_Verneed *>(p);
478 if (vn->vn_version != ELF::VER_NEED_CURRENT)
479 report_fatal_error("Unexpected verneed version");
480 // Iterate through the Vernaux entries
481 const char *paux = p + vn->vn_aux;
482 for (unsigned j = 0; j < vn->vn_cnt; j++) {
483 if (paux + sizeof(Elf_Vernaux) > sec_end)
484 report_fatal_error("Section ended unexpected while scanning auxiliary "
485 "version needed records.");
486 const Elf_Vernaux *vna = reinterpret_cast<const Elf_Vernaux *>(paux);
487 size_t index = vna->vna_other & ELF::VERSYM_VERSION;
488 if (index >= VersionMap.size())
489 VersionMap.resize(index + 1);
490 VersionMap[index] = VersionMapEntry(vna);
491 paux += vna->vna_next;
492 }
493 p += vn->vn_next;
494 }
495}
496
497// Iterate through the version definitions, and place each Elf_Verdef
498// in the VersionMap according to its index.
499template <class ELFT>
500void ELFDumper<ELFT>::LoadVersionDefs(const Elf_Shdr *sec) const {
501 unsigned vd_size = sec->sh_size; // Size of section in bytes
502 unsigned vd_count = sec->sh_info; // Number of Verdef entries
503 const char *sec_start = (const char *)Obj->base() + sec->sh_offset;
504 const char *sec_end = sec_start + vd_size;
505 // The first Verdef entry is at the start of the section.
506 const char *p = sec_start;
507 for (unsigned i = 0; i < vd_count; i++) {
508 if (p + sizeof(Elf_Verdef) > sec_end)
509 report_fatal_error("Section ended unexpectedly while scanning "
510 "version definitions.");
511 const Elf_Verdef *vd = reinterpret_cast<const Elf_Verdef *>(p);
512 if (vd->vd_version != ELF::VER_DEF_CURRENT)
513 report_fatal_error("Unexpected verdef version");
514 size_t index = vd->vd_ndx & ELF::VERSYM_VERSION;
515 if (index >= VersionMap.size())
516 VersionMap.resize(index + 1);
517 VersionMap[index] = VersionMapEntry(vd);
518 p += vd->vd_next;
519 }
520}
521
522template <class ELFT> void ELFDumper<ELFT>::LoadVersionMap() const {
523 // If there is no dynamic symtab or version table, there is nothing to do.
524 if (!DynSymRegion.Addr || !dot_gnu_version_sec)
525 return;
526
527 // Has the VersionMap already been loaded?
528 if (VersionMap.size() > 0)
529 return;
530
531 // The first two version indexes are reserved.
532 // Index 0 is LOCAL, index 1 is GLOBAL.
533 VersionMap.push_back(VersionMapEntry());
534 VersionMap.push_back(VersionMapEntry());
535
536 if (dot_gnu_version_d_sec)
537 LoadVersionDefs(dot_gnu_version_d_sec);
538
539 if (dot_gnu_version_r_sec)
540 LoadVersionNeeds(dot_gnu_version_r_sec);
541}
542
543template <typename ELFO, class ELFT>
544static void printVersionSymbolSection(ELFDumper<ELFT> *Dumper, const ELFO *Obj,
545 const typename ELFO::Elf_Shdr *Sec,
546 ScopedPrinter &W) {
547 DictScope SS(W, "Version symbols");
548 if (!Sec)
549 return;
550 StringRef Name = unwrapOrError(Obj->getSectionName(Sec));
551 W.printNumber("Section Name", Name, Sec->sh_name);
552 W.printHex("Address", Sec->sh_addr);
553 W.printHex("Offset", Sec->sh_offset);
554 W.printNumber("Link", Sec->sh_link);
555
556 const uint8_t *P = (const uint8_t *)Obj->base() + Sec->sh_offset;
557 StringRef StrTable = Dumper->getDynamicStringTable();
558
559 // Same number of entries in the dynamic symbol table (DT_SYMTAB).
560 ListScope Syms(W, "Symbols");
561 for (const typename ELFO::Elf_Sym &Sym : Dumper->dynamic_symbols()) {
562 DictScope S(W, "Symbol");
563 std::string FullSymbolName =
564 Dumper->getFullSymbolName(&Sym, StrTable, true /* IsDynamic */);
565 W.printNumber("Version", *P);
566 W.printString("Name", FullSymbolName);
567 P += sizeof(typename ELFO::Elf_Half);
568 }
569}
570
571static const EnumEntry<unsigned> SymVersionFlags[] = {
572 {"Base", "BASE", VER_FLG_BASE},
573 {"Weak", "WEAK", VER_FLG_WEAK},
574 {"Info", "INFO", VER_FLG_INFO}};
575
576template <typename ELFO, class ELFT>
577static void printVersionDefinitionSection(ELFDumper<ELFT> *Dumper,
578 const ELFO *Obj,
579 const typename ELFO::Elf_Shdr *Sec,
580 ScopedPrinter &W) {
581 using VerDef = typename ELFO::Elf_Verdef;
582 using VerdAux = typename ELFO::Elf_Verdaux;
583
584 DictScope SD(W, "SHT_GNU_verdef");
585 if (!Sec)
586 return;
587
588 // The number of entries in the section SHT_GNU_verdef
589 // is determined by DT_VERDEFNUM tag.
590 unsigned VerDefsNum = 0;
591 for (const typename ELFO::Elf_Dyn &Dyn : Dumper->dynamic_table()) {
592 if (Dyn.d_tag == DT_VERDEFNUM)
593 VerDefsNum = Dyn.d_un.d_val;
594 }
595 const uint8_t *SecStartAddress =
596 (const uint8_t *)Obj->base() + Sec->sh_offset;
597 const uint8_t *SecEndAddress = SecStartAddress + Sec->sh_size;
598 const uint8_t *P = SecStartAddress;
599 const typename ELFO::Elf_Shdr *StrTab =
600 unwrapOrError(Obj->getSection(Sec->sh_link));
601
602 while (VerDefsNum--) {
603 if (P + sizeof(VerDef) > SecEndAddress)
604 report_fatal_error("invalid offset in the section");
605
606 auto *VD = reinterpret_cast<const VerDef *>(P);
607 DictScope Def(W, "Definition");
608 W.printNumber("Version", VD->vd_version);
609 W.printEnum("Flags", VD->vd_flags, makeArrayRef(SymVersionFlags));
610 W.printNumber("Index", VD->vd_ndx);
611 W.printNumber("Hash", VD->vd_hash);
612 W.printString("Name",
613 StringRef((const char *)(Obj->base() + StrTab->sh_offset +
614 VD->getAux()->vda_name)));
615 if (!VD->vd_cnt)
616 report_fatal_error("at least one definition string must exist");
617 if (VD->vd_cnt > 2)
618 report_fatal_error("more than one predecessor is not expected");
619
620 if (VD->vd_cnt == 2) {
621 const uint8_t *PAux = P + VD->vd_aux + VD->getAux()->vda_next;
622 const VerdAux *Aux = reinterpret_cast<const VerdAux *>(PAux);
623 W.printString("Predecessor",
624 StringRef((const char *)(Obj->base() + StrTab->sh_offset +
625 Aux->vda_name)));
626 }
627
628 P += VD->vd_next;
629 }
630}
631
632template <typename ELFO, class ELFT>
633static void printVersionDependencySection(ELFDumper<ELFT> *Dumper,
634 const ELFO *Obj,
635 const typename ELFO::Elf_Shdr *Sec,
636 ScopedPrinter &W) {
637 using VerNeed = typename ELFO::Elf_Verneed;
638 using VernAux = typename ELFO::Elf_Vernaux;
639
640 DictScope SD(W, "SHT_GNU_verneed");
641 if (!Sec)
642 return;
643
644 unsigned VerNeedNum = 0;
645 for (const typename ELFO::Elf_Dyn &Dyn : Dumper->dynamic_table())
646 if (Dyn.d_tag == DT_VERNEEDNUM)
647 VerNeedNum = Dyn.d_un.d_val;
648
649 const uint8_t *SecData = (const uint8_t *)Obj->base() + Sec->sh_offset;
650 const typename ELFO::Elf_Shdr *StrTab =
651 unwrapOrError(Obj->getSection(Sec->sh_link));
652
653 const uint8_t *P = SecData;
654 for (unsigned I = 0; I < VerNeedNum; ++I) {
655 const VerNeed *Need = reinterpret_cast<const VerNeed *>(P);
656 DictScope Entry(W, "Dependency");
657 W.printNumber("Version", Need->vn_version);
658 W.printNumber("Count", Need->vn_cnt);
659 W.printString("FileName",
660 StringRef((const char *)(Obj->base() + StrTab->sh_offset +
661 Need->vn_file)));
662
663 const uint8_t *PAux = P + Need->vn_aux;
664 for (unsigned J = 0; J < Need->vn_cnt; ++J) {
665 const VernAux *Aux = reinterpret_cast<const VernAux *>(PAux);
666 DictScope Entry(W, "Entry");
667 W.printNumber("Hash", Aux->vna_hash);
668 W.printEnum("Flags", Aux->vna_flags, makeArrayRef(SymVersionFlags));
669 W.printNumber("Index", Aux->vna_other);
670 W.printString("Name",
671 StringRef((const char *)(Obj->base() + StrTab->sh_offset +
672 Aux->vna_name)));
673 PAux += Aux->vna_next;
674 }
675 P += Need->vn_next;
676 }
677}
678
679template <typename ELFT> void ELFDumper<ELFT>::printVersionInfo() {
680 // Dump version symbol section.
681 printVersionSymbolSection(this, Obj, dot_gnu_version_sec, W);
682
683 // Dump version definition section.
684 printVersionDefinitionSection(this, Obj, dot_gnu_version_d_sec, W);
685
686 // Dump version dependency section.
687 printVersionDependencySection(this, Obj, dot_gnu_version_r_sec, W);
688}
689
690template <typename ELFT>
691StringRef ELFDumper<ELFT>::getSymbolVersion(StringRef StrTab,
692 const Elf_Sym *symb,
693 bool &IsDefault) const {
694 // This is a dynamic symbol. Look in the GNU symbol version table.
695 if (!dot_gnu_version_sec) {
696 // No version table.
697 IsDefault = false;
698 return StringRef("");
699 }
700
701 // Determine the position in the symbol table of this entry.
702 size_t entry_index = (reinterpret_cast<uintptr_t>(symb) -
703 reinterpret_cast<uintptr_t>(DynSymRegion.Addr)) /
704 sizeof(Elf_Sym);
705
706 // Get the corresponding version index entry
707 const Elf_Versym *vs = unwrapOrError(
708 Obj->template getEntry<Elf_Versym>(dot_gnu_version_sec, entry_index));
709 size_t version_index = vs->vs_index & ELF::VERSYM_VERSION;
710
711 // Special markers for unversioned symbols.
712 if (version_index == ELF::VER_NDX_LOCAL ||
713 version_index == ELF::VER_NDX_GLOBAL) {
714 IsDefault = false;
715 return StringRef("");
716 }
717
718 // Lookup this symbol in the version table
719 LoadVersionMap();
720 if (version_index >= VersionMap.size() || VersionMap[version_index].isNull())
721 reportError("Invalid version entry");
722 const VersionMapEntry &entry = VersionMap[version_index];
723
724 // Get the version name string
725 size_t name_offset;
726 if (entry.isVerdef()) {
727 // The first Verdaux entry holds the name.
728 name_offset = entry.getVerdef()->getAux()->vda_name;
729 IsDefault = !(vs->vs_index & ELF::VERSYM_HIDDEN);
730 } else {
731 name_offset = entry.getVernaux()->vna_name;
732 IsDefault = false;
733 }
734 if (name_offset >= StrTab.size())
735 reportError("Invalid string offset");
736 return StringRef(StrTab.data() + name_offset);
737}
738
739template <typename ELFT>
740std::string ELFDumper<ELFT>::getFullSymbolName(const Elf_Sym *Symbol,
741 StringRef StrTable,
742 bool IsDynamic) const {
743 StringRef SymbolName = unwrapOrError(Symbol->getName(StrTable));
744 if (!IsDynamic)
745 return SymbolName;
746
747 std::string FullSymbolName(SymbolName);
748
749 bool IsDefault;
750 StringRef Version = getSymbolVersion(StrTable, &*Symbol, IsDefault);
751 FullSymbolName += (IsDefault ? "@@" : "@");
752 FullSymbolName += Version;
753 return FullSymbolName;
754}
755
756template <typename ELFT>
757void ELFDumper<ELFT>::getSectionNameIndex(const Elf_Sym *Symbol,
758 const Elf_Sym *FirstSym,
759 StringRef &SectionName,
760 unsigned &SectionIndex) const {
761 SectionIndex = Symbol->st_shndx;
762 if (Symbol->isUndefined())
763 SectionName = "Undefined";
764 else if (Symbol->isProcessorSpecific())
765 SectionName = "Processor Specific";
766 else if (Symbol->isOSSpecific())
767 SectionName = "Operating System Specific";
768 else if (Symbol->isAbsolute())
769 SectionName = "Absolute";
770 else if (Symbol->isCommon())
771 SectionName = "Common";
772 else if (Symbol->isReserved() && SectionIndex != SHN_XINDEX)
773 SectionName = "Reserved";
774 else {
775 if (SectionIndex == SHN_XINDEX)
776 SectionIndex = unwrapOrError(object::getExtendedSymbolTableIndex<ELFT>(
777 Symbol, FirstSym, ShndxTable));
778 const typename ELFT::Shdr *Sec =
779 unwrapOrError(Obj->getSection(SectionIndex));
780 SectionName = unwrapOrError(Obj->getSectionName(Sec));
781 }
782}
783
784template <class ELFO>
785static const typename ELFO::Elf_Shdr *
786findNotEmptySectionByAddress(const ELFO *Obj, uint64_t Addr) {
787 for (const auto &Shdr : unwrapOrError(Obj->sections()))
788 if (Shdr.sh_addr == Addr && Shdr.sh_size > 0)
789 return &Shdr;
790 return nullptr;
791}
792
793template <class ELFO>
794static const typename ELFO::Elf_Shdr *findSectionByName(const ELFO &Obj,
795 StringRef Name) {
796 for (const auto &Shdr : unwrapOrError(Obj.sections())) {
797 if (Name == unwrapOrError(Obj.getSectionName(&Shdr)))
798 return &Shdr;
799 }
800 return nullptr;
801}
802
803static const EnumEntry<unsigned> ElfClass[] = {
804 {"None", "none", ELF::ELFCLASSNONE},
805 {"32-bit", "ELF32", ELF::ELFCLASS32},
806 {"64-bit", "ELF64", ELF::ELFCLASS64},
807};
808
809static const EnumEntry<unsigned> ElfDataEncoding[] = {
810 {"None", "none", ELF::ELFDATANONE},
811 {"LittleEndian", "2's complement, little endian", ELF::ELFDATA2LSB},
812 {"BigEndian", "2's complement, big endian", ELF::ELFDATA2MSB},
813};
814
815static const EnumEntry<unsigned> ElfObjectFileType[] = {
816 {"None", "NONE (none)", ELF::ET_NONE},
817 {"Relocatable", "REL (Relocatable file)", ELF::ET_REL},
818 {"Executable", "EXEC (Executable file)", ELF::ET_EXEC},
819 {"SharedObject", "DYN (Shared object file)", ELF::ET_DYN},
820 {"Core", "CORE (Core file)", ELF::ET_CORE},
821};
822
823static const EnumEntry<unsigned> ElfOSABI[] = {
824 {"SystemV", "UNIX - System V", ELF::ELFOSABI_NONE},
825 {"HPUX", "UNIX - HP-UX", ELF::ELFOSABI_HPUX},
826 {"NetBSD", "UNIX - NetBSD", ELF::ELFOSABI_NETBSD},
827 {"GNU/Linux", "UNIX - GNU", ELF::ELFOSABI_LINUX},
828 {"GNU/Hurd", "GNU/Hurd", ELF::ELFOSABI_HURD},
829 {"Solaris", "UNIX - Solaris", ELF::ELFOSABI_SOLARIS},
830 {"AIX", "UNIX - AIX", ELF::ELFOSABI_AIX},
831 {"IRIX", "UNIX - IRIX", ELF::ELFOSABI_IRIX},
832 {"FreeBSD", "UNIX - FreeBSD", ELF::ELFOSABI_FREEBSD},
833 {"TRU64", "UNIX - TRU64", ELF::ELFOSABI_TRU64},
834 {"Modesto", "Novell - Modesto", ELF::ELFOSABI_MODESTO},
835 {"OpenBSD", "UNIX - OpenBSD", ELF::ELFOSABI_OPENBSD},
836 {"OpenVMS", "VMS - OpenVMS", ELF::ELFOSABI_OPENVMS},
837 {"NSK", "HP - Non-Stop Kernel", ELF::ELFOSABI_NSK},
838 {"AROS", "AROS", ELF::ELFOSABI_AROS},
839 {"FenixOS", "FenixOS", ELF::ELFOSABI_FENIXOS},
840 {"CloudABI", "CloudABI", ELF::ELFOSABI_CLOUDABI},
841 {"Standalone", "Standalone App", ELF::ELFOSABI_STANDALONE}
842};
843
844static const EnumEntry<unsigned> AMDGPUElfOSABI[] = {
845 {"AMDGPU_HSA", "AMDGPU - HSA", ELF::ELFOSABI_AMDGPU_HSA},
846 {"AMDGPU_PAL", "AMDGPU - PAL", ELF::ELFOSABI_AMDGPU_PAL},
847 {"AMDGPU_MESA3D", "AMDGPU - MESA3D", ELF::ELFOSABI_AMDGPU_MESA3D}
848};
849
850static const EnumEntry<unsigned> ARMElfOSABI[] = {
851 {"ARM", "ARM", ELF::ELFOSABI_ARM}
852};
853
854static const EnumEntry<unsigned> C6000ElfOSABI[] = {
855 {"C6000_ELFABI", "Bare-metal C6000", ELF::ELFOSABI_C6000_ELFABI},
856 {"C6000_LINUX", "Linux C6000", ELF::ELFOSABI_C6000_LINUX}
857};
858
859static const EnumEntry<unsigned> ElfMachineType[] = {
860 ENUM_ENT(EM_NONE, "None"){ "EM_NONE", "None", ELF::EM_NONE },
861 ENUM_ENT(EM_M32, "WE32100"){ "EM_M32", "WE32100", ELF::EM_M32 },
862 ENUM_ENT(EM_SPARC, "Sparc"){ "EM_SPARC", "Sparc", ELF::EM_SPARC },
863 ENUM_ENT(EM_386, "Intel 80386"){ "EM_386", "Intel 80386", ELF::EM_386 },
864 ENUM_ENT(EM_68K, "MC68000"){ "EM_68K", "MC68000", ELF::EM_68K },
865 ENUM_ENT(EM_88K, "MC88000"){ "EM_88K", "MC88000", ELF::EM_88K },
866 ENUM_ENT(EM_IAMCU, "EM_IAMCU"){ "EM_IAMCU", "EM_IAMCU", ELF::EM_IAMCU },
867 ENUM_ENT(EM_860, "Intel 80860"){ "EM_860", "Intel 80860", ELF::EM_860 },
868 ENUM_ENT(EM_MIPS, "MIPS R3000"){ "EM_MIPS", "MIPS R3000", ELF::EM_MIPS },
869 ENUM_ENT(EM_S370, "IBM System/370"){ "EM_S370", "IBM System/370", ELF::EM_S370 },
870 ENUM_ENT(EM_MIPS_RS3_LE, "MIPS R3000 little-endian"){ "EM_MIPS_RS3_LE", "MIPS R3000 little-endian", ELF::EM_MIPS_RS3_LE
}
,
871 ENUM_ENT(EM_PARISC, "HPPA"){ "EM_PARISC", "HPPA", ELF::EM_PARISC },
872 ENUM_ENT(EM_VPP500, "Fujitsu VPP500"){ "EM_VPP500", "Fujitsu VPP500", ELF::EM_VPP500 },
873 ENUM_ENT(EM_SPARC32PLUS, "Sparc v8+"){ "EM_SPARC32PLUS", "Sparc v8+", ELF::EM_SPARC32PLUS },
874 ENUM_ENT(EM_960, "Intel 80960"){ "EM_960", "Intel 80960", ELF::EM_960 },
875 ENUM_ENT(EM_PPC, "PowerPC"){ "EM_PPC", "PowerPC", ELF::EM_PPC },
876 ENUM_ENT(EM_PPC64, "PowerPC64"){ "EM_PPC64", "PowerPC64", ELF::EM_PPC64 },
877 ENUM_ENT(EM_S390, "IBM S/390"){ "EM_S390", "IBM S/390", ELF::EM_S390 },
878 ENUM_ENT(EM_SPU, "SPU"){ "EM_SPU", "SPU", ELF::EM_SPU },
879 ENUM_ENT(EM_V800, "NEC V800 series"){ "EM_V800", "NEC V800 series", ELF::EM_V800 },
880 ENUM_ENT(EM_FR20, "Fujistsu FR20"){ "EM_FR20", "Fujistsu FR20", ELF::EM_FR20 },
881 ENUM_ENT(EM_RH32, "TRW RH-32"){ "EM_RH32", "TRW RH-32", ELF::EM_RH32 },
882 ENUM_ENT(EM_RCE, "Motorola RCE"){ "EM_RCE", "Motorola RCE", ELF::EM_RCE },
883 ENUM_ENT(EM_ARM, "ARM"){ "EM_ARM", "ARM", ELF::EM_ARM },
884 ENUM_ENT(EM_ALPHA, "EM_ALPHA"){ "EM_ALPHA", "EM_ALPHA", ELF::EM_ALPHA },
885 ENUM_ENT(EM_SH, "Hitachi SH"){ "EM_SH", "Hitachi SH", ELF::EM_SH },
886 ENUM_ENT(EM_SPARCV9, "Sparc v9"){ "EM_SPARCV9", "Sparc v9", ELF::EM_SPARCV9 },
887 ENUM_ENT(EM_TRICORE, "Siemens Tricore"){ "EM_TRICORE", "Siemens Tricore", ELF::EM_TRICORE },
888 ENUM_ENT(EM_ARC, "ARC"){ "EM_ARC", "ARC", ELF::EM_ARC },
889 ENUM_ENT(EM_H8_300, "Hitachi H8/300"){ "EM_H8_300", "Hitachi H8/300", ELF::EM_H8_300 },
890 ENUM_ENT(EM_H8_300H, "Hitachi H8/300H"){ "EM_H8_300H", "Hitachi H8/300H", ELF::EM_H8_300H },
891 ENUM_ENT(EM_H8S, "Hitachi H8S"){ "EM_H8S", "Hitachi H8S", ELF::EM_H8S },
892 ENUM_ENT(EM_H8_500, "Hitachi H8/500"){ "EM_H8_500", "Hitachi H8/500", ELF::EM_H8_500 },
893 ENUM_ENT(EM_IA_64, "Intel IA-64"){ "EM_IA_64", "Intel IA-64", ELF::EM_IA_64 },
894 ENUM_ENT(EM_MIPS_X, "Stanford MIPS-X"){ "EM_MIPS_X", "Stanford MIPS-X", ELF::EM_MIPS_X },
895 ENUM_ENT(EM_COLDFIRE, "Motorola Coldfire"){ "EM_COLDFIRE", "Motorola Coldfire", ELF::EM_COLDFIRE },
896 ENUM_ENT(EM_68HC12, "Motorola MC68HC12 Microcontroller"){ "EM_68HC12", "Motorola MC68HC12 Microcontroller", ELF::EM_68HC12
}
,
897 ENUM_ENT(EM_MMA, "Fujitsu Multimedia Accelerator"){ "EM_MMA", "Fujitsu Multimedia Accelerator", ELF::EM_MMA },
898 ENUM_ENT(EM_PCP, "Siemens PCP"){ "EM_PCP", "Siemens PCP", ELF::EM_PCP },
899 ENUM_ENT(EM_NCPU, "Sony nCPU embedded RISC processor"){ "EM_NCPU", "Sony nCPU embedded RISC processor", ELF::EM_NCPU
}
,
900 ENUM_ENT(EM_NDR1, "Denso NDR1 microprocesspr"){ "EM_NDR1", "Denso NDR1 microprocesspr", ELF::EM_NDR1 },
901 ENUM_ENT(EM_STARCORE, "Motorola Star*Core processor"){ "EM_STARCORE", "Motorola Star*Core processor", ELF::EM_STARCORE
}
,
902 ENUM_ENT(EM_ME16, "Toyota ME16 processor"){ "EM_ME16", "Toyota ME16 processor", ELF::EM_ME16 },
903 ENUM_ENT(EM_ST100, "STMicroelectronics ST100 processor"){ "EM_ST100", "STMicroelectronics ST100 processor", ELF::EM_ST100
}
,
904 ENUM_ENT(EM_TINYJ, "Advanced Logic Corp. TinyJ embedded processor"){ "EM_TINYJ", "Advanced Logic Corp. TinyJ embedded processor"
, ELF::EM_TINYJ }
,
905 ENUM_ENT(EM_X86_64, "Advanced Micro Devices X86-64"){ "EM_X86_64", "Advanced Micro Devices X86-64", ELF::EM_X86_64
}
,
906 ENUM_ENT(EM_PDSP, "Sony DSP processor"){ "EM_PDSP", "Sony DSP processor", ELF::EM_PDSP },
907 ENUM_ENT(EM_PDP10, "Digital Equipment Corp. PDP-10"){ "EM_PDP10", "Digital Equipment Corp. PDP-10", ELF::EM_PDP10
}
,
908 ENUM_ENT(EM_PDP11, "Digital Equipment Corp. PDP-11"){ "EM_PDP11", "Digital Equipment Corp. PDP-11", ELF::EM_PDP11
}
,
909 ENUM_ENT(EM_FX66, "Siemens FX66 microcontroller"){ "EM_FX66", "Siemens FX66 microcontroller", ELF::EM_FX66 },
910 ENUM_ENT(EM_ST9PLUS, "STMicroelectronics ST9+ 8/16 bit microcontroller"){ "EM_ST9PLUS", "STMicroelectronics ST9+ 8/16 bit microcontroller"
, ELF::EM_ST9PLUS }
,
911 ENUM_ENT(EM_ST7, "STMicroelectronics ST7 8-bit microcontroller"){ "EM_ST7", "STMicroelectronics ST7 8-bit microcontroller", ELF
::EM_ST7 }
,
912 ENUM_ENT(EM_68HC16, "Motorola MC68HC16 Microcontroller"){ "EM_68HC16", "Motorola MC68HC16 Microcontroller", ELF::EM_68HC16
}
,
913 ENUM_ENT(EM_68HC11, "Motorola MC68HC11 Microcontroller"){ "EM_68HC11", "Motorola MC68HC11 Microcontroller", ELF::EM_68HC11
}
,
914 ENUM_ENT(EM_68HC08, "Motorola MC68HC08 Microcontroller"){ "EM_68HC08", "Motorola MC68HC08 Microcontroller", ELF::EM_68HC08
}
,
915 ENUM_ENT(EM_68HC05, "Motorola MC68HC05 Microcontroller"){ "EM_68HC05", "Motorola MC68HC05 Microcontroller", ELF::EM_68HC05
}
,
916 ENUM_ENT(EM_SVX, "Silicon Graphics SVx"){ "EM_SVX", "Silicon Graphics SVx", ELF::EM_SVX },
917 ENUM_ENT(EM_ST19, "STMicroelectronics ST19 8-bit microcontroller"){ "EM_ST19", "STMicroelectronics ST19 8-bit microcontroller",
ELF::EM_ST19 }
,
918 ENUM_ENT(EM_VAX, "Digital VAX"){ "EM_VAX", "Digital VAX", ELF::EM_VAX },
919 ENUM_ENT(EM_CRIS, "Axis Communications 32-bit embedded processor"){ "EM_CRIS", "Axis Communications 32-bit embedded processor",
ELF::EM_CRIS }
,
920 ENUM_ENT(EM_JAVELIN, "Infineon Technologies 32-bit embedded cpu"){ "EM_JAVELIN", "Infineon Technologies 32-bit embedded cpu", ELF
::EM_JAVELIN }
,
921 ENUM_ENT(EM_FIREPATH, "Element 14 64-bit DSP processor"){ "EM_FIREPATH", "Element 14 64-bit DSP processor", ELF::EM_FIREPATH
}
,
922 ENUM_ENT(EM_ZSP, "LSI Logic's 16-bit DSP processor"){ "EM_ZSP", "LSI Logic's 16-bit DSP processor", ELF::EM_ZSP },
923 ENUM_ENT(EM_MMIX, "Donald Knuth's educational 64-bit processor"){ "EM_MMIX", "Donald Knuth's educational 64-bit processor", ELF
::EM_MMIX }
,
924 ENUM_ENT(EM_HUANY, "Harvard Universitys's machine-independent object format"){ "EM_HUANY", "Harvard Universitys's machine-independent object format"
, ELF::EM_HUANY }
,
925 ENUM_ENT(EM_PRISM, "Vitesse Prism"){ "EM_PRISM", "Vitesse Prism", ELF::EM_PRISM },
926 ENUM_ENT(EM_AVR, "Atmel AVR 8-bit microcontroller"){ "EM_AVR", "Atmel AVR 8-bit microcontroller", ELF::EM_AVR },
927 ENUM_ENT(EM_FR30, "Fujitsu FR30"){ "EM_FR30", "Fujitsu FR30", ELF::EM_FR30 },
928 ENUM_ENT(EM_D10V, "Mitsubishi D10V"){ "EM_D10V", "Mitsubishi D10V", ELF::EM_D10V },
929 ENUM_ENT(EM_D30V, "Mitsubishi D30V"){ "EM_D30V", "Mitsubishi D30V", ELF::EM_D30V },
930 ENUM_ENT(EM_V850, "NEC v850"){ "EM_V850", "NEC v850", ELF::EM_V850 },
931 ENUM_ENT(EM_M32R, "Renesas M32R (formerly Mitsubishi M32r)"){ "EM_M32R", "Renesas M32R (formerly Mitsubishi M32r)", ELF::
EM_M32R }
,
932 ENUM_ENT(EM_MN10300, "Matsushita MN10300"){ "EM_MN10300", "Matsushita MN10300", ELF::EM_MN10300 },
933 ENUM_ENT(EM_MN10200, "Matsushita MN10200"){ "EM_MN10200", "Matsushita MN10200", ELF::EM_MN10200 },
934 ENUM_ENT(EM_PJ, "picoJava"){ "EM_PJ", "picoJava", ELF::EM_PJ },
935 ENUM_ENT(EM_OPENRISC, "OpenRISC 32-bit embedded processor"){ "EM_OPENRISC", "OpenRISC 32-bit embedded processor", ELF::EM_OPENRISC
}
,
936 ENUM_ENT(EM_ARC_COMPACT, "EM_ARC_COMPACT"){ "EM_ARC_COMPACT", "EM_ARC_COMPACT", ELF::EM_ARC_COMPACT },
937 ENUM_ENT(EM_XTENSA, "Tensilica Xtensa Processor"){ "EM_XTENSA", "Tensilica Xtensa Processor", ELF::EM_XTENSA },
938 ENUM_ENT(EM_VIDEOCORE, "Alphamosaic VideoCore processor"){ "EM_VIDEOCORE", "Alphamosaic VideoCore processor", ELF::EM_VIDEOCORE
}
,
939 ENUM_ENT(EM_TMM_GPP, "Thompson Multimedia General Purpose Processor"){ "EM_TMM_GPP", "Thompson Multimedia General Purpose Processor"
, ELF::EM_TMM_GPP }
,
940 ENUM_ENT(EM_NS32K, "National Semiconductor 32000 series"){ "EM_NS32K", "National Semiconductor 32000 series", ELF::EM_NS32K
}
,
941 ENUM_ENT(EM_TPC, "Tenor Network TPC processor"){ "EM_TPC", "Tenor Network TPC processor", ELF::EM_TPC },
942 ENUM_ENT(EM_SNP1K, "EM_SNP1K"){ "EM_SNP1K", "EM_SNP1K", ELF::EM_SNP1K },
943 ENUM_ENT(EM_ST200, "STMicroelectronics ST200 microcontroller"){ "EM_ST200", "STMicroelectronics ST200 microcontroller", ELF
::EM_ST200 }
,
944 ENUM_ENT(EM_IP2K, "Ubicom IP2xxx 8-bit microcontrollers"){ "EM_IP2K", "Ubicom IP2xxx 8-bit microcontrollers", ELF::EM_IP2K
}
,
945 ENUM_ENT(EM_MAX, "MAX Processor"){ "EM_MAX", "MAX Processor", ELF::EM_MAX },
946 ENUM_ENT(EM_CR, "National Semiconductor CompactRISC"){ "EM_CR", "National Semiconductor CompactRISC", ELF::EM_CR },
947 ENUM_ENT(EM_F2MC16, "Fujitsu F2MC16"){ "EM_F2MC16", "Fujitsu F2MC16", ELF::EM_F2MC16 },
948 ENUM_ENT(EM_MSP430, "Texas Instruments msp430 microcontroller"){ "EM_MSP430", "Texas Instruments msp430 microcontroller", ELF
::EM_MSP430 }
,
949 ENUM_ENT(EM_BLACKFIN, "Analog Devices Blackfin"){ "EM_BLACKFIN", "Analog Devices Blackfin", ELF::EM_BLACKFIN },
950 ENUM_ENT(EM_SE_C33, "S1C33 Family of Seiko Epson processors"){ "EM_SE_C33", "S1C33 Family of Seiko Epson processors", ELF::
EM_SE_C33 }
,
951 ENUM_ENT(EM_SEP, "Sharp embedded microprocessor"){ "EM_SEP", "Sharp embedded microprocessor", ELF::EM_SEP },
952 ENUM_ENT(EM_ARCA, "Arca RISC microprocessor"){ "EM_ARCA", "Arca RISC microprocessor", ELF::EM_ARCA },
953 ENUM_ENT(EM_UNICORE, "Unicore"){ "EM_UNICORE", "Unicore", ELF::EM_UNICORE },
954 ENUM_ENT(EM_EXCESS, "eXcess 16/32/64-bit configurable embedded CPU"){ "EM_EXCESS", "eXcess 16/32/64-bit configurable embedded CPU"
, ELF::EM_EXCESS }
,
955 ENUM_ENT(EM_DXP, "Icera Semiconductor Inc. Deep Execution Processor"){ "EM_DXP", "Icera Semiconductor Inc. Deep Execution Processor"
, ELF::EM_DXP }
,
956 ENUM_ENT(EM_ALTERA_NIOS2, "Altera Nios"){ "EM_ALTERA_NIOS2", "Altera Nios", ELF::EM_ALTERA_NIOS2 },
957 ENUM_ENT(EM_CRX, "National Semiconductor CRX microprocessor"){ "EM_CRX", "National Semiconductor CRX microprocessor", ELF::
EM_CRX }
,
958 ENUM_ENT(EM_XGATE, "Motorola XGATE embedded processor"){ "EM_XGATE", "Motorola XGATE embedded processor", ELF::EM_XGATE
}
,
959 ENUM_ENT(EM_C166, "Infineon Technologies xc16x"){ "EM_C166", "Infineon Technologies xc16x", ELF::EM_C166 },
960 ENUM_ENT(EM_M16C, "Renesas M16C"){ "EM_M16C", "Renesas M16C", ELF::EM_M16C },
961 ENUM_ENT(EM_DSPIC30F, "Microchip Technology dsPIC30F Digital Signal Controller"){ "EM_DSPIC30F", "Microchip Technology dsPIC30F Digital Signal Controller"
, ELF::EM_DSPIC30F }
,
962 ENUM_ENT(EM_CE, "Freescale Communication Engine RISC core"){ "EM_CE", "Freescale Communication Engine RISC core", ELF::EM_CE
}
,
963 ENUM_ENT(EM_M32C, "Renesas M32C"){ "EM_M32C", "Renesas M32C", ELF::EM_M32C },
964 ENUM_ENT(EM_TSK3000, "Altium TSK3000 core"){ "EM_TSK3000", "Altium TSK3000 core", ELF::EM_TSK3000 },
965 ENUM_ENT(EM_RS08, "Freescale RS08 embedded processor"){ "EM_RS08", "Freescale RS08 embedded processor", ELF::EM_RS08
}
,
966 ENUM_ENT(EM_SHARC, "EM_SHARC"){ "EM_SHARC", "EM_SHARC", ELF::EM_SHARC },
967 ENUM_ENT(EM_ECOG2, "Cyan Technology eCOG2 microprocessor"){ "EM_ECOG2", "Cyan Technology eCOG2 microprocessor", ELF::EM_ECOG2
}
,
968 ENUM_ENT(EM_SCORE7, "SUNPLUS S+Core"){ "EM_SCORE7", "SUNPLUS S+Core", ELF::EM_SCORE7 },
969 ENUM_ENT(EM_DSP24, "New Japan Radio (NJR) 24-bit DSP Processor"){ "EM_DSP24", "New Japan Radio (NJR) 24-bit DSP Processor", ELF
::EM_DSP24 }
,
970 ENUM_ENT(EM_VIDEOCORE3, "Broadcom VideoCore III processor"){ "EM_VIDEOCORE3", "Broadcom VideoCore III processor", ELF::EM_VIDEOCORE3
}
,
971 ENUM_ENT(EM_LATTICEMICO32, "Lattice Mico32"){ "EM_LATTICEMICO32", "Lattice Mico32", ELF::EM_LATTICEMICO32
}
,
972 ENUM_ENT(EM_SE_C17, "Seiko Epson C17 family"){ "EM_SE_C17", "Seiko Epson C17 family", ELF::EM_SE_C17 },
973 ENUM_ENT(EM_TI_C6000, "Texas Instruments TMS320C6000 DSP family"){ "EM_TI_C6000", "Texas Instruments TMS320C6000 DSP family", ELF
::EM_TI_C6000 }
,
974 ENUM_ENT(EM_TI_C2000, "Texas Instruments TMS320C2000 DSP family"){ "EM_TI_C2000", "Texas Instruments TMS320C2000 DSP family", ELF
::EM_TI_C2000 }
,
975 ENUM_ENT(EM_TI_C5500, "Texas Instruments TMS320C55x DSP family"){ "EM_TI_C5500", "Texas Instruments TMS320C55x DSP family", ELF
::EM_TI_C5500 }
,
976 ENUM_ENT(EM_MMDSP_PLUS, "STMicroelectronics 64bit VLIW Data Signal Processor"){ "EM_MMDSP_PLUS", "STMicroelectronics 64bit VLIW Data Signal Processor"
, ELF::EM_MMDSP_PLUS }
,
977 ENUM_ENT(EM_CYPRESS_M8C, "Cypress M8C microprocessor"){ "EM_CYPRESS_M8C", "Cypress M8C microprocessor", ELF::EM_CYPRESS_M8C
}
,
978 ENUM_ENT(EM_R32C, "Renesas R32C series microprocessors"){ "EM_R32C", "Renesas R32C series microprocessors", ELF::EM_R32C
}
,
979 ENUM_ENT(EM_TRIMEDIA, "NXP Semiconductors TriMedia architecture family"){ "EM_TRIMEDIA", "NXP Semiconductors TriMedia architecture family"
, ELF::EM_TRIMEDIA }
,
980 ENUM_ENT(EM_HEXAGON, "Qualcomm Hexagon"){ "EM_HEXAGON", "Qualcomm Hexagon", ELF::EM_HEXAGON },
981 ENUM_ENT(EM_8051, "Intel 8051 and variants"){ "EM_8051", "Intel 8051 and variants", ELF::EM_8051 },
982 ENUM_ENT(EM_STXP7X, "STMicroelectronics STxP7x family"){ "EM_STXP7X", "STMicroelectronics STxP7x family", ELF::EM_STXP7X
}
,
983 ENUM_ENT(EM_NDS32, "Andes Technology compact code size embedded RISC processor family"){ "EM_NDS32", "Andes Technology compact code size embedded RISC processor family"
, ELF::EM_NDS32 }
,
984 ENUM_ENT(EM_ECOG1, "Cyan Technology eCOG1 microprocessor"){ "EM_ECOG1", "Cyan Technology eCOG1 microprocessor", ELF::EM_ECOG1
}
,
985 ENUM_ENT(EM_ECOG1X, "Cyan Technology eCOG1X family"){ "EM_ECOG1X", "Cyan Technology eCOG1X family", ELF::EM_ECOG1X
}
,
986 ENUM_ENT(EM_MAXQ30, "Dallas Semiconductor MAXQ30 Core microcontrollers"){ "EM_MAXQ30", "Dallas Semiconductor MAXQ30 Core microcontrollers"
, ELF::EM_MAXQ30 }
,
987 ENUM_ENT(EM_XIMO16, "New Japan Radio (NJR) 16-bit DSP Processor"){ "EM_XIMO16", "New Japan Radio (NJR) 16-bit DSP Processor", ELF
::EM_XIMO16 }
,
988 ENUM_ENT(EM_MANIK, "M2000 Reconfigurable RISC Microprocessor"){ "EM_MANIK", "M2000 Reconfigurable RISC Microprocessor", ELF
::EM_MANIK }
,
989 ENUM_ENT(EM_CRAYNV2, "Cray Inc. NV2 vector architecture"){ "EM_CRAYNV2", "Cray Inc. NV2 vector architecture", ELF::EM_CRAYNV2
}
,
990 ENUM_ENT(EM_RX, "Renesas RX"){ "EM_RX", "Renesas RX", ELF::EM_RX },
991 ENUM_ENT(EM_METAG, "Imagination Technologies Meta processor architecture"){ "EM_METAG", "Imagination Technologies Meta processor architecture"
, ELF::EM_METAG }
,
992 ENUM_ENT(EM_MCST_ELBRUS, "MCST Elbrus general purpose hardware architecture"){ "EM_MCST_ELBRUS", "MCST Elbrus general purpose hardware architecture"
, ELF::EM_MCST_ELBRUS }
,
993 ENUM_ENT(EM_ECOG16, "Cyan Technology eCOG16 family"){ "EM_ECOG16", "Cyan Technology eCOG16 family", ELF::EM_ECOG16
}
,
994 ENUM_ENT(EM_CR16, "Xilinx MicroBlaze"){ "EM_CR16", "Xilinx MicroBlaze", ELF::EM_CR16 },
995 ENUM_ENT(EM_ETPU, "Freescale Extended Time Processing Unit"){ "EM_ETPU", "Freescale Extended Time Processing Unit", ELF::
EM_ETPU }
,
996 ENUM_ENT(EM_SLE9X, "Infineon Technologies SLE9X core"){ "EM_SLE9X", "Infineon Technologies SLE9X core", ELF::EM_SLE9X
}
,
997 ENUM_ENT(EM_L10M, "EM_L10M"){ "EM_L10M", "EM_L10M", ELF::EM_L10M },
998 ENUM_ENT(EM_K10M, "EM_K10M"){ "EM_K10M", "EM_K10M", ELF::EM_K10M },
999 ENUM_ENT(EM_AARCH64, "AArch64"){ "EM_AARCH64", "AArch64", ELF::EM_AARCH64 },
1000 ENUM_ENT(EM_AVR32, "Atmel Corporation 32-bit microprocessor family"){ "EM_AVR32", "Atmel Corporation 32-bit microprocessor family"
, ELF::EM_AVR32 }
,
1001 ENUM_ENT(EM_STM8, "STMicroeletronics STM8 8-bit microcontroller"){ "EM_STM8", "STMicroeletronics STM8 8-bit microcontroller", ELF
::EM_STM8 }
,
1002 ENUM_ENT(EM_TILE64, "Tilera TILE64 multicore architecture family"){ "EM_TILE64", "Tilera TILE64 multicore architecture family",
ELF::EM_TILE64 }
,
1003 ENUM_ENT(EM_TILEPRO, "Tilera TILEPro multicore architecture family"){ "EM_TILEPRO", "Tilera TILEPro multicore architecture family"
, ELF::EM_TILEPRO }
,
1004 ENUM_ENT(EM_CUDA, "NVIDIA CUDA architecture"){ "EM_CUDA", "NVIDIA CUDA architecture", ELF::EM_CUDA },
1005 ENUM_ENT(EM_TILEGX, "Tilera TILE-Gx multicore architecture family"){ "EM_TILEGX", "Tilera TILE-Gx multicore architecture family"
, ELF::EM_TILEGX }
,
1006 ENUM_ENT(EM_CLOUDSHIELD, "EM_CLOUDSHIELD"){ "EM_CLOUDSHIELD", "EM_CLOUDSHIELD", ELF::EM_CLOUDSHIELD },
1007 ENUM_ENT(EM_COREA_1ST, "EM_COREA_1ST"){ "EM_COREA_1ST", "EM_COREA_1ST", ELF::EM_COREA_1ST },
1008 ENUM_ENT(EM_COREA_2ND, "EM_COREA_2ND"){ "EM_COREA_2ND", "EM_COREA_2ND", ELF::EM_COREA_2ND },
1009 ENUM_ENT(EM_ARC_COMPACT2, "EM_ARC_COMPACT2"){ "EM_ARC_COMPACT2", "EM_ARC_COMPACT2", ELF::EM_ARC_COMPACT2 },
1010 ENUM_ENT(EM_OPEN8, "EM_OPEN8"){ "EM_OPEN8", "EM_OPEN8", ELF::EM_OPEN8 },
1011 ENUM_ENT(EM_RL78, "Renesas RL78"){ "EM_RL78", "Renesas RL78", ELF::EM_RL78 },
1012 ENUM_ENT(EM_VIDEOCORE5, "Broadcom VideoCore V processor"){ "EM_VIDEOCORE5", "Broadcom VideoCore V processor", ELF::EM_VIDEOCORE5
}
,
1013 ENUM_ENT(EM_78KOR, "EM_78KOR"){ "EM_78KOR", "EM_78KOR", ELF::EM_78KOR },
1014 ENUM_ENT(EM_56800EX, "EM_56800EX"){ "EM_56800EX", "EM_56800EX", ELF::EM_56800EX },
1015 ENUM_ENT(EM_AMDGPU, "EM_AMDGPU"){ "EM_AMDGPU", "EM_AMDGPU", ELF::EM_AMDGPU },
1016 ENUM_ENT(EM_RISCV, "RISC-V"){ "EM_RISCV", "RISC-V", ELF::EM_RISCV },
1017 ENUM_ENT(EM_WEBASSEMBLY, "EM_WEBASSEMBLY"){ "EM_WEBASSEMBLY", "EM_WEBASSEMBLY", ELF::EM_WEBASSEMBLY },
1018 ENUM_ENT(EM_LANAI, "EM_LANAI"){ "EM_LANAI", "EM_LANAI", ELF::EM_LANAI },
1019 ENUM_ENT(EM_BPF, "EM_BPF"){ "EM_BPF", "EM_BPF", ELF::EM_BPF },
1020};
1021
1022static const EnumEntry<unsigned> ElfSymbolBindings[] = {
1023 {"Local", "LOCAL", ELF::STB_LOCAL},
1024 {"Global", "GLOBAL", ELF::STB_GLOBAL},
1025 {"Weak", "WEAK", ELF::STB_WEAK},
1026 {"Unique", "UNIQUE", ELF::STB_GNU_UNIQUE}};
1027
1028static const EnumEntry<unsigned> ElfSymbolVisibilities[] = {
1029 {"DEFAULT", "DEFAULT", ELF::STV_DEFAULT},
1030 {"INTERNAL", "INTERNAL", ELF::STV_INTERNAL},
1031 {"HIDDEN", "HIDDEN", ELF::STV_HIDDEN},
1032 {"PROTECTED", "PROTECTED", ELF::STV_PROTECTED}};
1033
1034static const EnumEntry<unsigned> ElfSymbolTypes[] = {
1035 {"None", "NOTYPE", ELF::STT_NOTYPE},
1036 {"Object", "OBJECT", ELF::STT_OBJECT},
1037 {"Function", "FUNC", ELF::STT_FUNC},
1038 {"Section", "SECTION", ELF::STT_SECTION},
1039 {"File", "FILE", ELF::STT_FILE},
1040 {"Common", "COMMON", ELF::STT_COMMON},
1041 {"TLS", "TLS", ELF::STT_TLS},
1042 {"GNU_IFunc", "IFUNC", ELF::STT_GNU_IFUNC}};
1043
1044static const EnumEntry<unsigned> AMDGPUSymbolTypes[] = {
1045 { "AMDGPU_HSA_KERNEL", ELF::STT_AMDGPU_HSA_KERNEL }
1046};
1047
1048static const char *getGroupType(uint32_t Flag) {
1049 if (Flag & ELF::GRP_COMDAT)
1050 return "COMDAT";
1051 else
1052 return "(unknown)";
1053}
1054
1055static const EnumEntry<unsigned> ElfSectionFlags[] = {
1056 ENUM_ENT(SHF_WRITE, "W"){ "SHF_WRITE", "W", ELF::SHF_WRITE },
1057 ENUM_ENT(SHF_ALLOC, "A"){ "SHF_ALLOC", "A", ELF::SHF_ALLOC },
1058 ENUM_ENT(SHF_EXCLUDE, "E"){ "SHF_EXCLUDE", "E", ELF::SHF_EXCLUDE },
1059 ENUM_ENT(SHF_EXECINSTR, "X"){ "SHF_EXECINSTR", "X", ELF::SHF_EXECINSTR },
1060 ENUM_ENT(SHF_MERGE, "M"){ "SHF_MERGE", "M", ELF::SHF_MERGE },
1061 ENUM_ENT(SHF_STRINGS, "S"){ "SHF_STRINGS", "S", ELF::SHF_STRINGS },
1062 ENUM_ENT(SHF_INFO_LINK, "I"){ "SHF_INFO_LINK", "I", ELF::SHF_INFO_LINK },
1063 ENUM_ENT(SHF_LINK_ORDER, "L"){ "SHF_LINK_ORDER", "L", ELF::SHF_LINK_ORDER },
1064 ENUM_ENT(SHF_OS_NONCONFORMING, "o"){ "SHF_OS_NONCONFORMING", "o", ELF::SHF_OS_NONCONFORMING },
1065 ENUM_ENT(SHF_GROUP, "G"){ "SHF_GROUP", "G", ELF::SHF_GROUP },
1066 ENUM_ENT(SHF_TLS, "T"){ "SHF_TLS", "T", ELF::SHF_TLS },
1067 ENUM_ENT(SHF_MASKOS, "o"){ "SHF_MASKOS", "o", ELF::SHF_MASKOS },
1068 ENUM_ENT(SHF_MASKPROC, "p"){ "SHF_MASKPROC", "p", ELF::SHF_MASKPROC },
1069 ENUM_ENT_1(SHF_COMPRESSED){ "SHF_COMPRESSED", "SHF_COMPRESSED", ELF::SHF_COMPRESSED },
1070};
1071
1072static const EnumEntry<unsigned> ElfXCoreSectionFlags[] = {
1073 LLVM_READOBJ_ENUM_ENT(ELF, XCORE_SHF_CP_SECTION){ "XCORE_SHF_CP_SECTION", ELF::XCORE_SHF_CP_SECTION },
1074 LLVM_READOBJ_ENUM_ENT(ELF, XCORE_SHF_DP_SECTION){ "XCORE_SHF_DP_SECTION", ELF::XCORE_SHF_DP_SECTION }
1075};
1076
1077static const EnumEntry<unsigned> ElfARMSectionFlags[] = {
1078 LLVM_READOBJ_ENUM_ENT(ELF, SHF_ARM_PURECODE){ "SHF_ARM_PURECODE", ELF::SHF_ARM_PURECODE }
1079};
1080
1081static const EnumEntry<unsigned> ElfHexagonSectionFlags[] = {
1082 LLVM_READOBJ_ENUM_ENT(ELF, SHF_HEX_GPREL){ "SHF_HEX_GPREL", ELF::SHF_HEX_GPREL }
1083};
1084
1085static const EnumEntry<unsigned> ElfMipsSectionFlags[] = {
1086 LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_NODUPES){ "SHF_MIPS_NODUPES", ELF::SHF_MIPS_NODUPES },
1087 LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_NAMES ){ "SHF_MIPS_NAMES", ELF::SHF_MIPS_NAMES },
1088 LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_LOCAL ){ "SHF_MIPS_LOCAL", ELF::SHF_MIPS_LOCAL },
1089 LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_NOSTRIP){ "SHF_MIPS_NOSTRIP", ELF::SHF_MIPS_NOSTRIP },
1090 LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_GPREL ){ "SHF_MIPS_GPREL", ELF::SHF_MIPS_GPREL },
1091 LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_MERGE ){ "SHF_MIPS_MERGE", ELF::SHF_MIPS_MERGE },
1092 LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_ADDR ){ "SHF_MIPS_ADDR", ELF::SHF_MIPS_ADDR },
1093 LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_STRING ){ "SHF_MIPS_STRING", ELF::SHF_MIPS_STRING }
1094};
1095
1096static const EnumEntry<unsigned> ElfX86_64SectionFlags[] = {
1097 LLVM_READOBJ_ENUM_ENT(ELF, SHF_X86_64_LARGE){ "SHF_X86_64_LARGE", ELF::SHF_X86_64_LARGE }
1098};
1099
1100static std::string getGNUFlags(uint64_t Flags) {
1101 std::string Str;
1102 for (auto Entry : ElfSectionFlags) {
1103 uint64_t Flag = Entry.Value & Flags;
1104 Flags &= ~Entry.Value;
1105 switch (Flag) {
1106 case ELF::SHF_WRITE:
1107 case ELF::SHF_ALLOC:
1108 case ELF::SHF_EXECINSTR:
1109 case ELF::SHF_MERGE:
1110 case ELF::SHF_STRINGS:
1111 case ELF::SHF_INFO_LINK:
1112 case ELF::SHF_LINK_ORDER:
1113 case ELF::SHF_OS_NONCONFORMING:
1114 case ELF::SHF_GROUP:
1115 case ELF::SHF_TLS:
1116 case ELF::SHF_EXCLUDE:
1117 Str += Entry.AltName;
1118 break;
1119 default:
1120 if (Flag & ELF::SHF_MASKOS)
1121 Str += "o";
1122 else if (Flag & ELF::SHF_MASKPROC)
1123 Str += "p";
1124 else if (Flag)
1125 Str += "x";
1126 }
1127 }
1128 return Str;
1129}
1130
1131static const char *getElfSegmentType(unsigned Arch, unsigned Type) {
1132 // Check potentially overlapped processor-specific
1133 // program header type.
1134 switch (Arch) {
1135 case ELF::EM_ARM:
1136 switch (Type) {
1137 LLVM_READOBJ_ENUM_CASE(ELF, PT_ARM_EXIDX)case ELF::PT_ARM_EXIDX: return "PT_ARM_EXIDX";;
1138 }
1139 case ELF::EM_MIPS:
1140 case ELF::EM_MIPS_RS3_LE:
1141 switch (Type) {
1142 LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_REGINFO)case ELF::PT_MIPS_REGINFO: return "PT_MIPS_REGINFO";;
1143 LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_RTPROC)case ELF::PT_MIPS_RTPROC: return "PT_MIPS_RTPROC";;
1144 LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_OPTIONS)case ELF::PT_MIPS_OPTIONS: return "PT_MIPS_OPTIONS";;
1145 LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_ABIFLAGS)case ELF::PT_MIPS_ABIFLAGS: return "PT_MIPS_ABIFLAGS";;
1146 }
1147 }
1148
1149 switch (Type) {
1150 LLVM_READOBJ_ENUM_CASE(ELF, PT_NULL )case ELF::PT_NULL: return "PT_NULL";;
1151 LLVM_READOBJ_ENUM_CASE(ELF, PT_LOAD )case ELF::PT_LOAD: return "PT_LOAD";;
1152 LLVM_READOBJ_ENUM_CASE(ELF, PT_DYNAMIC)case ELF::PT_DYNAMIC: return "PT_DYNAMIC";;
1153 LLVM_READOBJ_ENUM_CASE(ELF, PT_INTERP )case ELF::PT_INTERP: return "PT_INTERP";;
1154 LLVM_READOBJ_ENUM_CASE(ELF, PT_NOTE )case ELF::PT_NOTE: return "PT_NOTE";;
1155 LLVM_READOBJ_ENUM_CASE(ELF, PT_SHLIB )case ELF::PT_SHLIB: return "PT_SHLIB";;
1156 LLVM_READOBJ_ENUM_CASE(ELF, PT_PHDR )case ELF::PT_PHDR: return "PT_PHDR";;
1157 LLVM_READOBJ_ENUM_CASE(ELF, PT_TLS )case ELF::PT_TLS: return "PT_TLS";;
1158
1159 LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_EH_FRAME)case ELF::PT_GNU_EH_FRAME: return "PT_GNU_EH_FRAME";;
1160 LLVM_READOBJ_ENUM_CASE(ELF, PT_SUNW_UNWIND)case ELF::PT_SUNW_UNWIND: return "PT_SUNW_UNWIND";;
1161
1162 LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_STACK)case ELF::PT_GNU_STACK: return "PT_GNU_STACK";;
1163 LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_RELRO)case ELF::PT_GNU_RELRO: return "PT_GNU_RELRO";;
1164
1165 LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_RANDOMIZE)case ELF::PT_OPENBSD_RANDOMIZE: return "PT_OPENBSD_RANDOMIZE"
;
;
1166 LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_WXNEEDED)case ELF::PT_OPENBSD_WXNEEDED: return "PT_OPENBSD_WXNEEDED";;
1167 LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_BOOTDATA)case ELF::PT_OPENBSD_BOOTDATA: return "PT_OPENBSD_BOOTDATA";;
1168
1169 default: return "";
1170 }
1171}
1172
1173static std::string getElfPtType(unsigned Arch, unsigned Type) {
1174 switch (Type) {
1175 LLVM_READOBJ_PHDR_ENUM(ELF, PT_NULL)case ELF::PT_NULL: return std::string("PT_NULL").substr(3);
1176 LLVM_READOBJ_PHDR_ENUM(ELF, PT_LOAD)case ELF::PT_LOAD: return std::string("PT_LOAD").substr(3);
1177 LLVM_READOBJ_PHDR_ENUM(ELF, PT_DYNAMIC)case ELF::PT_DYNAMIC: return std::string("PT_DYNAMIC").substr
(3);
1178 LLVM_READOBJ_PHDR_ENUM(ELF, PT_INTERP)case ELF::PT_INTERP: return std::string("PT_INTERP").substr(3
);
1179 LLVM_READOBJ_PHDR_ENUM(ELF, PT_NOTE)case ELF::PT_NOTE: return std::string("PT_NOTE").substr(3);
1180 LLVM_READOBJ_PHDR_ENUM(ELF, PT_SHLIB)case ELF::PT_SHLIB: return std::string("PT_SHLIB").substr(3);
1181 LLVM_READOBJ_PHDR_ENUM(ELF, PT_PHDR)case ELF::PT_PHDR: return std::string("PT_PHDR").substr(3);
1182 LLVM_READOBJ_PHDR_ENUM(ELF, PT_TLS)case ELF::PT_TLS: return std::string("PT_TLS").substr(3);
1183 LLVM_READOBJ_PHDR_ENUM(ELF, PT_GNU_EH_FRAME)case ELF::PT_GNU_EH_FRAME: return std::string("PT_GNU_EH_FRAME"
).substr(3);
1184 LLVM_READOBJ_PHDR_ENUM(ELF, PT_SUNW_UNWIND)case ELF::PT_SUNW_UNWIND: return std::string("PT_SUNW_UNWIND"
).substr(3);
1185 LLVM_READOBJ_PHDR_ENUM(ELF, PT_GNU_STACK)case ELF::PT_GNU_STACK: return std::string("PT_GNU_STACK").substr
(3);
1186 LLVM_READOBJ_PHDR_ENUM(ELF, PT_GNU_RELRO)case ELF::PT_GNU_RELRO: return std::string("PT_GNU_RELRO").substr
(3);
1187 default:
1188 // All machine specific PT_* types
1189 switch (Arch) {
1190 case ELF::EM_ARM:
1191 if (Type == ELF::PT_ARM_EXIDX)
1192 return "EXIDX";
1193 return "";
1194 case ELF::EM_MIPS:
1195 case ELF::EM_MIPS_RS3_LE:
1196 switch (Type) {
1197 case PT_MIPS_REGINFO:
1198 return "REGINFO";
1199 case PT_MIPS_RTPROC:
1200 return "RTPROC";
1201 case PT_MIPS_OPTIONS:
1202 return "OPTIONS";
1203 case PT_MIPS_ABIFLAGS:
1204 return "ABIFLAGS";
1205 }
1206 return "";
1207 }
1208 }
1209 return std::string("<unknown>: ") + to_string(format_hex(Type, 1));
1210}
1211
1212static const EnumEntry<unsigned> ElfSegmentFlags[] = {
1213 LLVM_READOBJ_ENUM_ENT(ELF, PF_X){ "PF_X", ELF::PF_X },
1214 LLVM_READOBJ_ENUM_ENT(ELF, PF_W){ "PF_W", ELF::PF_W },
1215 LLVM_READOBJ_ENUM_ENT(ELF, PF_R){ "PF_R", ELF::PF_R }
1216};
1217
1218static const EnumEntry<unsigned> ElfHeaderMipsFlags[] = {
1219 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_NOREORDER){ "EF_MIPS_NOREORDER", ELF::EF_MIPS_NOREORDER },
1220 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_PIC){ "EF_MIPS_PIC", ELF::EF_MIPS_PIC },
1221 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_CPIC){ "EF_MIPS_CPIC", ELF::EF_MIPS_CPIC },
1222 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ABI2){ "EF_MIPS_ABI2", ELF::EF_MIPS_ABI2 },
1223 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_32BITMODE){ "EF_MIPS_32BITMODE", ELF::EF_MIPS_32BITMODE },
1224 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_FP64){ "EF_MIPS_FP64", ELF::EF_MIPS_FP64 },
1225 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_NAN2008){ "EF_MIPS_NAN2008", ELF::EF_MIPS_NAN2008 },
1226 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ABI_O32){ "EF_MIPS_ABI_O32", ELF::EF_MIPS_ABI_O32 },
1227 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ABI_O64){ "EF_MIPS_ABI_O64", ELF::EF_MIPS_ABI_O64 },
1228 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ABI_EABI32){ "EF_MIPS_ABI_EABI32", ELF::EF_MIPS_ABI_EABI32 },
1229 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ABI_EABI64){ "EF_MIPS_ABI_EABI64", ELF::EF_MIPS_ABI_EABI64 },
1230 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_3900){ "EF_MIPS_MACH_3900", ELF::EF_MIPS_MACH_3900 },
1231 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_4010){ "EF_MIPS_MACH_4010", ELF::EF_MIPS_MACH_4010 },
1232 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_4100){ "EF_MIPS_MACH_4100", ELF::EF_MIPS_MACH_4100 },
1233 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_4650){ "EF_MIPS_MACH_4650", ELF::EF_MIPS_MACH_4650 },
1234 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_4120){ "EF_MIPS_MACH_4120", ELF::EF_MIPS_MACH_4120 },
1235 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_4111){ "EF_MIPS_MACH_4111", ELF::EF_MIPS_MACH_4111 },
1236 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_SB1){ "EF_MIPS_MACH_SB1", ELF::EF_MIPS_MACH_SB1 },
1237 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_OCTEON){ "EF_MIPS_MACH_OCTEON", ELF::EF_MIPS_MACH_OCTEON },
1238 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_XLR){ "EF_MIPS_MACH_XLR", ELF::EF_MIPS_MACH_XLR },
1239 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_OCTEON2){ "EF_MIPS_MACH_OCTEON2", ELF::EF_MIPS_MACH_OCTEON2 },
1240 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_OCTEON3){ "EF_MIPS_MACH_OCTEON3", ELF::EF_MIPS_MACH_OCTEON3 },
1241 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_5400){ "EF_MIPS_MACH_5400", ELF::EF_MIPS_MACH_5400 },
1242 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_5900){ "EF_MIPS_MACH_5900", ELF::EF_MIPS_MACH_5900 },
1243 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_5500){ "EF_MIPS_MACH_5500", ELF::EF_MIPS_MACH_5500 },
1244 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_9000){ "EF_MIPS_MACH_9000", ELF::EF_MIPS_MACH_9000 },
1245 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_LS2E){ "EF_MIPS_MACH_LS2E", ELF::EF_MIPS_MACH_LS2E },
1246 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_LS2F){ "EF_MIPS_MACH_LS2F", ELF::EF_MIPS_MACH_LS2F },
1247 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MACH_LS3A){ "EF_MIPS_MACH_LS3A", ELF::EF_MIPS_MACH_LS3A },
1248 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_MICROMIPS){ "EF_MIPS_MICROMIPS", ELF::EF_MIPS_MICROMIPS },
1249 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_ASE_M16){ "EF_MIPS_ARCH_ASE_M16", ELF::EF_MIPS_ARCH_ASE_M16 },
1250 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_ASE_MDMX){ "EF_MIPS_ARCH_ASE_MDMX", ELF::EF_MIPS_ARCH_ASE_MDMX },
1251 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_1){ "EF_MIPS_ARCH_1", ELF::EF_MIPS_ARCH_1 },
1252 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_2){ "EF_MIPS_ARCH_2", ELF::EF_MIPS_ARCH_2 },
1253 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_3){ "EF_MIPS_ARCH_3", ELF::EF_MIPS_ARCH_3 },
1254 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_4){ "EF_MIPS_ARCH_4", ELF::EF_MIPS_ARCH_4 },
1255 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_5){ "EF_MIPS_ARCH_5", ELF::EF_MIPS_ARCH_5 },
1256 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_32){ "EF_MIPS_ARCH_32", ELF::EF_MIPS_ARCH_32 },
1257 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_64){ "EF_MIPS_ARCH_64", ELF::EF_MIPS_ARCH_64 },
1258 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_32R2){ "EF_MIPS_ARCH_32R2", ELF::EF_MIPS_ARCH_32R2 },
1259 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_64R2){ "EF_MIPS_ARCH_64R2", ELF::EF_MIPS_ARCH_64R2 },
1260 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_32R6){ "EF_MIPS_ARCH_32R6", ELF::EF_MIPS_ARCH_32R6 },
1261 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_64R6){ "EF_MIPS_ARCH_64R6", ELF::EF_MIPS_ARCH_64R6 }
1262};
1263
1264static const EnumEntry<unsigned> ElfHeaderAMDGPUFlags[] = {
1265 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_NONE){ "EF_AMDGPU_MACH_NONE", ELF::EF_AMDGPU_MACH_NONE },
1266 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_R600){ "EF_AMDGPU_MACH_R600_R600", ELF::EF_AMDGPU_MACH_R600_R600 },
1267 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_R630){ "EF_AMDGPU_MACH_R600_R630", ELF::EF_AMDGPU_MACH_R600_R630 },
1268 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_RS880){ "EF_AMDGPU_MACH_R600_RS880", ELF::EF_AMDGPU_MACH_R600_RS880
}
,
1269 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_RV670){ "EF_AMDGPU_MACH_R600_RV670", ELF::EF_AMDGPU_MACH_R600_RV670
}
,
1270 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_RV710){ "EF_AMDGPU_MACH_R600_RV710", ELF::EF_AMDGPU_MACH_R600_RV710
}
,
1271 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_RV730){ "EF_AMDGPU_MACH_R600_RV730", ELF::EF_AMDGPU_MACH_R600_RV730
}
,
1272 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_RV770){ "EF_AMDGPU_MACH_R600_RV770", ELF::EF_AMDGPU_MACH_R600_RV770
}
,
1273 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_CEDAR){ "EF_AMDGPU_MACH_R600_CEDAR", ELF::EF_AMDGPU_MACH_R600_CEDAR
}
,
1274 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_CYPRESS){ "EF_AMDGPU_MACH_R600_CYPRESS", ELF::EF_AMDGPU_MACH_R600_CYPRESS
}
,
1275 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_JUNIPER){ "EF_AMDGPU_MACH_R600_JUNIPER", ELF::EF_AMDGPU_MACH_R600_JUNIPER
}
,
1276 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_REDWOOD){ "EF_AMDGPU_MACH_R600_REDWOOD", ELF::EF_AMDGPU_MACH_R600_REDWOOD
}
,
1277 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_SUMO){ "EF_AMDGPU_MACH_R600_SUMO", ELF::EF_AMDGPU_MACH_R600_SUMO },
1278 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_BARTS){ "EF_AMDGPU_MACH_R600_BARTS", ELF::EF_AMDGPU_MACH_R600_BARTS
}
,
1279 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_CAICOS){ "EF_AMDGPU_MACH_R600_CAICOS", ELF::EF_AMDGPU_MACH_R600_CAICOS
}
,
1280 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_CAYMAN){ "EF_AMDGPU_MACH_R600_CAYMAN", ELF::EF_AMDGPU_MACH_R600_CAYMAN
}
,
1281 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_R600_TURKS){ "EF_AMDGPU_MACH_R600_TURKS", ELF::EF_AMDGPU_MACH_R600_TURKS
}
,
1282 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX600){ "EF_AMDGPU_MACH_AMDGCN_GFX600", ELF::EF_AMDGPU_MACH_AMDGCN_GFX600
}
,
1283 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX601){ "EF_AMDGPU_MACH_AMDGCN_GFX601", ELF::EF_AMDGPU_MACH_AMDGCN_GFX601
}
,
1284 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX700){ "EF_AMDGPU_MACH_AMDGCN_GFX700", ELF::EF_AMDGPU_MACH_AMDGCN_GFX700
}
,
1285 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX701){ "EF_AMDGPU_MACH_AMDGCN_GFX701", ELF::EF_AMDGPU_MACH_AMDGCN_GFX701
}
,
1286 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX702){ "EF_AMDGPU_MACH_AMDGCN_GFX702", ELF::EF_AMDGPU_MACH_AMDGCN_GFX702
}
,
1287 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX703){ "EF_AMDGPU_MACH_AMDGCN_GFX703", ELF::EF_AMDGPU_MACH_AMDGCN_GFX703
}
,
1288 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX704){ "EF_AMDGPU_MACH_AMDGCN_GFX704", ELF::EF_AMDGPU_MACH_AMDGCN_GFX704
}
,
1289 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX801){ "EF_AMDGPU_MACH_AMDGCN_GFX801", ELF::EF_AMDGPU_MACH_AMDGCN_GFX801
}
,
1290 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX802){ "EF_AMDGPU_MACH_AMDGCN_GFX802", ELF::EF_AMDGPU_MACH_AMDGCN_GFX802
}
,
1291 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX803){ "EF_AMDGPU_MACH_AMDGCN_GFX803", ELF::EF_AMDGPU_MACH_AMDGCN_GFX803
}
,
1292 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX810){ "EF_AMDGPU_MACH_AMDGCN_GFX810", ELF::EF_AMDGPU_MACH_AMDGCN_GFX810
}
,
1293 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX900){ "EF_AMDGPU_MACH_AMDGCN_GFX900", ELF::EF_AMDGPU_MACH_AMDGCN_GFX900
}
,
1294 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX902){ "EF_AMDGPU_MACH_AMDGCN_GFX902", ELF::EF_AMDGPU_MACH_AMDGCN_GFX902
}
,
1295 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_XNACK){ "EF_AMDGPU_XNACK", ELF::EF_AMDGPU_XNACK }
1296};
1297
1298static const EnumEntry<unsigned> ElfHeaderRISCVFlags[] = {
1299 LLVM_READOBJ_ENUM_ENT(ELF, EF_RISCV_RVC){ "EF_RISCV_RVC", ELF::EF_RISCV_RVC },
1300 LLVM_READOBJ_ENUM_ENT(ELF, EF_RISCV_FLOAT_ABI_SINGLE){ "EF_RISCV_FLOAT_ABI_SINGLE", ELF::EF_RISCV_FLOAT_ABI_SINGLE
}
,
1301 LLVM_READOBJ_ENUM_ENT(ELF, EF_RISCV_FLOAT_ABI_DOUBLE){ "EF_RISCV_FLOAT_ABI_DOUBLE", ELF::EF_RISCV_FLOAT_ABI_DOUBLE
}
,
1302 LLVM_READOBJ_ENUM_ENT(ELF, EF_RISCV_FLOAT_ABI_QUAD){ "EF_RISCV_FLOAT_ABI_QUAD", ELF::EF_RISCV_FLOAT_ABI_QUAD },
1303 LLVM_READOBJ_ENUM_ENT(ELF, EF_RISCV_RVE){ "EF_RISCV_RVE", ELF::EF_RISCV_RVE }
1304};
1305
1306static const EnumEntry<unsigned> ElfSymOtherFlags[] = {
1307 LLVM_READOBJ_ENUM_ENT(ELF, STV_INTERNAL){ "STV_INTERNAL", ELF::STV_INTERNAL },
1308 LLVM_READOBJ_ENUM_ENT(ELF, STV_HIDDEN){ "STV_HIDDEN", ELF::STV_HIDDEN },
1309 LLVM_READOBJ_ENUM_ENT(ELF, STV_PROTECTED){ "STV_PROTECTED", ELF::STV_PROTECTED }
1310};
1311
1312static const EnumEntry<unsigned> ElfMipsSymOtherFlags[] = {
1313 LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_OPTIONAL){ "STO_MIPS_OPTIONAL", ELF::STO_MIPS_OPTIONAL },
1314 LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_PLT){ "STO_MIPS_PLT", ELF::STO_MIPS_PLT },
1315 LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_PIC){ "STO_MIPS_PIC", ELF::STO_MIPS_PIC },
1316 LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_MICROMIPS){ "STO_MIPS_MICROMIPS", ELF::STO_MIPS_MICROMIPS }
1317};
1318
1319static const EnumEntry<unsigned> ElfMips16SymOtherFlags[] = {
1320 LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_OPTIONAL){ "STO_MIPS_OPTIONAL", ELF::STO_MIPS_OPTIONAL },
1321 LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_PLT){ "STO_MIPS_PLT", ELF::STO_MIPS_PLT },
1322 LLVM_READOBJ_ENUM_ENT(ELF, STO_MIPS_MIPS16){ "STO_MIPS_MIPS16", ELF::STO_MIPS_MIPS16 }
1323};
1324
1325static const char *getElfMipsOptionsOdkType(unsigned Odk) {
1326 switch (Odk) {
1327 LLVM_READOBJ_ENUM_CASE(ELF, ODK_NULL)case ELF::ODK_NULL: return "ODK_NULL";;
1328 LLVM_READOBJ_ENUM_CASE(ELF, ODK_REGINFO)case ELF::ODK_REGINFO: return "ODK_REGINFO";;
1329 LLVM_READOBJ_ENUM_CASE(ELF, ODK_EXCEPTIONS)case ELF::ODK_EXCEPTIONS: return "ODK_EXCEPTIONS";;
1330 LLVM_READOBJ_ENUM_CASE(ELF, ODK_PAD)case ELF::ODK_PAD: return "ODK_PAD";;
1331 LLVM_READOBJ_ENUM_CASE(ELF, ODK_HWPATCH)case ELF::ODK_HWPATCH: return "ODK_HWPATCH";;
1332 LLVM_READOBJ_ENUM_CASE(ELF, ODK_FILL)case ELF::ODK_FILL: return "ODK_FILL";;
1333 LLVM_READOBJ_ENUM_CASE(ELF, ODK_TAGS)case ELF::ODK_TAGS: return "ODK_TAGS";;
1334 LLVM_READOBJ_ENUM_CASE(ELF, ODK_HWAND)case ELF::ODK_HWAND: return "ODK_HWAND";;
1335 LLVM_READOBJ_ENUM_CASE(ELF, ODK_HWOR)case ELF::ODK_HWOR: return "ODK_HWOR";;
1336 LLVM_READOBJ_ENUM_CASE(ELF, ODK_GP_GROUP)case ELF::ODK_GP_GROUP: return "ODK_GP_GROUP";;
1337 LLVM_READOBJ_ENUM_CASE(ELF, ODK_IDENT)case ELF::ODK_IDENT: return "ODK_IDENT";;
1338 LLVM_READOBJ_ENUM_CASE(ELF, ODK_PAGESIZE)case ELF::ODK_PAGESIZE: return "ODK_PAGESIZE";;
1339 default:
1340 return "Unknown";
1341 }
1342}
1343
1344template <typename ELFT>
1345ELFDumper<ELFT>::ELFDumper(const ELFFile<ELFT> *Obj, ScopedPrinter &Writer)
1346 : ObjDumper(Writer), Obj(Obj) {
1347 SmallVector<const Elf_Phdr *, 4> LoadSegments;
1348 for (const Elf_Phdr &Phdr : unwrapOrError(Obj->program_headers())) {
1349 if (Phdr.p_type == ELF::PT_DYNAMIC) {
1350 DynamicTable = createDRIFrom(&Phdr, sizeof(Elf_Dyn));
1351 continue;
1352 }
1353 if (Phdr.p_type != ELF::PT_LOAD || Phdr.p_filesz == 0)
1354 continue;
1355 LoadSegments.push_back(&Phdr);
1356 }
1357
1358 for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) {
1359 switch (Sec.sh_type) {
1360 case ELF::SHT_SYMTAB:
1361 if (DotSymtabSec != nullptr)
1362 reportError("Multiple SHT_SYMTAB");
1363 DotSymtabSec = &Sec;
1364 break;
1365 case ELF::SHT_DYNSYM:
1366 if (DynSymRegion.Size)
1367 reportError("Multiple SHT_DYNSYM");
1368 DynSymRegion = createDRIFrom(&Sec);
1369 // This is only used (if Elf_Shdr present)for naming section in GNU style
1370 DynSymtabName = unwrapOrError(Obj->getSectionName(&Sec));
1371 DynamicStringTable = unwrapOrError(Obj->getStringTableForSymtab(Sec));
1372 break;
1373 case ELF::SHT_SYMTAB_SHNDX:
1374 ShndxTable = unwrapOrError(Obj->getSHNDXTable(Sec));
1375 break;
1376 case ELF::SHT_GNU_versym:
1377 if (dot_gnu_version_sec != nullptr)
1378 reportError("Multiple SHT_GNU_versym");
1379 dot_gnu_version_sec = &Sec;
1380 break;
1381 case ELF::SHT_GNU_verdef:
1382 if (dot_gnu_version_d_sec != nullptr)
1383 reportError("Multiple SHT_GNU_verdef");
1384 dot_gnu_version_d_sec = &Sec;
1385 break;
1386 case ELF::SHT_GNU_verneed:
1387 if (dot_gnu_version_r_sec != nullptr)
1388 reportError("Multiple SHT_GNU_verneed");
1389 dot_gnu_version_r_sec = &Sec;
1390 break;
1391 }
1392 }
1393
1394 parseDynamicTable(LoadSegments);
1395
1396 if (opts::Output == opts::GNU)
1397 ELFDumperStyle.reset(new GNUStyle<ELFT>(Writer, this));
1398 else
1399 ELFDumperStyle.reset(new LLVMStyle<ELFT>(Writer, this));
1400}
1401
1402template <typename ELFT>
1403void ELFDumper<ELFT>::parseDynamicTable(
1404 ArrayRef<const Elf_Phdr *> LoadSegments) {
1405 auto toMappedAddr = [&](uint64_t VAddr) -> const uint8_t * {
1406 const Elf_Phdr *const *I =
1407 std::upper_bound(LoadSegments.begin(), LoadSegments.end(), VAddr,
1408 [](uint64_t VAddr, const Elf_Phdr_Impl<ELFT> *Phdr) {
1409 return VAddr < Phdr->p_vaddr;
1410 });
1411 if (I == LoadSegments.begin())
1412 report_fatal_error("Virtual address is not in any segment");
1413 --I;
1414 const Elf_Phdr &Phdr = **I;
1415 uint64_t Delta = VAddr - Phdr.p_vaddr;
1416 if (Delta >= Phdr.p_filesz)
1417 report_fatal_error("Virtual address is not in any segment");
1418 return Obj->base() + Phdr.p_offset + Delta;
1419 };
1420
1421 uint64_t SONameOffset = 0;
1422 const char *StringTableBegin = nullptr;
1423 uint64_t StringTableSize = 0;
1424 for (const Elf_Dyn &Dyn : dynamic_table()) {
1425 switch (Dyn.d_tag) {
1426 case ELF::DT_HASH:
1427 HashTable =
1428 reinterpret_cast<const Elf_Hash *>(toMappedAddr(Dyn.getPtr()));
1429 break;
1430 case ELF::DT_GNU_HASH:
1431 GnuHashTable =
1432 reinterpret_cast<const Elf_GnuHash *>(toMappedAddr(Dyn.getPtr()));
1433 break;
1434 case ELF::DT_STRTAB:
1435 StringTableBegin = (const char *)toMappedAddr(Dyn.getPtr());
1436 break;
1437 case ELF::DT_STRSZ:
1438 StringTableSize = Dyn.getVal();
1439 break;
1440 case ELF::DT_SYMTAB:
1441 DynSymRegion.Addr = toMappedAddr(Dyn.getPtr());
1442 DynSymRegion.EntSize = sizeof(Elf_Sym);
1443 break;
1444 case ELF::DT_RELA:
1445 DynRelaRegion.Addr = toMappedAddr(Dyn.getPtr());
1446 break;
1447 case ELF::DT_RELASZ:
1448 DynRelaRegion.Size = Dyn.getVal();
1449 break;
1450 case ELF::DT_RELAENT:
1451 DynRelaRegion.EntSize = Dyn.getVal();
1452 break;
1453 case ELF::DT_SONAME:
1454 SONameOffset = Dyn.getVal();
1455 break;
1456 case ELF::DT_REL:
1457 DynRelRegion.Addr = toMappedAddr(Dyn.getPtr());
1458 break;
1459 case ELF::DT_RELSZ:
1460 DynRelRegion.Size = Dyn.getVal();
1461 break;
1462 case ELF::DT_RELENT:
1463 DynRelRegion.EntSize = Dyn.getVal();
1464 break;
1465 case ELF::DT_PLTREL:
1466 if (Dyn.getVal() == DT_REL)
1467 DynPLTRelRegion.EntSize = sizeof(Elf_Rel);
1468 else if (Dyn.getVal() == DT_RELA)
1469 DynPLTRelRegion.EntSize = sizeof(Elf_Rela);
1470 else
1471 reportError(Twine("unknown DT_PLTREL value of ") +
1472 Twine((uint64_t)Dyn.getVal()));
1473 break;
1474 case ELF::DT_JMPREL:
1475 DynPLTRelRegion.Addr = toMappedAddr(Dyn.getPtr());
1476 break;
1477 case ELF::DT_PLTRELSZ:
1478 DynPLTRelRegion.Size = Dyn.getVal();
1479 break;
1480 }
1481 }
1482 if (StringTableBegin)
1483 DynamicStringTable = StringRef(StringTableBegin, StringTableSize);
1484 if (SONameOffset)
1485 SOName = getDynamicString(SONameOffset);
1486}
1487
1488template <typename ELFT>
1489typename ELFDumper<ELFT>::Elf_Rel_Range ELFDumper<ELFT>::dyn_rels() const {
1490 return DynRelRegion.getAsArrayRef<Elf_Rel>();
1491}
1492
1493template <typename ELFT>
1494typename ELFDumper<ELFT>::Elf_Rela_Range ELFDumper<ELFT>::dyn_relas() const {
1495 return DynRelaRegion.getAsArrayRef<Elf_Rela>();
1496}
1497
1498template<class ELFT>
1499void ELFDumper<ELFT>::printFileHeaders() {
1500 ELFDumperStyle->printFileHeaders(Obj);
1501}
1502
1503template<class ELFT>
1504void ELFDumper<ELFT>::printSections() {
1505 ELFDumperStyle->printSections(Obj);
1506}
1507
1508template<class ELFT>
1509void ELFDumper<ELFT>::printRelocations() {
1510 ELFDumperStyle->printRelocations(Obj);
1511}
1512
1513template <class ELFT> void ELFDumper<ELFT>::printProgramHeaders() {
1514 ELFDumperStyle->printProgramHeaders(Obj);
1515}
1516
1517template <class ELFT> void ELFDumper<ELFT>::printDynamicRelocations() {
1518 ELFDumperStyle->printDynamicRelocations(Obj);
1519}
1520
1521template<class ELFT>
1522void ELFDumper<ELFT>::printSymbols() {
1523 ELFDumperStyle->printSymbols(Obj);
1524}
1525
1526template<class ELFT>
1527void ELFDumper<ELFT>::printDynamicSymbols() {
1528 ELFDumperStyle->printDynamicSymbols(Obj);
1529}
1530
1531template <class ELFT> void ELFDumper<ELFT>::printHashHistogram() {
1532 ELFDumperStyle->printHashHistogram(Obj);
1533}
1534
1535template <class ELFT> void ELFDumper<ELFT>::printNotes() {
1536 ELFDumperStyle->printNotes(Obj);
1537}
1538
1539template <class ELFT> void ELFDumper<ELFT>::printELFLinkerOptions() {
1540 ELFDumperStyle->printELFLinkerOptions(Obj);
1541}
1542
1543static const char *getTypeString(unsigned Arch, uint64_t Type) {
1544#define DYNAMIC_TAG(n, v)
1545 switch (Arch) {
1546 case EM_HEXAGON:
1547 switch (Type) {
1548#define HEXAGON_DYNAMIC_TAG(name, value) \
1549 case DT_##name: \
1550 return #name;
1551#include "llvm/BinaryFormat/DynamicTags.def"
1552#undef HEXAGON_DYNAMIC_TAG
1553 }
1554 case EM_MIPS:
1555 switch (Type) {
1556#define MIPS_DYNAMIC_TAG(name, value) \
1557 case DT_##name: \
1558 return #name;
1559#include "llvm/BinaryFormat/DynamicTags.def"
1560#undef MIPS_DYNAMIC_TAG
1561 }
1562 }
1563#undef DYNAMIC_TAG
1564 switch (Type) {
1565// Now handle all dynamic tags except the architecture specific ones
1566#define MIPS_DYNAMIC_TAG(name, value)
1567#define HEXAGON_DYNAMIC_TAG(name, value)
1568// Also ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
1569#define DYNAMIC_TAG_MARKER(name, value)
1570#define DYNAMIC_TAG(name, value) \
1571 case DT_##name: \
1572 return #name;
1573#include "llvm/BinaryFormat/DynamicTags.def"
1574#undef DYNAMIC_TAG
1575#undef MIPS_DYNAMIC_TAG
1576#undef HEXAGON_DYNAMIC_TAG
1577#undef DYNAMIC_TAG_MARKER
1578 default: return "unknown";
1579 }
1580}
1581
1582#define LLVM_READOBJ_DT_FLAG_ENT(prefix, enum) \
1583 { #enum, prefix##_##enum }
1584
1585static const EnumEntry<unsigned> ElfDynamicDTFlags[] = {
1586 LLVM_READOBJ_DT_FLAG_ENT(DF, ORIGIN),
1587 LLVM_READOBJ_DT_FLAG_ENT(DF, SYMBOLIC),
1588 LLVM_READOBJ_DT_FLAG_ENT(DF, TEXTREL),
1589 LLVM_READOBJ_DT_FLAG_ENT(DF, BIND_NOW),
1590 LLVM_READOBJ_DT_FLAG_ENT(DF, STATIC_TLS)
1591};
1592
1593static const EnumEntry<unsigned> ElfDynamicDTFlags1[] = {
1594 LLVM_READOBJ_DT_FLAG_ENT(DF_1, NOW),
1595 LLVM_READOBJ_DT_FLAG_ENT(DF_1, GLOBAL),
1596 LLVM_READOBJ_DT_FLAG_ENT(DF_1, GROUP),
1597 LLVM_READOBJ_DT_FLAG_ENT(DF_1, NODELETE),
1598 LLVM_READOBJ_DT_FLAG_ENT(DF_1, LOADFLTR),
1599 LLVM_READOBJ_DT_FLAG_ENT(DF_1, INITFIRST),
1600 LLVM_READOBJ_DT_FLAG_ENT(DF_1, NOOPEN),
1601 LLVM_READOBJ_DT_FLAG_ENT(DF_1, ORIGIN),
1602 LLVM_READOBJ_DT_FLAG_ENT(DF_1, DIRECT),
1603 LLVM_READOBJ_DT_FLAG_ENT(DF_1, TRANS),
1604 LLVM_READOBJ_DT_FLAG_ENT(DF_1, INTERPOSE),
1605 LLVM_READOBJ_DT_FLAG_ENT(DF_1, NODEFLIB),
1606 LLVM_READOBJ_DT_FLAG_ENT(DF_1, NODUMP),
1607 LLVM_READOBJ_DT_FLAG_ENT(DF_1, CONFALT),
1608 LLVM_READOBJ_DT_FLAG_ENT(DF_1, ENDFILTEE),
1609 LLVM_READOBJ_DT_FLAG_ENT(DF_1, DISPRELDNE),
1610 LLVM_READOBJ_DT_FLAG_ENT(DF_1, NODIRECT),
1611 LLVM_READOBJ_DT_FLAG_ENT(DF_1, IGNMULDEF),
1612 LLVM_READOBJ_DT_FLAG_ENT(DF_1, NOKSYMS),
1613 LLVM_READOBJ_DT_FLAG_ENT(DF_1, NOHDR),
1614 LLVM_READOBJ_DT_FLAG_ENT(DF_1, EDITED),
1615 LLVM_READOBJ_DT_FLAG_ENT(DF_1, NORELOC),
1616 LLVM_READOBJ_DT_FLAG_ENT(DF_1, SYMINTPOSE),
1617 LLVM_READOBJ_DT_FLAG_ENT(DF_1, GLOBAUDIT),
1618 LLVM_READOBJ_DT_FLAG_ENT(DF_1, SINGLETON)
1619};
1620
1621static const EnumEntry<unsigned> ElfDynamicDTMipsFlags[] = {
1622 LLVM_READOBJ_DT_FLAG_ENT(RHF, NONE),
1623 LLVM_READOBJ_DT_FLAG_ENT(RHF, QUICKSTART),
1624 LLVM_READOBJ_DT_FLAG_ENT(RHF, NOTPOT),
1625 LLVM_READOBJ_DT_FLAG_ENT(RHS, NO_LIBRARY_REPLACEMENT),
1626 LLVM_READOBJ_DT_FLAG_ENT(RHF, NO_MOVE),
1627 LLVM_READOBJ_DT_FLAG_ENT(RHF, SGI_ONLY),
1628 LLVM_READOBJ_DT_FLAG_ENT(RHF, GUARANTEE_INIT),
1629 LLVM_READOBJ_DT_FLAG_ENT(RHF, DELTA_C_PLUS_PLUS),
1630 LLVM_READOBJ_DT_FLAG_ENT(RHF, GUARANTEE_START_INIT),
1631 LLVM_READOBJ_DT_FLAG_ENT(RHF, PIXIE),
1632 LLVM_READOBJ_DT_FLAG_ENT(RHF, DEFAULT_DELAY_LOAD),
1633 LLVM_READOBJ_DT_FLAG_ENT(RHF, REQUICKSTART),
1634 LLVM_READOBJ_DT_FLAG_ENT(RHF, REQUICKSTARTED),
1635 LLVM_READOBJ_DT_FLAG_ENT(RHF, CORD),
1636 LLVM_READOBJ_DT_FLAG_ENT(RHF, NO_UNRES_UNDEF),
1637 LLVM_READOBJ_DT_FLAG_ENT(RHF, RLD_ORDER_SAFE)
1638};
1639
1640#undef LLVM_READOBJ_DT_FLAG_ENT
1641
1642template <typename T, typename TFlag>
1643void printFlags(T Value, ArrayRef<EnumEntry<TFlag>> Flags, raw_ostream &OS) {
1644 using FlagEntry = EnumEntry<TFlag>;
1645 using FlagVector = SmallVector<FlagEntry, 10>;
1646 FlagVector SetFlags;
1647
1648 for (const auto &Flag : Flags) {
1649 if (Flag.Value == 0)
1650 continue;
1651
1652 if ((Value & Flag.Value) == Flag.Value)
1653 SetFlags.push_back(Flag);
1654 }
1655
1656 for (const auto &Flag : SetFlags) {
1657 OS << Flag.Name << " ";
1658 }
1659}
1660
1661template <class ELFT>
1662StringRef ELFDumper<ELFT>::getDynamicString(uint64_t Value) const {
1663 if (Value >= DynamicStringTable.size())
1664 reportError("Invalid dynamic string table reference");
1665 return StringRef(DynamicStringTable.data() + Value);
1666}
1667
1668static void printLibrary(raw_ostream &OS, const Twine &Tag, const Twine &Name) {
1669 OS << Tag << ": [" << Name << "]";
1670}
1671
1672template <class ELFT>
1673void ELFDumper<ELFT>::printValue(uint64_t Type, uint64_t Value) {
1674 raw_ostream &OS = W.getOStream();
1675 const char* ConvChar = (opts::Output == opts::GNU) ? "0x%" PRIx64"l" "x" : "0x%" PRIX64"l" "X";
1676 switch (Type) {
1677 case DT_PLTREL:
1678 if (Value == DT_REL) {
1679 OS << "REL";
1680 break;
1681 } else if (Value == DT_RELA) {
1682 OS << "RELA";
1683 break;
1684 }
1685 LLVM_FALLTHROUGH[[clang::fallthrough]];
1686 case DT_PLTGOT:
1687 case DT_HASH:
1688 case DT_STRTAB:
1689 case DT_SYMTAB:
1690 case DT_RELA:
1691 case DT_INIT:
1692 case DT_FINI:
1693 case DT_REL:
1694 case DT_JMPREL:
1695 case DT_INIT_ARRAY:
1696 case DT_FINI_ARRAY:
1697 case DT_PREINIT_ARRAY:
1698 case DT_DEBUG:
1699 case DT_VERDEF:
1700 case DT_VERNEED:
1701 case DT_VERSYM:
1702 case DT_GNU_HASH:
1703 case DT_NULL:
1704 case DT_MIPS_BASE_ADDRESS:
1705 case DT_MIPS_GOTSYM:
1706 case DT_MIPS_RLD_MAP:
1707 case DT_MIPS_RLD_MAP_REL:
1708 case DT_MIPS_PLTGOT:
1709 case DT_MIPS_OPTIONS:
1710 OS << format(ConvChar, Value);
1711 break;
1712 case DT_RELACOUNT:
1713 case DT_RELCOUNT:
1714 case DT_VERDEFNUM:
1715 case DT_VERNEEDNUM:
1716 case DT_MIPS_RLD_VERSION:
1717 case DT_MIPS_LOCAL_GOTNO:
1718 case DT_MIPS_SYMTABNO:
1719 case DT_MIPS_UNREFEXTNO:
1720 OS << Value;
1721 break;
1722 case DT_PLTRELSZ:
1723 case DT_RELASZ:
1724 case DT_RELAENT:
1725 case DT_STRSZ:
1726 case DT_SYMENT:
1727 case DT_RELSZ:
1728 case DT_RELENT:
1729 case DT_INIT_ARRAYSZ:
1730 case DT_FINI_ARRAYSZ:
1731 case DT_PREINIT_ARRAYSZ:
1732 case DT_ANDROID_RELSZ:
1733 case DT_ANDROID_RELASZ:
1734 OS << Value << " (bytes)";
1735 break;
1736 case DT_NEEDED:
1737 printLibrary(OS, "Shared library", getDynamicString(Value));
1738 break;
1739 case DT_SONAME:
1740 printLibrary(OS, "Library soname", getDynamicString(Value));
1741 break;
1742 case DT_AUXILIARY:
1743 printLibrary(OS, "Auxiliary library", getDynamicString(Value));
1744 break;
1745 case DT_FILTER:
1746 printLibrary(OS, "Filter library", getDynamicString(Value));
1747 break;
1748 case DT_RPATH:
1749 case DT_RUNPATH:
1750 OS << getDynamicString(Value);
1751 break;
1752 case DT_MIPS_FLAGS:
1753 printFlags(Value, makeArrayRef(ElfDynamicDTMipsFlags), OS);
1754 break;
1755 case DT_FLAGS:
1756 printFlags(Value, makeArrayRef(ElfDynamicDTFlags), OS);
1757 break;
1758 case DT_FLAGS_1:
1759 printFlags(Value, makeArrayRef(ElfDynamicDTFlags1), OS);
1760 break;
1761 default:
1762 OS << format(ConvChar, Value);
1763 break;
1764 }
1765}
1766
1767template<class ELFT>
1768void ELFDumper<ELFT>::printUnwindInfo() {
1769 const unsigned Machine = Obj->getHeader()->e_machine;
1770 if (Machine == EM_386 || Machine == EM_X86_64) {
1771 DwarfCFIEH::PrinterContext<ELFT> Ctx(W, Obj);
1772 return Ctx.printUnwindInformation();
1773 }
1774 W.startLine() << "UnwindInfo not implemented.\n";
1775}
1776
1777namespace {
1778
1779template <> void ELFDumper<ELF32LE>::printUnwindInfo() {
1780 const unsigned Machine = Obj->getHeader()->e_machine;
1781 if (Machine == EM_ARM) {
1782 ARM::EHABI::PrinterContext<ELF32LE> Ctx(W, Obj, DotSymtabSec);
1783 return Ctx.PrintUnwindInformation();
1784 }
1785 W.startLine() << "UnwindInfo not implemented.\n";
1786}
1787
1788} // end anonymous namespace
1789
1790template<class ELFT>
1791void ELFDumper<ELFT>::printDynamicTable() {
1792 auto I = dynamic_table().begin();
1793 auto E = dynamic_table().end();
1794
1795 if (I == E)
1796 return;
1797
1798 --E;
1799 while (I != E && E->getTag() == ELF::DT_NULL)
1800 --E;
1801 if (E->getTag() != ELF::DT_NULL)
1802 ++E;
1803 ++E;
1804
1805 ptrdiff_t Total = std::distance(I, E);
1806 if (Total == 0)
1807 return;
1808
1809 raw_ostream &OS = W.getOStream();
1810 W.startLine() << "DynamicSection [ (" << Total << " entries)\n";
1811
1812 bool Is64 = ELFT::Is64Bits;
1813
1814 W.startLine()
1815 << " Tag" << (Is64 ? " " : " ") << "Type"
1816 << " " << "Name/Value\n";
1817 while (I != E) {
1818 const Elf_Dyn &Entry = *I;
1819 uintX_t Tag = Entry.getTag();
1820 ++I;
1821 W.startLine() << " " << format_hex(Tag, Is64 ? 18 : 10, opts::Output != opts::GNU) << " "
1822 << format("%-21s", getTypeString(Obj->getHeader()->e_machine, Tag));
1823 printValue(Tag, Entry.getVal());
1824 OS << "\n";
1825 }
1826
1827 W.startLine() << "]\n";
1828}
1829
1830template<class ELFT>
1831void ELFDumper<ELFT>::printNeededLibraries() {
1832 ListScope D(W, "NeededLibraries");
1833
1834 using LibsTy = std::vector<StringRef>;
1835 LibsTy Libs;
1836
1837 for (const auto &Entry : dynamic_table())
1838 if (Entry.d_tag == ELF::DT_NEEDED)
1839 Libs.push_back(getDynamicString(Entry.d_un.d_val));
1840
1841 std::stable_sort(Libs.begin(), Libs.end());
1842
1843 for (const auto &L : Libs)
1844 W.startLine() << L << "\n";
1845}
1846
1847
1848template <typename ELFT>
1849void ELFDumper<ELFT>::printHashTable() {
1850 DictScope D(W, "HashTable");
1851 if (!HashTable)
1852 return;
1853 W.printNumber("Num Buckets", HashTable->nbucket);
1854 W.printNumber("Num Chains", HashTable->nchain);
1855 W.printList("Buckets", HashTable->buckets());
1856 W.printList("Chains", HashTable->chains());
1857}
1858
1859template <typename ELFT>
1860void ELFDumper<ELFT>::printGnuHashTable() {
1861 DictScope D(W, "GnuHashTable");
1862 if (!GnuHashTable)
1863 return;
1864 W.printNumber("Num Buckets", GnuHashTable->nbuckets);
1865 W.printNumber("First Hashed Symbol Index", GnuHashTable->symndx);
1866 W.printNumber("Num Mask Words", GnuHashTable->maskwords);
1867 W.printNumber("Shift Count", GnuHashTable->shift2);
1868 W.printHexList("Bloom Filter", GnuHashTable->filter());
1869 W.printList("Buckets", GnuHashTable->buckets());
1870 Elf_Sym_Range Syms = dynamic_symbols();
1871 unsigned NumSyms = std::distance(Syms.begin(), Syms.end());
1872 if (!NumSyms)
1873 reportError("No dynamic symbol section");
1874 W.printHexList("Values", GnuHashTable->values(NumSyms));
1875}
1876
1877template <typename ELFT> void ELFDumper<ELFT>::printLoadName() {
1878 W.printString("LoadName", SOName);
1879}
1880
1881template <class ELFT>
1882void ELFDumper<ELFT>::printAttributes() {
1883 W.startLine() << "Attributes not implemented.\n";
1884}
1885
1886namespace {
1887
1888template <> void ELFDumper<ELF32LE>::printAttributes() {
1889 if (Obj->getHeader()->e_machine != EM_ARM) {
1890 W.startLine() << "Attributes not implemented.\n";
1891 return;
1892 }
1893
1894 DictScope BA(W, "BuildAttributes");
1895 for (const ELFO::Elf_Shdr &Sec : unwrapOrError(Obj->sections())) {
1896 if (Sec.sh_type != ELF::SHT_ARM_ATTRIBUTES)
1897 continue;
1898
1899 ArrayRef<uint8_t> Contents = unwrapOrError(Obj->getSectionContents(&Sec));
1900 if (Contents[0] != ARMBuildAttrs::Format_Version) {
1901 errs() << "unrecognised FormatVersion: 0x"
1902 << Twine::utohexstr(Contents[0]) << '\n';
1903 continue;
1904 }
1905
1906 W.printHex("FormatVersion", Contents[0]);
1907 if (Contents.size() == 1)
1908 continue;
1909
1910 ARMAttributeParser(&W).Parse(Contents, true);
1911 }
1912}
1913
1914template <class ELFT> class MipsGOTParser {
1915public:
1916 TYPEDEF_ELF_TYPES(ELFT)using ELFO = ELFFile<ELFT>; using Elf_Addr = typename ELFT
::Addr; using Elf_Shdr = typename ELFT::Shdr; using Elf_Sym =
typename ELFT::Sym; using Elf_Dyn = typename ELFT::Dyn; using
Elf_Dyn_Range = typename ELFT::DynRange; using Elf_Rel = typename
ELFT::Rel; using Elf_Rela = typename ELFT::Rela; using Elf_Rel_Range
= typename ELFT::RelRange; using Elf_Rela_Range = typename ELFT
::RelaRange; using Elf_Phdr = typename ELFT::Phdr; using Elf_Half
= typename ELFT::Half; using Elf_Ehdr = typename ELFT::Ehdr;
using Elf_Word = typename ELFT::Word; using Elf_Hash = typename
ELFT::Hash; using Elf_GnuHash = typename ELFT::GnuHash; using
Elf_Note = typename ELFT::Note; using Elf_Sym_Range = typename
ELFT::SymRange; using Elf_Versym = typename ELFT::Versym; using
Elf_Verneed = typename ELFT::Verneed; using Elf_Vernaux = typename
ELFT::Vernaux; using Elf_Verdef = typename ELFT::Verdef; using
Elf_Verdaux = typename ELFT::Verdaux; using uintX_t = typename
ELFT::uint;
1917 using Entry = typename ELFO::Elf_Addr;
1918 using Entries = ArrayRef<Entry>;
1919
1920 const bool IsStatic;
1921 const ELFO * const Obj;
1922
1923 MipsGOTParser(const ELFO *Obj, Elf_Dyn_Range DynTable, Elf_Sym_Range DynSyms);
1924
1925 bool hasGot() const { return !GotEntries.empty(); }
1926 bool hasPlt() const { return !PltEntries.empty(); }
1927
1928 uint64_t getGp() const;
1929
1930 const Entry *getGotLazyResolver() const;
1931 const Entry *getGotModulePointer() const;
1932 const Entry *getPltLazyResolver() const;
1933 const Entry *getPltModulePointer() const;
1934
1935 Entries getLocalEntries() const;
1936 Entries getGlobalEntries() const;
1937 Entries getOtherEntries() const;
1938 Entries getPltEntries() const;
1939
1940 uint64_t getGotAddress(const Entry * E) const;
1941 int64_t getGotOffset(const Entry * E) const;
1942 const Elf_Sym *getGotSym(const Entry *E) const;
1943
1944 uint64_t getPltAddress(const Entry * E) const;
1945 const Elf_Sym *getPltSym(const Entry *E) const;
1946
1947 StringRef getPltStrTable() const { return PltStrTable; }
1948
1949private:
1950 const Elf_Shdr *GotSec;
1951 size_t LocalNum;
1952 size_t GlobalNum;
1953
1954 const Elf_Shdr *PltSec;
1955 const Elf_Shdr *PltRelSec;
1956 const Elf_Shdr *PltSymTable;
1957 Elf_Sym_Range GotDynSyms;
1958 StringRef PltStrTable;
1959
1960 Entries GotEntries;
1961 Entries PltEntries;
1962};
1963
1964} // end anonymous namespace
1965
1966template <class ELFT>
1967MipsGOTParser<ELFT>::MipsGOTParser(const ELFO *Obj, Elf_Dyn_Range DynTable,
1968 Elf_Sym_Range DynSyms)
1969 : IsStatic(DynTable.empty()), Obj(Obj), GotSec(nullptr), LocalNum(0),
1970 GlobalNum(0), PltSec(nullptr), PltRelSec(nullptr), PltSymTable(nullptr) {
1971 // See "Global Offset Table" in Chapter 5 in the following document
1972 // for detailed GOT description.
1973 // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
1974
1975 // Find static GOT secton.
1976 if (IsStatic) {
1977 GotSec = findSectionByName(*Obj, ".got");
1978 if (!GotSec)
1979 reportError("Cannot find .got section");
1980
1981 ArrayRef<uint8_t> Content = unwrapOrError(Obj->getSectionContents(GotSec));
1982 GotEntries = Entries(reinterpret_cast<const Entry *>(Content.data()),
1983 Content.size() / sizeof(Entry));
1984 LocalNum = GotEntries.size();
1985 return;
1986 }
1987
1988 // Lookup dynamic table tags which define GOT/PLT layouts.
1989 Optional<uint64_t> DtPltGot;
1990 Optional<uint64_t> DtLocalGotNum;
1991 Optional<uint64_t> DtGotSym;
1992 Optional<uint64_t> DtMipsPltGot;
1993 Optional<uint64_t> DtJmpRel;
1994 for (const auto &Entry : DynTable) {
1995 switch (Entry.getTag()) {
1996 case ELF::DT_PLTGOT:
1997 DtPltGot = Entry.getVal();
1998 break;
1999 case ELF::DT_MIPS_LOCAL_GOTNO:
2000 DtLocalGotNum = Entry.getVal();
2001 break;
2002 case ELF::DT_MIPS_GOTSYM:
2003 DtGotSym = Entry.getVal();
2004 break;
2005 case ELF::DT_MIPS_PLTGOT:
2006 DtMipsPltGot = Entry.getVal();
2007 break;
2008 case ELF::DT_JMPREL:
2009 DtJmpRel = Entry.getVal();
2010 break;
2011 }
2012 }
2013
2014 // Find dynamic GOT section.
2015 if (DtPltGot || DtLocalGotNum || DtGotSym) {
2016 if (!DtPltGot)
2017 report_fatal_error("Cannot find PLTGOT dynamic table tag.");
2018 if (!DtLocalGotNum)
2019 report_fatal_error("Cannot find MIPS_LOCAL_GOTNO dynamic table tag.");
2020 if (!DtGotSym)
2021 report_fatal_error("Cannot find MIPS_GOTSYM dynamic table tag.");
2022
2023 size_t DynSymTotal = DynSyms.size();
2024 if (*DtGotSym > DynSymTotal)
2025 reportError("MIPS_GOTSYM exceeds a number of dynamic symbols");
2026
2027 GotSec = findNotEmptySectionByAddress(Obj, *DtPltGot);
2028 if (!GotSec)
2029 reportError("There is no not empty GOT section at 0x" +
2030 Twine::utohexstr(*DtPltGot));
2031
2032 LocalNum = *DtLocalGotNum;
2033 GlobalNum = DynSymTotal - *DtGotSym;
2034
2035 ArrayRef<uint8_t> Content = unwrapOrError(Obj->getSectionContents(GotSec));
2036 GotEntries = Entries(reinterpret_cast<const Entry *>(Content.data()),
2037 Content.size() / sizeof(Entry));
2038 GotDynSyms = DynSyms.drop_front(*DtGotSym);
2039 }
2040
2041 // Find PLT section.
2042 if (DtMipsPltGot || DtJmpRel) {
2043 if (!DtMipsPltGot)
2044 report_fatal_error("Cannot find MIPS_PLTGOT dynamic table tag.");
2045 if (!DtJmpRel)
2046 report_fatal_error("Cannot find JMPREL dynamic table tag.");
2047
2048 PltSec = findNotEmptySectionByAddress(Obj, *DtMipsPltGot);
2049 if (!PltSec)
2050 report_fatal_error("There is no not empty PLTGOT section at 0x " +
2051 Twine::utohexstr(*DtMipsPltGot));
2052
2053 PltRelSec = findNotEmptySectionByAddress(Obj, *DtJmpRel);
2054 if (!PltRelSec)
2055 report_fatal_error("There is no not empty RELPLT section at 0x" +
2056 Twine::utohexstr(*DtJmpRel));
2057
2058 ArrayRef<uint8_t> PltContent =
2059 unwrapOrError(Obj->getSectionContents(PltSec));
2060 PltEntries = Entries(reinterpret_cast<const Entry *>(PltContent.data()),
2061 PltContent.size() / sizeof(Entry));
2062
2063 PltSymTable = unwrapOrError(Obj->getSection(PltRelSec->sh_link));
2064 PltStrTable = unwrapOrError(Obj->getStringTableForSymtab(*PltSymTable));
2065 }
2066}
2067
2068template <class ELFT> uint64_t MipsGOTParser<ELFT>::getGp() const {
2069 return GotSec->sh_addr + 0x7ff0;
2070}
2071
2072template <class ELFT>
2073const typename MipsGOTParser<ELFT>::Entry *
2074MipsGOTParser<ELFT>::getGotLazyResolver() const {
2075 return LocalNum > 0 ? &GotEntries[0] : nullptr;
2076}
2077
2078template <class ELFT>
2079const typename MipsGOTParser<ELFT>::Entry *
2080MipsGOTParser<ELFT>::getGotModulePointer() const {
2081 if (LocalNum < 2)
2082 return nullptr;
2083 const Entry &E = GotEntries[1];
2084 if ((E >> (sizeof(Entry) * 8 - 1)) == 0)
2085 return nullptr;
2086 return &E;
2087}
2088
2089template <class ELFT>
2090typename MipsGOTParser<ELFT>::Entries
2091MipsGOTParser<ELFT>::getLocalEntries() const {
2092 size_t Skip = getGotModulePointer() ? 2 : 1;
2093 if (LocalNum - Skip <= 0)
2094 return Entries();
2095 return GotEntries.slice(Skip, LocalNum - Skip);
2096}
2097
2098template <class ELFT>
2099typename MipsGOTParser<ELFT>::Entries
2100MipsGOTParser<ELFT>::getGlobalEntries() const {
2101 if (GlobalNum == 0)
2102 return Entries();
2103 return GotEntries.slice(LocalNum, GlobalNum);
2104}
2105
2106template <class ELFT>
2107typename MipsGOTParser<ELFT>::Entries
2108MipsGOTParser<ELFT>::getOtherEntries() const {
2109 size_t OtherNum = GotEntries.size() - LocalNum - GlobalNum;
2110 if (OtherNum == 0)
2111 return Entries();
2112 return GotEntries.slice(LocalNum + GlobalNum, OtherNum);
2113}
2114
2115template <class ELFT>
2116uint64_t MipsGOTParser<ELFT>::getGotAddress(const Entry *E) const {
2117 int64_t Offset = std::distance(GotEntries.data(), E) * sizeof(Entry);
2118 return GotSec->sh_addr + Offset;
2119}
2120
2121template <class ELFT>
2122int64_t MipsGOTParser<ELFT>::getGotOffset(const Entry *E) const {
2123 int64_t Offset = std::distance(GotEntries.data(), E) * sizeof(Entry);
2124 return Offset - 0x7ff0;
2125}
2126
2127template <class ELFT>
2128const typename MipsGOTParser<ELFT>::Elf_Sym *
2129MipsGOTParser<ELFT>::getGotSym(const Entry *E) const {
2130 int64_t Offset = std::distance(GotEntries.data(), E);
2131 return &GotDynSyms[Offset - LocalNum];
2132}
2133
2134template <class ELFT>
2135const typename MipsGOTParser<ELFT>::Entry *
2136MipsGOTParser<ELFT>::getPltLazyResolver() const {
2137 return PltEntries.empty() ? nullptr : &PltEntries[0];
2138}
2139
2140template <class ELFT>
2141const typename MipsGOTParser<ELFT>::Entry *
2142MipsGOTParser<ELFT>::getPltModulePointer() const {
2143 return PltEntries.size() < 2 ? nullptr : &PltEntries[1];
2144}
2145
2146template <class ELFT>
2147typename MipsGOTParser<ELFT>::Entries
2148MipsGOTParser<ELFT>::getPltEntries() const {
2149 if (PltEntries.size() <= 2)
2150 return Entries();
2151 return PltEntries.slice(2, PltEntries.size() - 2);
2152}
2153
2154template <class ELFT>
2155uint64_t MipsGOTParser<ELFT>::getPltAddress(const Entry *E) const {
2156 int64_t Offset = std::distance(PltEntries.data(), E) * sizeof(Entry);
2157 return PltSec->sh_addr + Offset;
2158}
2159
2160template <class ELFT>
2161const typename MipsGOTParser<ELFT>::Elf_Sym *
2162MipsGOTParser<ELFT>::getPltSym(const Entry *E) const {
2163 int64_t Offset = std::distance(getPltEntries().data(), E);
2164 if (PltRelSec->sh_type == ELF::SHT_REL) {
2165 Elf_Rel_Range Rels = unwrapOrError(Obj->rels(PltRelSec));
2166 return unwrapOrError(Obj->getRelocationSymbol(&Rels[Offset], PltSymTable));
2167 } else {
2168 Elf_Rela_Range Rels = unwrapOrError(Obj->relas(PltRelSec));
2169 return unwrapOrError(Obj->getRelocationSymbol(&Rels[Offset], PltSymTable));
2170 }
2171}
2172
2173template <class ELFT> void ELFDumper<ELFT>::printMipsPLTGOT() {
2174 if (Obj->getHeader()->e_machine != EM_MIPS)
2175 reportError("MIPS PLT GOT is available for MIPS targets only");
2176
2177 MipsGOTParser<ELFT> Parser(Obj, dynamic_table(), dynamic_symbols());
2178 if (Parser.hasGot())
2179 ELFDumperStyle->printMipsGOT(Parser);
2180 if (Parser.hasPlt())
2181 ELFDumperStyle->printMipsPLT(Parser);
2182}
2183
2184static const EnumEntry<unsigned> ElfMipsISAExtType[] = {
2185 {"None", Mips::AFL_EXT_NONE},
2186 {"Broadcom SB-1", Mips::AFL_EXT_SB1},
2187 {"Cavium Networks Octeon", Mips::AFL_EXT_OCTEON},
2188 {"Cavium Networks Octeon2", Mips::AFL_EXT_OCTEON2},
2189 {"Cavium Networks OcteonP", Mips::AFL_EXT_OCTEONP},
2190 {"Cavium Networks Octeon3", Mips::AFL_EXT_OCTEON3},
2191 {"LSI R4010", Mips::AFL_EXT_4010},
2192 {"Loongson 2E", Mips::AFL_EXT_LOONGSON_2E},
2193 {"Loongson 2F", Mips::AFL_EXT_LOONGSON_2F},
2194 {"Loongson 3A", Mips::AFL_EXT_LOONGSON_3A},
2195 {"MIPS R4650", Mips::AFL_EXT_4650},
2196 {"MIPS R5900", Mips::AFL_EXT_5900},
2197 {"MIPS R10000", Mips::AFL_EXT_10000},
2198 {"NEC VR4100", Mips::AFL_EXT_4100},
2199 {"NEC VR4111/VR4181", Mips::AFL_EXT_4111},
2200 {"NEC VR4120", Mips::AFL_EXT_4120},
2201 {"NEC VR5400", Mips::AFL_EXT_5400},
2202 {"NEC VR5500", Mips::AFL_EXT_5500},
2203 {"RMI Xlr", Mips::AFL_EXT_XLR},
2204 {"Toshiba R3900", Mips::AFL_EXT_3900}
2205};
2206
2207static const EnumEntry<unsigned> ElfMipsASEFlags[] = {
2208 {"DSP", Mips::AFL_ASE_DSP},
2209 {"DSPR2", Mips::AFL_ASE_DSPR2},
2210 {"Enhanced VA Scheme", Mips::AFL_ASE_EVA},
2211 {"MCU", Mips::AFL_ASE_MCU},
2212 {"MDMX", Mips::AFL_ASE_MDMX},
2213 {"MIPS-3D", Mips::AFL_ASE_MIPS3D},
2214 {"MT", Mips::AFL_ASE_MT},
2215 {"SmartMIPS", Mips::AFL_ASE_SMARTMIPS},
2216 {"VZ", Mips::AFL_ASE_VIRT},
2217 {"MSA", Mips::AFL_ASE_MSA},
2218 {"MIPS16", Mips::AFL_ASE_MIPS16},
2219 {"microMIPS", Mips::AFL_ASE_MICROMIPS},
2220 {"XPA", Mips::AFL_ASE_XPA},
2221 {"CRC", Mips::AFL_ASE_CRC},
2222};
2223
2224static const EnumEntry<unsigned> ElfMipsFpABIType[] = {
2225 {"Hard or soft float", Mips::Val_GNU_MIPS_ABI_FP_ANY},
2226 {"Hard float (double precision)", Mips::Val_GNU_MIPS_ABI_FP_DOUBLE},
2227 {"Hard float (single precision)", Mips::Val_GNU_MIPS_ABI_FP_SINGLE},
2228 {"Soft float", Mips::Val_GNU_MIPS_ABI_FP_SOFT},
2229 {"Hard float (MIPS32r2 64-bit FPU 12 callee-saved)",
2230 Mips::Val_GNU_MIPS_ABI_FP_OLD_64},
2231 {"Hard float (32-bit CPU, Any FPU)", Mips::Val_GNU_MIPS_ABI_FP_XX},
2232 {"Hard float (32-bit CPU, 64-bit FPU)", Mips::Val_GNU_MIPS_ABI_FP_64},
2233 {"Hard float compat (32-bit CPU, 64-bit FPU)",
2234 Mips::Val_GNU_MIPS_ABI_FP_64A}
2235};
2236
2237static const EnumEntry<unsigned> ElfMipsFlags1[] {
2238 {"ODDSPREG", Mips::AFL_FLAGS1_ODDSPREG},
2239};
2240
2241static int getMipsRegisterSize(uint8_t Flag) {
2242 switch (Flag) {
2243 case Mips::AFL_REG_NONE:
2244 return 0;
2245 case Mips::AFL_REG_32:
2246 return 32;
2247 case Mips::AFL_REG_64:
2248 return 64;
2249 case Mips::AFL_REG_128:
2250 return 128;
2251 default:
2252 return -1;
2253 }
2254}
2255
2256template <class ELFT> void ELFDumper<ELFT>::printMipsABIFlags() {
2257 const Elf_Shdr *Shdr = findSectionByName(*Obj, ".MIPS.abiflags");
2258 if (!Shdr) {
2259 W.startLine() << "There is no .MIPS.abiflags section in the file.\n";
2260 return;
2261 }
2262 ArrayRef<uint8_t> Sec = unwrapOrError(Obj->getSectionContents(Shdr));
2263 if (Sec.size() != sizeof(Elf_Mips_ABIFlags<ELFT>)) {
2264 W.startLine() << "The .MIPS.abiflags section has a wrong size.\n";
2265 return;
2266 }
2267
2268 auto *Flags = reinterpret_cast<const Elf_Mips_ABIFlags<ELFT> *>(Sec.data());
2269
2270 raw_ostream &OS = W.getOStream();
2271 DictScope GS(W, "MIPS ABI Flags");
2272
2273 W.printNumber("Version", Flags->version);
2274 W.startLine() << "ISA: ";
2275 if (Flags->isa_rev <= 1)
2276 OS << format("MIPS%u", Flags->isa_level);
2277 else
2278 OS << format("MIPS%ur%u", Flags->isa_level, Flags->isa_rev);
2279 OS << "\n";
2280 W.printEnum("ISA Extension", Flags->isa_ext, makeArrayRef(ElfMipsISAExtType));
2281 W.printFlags("ASEs", Flags->ases, makeArrayRef(ElfMipsASEFlags));
2282 W.printEnum("FP ABI", Flags->fp_abi, makeArrayRef(ElfMipsFpABIType));
2283 W.printNumber("GPR size", getMipsRegisterSize(Flags->gpr_size));
2284 W.printNumber("CPR1 size", getMipsRegisterSize(Flags->cpr1_size));
2285 W.printNumber("CPR2 size", getMipsRegisterSize(Flags->cpr2_size));
2286 W.printFlags("Flags 1", Flags->flags1, makeArrayRef(ElfMipsFlags1));
2287 W.printHex("Flags 2", Flags->flags2);
2288}
2289
2290template <class ELFT>
2291static void printMipsReginfoData(ScopedPrinter &W,
2292 const Elf_Mips_RegInfo<ELFT> &Reginfo) {
2293 W.printHex("GP", Reginfo.ri_gp_value);
2294 W.printHex("General Mask", Reginfo.ri_gprmask);
2295 W.printHex("Co-Proc Mask0", Reginfo.ri_cprmask[0]);
2296 W.printHex("Co-Proc Mask1", Reginfo.ri_cprmask[1]);
2297 W.printHex("Co-Proc Mask2", Reginfo.ri_cprmask[2]);
2298 W.printHex("Co-Proc Mask3", Reginfo.ri_cprmask[3]);
2299}
2300
2301template <class ELFT> void ELFDumper<ELFT>::printMipsReginfo() {
2302 const Elf_Shdr *Shdr = findSectionByName(*Obj, ".reginfo");
2303 if (!Shdr) {
2304 W.startLine() << "There is no .reginfo section in the file.\n";
2305 return;
2306 }
2307 ArrayRef<uint8_t> Sec = unwrapOrError(Obj->getSectionContents(Shdr));
2308 if (Sec.size() != sizeof(Elf_Mips_RegInfo<ELFT>)) {
2309 W.startLine() << "The .reginfo section has a wrong size.\n";
2310 return;
2311 }
2312
2313 DictScope GS(W, "MIPS RegInfo");
2314 auto *Reginfo = reinterpret_cast<const Elf_Mips_RegInfo<ELFT> *>(Sec.data());
2315 printMipsReginfoData(W, *Reginfo);
2316}
2317
2318template <class ELFT> void ELFDumper<ELFT>::printMipsOptions() {
2319 const Elf_Shdr *Shdr = findSectionByName(*Obj, ".MIPS.options");
2320 if (!Shdr) {
2321 W.startLine() << "There is no .MIPS.options section in the file.\n";
2322 return;
2323 }
2324
2325 DictScope GS(W, "MIPS Options");
2326
2327 ArrayRef<uint8_t> Sec = unwrapOrError(Obj->getSectionContents(Shdr));
2328 while (!Sec.empty()) {
2329 if (Sec.size() < sizeof(Elf_Mips_Options<ELFT>)) {
2330 W.startLine() << "The .MIPS.options section has a wrong size.\n";
2331 return;
2332 }
2333 auto *O = reinterpret_cast<const Elf_Mips_Options<ELFT> *>(Sec.data());
2334 DictScope GS(W, getElfMipsOptionsOdkType(O->kind));
2335 switch (O->kind) {
2336 case ODK_REGINFO:
2337 printMipsReginfoData(W, O->getRegInfo());
2338 break;
2339 default:
2340 W.startLine() << "Unsupported MIPS options tag.\n";
2341 break;
2342 }
2343 Sec = Sec.slice(O->size);
2344 }
2345}
2346
2347template <class ELFT> void ELFDumper<ELFT>::printStackMap() const {
2348 const Elf_Shdr *StackMapSection = nullptr;
2349 for (const auto &Sec : unwrapOrError(Obj->sections())) {
2350 StringRef Name = unwrapOrError(Obj->getSectionName(&Sec));
2351 if (Name == ".llvm_stackmaps") {
2352 StackMapSection = &Sec;
2353 break;
2354 }
2355 }
2356
2357 if (!StackMapSection)
2358 return;
2359
2360 ArrayRef<uint8_t> StackMapContentsArray =
2361 unwrapOrError(Obj->getSectionContents(StackMapSection));
2362
2363 prettyPrintStackMap(
2364 W, StackMapV2Parser<ELFT::TargetEndianness>(StackMapContentsArray));
2365}
2366
2367template <class ELFT> void ELFDumper<ELFT>::printGroupSections() {
2368 ELFDumperStyle->printGroupSections(Obj);
2369}
2370
2371static inline void printFields(formatted_raw_ostream &OS, StringRef Str1,
2372 StringRef Str2) {
2373 OS.PadToColumn(2u);
2374 OS << Str1;
2375 OS.PadToColumn(37u);
2376 OS << Str2 << "\n";
2377 OS.flush();
2378}
2379
2380template <class ELFT> void GNUStyle<ELFT>::printFileHeaders(const ELFO *Obj) {
2381 const Elf_Ehdr *e = Obj->getHeader();
2382 OS << "ELF Header:\n";
2383 OS << " Magic: ";
2384 std::string Str;
2385 for (int i = 0; i < ELF::EI_NIDENT; i++)
2386 OS << format(" %02x", static_cast<int>(e->e_ident[i]));
2387 OS << "\n";
2388 Str = printEnum(e->e_ident[ELF::EI_CLASS], makeArrayRef(ElfClass));
2389 printFields(OS, "Class:", Str);
2390 Str = printEnum(e->e_ident[ELF::EI_DATA], makeArrayRef(ElfDataEncoding));
2391 printFields(OS, "Data:", Str);
2392 OS.PadToColumn(2u);
2393 OS << "Version:";
2394 OS.PadToColumn(37u);
2395 OS << to_hexString(e->e_ident[ELF::EI_VERSION]);
2396 if (e->e_version == ELF::EV_CURRENT)
2397 OS << " (current)";
2398 OS << "\n";
2399 Str = printEnum(e->e_ident[ELF::EI_OSABI], makeArrayRef(ElfOSABI));
2400 printFields(OS, "OS/ABI:", Str);
2401 Str = "0x" + to_hexString(e->e_ident[ELF::EI_ABIVERSION]);
2402 printFields(OS, "ABI Version:", Str);
2403 Str = printEnum(e->e_type, makeArrayRef(ElfObjectFileType));
2404 printFields(OS, "Type:", Str);
2405 Str = printEnum(e->e_machine, makeArrayRef(ElfMachineType));
2406 printFields(OS, "Machine:", Str);
2407 Str = "0x" + to_hexString(e->e_version);
2408 printFields(OS, "Version:", Str);
2409 Str = "0x" + to_hexString(e->e_entry);
2410 printFields(OS, "Entry point address:", Str);
2411 Str = to_string(e->e_phoff) + " (bytes into file)";
2412 printFields(OS, "Start of program headers:", Str);
2413 Str = to_string(e->e_shoff) + " (bytes into file)";
2414 printFields(OS, "Start of section headers:", Str);
2415 Str = "0x" + to_hexString(e->e_flags);
2416 printFields(OS, "Flags:", Str);
2417 Str = to_string(e->e_ehsize) + " (bytes)";
2418 printFields(OS, "Size of this header:", Str);
2419 Str = to_string(e->e_phentsize) + " (bytes)";
2420 printFields(OS, "Size of program headers:", Str);
2421 Str = to_string(e->e_phnum);
2422 printFields(OS, "Number of program headers:", Str);
2423 Str = to_string(e->e_shentsize) + " (bytes)";
2424 printFields(OS, "Size of section headers:", Str);
2425 Str = to_string(e->e_shnum);
2426 printFields(OS, "Number of section headers:", Str);
2427 Str = to_string(e->e_shstrndx);
2428 printFields(OS, "Section header string table index:", Str);
2429}
2430
2431namespace {
2432struct GroupMember {
2433 StringRef Name;
2434 uint64_t Index;
2435};
2436
2437struct GroupSection {
2438 StringRef Name;
2439 StringRef Signature;
2440 uint64_t ShName;
2441 uint64_t Index;
2442 uint32_t Link;
2443 uint32_t Info;
2444 uint32_t Type;
2445 std::vector<GroupMember> Members;
2446};
2447
2448template <class ELFT>
2449std::vector<GroupSection> getGroups(const ELFFile<ELFT> *Obj) {
2450 using Elf_Shdr = typename ELFT::Shdr;
2451 using Elf_Sym = typename ELFT::Sym;
2452 using Elf_Word = typename ELFT::Word;
2453
2454 std::vector<GroupSection> Ret;
2455 uint64_t I = 0;
2456 for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) {
2457 ++I;
2458 if (Sec.sh_type != ELF::SHT_GROUP)
2459 continue;
2460
2461 const Elf_Shdr *Symtab = unwrapOrError(Obj->getSection(Sec.sh_link));
2462 StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*Symtab));
2463 const Elf_Sym *Sym =
2464 unwrapOrError(Obj->template getEntry<Elf_Sym>(Symtab, Sec.sh_info));
2465 auto Data =
2466 unwrapOrError(Obj->template getSectionContentsAsArray<Elf_Word>(&Sec));
2467
2468 StringRef Name = unwrapOrError(Obj->getSectionName(&Sec));
2469 StringRef Signature = StrTable.data() + Sym->st_name;
2470 Ret.push_back({Name,
2471 Signature,
2472 Sec.sh_name,
2473 I - 1,
2474 Sec.sh_link,
2475 Sec.sh_info,
2476 Data[0],
2477 {}});
2478
2479 std::vector<GroupMember> &GM = Ret.back().Members;
2480 for (uint32_t Ndx : Data.slice(1)) {
2481 auto Sec = unwrapOrError(Obj->getSection(Ndx));
2482 const StringRef Name = unwrapOrError(Obj->getSectionName(Sec));
2483 GM.push_back({Name, Ndx});
2484 }
2485 }
2486 return Ret;
2487}
2488
2489DenseMap<uint64_t, const GroupSection *>
2490mapSectionsToGroups(ArrayRef<GroupSection> Groups) {
2491 DenseMap<uint64_t, const GroupSection *> Ret;
2492 for (const GroupSection &G : Groups)
2493 for (const GroupMember &GM : G.Members)
2494 Ret.insert({GM.Index, &G});
2495 return Ret;
2496}
2497
2498} // namespace
2499
2500template <class ELFT> void GNUStyle<ELFT>::printGroupSections(const ELFO *Obj) {
2501 std::vector<GroupSection> V = getGroups<ELFT>(Obj);
2502 DenseMap<uint64_t, const GroupSection *> Map = mapSectionsToGroups(V);
2503 for (const GroupSection &G : V) {
2504 OS << "\n"
2505 << getGroupType(G.Type) << " group section ["
2506 << format_decimal(G.Index, 5) << "] `" << G.Name << "' [" << G.Signature
2507 << "] contains " << G.Members.size() << " sections:\n"
2508 << " [Index] Name\n";
2509 for (const GroupMember &GM : G.Members) {
2510 const GroupSection *MainGroup = Map[GM.Index];
2511 if (MainGroup != &G) {
2512 OS.flush();
2513 errs() << "Error: section [" << format_decimal(GM.Index, 5)
2514 << "] in group section [" << format_decimal(G.Index, 5)
2515 << "] already in group section ["
2516 << format_decimal(MainGroup->Index, 5) << "]";
2517 errs().flush();
2518 continue;
2519 }
2520 OS << " [" << format_decimal(GM.Index, 5) << "] " << GM.Name << "\n";
2521 }
2522 }
2523
2524 if (V.empty())
2525 OS << "There are no section groups in this file.\n";
2526}
2527
2528template <class ELFT>
2529void GNUStyle<ELFT>::printRelocation(const ELFO *Obj, const Elf_Shdr *SymTab,
2530 const Elf_Rela &R, bool IsRela) {
2531 std::string Offset, Info, Addend, Value;
2532 SmallString<32> RelocName;
2533 StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*SymTab));
2534 StringRef TargetName;
2535 const Elf_Sym *Sym = nullptr;
2536 unsigned Width = ELFT::Is64Bits ? 16 : 8;
2537 unsigned Bias = ELFT::Is64Bits ? 8 : 0;
2538
2539 // First two fields are bit width dependent. The rest of them are after are
2540 // fixed width.
2541 Field Fields[5] = {0, 10 + Bias, 19 + 2 * Bias, 42 + 2 * Bias, 53 + 2 * Bias};
2542 Obj->getRelocationTypeName(R.getType(Obj->isMips64EL()), RelocName);
2543 Sym = unwrapOrError(Obj->getRelocationSymbol(&R, SymTab));
2544 if (Sym && Sym->getType() == ELF::STT_SECTION) {
2545 const Elf_Shdr *Sec = unwrapOrError(
2546 Obj->getSection(Sym, SymTab, this->dumper()->getShndxTable()));
2547 TargetName = unwrapOrError(Obj->getSectionName(Sec));
2548 } else if (Sym) {
2549 TargetName = unwrapOrError(Sym->getName(StrTable));
2550 }
2551
2552 if (Sym && IsRela) {
2553 if (R.r_addend < 0)
2554 Addend = " - ";
2555 else
2556 Addend = " + ";
2557 }
2558
2559 Offset = to_string(format_hex_no_prefix(R.r_offset, Width));
2560 Info = to_string(format_hex_no_prefix(R.r_info, Width));
2561
2562 int64_t RelAddend = R.r_addend;
2563 if (IsRela)
2564 Addend += to_hexString(std::abs(RelAddend), false);
2565
2566 if (Sym)
2567 Value = to_string(format_hex_no_prefix(Sym->getValue(), Width));
2568
2569 Fields[0].Str = Offset;
2570 Fields[1].Str = Info;
2571 Fields[2].Str = RelocName;
2572 Fields[3].Str = Value;
2573 Fields[4].Str = TargetName;
2574 for (auto &field : Fields)
2575 printField(field);
2576 OS << Addend;
2577 OS << "\n";
2578}
2579
2580static inline void printRelocHeader(raw_ostream &OS, bool Is64, bool IsRela) {
2581 if (Is64)
2582 OS << " Offset Info Type"
2583 << " Symbol's Value Symbol's Name";
2584 else
2585 OS << " Offset Info Type Sym. Value "
2586 << "Symbol's Name";
2587 if (IsRela)
2588 OS << (IsRela ? " + Addend" : "");
2589 OS << "\n";
2590}
2591
2592template <class ELFT> void GNUStyle<ELFT>::printRelocations(const ELFO *Obj) {
2593 bool HasRelocSections = false;
2594 for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) {
2595 if (Sec.sh_type != ELF::SHT_REL && Sec.sh_type != ELF::SHT_RELA &&
2596 Sec.sh_type != ELF::SHT_ANDROID_REL &&
2597 Sec.sh_type != ELF::SHT_ANDROID_RELA)
2598 continue;
2599 HasRelocSections = true;
2600 StringRef Name = unwrapOrError(Obj->getSectionName(&Sec));
2601 unsigned Entries = Sec.getEntityCount();
2602 uintX_t Offset = Sec.sh_offset;
2603 OS << "\nRelocation section '" << Name << "' at offset 0x"
2604 << to_hexString(Offset, false) << " contains " << Entries
2605 << " entries:\n";
2606 printRelocHeader(OS, ELFT::Is64Bits,
2607 Sec.sh_type == ELF::SHT_RELA ||
2608 Sec.sh_type == ELF::SHT_ANDROID_RELA);
2609 const Elf_Shdr *SymTab = unwrapOrError(Obj->getSection(Sec.sh_link));
2610 switch (Sec.sh_type) {
2611 case ELF::SHT_REL:
2612 for (const auto &R : unwrapOrError(Obj->rels(&Sec))) {
2613 Elf_Rela Rela;
2614 Rela.r_offset = R.r_offset;
2615 Rela.r_info = R.r_info;
2616 Rela.r_addend = 0;
2617 printRelocation(Obj, SymTab, Rela, false);
2618 }
2619 break;
2620 case ELF::SHT_RELA:
2621 for (const auto &R : unwrapOrError(Obj->relas(&Sec)))
2622 printRelocation(Obj, SymTab, R, true);
2623 break;
2624 case ELF::SHT_ANDROID_REL:
2625 case ELF::SHT_ANDROID_RELA:
2626 for (const auto &R : unwrapOrError(Obj->android_relas(&Sec)))
2627 printRelocation(Obj, SymTab, R, Sec.sh_type == ELF::SHT_ANDROID_RELA);
2628 break;
2629 }
2630 }
2631 if (!HasRelocSections)
2632 OS << "\nThere are no relocations in this file.\n";
2633}
2634
2635std::string getSectionTypeString(unsigned Arch, unsigned Type) {
2636 using namespace ELF;
2637
2638 switch (Arch) {
2639 case EM_ARM:
2640 switch (Type) {
2641 case SHT_ARM_EXIDX:
2642 return "ARM_EXIDX";
2643 case SHT_ARM_PREEMPTMAP:
2644 return "ARM_PREEMPTMAP";
2645 case SHT_ARM_ATTRIBUTES:
2646 return "ARM_ATTRIBUTES";
2647 case SHT_ARM_DEBUGOVERLAY:
2648 return "ARM_DEBUGOVERLAY";
2649 case SHT_ARM_OVERLAYSECTION:
2650 return "ARM_OVERLAYSECTION";
2651 }
2652 case EM_X86_64:
2653 switch (Type) {
2654 case SHT_X86_64_UNWIND:
2655 return "X86_64_UNWIND";
2656 }
2657 case EM_MIPS:
2658 case EM_MIPS_RS3_LE:
2659 switch (Type) {
2660 case SHT_MIPS_REGINFO:
2661 return "MIPS_REGINFO";
2662 case SHT_MIPS_OPTIONS:
2663 return "MIPS_OPTIONS";
2664 case SHT_MIPS_ABIFLAGS:
2665 return "MIPS_ABIFLAGS";
2666 case SHT_MIPS_DWARF:
2667 return "SHT_MIPS_DWARF";
2668 }
2669 }
2670 switch (Type) {
2671 case SHT_NULL:
2672 return "NULL";
2673 case SHT_PROGBITS:
2674 return "PROGBITS";
2675 case SHT_SYMTAB:
2676 return "SYMTAB";
2677 case SHT_STRTAB:
2678 return "STRTAB";
2679 case SHT_RELA:
2680 return "RELA";
2681 case SHT_HASH:
2682 return "HASH";
2683 case SHT_DYNAMIC:
2684 return "DYNAMIC";
2685 case SHT_NOTE:
2686 return "NOTE";
2687 case SHT_NOBITS:
2688 return "NOBITS";
2689 case SHT_REL:
2690 return "REL";
2691 case SHT_SHLIB:
2692 return "SHLIB";
2693 case SHT_DYNSYM:
2694 return "DYNSYM";
2695 case SHT_INIT_ARRAY:
2696 return "INIT_ARRAY";
2697 case SHT_FINI_ARRAY:
2698 return "FINI_ARRAY";
2699 case SHT_PREINIT_ARRAY:
2700 return "PREINIT_ARRAY";
2701 case SHT_GROUP:
2702 return "GROUP";
2703 case SHT_SYMTAB_SHNDX:
2704 return "SYMTAB SECTION INDICES";
2705 case SHT_LLVM_ODRTAB:
2706 return "LLVM_ODRTAB";
2707 case SHT_LLVM_LINKER_OPTIONS:
2708 return "LLVM_LINKER_OPTIONS";
2709 // FIXME: Parse processor specific GNU attributes
2710 case SHT_GNU_ATTRIBUTES:
2711 return "ATTRIBUTES";
2712 case SHT_GNU_HASH:
2713 return "GNU_HASH";
2714 case SHT_GNU_verdef:
2715 return "VERDEF";
2716 case SHT_GNU_verneed:
2717 return "VERNEED";
2718 case SHT_GNU_versym:
2719 return "VERSYM";
2720 default:
2721 return "";
2722 }
2723 return "";
2724}
2725
2726template <class ELFT> void GNUStyle<ELFT>::printSections(const ELFO *Obj) {
2727 size_t SectionIndex = 0;
2728 std::string Number, Type, Size, Address, Offset, Flags, Link, Info, EntrySize,
2729 Alignment;
2730 unsigned Bias;
2731 unsigned Width;
2732
2733 if (ELFT::Is64Bits) {
2734 Bias = 0;
2735 Width = 16;
2736 } else {
2737 Bias = 8;
2738 Width = 8;
2739 }
2740 OS << "There are " << to_string(Obj->getHeader()->e_shnum)
2741 << " section headers, starting at offset "
2742 << "0x" << to_hexString(Obj->getHeader()->e_shoff, false) << ":\n\n";
2743 OS << "Section Headers:\n";
2744 Field Fields[11] = {{"[Nr]", 2},
2745 {"Name", 7},
2746 {"Type", 25},
2747 {"Address", 41},
2748 {"Off", 58 - Bias},
2749 {"Size", 65 - Bias},
2750 {"ES", 72 - Bias},
2751 {"Flg", 75 - Bias},
2752 {"Lk", 79 - Bias},
2753 {"Inf", 82 - Bias},
2754 {"Al", 86 - Bias}};
2755 for (auto &f : Fields)
2756 printField(f);
2757 OS << "\n";
2758
2759 for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) {
2760 Number = to_string(SectionIndex);
2761 Fields[0].Str = Number;
2762 Fields[1].Str = unwrapOrError(Obj->getSectionName(&Sec));
2763 Type = getSectionTypeString(Obj->getHeader()->e_machine, Sec.sh_type);
2764 Fields[2].Str = Type;
2765 Address = to_string(format_hex_no_prefix(Sec.sh_addr, Width));
2766 Fields[3].Str = Address;
2767 Offset = to_string(format_hex_no_prefix(Sec.sh_offset, 6));
2768 Fields[4].Str = Offset;
2769 Size = to_string(format_hex_no_prefix(Sec.sh_size, 6));
2770 Fields[5].Str = Size;
2771 EntrySize = to_string(format_hex_no_prefix(Sec.sh_entsize, 2));
2772 Fields[6].Str = EntrySize;
2773 Flags = getGNUFlags(Sec.sh_flags);
2774 Fields[7].Str = Flags;
2775 Link = to_string(Sec.sh_link);
2776 Fields[8].Str = Link;
2777 Info = to_string(Sec.sh_info);
2778 Fields[9].Str = Info;
2779 Alignment = to_string(Sec.sh_addralign);
2780 Fields[10].Str = Alignment;
2781 OS.PadToColumn(Fields[0].Column);
2782 OS << "[" << right_justify(Fields[0].Str, 2) << "]";
2783 for (int i = 1; i < 7; i++)
2784 printField(Fields[i]);
2785 OS.PadToColumn(Fields[7].Column);
2786 OS << right_justify(Fields[7].Str, 3);
2787 OS.PadToColumn(Fields[8].Column);
2788 OS << right_justify(Fields[8].Str, 2);
2789 OS.PadToColumn(Fields[9].Column);
2790 OS << right_justify(Fields[9].Str, 3);
2791 OS.PadToColumn(Fields[10].Column);
2792 OS << right_justify(Fields[10].Str, 2);
2793 OS << "\n";
2794 ++SectionIndex;
2795 }
2796 OS << "Key to Flags:\n"
2797 << " W (write), A (alloc), X (execute), M (merge), S (strings), l "
2798 "(large)\n"
2799 << " I (info), L (link order), G (group), T (TLS), E (exclude),\
2800 x (unknown)\n"
2801 << " O (extra OS processing required) o (OS specific),\
2802 p (processor specific)\n";
2803}
2804
2805template <class ELFT>
2806void GNUStyle<ELFT>::printSymtabMessage(const ELFO *Obj, StringRef Name,
2807 size_t Entries) {
2808 if (!Name.empty())
2809 OS << "\nSymbol table '" << Name << "' contains " << Entries
2810 << " entries:\n";
2811 else
2812 OS << "\n Symbol table for image:\n";
2813
2814 if (ELFT::Is64Bits)
2815 OS << " Num: Value Size Type Bind Vis Ndx Name\n";
2816 else
2817 OS << " Num: Value Size Type Bind Vis Ndx Name\n";
2818}
2819
2820template <class ELFT>
2821std::string GNUStyle<ELFT>::getSymbolSectionNdx(const ELFO *Obj,
2822 const Elf_Sym *Symbol,
2823 const Elf_Sym *FirstSym) {
2824 unsigned SectionIndex = Symbol->st_shndx;
2825 switch (SectionIndex) {
2826 case ELF::SHN_UNDEF:
2827 return "UND";
2828 case ELF::SHN_ABS:
2829 return "ABS";
2830 case ELF::SHN_COMMON:
2831 return "COM";
2832 case ELF::SHN_XINDEX:
2833 SectionIndex = unwrapOrError(object::getExtendedSymbolTableIndex<ELFT>(
2834 Symbol, FirstSym, this->dumper()->getShndxTable()));
2835 LLVM_FALLTHROUGH[[clang::fallthrough]];
2836 default:
2837 // Find if:
2838 // Processor specific
2839 if (SectionIndex >= ELF::SHN_LOPROC && SectionIndex <= ELF::SHN_HIPROC)
2840 return std::string("PRC[0x") +
2841 to_string(format_hex_no_prefix(SectionIndex, 4)) + "]";
2842 // OS specific
2843 if (SectionIndex >= ELF::SHN_LOOS && SectionIndex <= ELF::SHN_HIOS)
2844 return std::string("OS[0x") +
2845 to_string(format_hex_no_prefix(SectionIndex, 4)) + "]";
2846 // Architecture reserved:
2847 if (SectionIndex >= ELF::SHN_LORESERVE &&
2848 SectionIndex <= ELF::SHN_HIRESERVE)
2849 return std::string("RSV[0x") +
2850 to_string(format_hex_no_prefix(SectionIndex, 4)) + "]";
2851 // A normal section with an index
2852 return to_string(format_decimal(SectionIndex, 3));
2853 }
2854}
2855
2856template <class ELFT>
2857void GNUStyle<ELFT>::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol,
2858 const Elf_Sym *FirstSym, StringRef StrTable,
2859 bool IsDynamic) {
2860 static int Idx = 0;
2861 static bool Dynamic = true;
2862 size_t Width;
2863
2864 // If this function was called with a different value from IsDynamic
2865 // from last call, happens when we move from dynamic to static symbol
2866 // table, "Num" field should be reset.
2867 if (!Dynamic != !IsDynamic) {
2868 Idx = 0;
2869 Dynamic = false;
2870 }
2871 std::string Num, Name, Value, Size, Binding, Type, Visibility, Section;
2872 unsigned Bias = 0;
2873 if (ELFT::Is64Bits) {
2874 Bias = 8;
2875 Width = 16;
2876 } else {
2877 Bias = 0;
2878 Width = 8;
2879 }
2880 Field Fields[8] = {0, 8, 17 + Bias, 23 + Bias,
2881 31 + Bias, 38 + Bias, 47 + Bias, 51 + Bias};
2882 Num = to_string(format_decimal(Idx++, 6)) + ":";
2883 Value = to_string(format_hex_no_prefix(Symbol->st_value, Width));
2884 Size = to_string(format_decimal(Symbol->st_size, 5));
2885 unsigned char SymbolType = Symbol->getType();
2886 if (Obj->getHeader()->e_machine == ELF::EM_AMDGPU &&
2887 SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS)
2888 Type = printEnum(SymbolType, makeArrayRef(AMDGPUSymbolTypes));
2889 else
2890 Type = printEnum(SymbolType, makeArrayRef(ElfSymbolTypes));
2891 unsigned Vis = Symbol->getVisibility();
2892 Binding = printEnum(Symbol->getBinding(), makeArrayRef(ElfSymbolBindings));
2893 Visibility = printEnum(Vis, makeArrayRef(ElfSymbolVisibilities));
2894 Section = getSymbolSectionNdx(Obj, Symbol, FirstSym);
2895 Name = this->dumper()->getFullSymbolName(Symbol, StrTable, IsDynamic);
2896 Fields[0].Str = Num;
2897 Fields[1].Str = Value;
2898 Fields[2].Str = Size;
2899 Fields[3].Str = Type;
2900 Fields[4].Str = Binding;
2901 Fields[5].Str = Visibility;
2902 Fields[6].Str = Section;
2903 Fields[7].Str = Name;
2904 for (auto &Entry : Fields)
2905 printField(Entry);
2906 OS << "\n";
2907}
2908template <class ELFT>
2909void GNUStyle<ELFT>::printHashedSymbol(const ELFO *Obj, const Elf_Sym *FirstSym,
2910 uint32_t Sym, StringRef StrTable,
2911 uint32_t Bucket) {
2912 std::string Num, Buc, Name, Value, Size, Binding, Type, Visibility, Section;
2913 unsigned Width, Bias = 0;
2914 if (ELFT::Is64Bits) {
2915 Bias = 8;
2916 Width = 16;
2917 } else {
2918 Bias = 0;
2919 Width = 8;
2920 }
2921 Field Fields[9] = {0, 6, 11, 20 + Bias, 25 + Bias,
2922 34 + Bias, 41 + Bias, 49 + Bias, 53 + Bias};
2923 Num = to_string(format_decimal(Sym, 5));
2924 Buc = to_string(format_decimal(Bucket, 3)) + ":";
2925
2926 const auto Symbol = FirstSym + Sym;
2927 Value = to_string(format_hex_no_prefix(Symbol->st_value, Width));
2928 Size = to_string(format_decimal(Symbol->st_size, 5));
2929 unsigned char SymbolType = Symbol->getType();
2930 if (Obj->getHeader()->e_machine == ELF::EM_AMDGPU &&
2931 SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS)
2932 Type = printEnum(SymbolType, makeArrayRef(AMDGPUSymbolTypes));
2933 else
2934 Type = printEnum(SymbolType, makeArrayRef(ElfSymbolTypes));
2935 unsigned Vis = Symbol->getVisibility();
2936 Binding = printEnum(Symbol->getBinding(), makeArrayRef(ElfSymbolBindings));
2937 Visibility = printEnum(Vis, makeArrayRef(ElfSymbolVisibilities));
2938 Section = getSymbolSectionNdx(Obj, Symbol, FirstSym);
2939 Name = this->dumper()->getFullSymbolName(Symbol, StrTable, true);
2940 Fields[0].Str = Num;
2941 Fields[1].Str = Buc;
2942 Fields[2].Str = Value;
2943 Fields[3].Str = Size;
2944 Fields[4].Str = Type;
2945 Fields[5].Str = Binding;
2946 Fields[6].Str = Visibility;
2947 Fields[7].Str = Section;
2948 Fields[8].Str = Name;
2949 for (auto &Entry : Fields)
2950 printField(Entry);
2951 OS << "\n";
2952}
2953
2954template <class ELFT> void GNUStyle<ELFT>::printSymbols(const ELFO *Obj) {
2955 if (opts::DynamicSymbols)
2956 return;
2957 this->dumper()->printSymbolsHelper(true);
2958 this->dumper()->printSymbolsHelper(false);
2959}
2960
2961template <class ELFT>
2962void GNUStyle<ELFT>::printDynamicSymbols(const ELFO *Obj) {
2963 if (this->dumper()->getDynamicStringTable().empty())
1
Assuming the condition is false
2
Taking false branch
2964 return;
2965 auto StringTable = this->dumper()->getDynamicStringTable();
2966 auto DynSyms = this->dumper()->dynamic_symbols();
2967 auto GnuHash = this->dumper()->getGnuHashTable();
2968 auto SysVHash = this->dumper()->getHashTable();
3
Calling 'ELFDumper::getHashTable'
4
Returning from 'ELFDumper::getHashTable'
5
'SysVHash' initialized here
2969
2970 // If no hash or .gnu.hash found, try using symbol table
2971 if (GnuHash == nullptr && SysVHash == nullptr)
6
Assuming the condition is true
7
Assuming pointer value is null
8
Taking true branch
2972 this->dumper()->printSymbolsHelper(true);
2973
2974 // Try printing .hash
2975 if (this->dumper()->getHashTable()) {
9
Assuming the condition is true
10
Taking true branch
2976 OS << "\n Symbol table of .hash for image:\n";
2977 if (ELFT::Is64Bits)
11
Taking true branch
2978 OS << " Num Buc: Value Size Type Bind Vis Ndx Name";
2979 else
2980 OS << " Num Buc: Value Size Type Bind Vis Ndx Name";
2981 OS << "\n";
2982
2983 uint32_t NBuckets = SysVHash->nbucket;
12
Called C++ object pointer is null
2984 uint32_t NChains = SysVHash->nchain;
2985 auto Buckets = SysVHash->buckets();
2986 auto Chains = SysVHash->chains();
2987 for (uint32_t Buc = 0; Buc < NBuckets; Buc++) {
2988 if (Buckets[Buc] == ELF::STN_UNDEF)
2989 continue;
2990 for (uint32_t Ch = Buckets[Buc]; Ch < NChains; Ch = Chains[Ch]) {
2991 if (Ch == ELF::STN_UNDEF)
2992 break;
2993 printHashedSymbol(Obj, &DynSyms[0], Ch, StringTable, Buc);
2994 }
2995 }
2996 }
2997
2998 // Try printing .gnu.hash
2999 if (GnuHash) {
3000 OS << "\n Symbol table of .gnu.hash for image:\n";
3001 if (ELFT::Is64Bits)
3002 OS << " Num Buc: Value Size Type Bind Vis Ndx Name";
3003 else
3004 OS << " Num Buc: Value Size Type Bind Vis Ndx Name";
3005 OS << "\n";
3006 uint32_t NBuckets = GnuHash->nbuckets;
3007 auto Buckets = GnuHash->buckets();
3008 for (uint32_t Buc = 0; Buc < NBuckets; Buc++) {
3009 if (Buckets[Buc] == ELF::STN_UNDEF)
3010 continue;
3011 uint32_t Index = Buckets[Buc];
3012 uint32_t GnuHashable = Index - GnuHash->symndx;
3013 // Print whole chain
3014 while (true) {
3015 printHashedSymbol(Obj, &DynSyms[0], Index++, StringTable, Buc);
3016 // Chain ends at symbol with stopper bit
3017 if ((GnuHash->values(DynSyms.size())[GnuHashable++] & 1) == 1)
3018 break;
3019 }
3020 }
3021 }
3022}
3023
3024static inline std::string printPhdrFlags(unsigned Flag) {
3025 std::string Str;
3026 Str = (Flag & PF_R) ? "R" : " ";
3027 Str += (Flag & PF_W) ? "W" : " ";
3028 Str += (Flag & PF_X) ? "E" : " ";
3029 return Str;
3030}
3031
3032// SHF_TLS sections are only in PT_TLS, PT_LOAD or PT_GNU_RELRO
3033// PT_TLS must only have SHF_TLS sections
3034template <class ELFT>
3035bool GNUStyle<ELFT>::checkTLSSections(const Elf_Phdr &Phdr,
3036 const Elf_Shdr &Sec) {
3037 return (((Sec.sh_flags & ELF::SHF_TLS) &&
3038 ((Phdr.p_type == ELF::PT_TLS) || (Phdr.p_type == ELF::PT_LOAD) ||
3039 (Phdr.p_type == ELF::PT_GNU_RELRO))) ||
3040 (!(Sec.sh_flags & ELF::SHF_TLS) && Phdr.p_type != ELF::PT_TLS));
3041}
3042
3043// Non-SHT_NOBITS must have its offset inside the segment
3044// Only non-zero section can be at end of segment
3045template <class ELFT>
3046bool GNUStyle<ELFT>::checkoffsets(const Elf_Phdr &Phdr, const Elf_Shdr &Sec) {
3047 if (Sec.sh_type == ELF::SHT_NOBITS)
3048 return true;
3049 bool IsSpecial =
3050 (Sec.sh_type == ELF::SHT_NOBITS) && ((Sec.sh_flags & ELF::SHF_TLS) != 0);
3051 // .tbss is special, it only has memory in PT_TLS and has NOBITS properties
3052 auto SectionSize =
3053 (IsSpecial && Phdr.p_type != ELF::PT_TLS) ? 0 : Sec.sh_size;
3054 if (Sec.sh_offset >= Phdr.p_offset)
3055 return ((Sec.sh_offset + SectionSize <= Phdr.p_filesz + Phdr.p_offset)
3056 /*only non-zero sized sections at end*/ &&
3057 (Sec.sh_offset + 1 <= Phdr.p_offset + Phdr.p_filesz));
3058 return false;
3059}
3060
3061// SHF_ALLOC must have VMA inside segment
3062// Only non-zero section can be at end of segment
3063template <class ELFT>
3064bool GNUStyle<ELFT>::checkVMA(const Elf_Phdr &Phdr, const Elf_Shdr &Sec) {
3065 if (!(Sec.sh_flags & ELF::SHF_ALLOC))
3066 return true;
3067 bool IsSpecial =
3068 (Sec.sh_type == ELF::SHT_NOBITS) && ((Sec.sh_flags & ELF::SHF_TLS) != 0);
3069 // .tbss is special, it only has memory in PT_TLS and has NOBITS properties
3070 auto SectionSize =
3071 (IsSpecial && Phdr.p_type != ELF::PT_TLS) ? 0 : Sec.sh_size;
3072 if (Sec.sh_addr >= Phdr.p_vaddr)
3073 return ((Sec.sh_addr + SectionSize <= Phdr.p_vaddr + Phdr.p_memsz) &&
3074 (Sec.sh_addr + 1 <= Phdr.p_vaddr + Phdr.p_memsz));
3075 return false;
3076}
3077
3078// No section with zero size must be at start or end of PT_DYNAMIC
3079template <class ELFT>
3080bool GNUStyle<ELFT>::checkPTDynamic(const Elf_Phdr &Phdr, const Elf_Shdr &Sec) {
3081 if (Phdr.p_type != ELF::PT_DYNAMIC || Sec.sh_size != 0 || Phdr.p_memsz == 0)
3082 return true;
3083 // Is section within the phdr both based on offset and VMA ?
3084 return ((Sec.sh_type == ELF::SHT_NOBITS) ||
3085 (Sec.sh_offset > Phdr.p_offset &&
3086 Sec.sh_offset < Phdr.p_offset + Phdr.p_filesz)) &&
3087 (!(Sec.sh_flags & ELF::SHF_ALLOC) ||
3088 (Sec.sh_addr > Phdr.p_vaddr && Sec.sh_addr < Phdr.p_memsz));
3089}
3090
3091template <class ELFT>
3092void GNUStyle<ELFT>::printProgramHeaders(const ELFO *Obj) {
3093 unsigned Bias = ELFT::Is64Bits ? 8 : 0;
3094 unsigned Width = ELFT::Is64Bits ? 18 : 10;
3095 unsigned SizeWidth = ELFT::Is64Bits ? 8 : 7;
3096 std::string Type, Offset, VMA, LMA, FileSz, MemSz, Flag, Align;
3097
3098 const Elf_Ehdr *Header = Obj->getHeader();
3099 Field Fields[8] = {2, 17, 26, 37 + Bias,
3100 48 + Bias, 56 + Bias, 64 + Bias, 68 + Bias};
3101 OS << "\nElf file type is "
3102 << printEnum(Header->e_type, makeArrayRef(ElfObjectFileType)) << "\n"
3103 << "Entry point " << format_hex(Header->e_entry, 3) << "\n"
3104 << "There are " << Header->e_phnum << " program headers,"
3105 << " starting at offset " << Header->e_phoff << "\n\n"
3106 << "Program Headers:\n";
3107 if (ELFT::Is64Bits)
3108 OS << " Type Offset VirtAddr PhysAddr "
3109 << " FileSiz MemSiz Flg Align\n";
3110 else
3111 OS << " Type Offset VirtAddr PhysAddr FileSiz "
3112 << "MemSiz Flg Align\n";
3113 for (const auto &Phdr : unwrapOrError(Obj->program_headers())) {
3114 Type = getElfPtType(Header->e_machine, Phdr.p_type);
3115 Offset = to_string(format_hex(Phdr.p_offset, 8));
3116 VMA = to_string(format_hex(Phdr.p_vaddr, Width));
3117 LMA = to_string(format_hex(Phdr.p_paddr, Width));
3118 FileSz = to_string(format_hex(Phdr.p_filesz, SizeWidth));
3119 MemSz = to_string(format_hex(Phdr.p_memsz, SizeWidth));
3120 Flag = printPhdrFlags(Phdr.p_flags);
3121 Align = to_string(format_hex(Phdr.p_align, 1));
3122 Fields[0].Str = Type;
3123 Fields[1].Str = Offset;
3124 Fields[2].Str = VMA;
3125 Fields[3].Str = LMA;
3126 Fields[4].Str = FileSz;
3127 Fields[5].Str = MemSz;
3128 Fields[6].Str = Flag;
3129 Fields[7].Str = Align;
3130 for (auto Field : Fields)
3131 printField(Field);
3132 if (Phdr.p_type == ELF::PT_INTERP) {
3133 OS << "\n [Requesting program interpreter: ";
3134 OS << reinterpret_cast<const char *>(Obj->base()) + Phdr.p_offset << "]";
3135 }
3136 OS << "\n";
3137 }
3138 OS << "\n Section to Segment mapping:\n Segment Sections...\n";
3139 int Phnum = 0;
3140 for (const Elf_Phdr &Phdr : unwrapOrError(Obj->program_headers())) {
3141 std::string Sections;
3142 OS << format(" %2.2d ", Phnum++);
3143 for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) {
3144 // Check if each section is in a segment and then print mapping.
3145 // readelf additionally makes sure it does not print zero sized sections
3146 // at end of segments and for PT_DYNAMIC both start and end of section
3147 // .tbss must only be shown in PT_TLS section.
3148 bool TbssInNonTLS = (Sec.sh_type == ELF::SHT_NOBITS) &&
3149 ((Sec.sh_flags & ELF::SHF_TLS) != 0) &&
3150 Phdr.p_type != ELF::PT_TLS;
3151 if (!TbssInNonTLS && checkTLSSections(Phdr, Sec) &&
3152 checkoffsets(Phdr, Sec) && checkVMA(Phdr, Sec) &&
3153 checkPTDynamic(Phdr, Sec) && (Sec.sh_type != ELF::SHT_NULL))
3154 Sections += unwrapOrError(Obj->getSectionName(&Sec)).str() + " ";
3155 }
3156 OS << Sections << "\n";
3157 OS.flush();
3158 }
3159}
3160
3161template <class ELFT>
3162void GNUStyle<ELFT>::printDynamicRelocation(const ELFO *Obj, Elf_Rela R,
3163 bool IsRela) {
3164 SmallString<32> RelocName;
3165 StringRef SymbolName;
3166 unsigned Width = ELFT::Is64Bits ? 16 : 8;
3167 unsigned Bias = ELFT::Is64Bits ? 8 : 0;
3168 // First two fields are bit width dependent. The rest of them are after are
3169 // fixed width.
3170 Field Fields[5] = {0, 10 + Bias, 19 + 2 * Bias, 42 + 2 * Bias, 53 + 2 * Bias};
3171
3172 uint32_t SymIndex = R.getSymbol(Obj->isMips64EL());
3173 const Elf_Sym *Sym = this->dumper()->dynamic_symbols().begin() + SymIndex;
3174 Obj->getRelocationTypeName(R.getType(Obj->isMips64EL()), RelocName);
3175 SymbolName =
3176 unwrapOrError(Sym->getName(this->dumper()->getDynamicStringTable()));
3177 std::string Addend, Info, Offset, Value;
3178 Offset = to_string(format_hex_no_prefix(R.r_offset, Width));
3179 Info = to_string(format_hex_no_prefix(R.r_info, Width));
3180 Value = to_string(format_hex_no_prefix(Sym->getValue(), Width));
3181 int64_t RelAddend = R.r_addend;
3182 if (!SymbolName.empty() && IsRela) {
3183 if (R.r_addend < 0)
3184 Addend = " - ";
3185 else
3186 Addend = " + ";
3187 }
3188
3189 if (SymbolName.empty() && Sym->getValue() == 0)
3190 Value = "";
3191
3192 if (IsRela)
3193 Addend += to_string(format_hex_no_prefix(std::abs(RelAddend), 1));
3194
3195
3196 Fields[0].Str = Offset;
3197 Fields[1].Str = Info;
3198 Fields[2].Str = RelocName.c_str();
3199 Fields[3].Str = Value;
3200 Fields[4].Str = SymbolName;
3201 for (auto &Field : Fields)
3202 printField(Field);
3203 OS << Addend;
3204 OS << "\n";
3205}
3206
3207template <class ELFT>
3208void GNUStyle<ELFT>::printDynamicRelocations(const ELFO *Obj) {
3209 const DynRegionInfo &DynRelRegion = this->dumper()->getDynRelRegion();
3210 const DynRegionInfo &DynRelaRegion = this->dumper()->getDynRelaRegion();
3211 const DynRegionInfo &DynPLTRelRegion = this->dumper()->getDynPLTRelRegion();
3212 if (DynRelaRegion.Size > 0) {
3213 OS << "\n'RELA' relocation section at offset "
3214 << format_hex(reinterpret_cast<const uint8_t *>(DynRelaRegion.Addr) -
3215 Obj->base(),
3216 1) << " contains " << DynRelaRegion.Size << " bytes:\n";
3217 printRelocHeader(OS, ELFT::Is64Bits, true);
3218 for (const Elf_Rela &Rela : this->dumper()->dyn_relas())
3219 printDynamicRelocation(Obj, Rela, true);
3220 }
3221 if (DynRelRegion.Size > 0) {
3222 OS << "\n'REL' relocation section at offset "
3223 << format_hex(reinterpret_cast<const uint8_t *>(DynRelRegion.Addr) -
3224 Obj->base(),
3225 1) << " contains " << DynRelRegion.Size << " bytes:\n";
3226 printRelocHeader(OS, ELFT::Is64Bits, false);
3227 for (const Elf_Rel &Rel : this->dumper()->dyn_rels()) {
3228 Elf_Rela Rela;
3229 Rela.r_offset = Rel.r_offset;
3230 Rela.r_info = Rel.r_info;
3231 Rela.r_addend = 0;
3232 printDynamicRelocation(Obj, Rela, false);
3233 }
3234 }
3235 if (DynPLTRelRegion.Size) {
3236 OS << "\n'PLT' relocation section at offset "
3237 << format_hex(reinterpret_cast<const uint8_t *>(DynPLTRelRegion.Addr) -
3238 Obj->base(),
3239 1) << " contains " << DynPLTRelRegion.Size << " bytes:\n";
3240 }
3241 if (DynPLTRelRegion.EntSize == sizeof(Elf_Rela)) {
3242 printRelocHeader(OS, ELFT::Is64Bits, true);
3243 for (const Elf_Rela &Rela : DynPLTRelRegion.getAsArrayRef<Elf_Rela>())
3244 printDynamicRelocation(Obj, Rela, true);
3245 } else {
3246 printRelocHeader(OS, ELFT::Is64Bits, false);
3247 for (const Elf_Rel &Rel : DynPLTRelRegion.getAsArrayRef<Elf_Rel>()) {
3248 Elf_Rela Rela;
3249 Rela.r_offset = Rel.r_offset;
3250 Rela.r_info = Rel.r_info;
3251 Rela.r_addend = 0;
3252 printDynamicRelocation(Obj, Rela, false);
3253 }
3254 }
3255}
3256
3257// Hash histogram shows statistics of how efficient the hash was for the
3258// dynamic symbol table. The table shows number of hash buckets for different
3259// lengths of chains as absolute number and percentage of the total buckets.
3260// Additionally cumulative coverage of symbols for each set of buckets.
3261template <class ELFT>
3262void GNUStyle<ELFT>::printHashHistogram(const ELFFile<ELFT> *Obj) {
3263
3264 const Elf_Hash *HashTable = this->dumper()->getHashTable();
3265 const Elf_GnuHash *GnuHashTable = this->dumper()->getGnuHashTable();
3266
3267 // Print histogram for .hash section
3268 if (HashTable) {
3269 size_t NBucket = HashTable->nbucket;
3270 size_t NChain = HashTable->nchain;
3271 ArrayRef<Elf_Word> Buckets = HashTable->buckets();
3272 ArrayRef<Elf_Word> Chains = HashTable->chains();
3273 size_t TotalSyms = 0;
3274 // If hash table is correct, we have at least chains with 0 length
3275 size_t MaxChain = 1;
3276 size_t CumulativeNonZero = 0;
3277
3278 if (NChain == 0 || NBucket == 0)
3279 return;
3280
3281 std::vector<size_t> ChainLen(NBucket, 0);
3282 // Go over all buckets and and note chain lengths of each bucket (total
3283 // unique chain lengths).
3284 for (size_t B = 0; B < NBucket; B++) {
3285 for (size_t C = Buckets[B]; C > 0 && C < NChain; C = Chains[C])
3286 if (MaxChain <= ++ChainLen[B])
3287 MaxChain++;
3288 TotalSyms += ChainLen[B];
3289 }
3290
3291 if (!TotalSyms)
3292 return;
3293
3294 std::vector<size_t> Count(MaxChain, 0) ;
3295 // Count how long is the chain for each bucket
3296 for (size_t B = 0; B < NBucket; B++)
3297 ++Count[ChainLen[B]];
3298 // Print Number of buckets with each chain lengths and their cumulative
3299 // coverage of the symbols
3300 OS << "Histogram for bucket list length (total of " << NBucket
3301 << " buckets)\n"
3302 << " Length Number % of total Coverage\n";
3303 for (size_t I = 0; I < MaxChain; I++) {
3304 CumulativeNonZero += Count[I] * I;
3305 OS << format("%7lu %-10lu (%5.1f%%) %5.1f%%\n", I, Count[I],
3306 (Count[I] * 100.0) / NBucket,
3307 (CumulativeNonZero * 100.0) / TotalSyms);
3308 }
3309 }
3310
3311 // Print histogram for .gnu.hash section
3312 if (GnuHashTable) {
3313 size_t NBucket = GnuHashTable->nbuckets;
3314 ArrayRef<Elf_Word> Buckets = GnuHashTable->buckets();
3315 unsigned NumSyms = this->dumper()->dynamic_symbols().size();
3316 if (!NumSyms)
3317 return;
3318 ArrayRef<Elf_Word> Chains = GnuHashTable->values(NumSyms);
3319 size_t Symndx = GnuHashTable->symndx;
3320 size_t TotalSyms = 0;
3321 size_t MaxChain = 1;
3322 size_t CumulativeNonZero = 0;
3323
3324 if (Chains.empty() || NBucket == 0)
3325 return;
3326
3327 std::vector<size_t> ChainLen(NBucket, 0);
3328
3329 for (size_t B = 0; B < NBucket; B++) {
3330 if (!Buckets[B])
3331 continue;
3332 size_t Len = 1;
3333 for (size_t C = Buckets[B] - Symndx;
3334 C < Chains.size() && (Chains[C] & 1) == 0; C++)
3335 if (MaxChain < ++Len)
3336 MaxChain++;
3337 ChainLen[B] = Len;
3338 TotalSyms += Len;
3339 }
3340 MaxChain++;
3341
3342 if (!TotalSyms)
3343 return;
3344
3345 std::vector<size_t> Count(MaxChain, 0) ;
3346 for (size_t B = 0; B < NBucket; B++)
3347 ++Count[ChainLen[B]];
3348 // Print Number of buckets with each chain lengths and their cumulative
3349 // coverage of the symbols
3350 OS << "Histogram for `.gnu.hash' bucket list length (total of " << NBucket
3351 << " buckets)\n"
3352 << " Length Number % of total Coverage\n";
3353 for (size_t I = 0; I <MaxChain; I++) {
3354 CumulativeNonZero += Count[I] * I;
3355 OS << format("%7lu %-10lu (%5.1f%%) %5.1f%%\n", I, Count[I],
3356 (Count[I] * 100.0) / NBucket,
3357 (CumulativeNonZero * 100.0) / TotalSyms);
3358 }
3359 }
3360}
3361
3362static std::string getGNUNoteTypeName(const uint32_t NT) {
3363 static const struct {
3364 uint32_t ID;
3365 const char *Name;
3366 } Notes[] = {
3367 {ELF::NT_GNU_ABI_TAG, "NT_GNU_ABI_TAG (ABI version tag)"},
3368 {ELF::NT_GNU_HWCAP, "NT_GNU_HWCAP (DSO-supplied software HWCAP info)"},
3369 {ELF::NT_GNU_BUILD_ID, "NT_GNU_BUILD_ID (unique build ID bitstring)"},
3370 {ELF::NT_GNU_GOLD_VERSION, "NT_GNU_GOLD_VERSION (gold version)"},
3371 {ELF::NT_GNU_PROPERTY_TYPE_0, "NT_GNU_PROPERTY_TYPE_0 (property note)"},
3372 };
3373
3374 for (const auto &Note : Notes)
3375 if (Note.ID == NT)
3376 return std::string(Note.Name);
3377
3378 std::string string;
3379 raw_string_ostream OS(string);
3380 OS << format("Unknown note type (0x%08x)", NT);
3381 return OS.str();
3382}
3383
3384static std::string getFreeBSDNoteTypeName(const uint32_t NT) {
3385 static const struct {
3386 uint32_t ID;
3387 const char *Name;
3388 } Notes[] = {
3389 {ELF::NT_FREEBSD_THRMISC, "NT_THRMISC (thrmisc structure)"},
3390 {ELF::NT_FREEBSD_PROCSTAT_PROC, "NT_PROCSTAT_PROC (proc data)"},
3391 {ELF::NT_FREEBSD_PROCSTAT_FILES, "NT_PROCSTAT_FILES (files data)"},
3392 {ELF::NT_FREEBSD_PROCSTAT_VMMAP, "NT_PROCSTAT_VMMAP (vmmap data)"},
3393 {ELF::NT_FREEBSD_PROCSTAT_GROUPS, "NT_PROCSTAT_GROUPS (groups data)"},
3394 {ELF::NT_FREEBSD_PROCSTAT_UMASK, "NT_PROCSTAT_UMASK (umask data)"},
3395 {ELF::NT_FREEBSD_PROCSTAT_RLIMIT, "NT_PROCSTAT_RLIMIT (rlimit data)"},
3396 {ELF::NT_FREEBSD_PROCSTAT_OSREL, "NT_PROCSTAT_OSREL (osreldate data)"},
3397 {ELF::NT_FREEBSD_PROCSTAT_PSSTRINGS,
3398 "NT_PROCSTAT_PSSTRINGS (ps_strings data)"},
3399 {ELF::NT_FREEBSD_PROCSTAT_AUXV, "NT_PROCSTAT_AUXV (auxv data)"},
3400 };
3401
3402 for (const auto &Note : Notes)
3403 if (Note.ID == NT)
3404 return std::string(Note.Name);
3405
3406 std::string string;
3407 raw_string_ostream OS(string);
3408 OS << format("Unknown note type (0x%08x)", NT);
3409 return OS.str();
3410}
3411
3412static std::string getAMDGPUNoteTypeName(const uint32_t NT) {
3413 static const struct {
3414 uint32_t ID;
3415 const char *Name;
3416 } Notes[] = {
3417 {ELF::NT_AMD_AMDGPU_HSA_METADATA,
3418 "NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata)"},
3419 {ELF::NT_AMD_AMDGPU_ISA,
3420 "NT_AMD_AMDGPU_ISA (ISA Version)"},
3421 {ELF::NT_AMD_AMDGPU_PAL_METADATA,
3422 "NT_AMD_AMDGPU_PAL_METADATA (PAL Metadata)"}
3423 };
3424
3425 for (const auto &Note : Notes)
3426 if (Note.ID == NT)
3427 return std::string(Note.Name);
3428
3429 std::string string;
3430 raw_string_ostream OS(string);
3431 OS << format("Unknown note type (0x%08x)", NT);
3432 return OS.str();
3433}
3434
3435template <typename ELFT>
3436static void printGNUProperty(raw_ostream &OS, uint32_t Type, uint32_t DataSize,
3437 ArrayRef<uint8_t> Data) {
3438 switch (Type) {
3439 default:
3440 OS << format(" <application-specific type 0x%x>\n", Type);
3441 return;
3442 case GNU_PROPERTY_STACK_SIZE: {
3443 OS << " stack size: ";
3444 if (DataSize == sizeof(typename ELFT::uint))
3445 OS << format("0x%x\n",
3446 (uint64_t)(*(const typename ELFT::Addr *)Data.data()));
3447 else
3448 OS << format("<corrupt length: 0x%x>\n", DataSize);
3449 break;
3450 }
3451 case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
3452 OS << " no copy on protected";
3453 if (DataSize)
3454 OS << format(" <corrupt length: 0x%x>", DataSize);
3455 OS << "\n";
3456 break;
3457 }
3458}
3459
3460template <typename ELFT>
3461static void printGNUNote(raw_ostream &OS, uint32_t NoteType,
3462 ArrayRef<typename ELFT::Word> Words, size_t Size) {
3463 using Elf_Word = typename ELFT::Word;
3464
3465 switch (NoteType) {
3466 default:
3467 return;
3468 case ELF::NT_GNU_ABI_TAG: {
3469 static const char *OSNames[] = {
3470 "Linux", "Hurd", "Solaris", "FreeBSD", "NetBSD", "Syllable", "NaCl",
3471 };
3472
3473 StringRef OSName = "Unknown";
3474 if (Words[0] < array_lengthof(OSNames))
3475 OSName = OSNames[Words[0]];
3476 uint32_t Major = Words[1], Minor = Words[2], Patch = Words[3];
3477
3478 if (Words.size() < 4)
3479 OS << " <corrupt GNU_ABI_TAG>";
3480 else
3481 OS << " OS: " << OSName << ", ABI: " << Major << "." << Minor << "."
3482 << Patch;
3483 break;
3484 }
3485 case ELF::NT_GNU_BUILD_ID: {
3486 OS << " Build ID: ";
3487 ArrayRef<uint8_t> ID(reinterpret_cast<const uint8_t *>(Words.data()), Size);
3488 for (const auto &B : ID)
3489 OS << format_hex_no_prefix(B, 2);
3490 break;
3491 }
3492 case ELF::NT_GNU_GOLD_VERSION:
3493 OS << " Version: "
3494 << StringRef(reinterpret_cast<const char *>(Words.data()), Size);
3495 break;
3496 case ELF::NT_GNU_PROPERTY_TYPE_0:
3497 OS << " Properties:";
3498
3499 ArrayRef<uint8_t> Arr(reinterpret_cast<const uint8_t *>(Words.data()),
3500 Size);
3501 while (Arr.size() >= 8) {
3502 uint32_t Type = *reinterpret_cast<const Elf_Word *>(Arr.data());
3503 uint32_t DataSize = *reinterpret_cast<const Elf_Word *>(Arr.data() + 4);
3504 Arr = Arr.drop_front(8);
3505
3506 // Take padding size into account if present.
3507 uint64_t PaddedSize = alignTo(DataSize, sizeof(typename ELFT::uint));
3508 if (Arr.size() < PaddedSize) {
3509 OS << format(" <corrupt type (0x%x) datasz: 0x%x>\n", Type,
3510 DataSize);
3511 break;
3512 }
3513 printGNUProperty<ELFT>(OS, Type, DataSize, Arr.take_front(PaddedSize));
3514 Arr = Arr.drop_front(PaddedSize);
3515 }
3516
3517 if (!Arr.empty())
3518 OS << " <corrupted GNU_PROPERTY_TYPE_0>";
3519 break;
3520 }
3521 OS << '\n';
3522}
3523
3524template <typename ELFT>
3525static void printAMDGPUNote(raw_ostream &OS, uint32_t NoteType,
3526 ArrayRef<typename ELFT::Word> Words, size_t Size) {
3527 switch (NoteType) {
3528 default:
3529 return;
3530 case ELF::NT_AMD_AMDGPU_HSA_METADATA:
3531 OS << " HSA Metadata:\n"
3532 << StringRef(reinterpret_cast<const char *>(Words.data()), Size);
3533 break;
3534 case ELF::NT_AMD_AMDGPU_ISA:
3535 OS << " ISA Version:\n"
3536 << " "
3537 << StringRef(reinterpret_cast<const char *>(Words.data()), Size);
3538 break;
3539 case ELF::NT_AMD_AMDGPU_PAL_METADATA:
3540 const uint32_t *PALMetadataBegin = reinterpret_cast<const uint32_t *>(Words.data());
3541 const uint32_t *PALMetadataEnd = PALMetadataBegin + Size;
3542 std::vector<uint32_t> PALMetadata(PALMetadataBegin, PALMetadataEnd);
3543 std::string PALMetadataString;
3544 auto Error = AMDGPU::PALMD::toString(PALMetadata, PALMetadataString);
3545 OS << " PAL Metadata:\n";
3546 if (Error) {
3547 OS << " Invalid";
3548 return;
3549 }
3550 OS << PALMetadataString;
3551 break;
3552 }
3553 OS.flush();
3554}
3555
3556template <class ELFT>
3557void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
3558 const Elf_Ehdr *e = Obj->getHeader();
3559 bool IsCore = e->e_type == ELF::ET_CORE;
3560
3561 auto PrintHeader = [&](const typename ELFT::Off Offset,
3562 const typename ELFT::Addr Size) {
3563 OS << "Displaying notes found at file offset " << format_hex(Offset, 10)
3564 << " with length " << format_hex(Size, 10) << ":\n"
3565 << " Owner Data size\tDescription\n";
3566 };
3567
3568 auto ProcessNote = [&](const Elf_Note &Note) {
3569 StringRef Name = Note.getName();
3570 ArrayRef<Elf_Word> Descriptor = Note.getDesc();
3571 Elf_Word Type = Note.getType();
3572
3573 OS << " " << Name << std::string(22 - Name.size(), ' ')
3574 << format_hex(Descriptor.size(), 10) << '\t';
3575
3576 if (Name == "GNU") {
3577 OS << getGNUNoteTypeName(Type) << '\n';
3578 printGNUNote<ELFT>(OS, Type, Descriptor, Descriptor.size());
3579 } else if (Name == "FreeBSD") {
3580 OS << getFreeBSDNoteTypeName(Type) << '\n';
3581 } else if (Name == "AMD") {
3582 OS << getAMDGPUNoteTypeName(Type) << '\n';
3583 printAMDGPUNote<ELFT>(OS, Type, Descriptor, Descriptor.size());
3584 } else {
3585 OS << "Unknown note type: (" << format_hex(Type, 10) << ')';
3586 }
3587 OS << '\n';
3588 };
3589
3590 if (IsCore) {
3591 for (const auto &P : unwrapOrError(Obj->program_headers())) {
3592 if (P.p_type != PT_NOTE)
3593 continue;
3594 PrintHeader(P.p_offset, P.p_filesz);
3595 Error Err = Error::success();
3596 for (const auto &Note : Obj->notes(P, Err))
3597 ProcessNote(Note);
3598 if (Err)
3599 error(std::move(Err));
3600 }
3601 } else {
3602 for (const auto &S : unwrapOrError(Obj->sections())) {
3603 if (S.sh_type != SHT_NOTE)
3604 continue;
3605 PrintHeader(S.sh_offset, S.sh_size);
3606 Error Err = Error::success();
3607 for (const auto &Note : Obj->notes(S, Err))
3608 ProcessNote(Note);
3609 if (Err)
3610 error(std::move(Err));
3611 }
3612 }
3613}
3614
3615template <class ELFT>
3616void GNUStyle<ELFT>::printELFLinkerOptions(const ELFFile<ELFT> *Obj) {
3617 OS << "printELFLinkerOptions not implemented!\n";
3618}
3619
3620template <class ELFT>
3621void GNUStyle<ELFT>::printMipsGOT(const MipsGOTParser<ELFT> &Parser) {
3622 size_t Bias = ELFT::Is64Bits ? 8 : 0;
3623 auto PrintEntry = [&](const Elf_Addr *E, StringRef Purpose) {
3624 OS.PadToColumn(2);
3625 OS << format_hex_no_prefix(Parser.getGotAddress(E), 8 + Bias);
3626 OS.PadToColumn(11 + Bias);
3627 OS << format_decimal(Parser.getGotOffset(E), 6) << "(gp)";
3628 OS.PadToColumn(22 + Bias);
3629 OS << format_hex_no_prefix(*E, 8 + Bias);
3630 OS.PadToColumn(31 + 2 * Bias);
3631 OS << Purpose << "\n";
3632 };
3633
3634 OS << (Parser.IsStatic ? "Static GOT:\n" : "Primary GOT:\n");
3635 OS << " Canonical gp value: "
3636 << format_hex_no_prefix(Parser.getGp(), 8 + Bias) << "\n\n";
3637
3638 OS << " Reserved entries:\n";
3639 OS << " Address Access Initial Purpose\n";
3640 PrintEntry(Parser.getGotLazyResolver(), "Lazy resolver");
3641 if (Parser.getGotModulePointer())
3642 PrintEntry(Parser.getGotModulePointer(), "Module pointer (GNU extension)");
3643
3644 if (!Parser.getLocalEntries().empty()) {
3645 OS << "\n";
3646 OS << " Local entries:\n";
3647 OS << " Address Access Initial\n";
3648 for (auto &E : Parser.getLocalEntries())
3649 PrintEntry(&E, "");
3650 }
3651
3652 if (Parser.IsStatic)
3653 return;
3654
3655 if (!Parser.getGlobalEntries().empty()) {
3656 OS << "\n";
3657 OS << " Global entries:\n";
3658 OS << " Address Access Initial Sym.Val. Type Ndx Name\n";
3659 for (auto &E : Parser.getGlobalEntries()) {
3660 const Elf_Sym *Sym = Parser.getGotSym(&E);
3661 std::string SymName = this->dumper()->getFullSymbolName(
3662 Sym, this->dumper()->getDynamicStringTable(), false);
3663
3664 OS.PadToColumn(2);
3665 OS << to_string(format_hex_no_prefix(Parser.getGotAddress(&E), 8 + Bias));
3666 OS.PadToColumn(11 + Bias);
3667 OS << to_string(format_decimal(Parser.getGotOffset(&E), 6)) + "(gp)";
3668 OS.PadToColumn(22 + Bias);
3669 OS << to_string(format_hex_no_prefix(E, 8 + Bias));
3670 OS.PadToColumn(31 + 2 * Bias);
3671 OS << to_string(format_hex_no_prefix(Sym->st_value, 8 + Bias));
3672 OS.PadToColumn(40 + 3 * Bias);
3673 OS << printEnum(Sym->getType(), makeArrayRef(ElfSymbolTypes));
3674 OS.PadToColumn(48 + 3 * Bias);
3675 OS << getSymbolSectionNdx(Parser.Obj, Sym,
3676 this->dumper()->dynamic_symbols().begin());
3677 OS.PadToColumn(52 + 3 * Bias);
3678 OS << SymName << "\n";
3679 }
3680 }
3681
3682 if (!Parser.getOtherEntries().empty())
3683 OS << "\n Number of TLS and multi-GOT entries "
3684 << Parser.getOtherEntries().size() << "\n";
3685}
3686
3687template <class ELFT>
3688void GNUStyle<ELFT>::printMipsPLT(const MipsGOTParser<ELFT> &Parser) {
3689 size_t Bias = ELFT::Is64Bits ? 8 : 0;
3690 auto PrintEntry = [&](const Elf_Addr *E, StringRef Purpose) {
3691 OS.PadToColumn(2);
3692 OS << format_hex_no_prefix(Parser.getGotAddress(E), 8 + Bias);
3693 OS.PadToColumn(11 + Bias);
3694 OS << format_hex_no_prefix(*E, 8 + Bias);
3695 OS.PadToColumn(20 + 2 * Bias);
3696 OS << Purpose << "\n";
3697 };
3698
3699 OS << "PLT GOT:\n\n";
3700
3701 OS << " Reserved entries:\n";
3702 OS << " Address Initial Purpose\n";
3703 PrintEntry(Parser.getPltLazyResolver(), "PLT lazy resolver");
3704 if (Parser.getPltModulePointer())
3705 PrintEntry(Parser.getGotModulePointer(), "Module pointer");
3706
3707 if (!Parser.getPltEntries().empty()) {
3708 OS << "\n";
3709 OS << " Entries:\n";
3710 OS << " Address Initial Sym.Val. Type Ndx Name\n";
3711 for (auto &E : Parser.getPltEntries()) {
3712 const Elf_Sym *Sym = Parser.getPltSym(&E);
3713 std::string SymName = this->dumper()->getFullSymbolName(
3714 Sym, this->dumper()->getDynamicStringTable(), false);
3715
3716 OS.PadToColumn(2);
3717 OS << to_string(format_hex_no_prefix(Parser.getGotAddress(&E), 8 + Bias));
3718 OS.PadToColumn(11 + Bias);
3719 OS << to_string(format_hex_no_prefix(E, 8 + Bias));
3720 OS.PadToColumn(20 + 2 * Bias);
3721 OS << to_string(format_hex_no_prefix(Sym->st_value, 8 + Bias));
3722 OS.PadToColumn(29 + 3 * Bias);
3723 OS << printEnum(Sym->getType(), makeArrayRef(ElfSymbolTypes));
3724 OS.PadToColumn(37 + 3 * Bias);
3725 OS << getSymbolSectionNdx(Parser.Obj, Sym,
3726 this->dumper()->dynamic_symbols().begin());
3727 OS.PadToColumn(41 + 3 * Bias);
3728 OS << SymName << "\n";
3729 }
3730 }
3731}
3732
3733template <class ELFT> void LLVMStyle<ELFT>::printFileHeaders(const ELFO *Obj) {
3734 const Elf_Ehdr *e = Obj->getHeader();
3735 {
3736 DictScope D(W, "ElfHeader");
3737 {
3738 DictScope D(W, "Ident");
3739 W.printBinary("Magic", makeArrayRef(e->e_ident).slice(ELF::EI_MAG0, 4));
3740 W.printEnum("Class", e->e_ident[ELF::EI_CLASS], makeArrayRef(ElfClass));
3741 W.printEnum("DataEncoding", e->e_ident[ELF::EI_DATA],
3742 makeArrayRef(ElfDataEncoding));
3743 W.printNumber("FileVersion", e->e_ident[ELF::EI_VERSION]);
3744
3745 auto OSABI = makeArrayRef(ElfOSABI);
3746 if (e->e_ident[ELF::EI_OSABI] >= ELF::ELFOSABI_FIRST_ARCH &&
3747 e->e_ident[ELF::EI_OSABI] <= ELF::ELFOSABI_LAST_ARCH) {
3748 switch (e->e_machine) {
3749 case ELF::EM_AMDGPU:
3750 OSABI = makeArrayRef(AMDGPUElfOSABI);
3751 break;
3752 case ELF::EM_ARM:
3753 OSABI = makeArrayRef(ARMElfOSABI);
3754 break;
3755 case ELF::EM_TI_C6000:
3756 OSABI = makeArrayRef(C6000ElfOSABI);
3757 break;
3758 }
3759 }
3760 W.printEnum("OS/ABI", e->e_ident[ELF::EI_OSABI], OSABI);
3761 W.printNumber("ABIVersion", e->e_ident[ELF::EI_ABIVERSION]);
3762 W.printBinary("Unused", makeArrayRef(e->e_ident).slice(ELF::EI_PAD));
3763 }
3764
3765 W.printEnum("Type", e->e_type, makeArrayRef(ElfObjectFileType));
3766 W.printEnum("Machine", e->e_machine, makeArrayRef(ElfMachineType));
3767 W.printNumber("Version", e->e_version);
3768 W.printHex("Entry", e->e_entry);
3769 W.printHex("ProgramHeaderOffset", e->e_phoff);
3770 W.printHex("SectionHeaderOffset", e->e_shoff);
3771 if (e->e_machine == EM_MIPS)
3772 W.printFlags("Flags", e->e_flags, makeArrayRef(ElfHeaderMipsFlags),
3773 unsigned(ELF::EF_MIPS_ARCH), unsigned(ELF::EF_MIPS_ABI),
3774 unsigned(ELF::EF_MIPS_MACH));
3775 else if (e->e_machine == EM_AMDGPU)
3776 W.printFlags("Flags", e->e_flags, makeArrayRef(ElfHeaderAMDGPUFlags),
3777 unsigned(ELF::EF_AMDGPU_MACH));
3778 else if (e->e_machine == EM_RISCV)
3779 W.printFlags("Flags", e->e_flags, makeArrayRef(ElfHeaderRISCVFlags));
3780 else
3781 W.printFlags("Flags", e->e_flags);
3782 W.printNumber("HeaderSize", e->e_ehsize);
3783 W.printNumber("ProgramHeaderEntrySize", e->e_phentsize);
3784 W.printNumber("ProgramHeaderCount", e->e_phnum);
3785 W.printNumber("SectionHeaderEntrySize", e->e_shentsize);
3786 W.printNumber("SectionHeaderCount", e->e_shnum);
3787 W.printNumber("StringTableSectionIndex", e->e_shstrndx);
3788 }
3789}
3790
3791template <class ELFT>
3792void LLVMStyle<ELFT>::printGroupSections(const ELFO *Obj) {
3793 DictScope Lists(W, "Groups");
3794 std::vector<GroupSection> V = getGroups<ELFT>(Obj);
3795 DenseMap<uint64_t, const GroupSection *> Map = mapSectionsToGroups(V);
3796 for (const GroupSection &G : V) {
3797 DictScope D(W, "Group");
3798 W.printNumber("Name", G.Name, G.ShName);
3799 W.printNumber("Index", G.Index);
3800 W.printNumber("Link", G.Link);
3801 W.printNumber("Info", G.Info);
3802 W.printHex("Type", getGroupType(G.Type), G.Type);
3803 W.startLine() << "Signature: " << G.Signature << "\n";
3804
3805 ListScope L(W, "Section(s) in group");
3806 for (const GroupMember &GM : G.Members) {
3807 const GroupSection *MainGroup = Map[GM.Index];
3808 if (MainGroup != &G) {
3809 W.flush();
3810 errs() << "Error: " << GM.Name << " (" << GM.Index
3811 << ") in a group " + G.Name + " (" << G.Index
3812 << ") is already in a group " + MainGroup->Name + " ("
3813 << MainGroup->Index << ")\n";
3814 errs().flush();
3815 continue;
3816 }
3817 W.startLine() << GM.Name << " (" << GM.Index << ")\n";
3818 }
3819 }
3820
3821 if (V.empty())
3822 W.startLine() << "There are no group sections in the file.\n";
3823}
3824
3825template <class ELFT> void LLVMStyle<ELFT>::printRelocations(const ELFO *Obj) {
3826 ListScope D(W, "Relocations");
3827
3828 int SectionNumber = -1;
3829 for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) {
3830 ++SectionNumber;
3831
3832 if (Sec.sh_type != ELF::SHT_REL && Sec.sh_type != ELF::SHT_RELA &&
3833 Sec.sh_type != ELF::SHT_ANDROID_REL &&
3834 Sec.sh_type != ELF::SHT_ANDROID_RELA)
3835 continue;
3836
3837 StringRef Name = unwrapOrError(Obj->getSectionName(&Sec));
3838
3839 W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n";
3840 W.indent();
3841
3842 printRelocations(&Sec, Obj);
3843
3844 W.unindent();
3845 W.startLine() << "}\n";
3846 }
3847}
3848
3849template <class ELFT>
3850void LLVMStyle<ELFT>::printRelocations(const Elf_Shdr *Sec, const ELFO *Obj) {
3851 const Elf_Shdr *SymTab = unwrapOrError(Obj->getSection(Sec->sh_link));
3852
3853 switch (Sec->sh_type) {
3854 case ELF::SHT_REL:
3855 for (const Elf_Rel &R : unwrapOrError(Obj->rels(Sec))) {
3856 Elf_Rela Rela;
3857 Rela.r_offset = R.r_offset;
3858 Rela.r_info = R.r_info;
3859 Rela.r_addend = 0;
3860 printRelocation(Obj, Rela, SymTab);
3861 }
3862 break;
3863 case ELF::SHT_RELA:
3864 for (const Elf_Rela &R : unwrapOrError(Obj->relas(Sec)))
3865 printRelocation(Obj, R, SymTab);
3866 break;
3867 case ELF::SHT_ANDROID_REL:
3868 case ELF::SHT_ANDROID_RELA:
3869 for (const Elf_Rela &R : unwrapOrError(Obj->android_relas(Sec)))
3870 printRelocation(Obj, R, SymTab);
3871 break;
3872 }
3873}
3874
3875template <class ELFT>
3876void LLVMStyle<ELFT>::printRelocation(const ELFO *Obj, Elf_Rela Rel,
3877 const Elf_Shdr *SymTab) {
3878 SmallString<32> RelocName;
3879 Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName);
3880 StringRef TargetName;
3881 const Elf_Sym *Sym = unwrapOrError(Obj->getRelocationSymbol(&Rel, SymTab));
3882 if (Sym && Sym->getType() == ELF::STT_SECTION) {
3883 const Elf_Shdr *Sec = unwrapOrError(
3884 Obj->getSection(Sym, SymTab, this->dumper()->getShndxTable()));
3885 TargetName = unwrapOrError(Obj->getSectionName(Sec));
3886 } else if (Sym) {
3887 StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*SymTab));
3888 TargetName = unwrapOrError(Sym->getName(StrTable));
3889 }
3890
3891 if (opts::ExpandRelocs) {
3892 DictScope Group(W, "Relocation");
3893 W.printHex("Offset", Rel.r_offset);
3894 W.printNumber("Type", RelocName, (int)Rel.getType(Obj->isMips64EL()));
3895 W.printNumber("Symbol", !TargetName.empty() ? TargetName : "-",
3896 Rel.getSymbol(Obj->isMips64EL()));
3897 W.printHex("Addend", Rel.r_addend);
3898 } else {
3899 raw_ostream &OS = W.startLine();
3900 OS << W.hex(Rel.r_offset) << " " << RelocName << " "
3901 << (!TargetName.empty() ? TargetName : "-") << " "
3902 << W.hex(Rel.r_addend) << "\n";
3903 }
3904}
3905
3906template <class ELFT> void LLVMStyle<ELFT>::printSections(const ELFO *Obj) {
3907 ListScope SectionsD(W, "Sections");
3908
3909 int SectionIndex = -1;
3910 for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) {
3911 ++SectionIndex;
3912
3913 StringRef Name = unwrapOrError(Obj->getSectionName(&Sec));
3914
3915 DictScope SectionD(W, "Section");
3916 W.printNumber("Index", SectionIndex);
3917 W.printNumber("Name", Name, Sec.sh_name);
3918 W.printHex(
3919 "Type",
3920 object::getELFSectionTypeName(Obj->getHeader()->e_machine, Sec.sh_type),
3921 Sec.sh_type);
3922 std::vector<EnumEntry<unsigned>> SectionFlags(std::begin(ElfSectionFlags),
3923 std::end(ElfSectionFlags));
3924 switch (Obj->getHeader()->e_machine) {
3925 case EM_ARM:
3926 SectionFlags.insert(SectionFlags.end(), std::begin(ElfARMSectionFlags),
3927 std::end(ElfARMSectionFlags));
3928 break;
3929 case EM_HEXAGON:
3930 SectionFlags.insert(SectionFlags.end(),
3931 std::begin(ElfHexagonSectionFlags),
3932 std::end(ElfHexagonSectionFlags));
3933 break;
3934 case EM_MIPS:
3935 SectionFlags.insert(SectionFlags.end(), std::begin(ElfMipsSectionFlags),
3936 std::end(ElfMipsSectionFlags));
3937 break;
3938 case EM_X86_64:
3939 SectionFlags.insert(SectionFlags.end(), std::begin(ElfX86_64SectionFlags),
3940 std::end(ElfX86_64SectionFlags));
3941 break;
3942 case EM_XCORE:
3943 SectionFlags.insert(SectionFlags.end(), std::begin(ElfXCoreSectionFlags),
3944 std::end(ElfXCoreSectionFlags));
3945 break;
3946 default:
3947 // Nothing to do.
3948 break;
3949 }
3950 W.printFlags("Flags", Sec.sh_flags, makeArrayRef(SectionFlags));
3951 W.printHex("Address", Sec.sh_addr);
3952 W.printHex("Offset", Sec.sh_offset);
3953 W.printNumber("Size", Sec.sh_size);
3954 W.printNumber("Link", Sec.sh_link);
3955 W.printNumber("Info", Sec.sh_info);
3956 W.printNumber("AddressAlignment", Sec.sh_addralign);
3957 W.printNumber("EntrySize", Sec.sh_entsize);
3958
3959 if (opts::SectionRelocations) {
3960 ListScope D(W, "Relocations");
3961 printRelocations(&Sec, Obj);
3962 }
3963
3964 if (opts::SectionSymbols) {
3965 ListScope D(W, "Symbols");
3966 const Elf_Shdr *Symtab = this->dumper()->getDotSymtabSec();
3967 StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*Symtab));
3968
3969 for (const Elf_Sym &Sym : unwrapOrError(Obj->symbols(Symtab))) {
3970 const Elf_Shdr *SymSec = unwrapOrError(
3971 Obj->getSection(&Sym, Symtab, this->dumper()->getShndxTable()));
3972 if (SymSec == &Sec)
3973 printSymbol(Obj, &Sym, unwrapOrError(Obj->symbols(Symtab)).begin(),
3974 StrTable, false);
3975 }
3976 }
3977
3978 if (opts::SectionData && Sec.sh_type != ELF::SHT_NOBITS) {
3979 ArrayRef<uint8_t> Data = unwrapOrError(Obj->getSectionContents(&Sec));
3980 W.printBinaryBlock("SectionData",
3981 StringRef((const char *)Data.data(), Data.size()));
3982 }
3983 }
3984}
3985
3986template <class ELFT>
3987void LLVMStyle<ELFT>::printSymbol(const ELFO *Obj, const Elf_Sym *Symbol,
3988 const Elf_Sym *First, StringRef StrTable,
3989 bool IsDynamic) {
3990 unsigned SectionIndex = 0;
3991 StringRef SectionName;
3992 this->dumper()->getSectionNameIndex(Symbol, First, SectionName, SectionIndex);
3993 std::string FullSymbolName =
3994 this->dumper()->getFullSymbolName(Symbol, StrTable, IsDynamic);
3995 unsigned char SymbolType = Symbol->getType();
3996
3997 DictScope D(W, "Symbol");
3998 W.printNumber("Name", FullSymbolName, Symbol->st_name);
3999 W.printHex("Value", Symbol->st_value);
4000 W.printNumber("Size", Symbol->st_size);
4001 W.printEnum("Binding", Symbol->getBinding(), makeArrayRef(ElfSymbolBindings));
4002 if (Obj->getHeader()->e_machine == ELF::EM_AMDGPU &&
4003 SymbolType >= ELF::STT_LOOS && SymbolType < ELF::STT_HIOS)
4004 W.printEnum("Type", SymbolType, makeArrayRef(AMDGPUSymbolTypes));
4005 else
4006 W.printEnum("Type", SymbolType, makeArrayRef(ElfSymbolTypes));
4007 if (Symbol->st_other == 0)
4008 // Usually st_other flag is zero. Do not pollute the output
4009 // by flags enumeration in that case.
4010 W.printNumber("Other", 0);
4011 else {
4012 std::vector<EnumEntry<unsigned>> SymOtherFlags(std::begin(ElfSymOtherFlags),
4013 std::end(ElfSymOtherFlags));
4014 if (Obj->getHeader()->e_machine == EM_MIPS) {
4015 // Someones in their infinite wisdom decided to make STO_MIPS_MIPS16
4016 // flag overlapped with other ST_MIPS_xxx flags. So consider both
4017 // cases separately.
4018 if ((Symbol->st_other & STO_MIPS_MIPS16) == STO_MIPS_MIPS16)
4019 SymOtherFlags.insert(SymOtherFlags.end(),
4020 std::begin(ElfMips16SymOtherFlags),
4021 std::end(ElfMips16SymOtherFlags));
4022 else
4023 SymOtherFlags.insert(SymOtherFlags.end(),
4024 std::begin(ElfMipsSymOtherFlags),
4025 std::end(ElfMipsSymOtherFlags));
4026 }
4027 W.printFlags("Other", Symbol->st_other, makeArrayRef(SymOtherFlags), 0x3u);
4028 }
4029 W.printHex("Section", SectionName, SectionIndex);
4030}
4031
4032template <class ELFT> void LLVMStyle<ELFT>::printSymbols(const ELFO *Obj) {
4033 ListScope Group(W, "Symbols");
4034 this->dumper()->printSymbolsHelper(false);
4035}
4036
4037template <class ELFT>
4038void LLVMStyle<ELFT>::printDynamicSymbols(const ELFO *Obj) {
4039 ListScope Group(W, "DynamicSymbols");
4040 this->dumper()->printSymbolsHelper(true);
4041}
4042
4043template <class ELFT>
4044void LLVMStyle<ELFT>::printDynamicRelocations(const ELFO *Obj) {
4045 const DynRegionInfo &DynRelRegion = this->dumper()->getDynRelRegion();
4046 const DynRegionInfo &DynRelaRegion = this->dumper()->getDynRelaRegion();
4047 const DynRegionInfo &DynPLTRelRegion = this->dumper()->getDynPLTRelRegion();
4048 if (DynRelRegion.Size && DynRelaRegion.Size)
4049 report_fatal_error("There are both REL and RELA dynamic relocations");
4050 W.startLine() << "Dynamic Relocations {\n";
4051 W.indent();
4052 if (DynRelaRegion.Size > 0)
4053 for (const Elf_Rela &Rela : this->dumper()->dyn_relas())
4054 printDynamicRelocation(Obj, Rela);
4055 else
4056 for (const Elf_Rel &Rel : this->dumper()->dyn_rels()) {
4057 Elf_Rela Rela;
4058 Rela.r_offset = Rel.r_offset;
4059 Rela.r_info = Rel.r_info;
4060 Rela.r_addend = 0;
4061 printDynamicRelocation(Obj, Rela);
4062 }
4063 if (DynPLTRelRegion.EntSize == sizeof(Elf_Rela))
4064 for (const Elf_Rela &Rela : DynPLTRelRegion.getAsArrayRef<Elf_Rela>())
4065 printDynamicRelocation(Obj, Rela);
4066 else
4067 for (const Elf_Rel &Rel : DynPLTRelRegion.getAsArrayRef<Elf_Rel>()) {
4068 Elf_Rela Rela;
4069 Rela.r_offset = Rel.r_offset;
4070 Rela.r_info = Rel.r_info;
4071 Rela.r_addend = 0;
4072 printDynamicRelocation(Obj, Rela);
4073 }
4074 W.unindent();
4075 W.startLine() << "}\n";
4076}
4077
4078template <class ELFT>
4079void LLVMStyle<ELFT>::printDynamicRelocation(const ELFO *Obj, Elf_Rela Rel) {
4080 SmallString<32> RelocName;
4081 Obj->getRelocationTypeName(Rel.getType(Obj->isMips64EL()), RelocName);
4082 StringRef SymbolName;
4083 uint32_t SymIndex = Rel.getSymbol(Obj->isMips64EL());
4084 const Elf_Sym *Sym = this->dumper()->dynamic_symbols().begin() + SymIndex;
4085 SymbolName =
4086 unwrapOrError(Sym->getName(this->dumper()->getDynamicStringTable()));
4087 if (opts::ExpandRelocs) {
4088 DictScope Group(W, "Relocation");
4089 W.printHex("Offset", Rel.r_offset);
4090 W.printNumber("Type", RelocName, (int)Rel.getType(Obj->isMips64EL()));
4091 W.printString("Symbol", !SymbolName.empty() ? SymbolName : "-");
4092 W.printHex("Addend", Rel.r_addend);
4093 } else {
4094 raw_ostream &OS = W.startLine();
4095 OS << W.hex(Rel.r_offset) << " " << RelocName << " "
4096 << (!SymbolName.empty() ? SymbolName : "-") << " "
4097 << W.hex(Rel.r_addend) << "\n";
4098 }
4099}
4100
4101template <class ELFT>
4102void LLVMStyle<ELFT>::printProgramHeaders(const ELFO *Obj) {
4103 ListScope L(W, "ProgramHeaders");
4104
4105 for (const Elf_Phdr &Phdr : unwrapOrError(Obj->program_headers())) {
4106 DictScope P(W, "ProgramHeader");
4107 W.printHex("Type",
4108 getElfSegmentType(Obj->getHeader()->e_machine, Phdr.p_type),
4109 Phdr.p_type);
4110 W.printHex("Offset", Phdr.p_offset);
4111 W.printHex("VirtualAddress", Phdr.p_vaddr);
4112 W.printHex("PhysicalAddress", Phdr.p_paddr);
4113 W.printNumber("FileSize", Phdr.p_filesz);
4114 W.printNumber("MemSize", Phdr.p_memsz);
4115 W.printFlags("Flags", Phdr.p_flags, makeArrayRef(ElfSegmentFlags));
4116 W.printNumber("Alignment", Phdr.p_align);
4117 }
4118}
4119
4120template <class ELFT>
4121void LLVMStyle<ELFT>::printHashHistogram(const ELFFile<ELFT> *Obj) {
4122 W.startLine() << "Hash Histogram not implemented!\n";
4123}
4124
4125template <class ELFT>
4126void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
4127 W.startLine() << "printNotes not implemented!\n";
4128}
4129
4130template <class ELFT>
4131void LLVMStyle<ELFT>::printELFLinkerOptions(const ELFFile<ELFT> *Obj) {
4132 ListScope L(W, "LinkerOptions");
4133
4134 for (const Elf_Shdr &Shdr : unwrapOrError(Obj->sections())) {
4135 if (Shdr.sh_type != ELF::SHT_LLVM_LINKER_OPTIONS)
4136 continue;
4137
4138 ArrayRef<uint8_t> Contents = unwrapOrError(Obj->getSectionContents(&Shdr));
4139 for (const uint8_t *P = Contents.begin(), *E = Contents.end(); P < E; ) {
4140 StringRef Key = StringRef(reinterpret_cast<const char *>(P));
4141 StringRef Value =
4142 StringRef(reinterpret_cast<const char *>(P) + Key.size() + 1);
4143
4144 W.printString(Key, Value);
4145
4146 P = P + Key.size() + Value.size() + 2;
4147 }
4148 }
4149}
4150
4151template <class ELFT>
4152void LLVMStyle<ELFT>::printMipsGOT(const MipsGOTParser<ELFT> &Parser) {
4153 auto PrintEntry = [&](const Elf_Addr *E) {
4154 W.printHex("Address", Parser.getGotAddress(E));
4155 W.printNumber("Access", Parser.getGotOffset(E));
4156 W.printHex("Initial", *E);
4157 };
4158
4159 DictScope GS(W, Parser.IsStatic ? "Static GOT" : "Primary GOT");
4160
4161 W.printHex("Canonical gp value", Parser.getGp());
4162 {
4163 ListScope RS(W, "Reserved entries");
4164 {
4165 DictScope D(W, "Entry");
4166 PrintEntry(Parser.getGotLazyResolver());
4167 W.printString("Purpose", StringRef("Lazy resolver"));
4168 }
4169
4170 if (Parser.getGotModulePointer()) {
4171 DictScope D(W, "Entry");
4172 PrintEntry(Parser.getGotModulePointer());
4173 W.printString("Purpose", StringRef("Module pointer (GNU extension)"));
4174 }
4175 }
4176 {
4177 ListScope LS(W, "Local entries");
4178 for (auto &E : Parser.getLocalEntries()) {
4179 DictScope D(W, "Entry");
4180 PrintEntry(&E);
4181 }
4182 }
4183
4184 if (Parser.IsStatic)
4185 return;
4186
4187 {
4188 ListScope GS(W, "Global entries");
4189 for (auto &E : Parser.getGlobalEntries()) {
4190 DictScope D(W, "Entry");
4191
4192 PrintEntry(&E);
4193
4194 const Elf_Sym *Sym = Parser.getGotSym(&E);
4195 W.printHex("Value", Sym->st_value);
4196 W.printEnum("Type", Sym->getType(), makeArrayRef(ElfSymbolTypes));
4197
4198 unsigned SectionIndex = 0;
4199 StringRef SectionName;
4200 this->dumper()->getSectionNameIndex(
4201 Sym, this->dumper()->dynamic_symbols().begin(), SectionName,
4202 SectionIndex);
4203 W.printHex("Section", SectionName, SectionIndex);
4204
4205 std::string SymName = this->dumper()->getFullSymbolName(
4206 Sym, this->dumper()->getDynamicStringTable(), true);
4207 W.printNumber("Name", SymName, Sym->st_name);
4208 }
4209 }
4210
4211 W.printNumber("Number of TLS and multi-GOT entries",
4212 uint64_t(Parser.getOtherEntries().size()));
4213}
4214
4215template <class ELFT>
4216void LLVMStyle<ELFT>::printMipsPLT(const MipsGOTParser<ELFT> &Parser) {
4217 auto PrintEntry = [&](const Elf_Addr *E) {
4218 W.printHex("Address", Parser.getPltAddress(E));
4219 W.printHex("Initial", *E);
4220 };
4221
4222 DictScope GS(W, "PLT GOT");
4223
4224 {
4225 ListScope RS(W, "Reserved entries");
4226 {
4227 DictScope D(W, "Entry");
4228 PrintEntry(Parser.getPltLazyResolver());
4229 W.printString("Purpose", StringRef("PLT lazy resolver"));
4230 }
4231
4232 if (auto E = Parser.getPltModulePointer()) {
4233 DictScope D(W, "Entry");
4234 PrintEntry(E);
4235 W.printString("Purpose", StringRef("Module pointer"));
4236 }
4237 }
4238 {
4239 ListScope LS(W, "Entries");
4240 for (auto &E : Parser.getPltEntries()) {
4241 DictScope D(W, "Entry");
4242 PrintEntry(&E);
4243
4244 const Elf_Sym *Sym = Parser.getPltSym(&E);
4245 W.printHex("Value", Sym->st_value);
4246 W.printEnum("Type", Sym->getType(), makeArrayRef(ElfSymbolTypes));
4247
4248 unsigned SectionIndex = 0;
4249 StringRef SectionName;
4250 this->dumper()->getSectionNameIndex(
4251 Sym, this->dumper()->dynamic_symbols().begin(), SectionName,
4252 SectionIndex);
4253 W.printHex("Section", SectionName, SectionIndex);
4254
4255 std::string SymName =
4256 this->dumper()->getFullSymbolName(Sym, Parser.getPltStrTable(), true);
4257 W.printNumber("Name", SymName, Sym->st_name);
4258 }
4259 }
4260}