Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Object/ELF.h
Line
Count
Source (jump to first uncovered line)
1
//===- ELF.h - ELF object file implementation -------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file declares the ELFFile template class.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_OBJECT_ELF_H
14
#define LLVM_OBJECT_ELF_H
15
16
#include "llvm/ADT/ArrayRef.h"
17
#include "llvm/ADT/SmallVector.h"
18
#include "llvm/ADT/StringRef.h"
19
#include "llvm/BinaryFormat/ELF.h"
20
#include "llvm/Object/ELFTypes.h"
21
#include "llvm/Object/Error.h"
22
#include "llvm/Support/Endian.h"
23
#include "llvm/Support/Error.h"
24
#include <cassert>
25
#include <cstddef>
26
#include <cstdint>
27
#include <limits>
28
#include <utility>
29
30
namespace llvm {
31
namespace object {
32
33
StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type);
34
uint32_t getELFRelativeRelocationType(uint32_t Machine);
35
StringRef getELFSectionTypeName(uint32_t Machine, uint32_t Type);
36
37
// Subclasses of ELFFile may need this for template instantiation
38
inline std::pair<unsigned char, unsigned char>
39
15.7k
getElfArchType(StringRef Object) {
40
15.7k
  if (Object.size() < ELF::EI_NIDENT)
41
0
    return std::make_pair((uint8_t)ELF::ELFCLASSNONE,
42
0
                          (uint8_t)ELF::ELFDATANONE);
43
15.7k
  return std::make_pair((uint8_t)Object[ELF::EI_CLASS],
44
15.7k
                        (uint8_t)Object[ELF::EI_DATA]);
45
15.7k
}
46
47
81
static inline Error createError(const Twine &Err) {
48
81
  return make_error<StringError>(Err, object_error::parse_failed);
49
81
}
Unexecuted instantiation: ObjectFilePCHContainerOperations.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFAbbreviationDeclaration.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFAcceleratorTable.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFCompileUnit.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFContext.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFDataExtractor.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFDebugAddr.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFDebugAranges.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFDebugInfoEntry.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFDebugLine.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFDebugLoc.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFDebugPubTable.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFDebugRangeList.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFDebugRnglists.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFDie.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFExpression.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFFormValue.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFTypeUnit.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFUnit.cpp:llvm::object::createError(llvm::Twine const&)
Unexecuted instantiation: DWARFVerifier.cpp:llvm::object::createError(llvm::Twine const&)
Decompressor.cpp:llvm::object::createError(llvm::Twine const&)
Line
Count
Source
47
6
static inline Error createError(const Twine &Err) {
48
6
  return make_error<StringError>(Err, object_error::parse_failed);
49
6
}
ELF.cpp:llvm::object::createError(llvm::Twine const&)
Line
Count
Source
47
38
static inline Error createError(const Twine &Err) {
48
38
  return make_error<StringError>(Err, object_error::parse_failed);
49
38
}
ELFObjectFile.cpp:llvm::object::createError(llvm::Twine const&)
Line
Count
Source
47
37
static inline Error createError(const Twine &Err) {
48
37
  return make_error<StringError>(Err, object_error::parse_failed);
49
37
}
Unexecuted instantiation: RelocationResolver.cpp:llvm::object::createError(llvm::Twine const&)
50
51
template <class ELFT> class ELFFile;
52
53
template <class ELFT>
54
std::string getSecIndexForError(const ELFFile<ELFT> *Obj,
55
59
                                const typename ELFT::Shdr *Sec) {
56
59
  auto TableOrErr = Obj->sections();
57
59
  if (TableOrErr)
58
59
    return "[index " + std::to_string(Sec - &TableOrErr->front()) + "]";
59
0
  // To make this helper be more convenient for error reporting purposes we
60
0
  // drop the error. But really it should never be triggered. Before this point,
61
0
  // our code should have called 'sections()' and reported a proper error on
62
0
  // failure.
63
0
  llvm::consumeError(TableOrErr.takeError());
64
0
  return "[unknown index]";
65
0
}
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > llvm::object::getSecIndexForError<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*, llvm::object::ELFType<(llvm::support::endianness)1, false>::Shdr const*)
Line
Count
Source
55
28
                                const typename ELFT::Shdr *Sec) {
56
28
  auto TableOrErr = Obj->sections();
57
28
  if (TableOrErr)
58
28
    return "[index " + std::to_string(Sec - &TableOrErr->front()) + "]";
59
0
  // To make this helper be more convenient for error reporting purposes we
60
0
  // drop the error. But really it should never be triggered. Before this point,
61
0
  // our code should have called 'sections()' and reported a proper error on
62
0
  // failure.
63
0
  llvm::consumeError(TableOrErr.takeError());
64
0
  return "[unknown index]";
65
0
}
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > llvm::object::getSecIndexForError<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*, llvm::object::ELFType<(llvm::support::endianness)0, false>::Shdr const*)
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > llvm::object::getSecIndexForError<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*, llvm::object::ELFType<(llvm::support::endianness)1, true>::Shdr const*)
Line
Count
Source
55
31
                                const typename ELFT::Shdr *Sec) {
56
31
  auto TableOrErr = Obj->sections();
57
31
  if (TableOrErr)
58
31
    return "[index " + std::to_string(Sec - &TableOrErr->front()) + "]";
59
0
  // To make this helper be more convenient for error reporting purposes we
60
0
  // drop the error. But really it should never be triggered. Before this point,
61
0
  // our code should have called 'sections()' and reported a proper error on
62
0
  // failure.
63
0
  llvm::consumeError(TableOrErr.takeError());
64
0
  return "[unknown index]";
65
0
}
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > llvm::object::getSecIndexForError<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*, llvm::object::ELFType<(llvm::support::endianness)0, true>::Shdr const*)
66
67
template <class ELFT>
68
class ELFFile {
69
public:
70
  LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
71
  using uintX_t = typename ELFT::uint;
72
  using Elf_Ehdr = typename ELFT::Ehdr;
73
  using Elf_Shdr = typename ELFT::Shdr;
74
  using Elf_Sym = typename ELFT::Sym;
75
  using Elf_Dyn = typename ELFT::Dyn;
76
  using Elf_Phdr = typename ELFT::Phdr;
77
  using Elf_Rel = typename ELFT::Rel;
78
  using Elf_Rela = typename ELFT::Rela;
79
  using Elf_Relr = typename ELFT::Relr;
80
  using Elf_Verdef = typename ELFT::Verdef;
81
  using Elf_Verdaux = typename ELFT::Verdaux;
82
  using Elf_Verneed = typename ELFT::Verneed;
83
  using Elf_Vernaux = typename ELFT::Vernaux;
84
  using Elf_Versym = typename ELFT::Versym;
85
  using Elf_Hash = typename ELFT::Hash;
86
  using Elf_GnuHash = typename ELFT::GnuHash;
87
  using Elf_Nhdr = typename ELFT::Nhdr;
88
  using Elf_Note = typename ELFT::Note;
89
  using Elf_Note_Iterator = typename ELFT::NoteIterator;
90
  using Elf_Dyn_Range = typename ELFT::DynRange;
91
  using Elf_Shdr_Range = typename ELFT::ShdrRange;
92
  using Elf_Sym_Range = typename ELFT::SymRange;
93
  using Elf_Rel_Range = typename ELFT::RelRange;
94
  using Elf_Rela_Range = typename ELFT::RelaRange;
95
  using Elf_Relr_Range = typename ELFT::RelrRange;
96
  using Elf_Phdr_Range = typename ELFT::PhdrRange;
97
98
11.0M
  const uint8_t *base() const { return Buf.bytes_begin(); }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::base() const
Line
Count
Source
98
1.03M
  const uint8_t *base() const { return Buf.bytes_begin(); }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::base() const
Line
Count
Source
98
146k
  const uint8_t *base() const { return Buf.bytes_begin(); }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::base() const
Line
Count
Source
98
9.79M
  const uint8_t *base() const { return Buf.bytes_begin(); }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::base() const
Line
Count
Source
98
107k
  const uint8_t *base() const { return Buf.bytes_begin(); }
99
100
12.0k
  size_t getBufSize() const { return Buf.size(); }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getBufSize() const
Line
Count
Source
100
1.77k
  size_t getBufSize() const { return Buf.size(); }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getBufSize() const
Line
Count
Source
100
584
  size_t getBufSize() const { return Buf.size(); }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getBufSize() const
Line
Count
Source
100
9.34k
  size_t getBufSize() const { return Buf.size(); }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getBufSize() const
Line
Count
Source
100
346
  size_t getBufSize() const { return Buf.size(); }
101
102
private:
103
  StringRef Buf;
104
105
  ELFFile(StringRef Object);
106
107
public:
108
7.24M
  const Elf_Ehdr *getHeader() const {
109
7.24M
    return reinterpret_cast<const Elf_Ehdr *>(base());
110
7.24M
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getHeader() const
Line
Count
Source
108
715k
  const Elf_Ehdr *getHeader() const {
109
715k
    return reinterpret_cast<const Elf_Ehdr *>(base());
110
715k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getHeader() const
Line
Count
Source
108
102k
  const Elf_Ehdr *getHeader() const {
109
102k
    return reinterpret_cast<const Elf_Ehdr *>(base());
110
102k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getHeader() const
Line
Count
Source
108
6.35M
  const Elf_Ehdr *getHeader() const {
109
6.35M
    return reinterpret_cast<const Elf_Ehdr *>(base());
110
6.35M
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getHeader() const
Line
Count
Source
108
75.4k
  const Elf_Ehdr *getHeader() const {
109
75.4k
    return reinterpret_cast<const Elf_Ehdr *>(base());
110
75.4k
  }
111
112
  template <typename T>
113
  Expected<const T *> getEntry(uint32_t Section, uint32_t Entry) const;
114
  template <typename T>
115
  Expected<const T *> getEntry(const Elf_Shdr *Section, uint32_t Entry) const;
116
117
  Expected<StringRef> getStringTable(const Elf_Shdr *Section) const;
118
  Expected<StringRef> getStringTableForSymtab(const Elf_Shdr &Section) const;
119
  Expected<StringRef> getStringTableForSymtab(const Elf_Shdr &Section,
120
                                              Elf_Shdr_Range Sections) const;
121
122
  Expected<ArrayRef<Elf_Word>> getSHNDXTable(const Elf_Shdr &Section) const;
123
  Expected<ArrayRef<Elf_Word>> getSHNDXTable(const Elf_Shdr &Section,
124
                                             Elf_Shdr_Range Sections) const;
125
126
  StringRef getRelocationTypeName(uint32_t Type) const;
127
  void getRelocationTypeName(uint32_t Type,
128
                             SmallVectorImpl<char> &Result) const;
129
  uint32_t getRelativeRelocationType() const;
130
131
  std::string getDynamicTagAsString(unsigned Arch, uint64_t Type) const;
132
  std::string getDynamicTagAsString(uint64_t Type) const;
133
134
  /// Get the symbol for a given relocation.
135
  Expected<const Elf_Sym *> getRelocationSymbol(const Elf_Rel *Rel,
136
                                                const Elf_Shdr *SymTab) const;
137
138
  static Expected<ELFFile> create(StringRef Object);
139
140
40.8k
  bool isMipsELF64() const {
141
40.8k
    return getHeader()->e_machine == ELF::EM_MIPS &&
142
40.8k
           
getHeader()->getFileClass() == ELF::ELFCLASS643.42k
;
143
40.8k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::isMipsELF64() const
Line
Count
Source
140
7.86k
  bool isMipsELF64() const {
141
7.86k
    return getHeader()->e_machine == ELF::EM_MIPS &&
142
7.86k
           
getHeader()->getFileClass() == ELF::ELFCLASS64747
;
143
7.86k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::isMipsELF64() const
Line
Count
Source
140
2.18k
  bool isMipsELF64() const {
141
2.18k
    return getHeader()->e_machine == ELF::EM_MIPS &&
142
2.18k
           
getHeader()->getFileClass() == ELF::ELFCLASS641.69k
;
143
2.18k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::isMipsELF64() const
Line
Count
Source
140
27.5k
  bool isMipsELF64() const {
141
27.5k
    return getHeader()->e_machine == ELF::EM_MIPS &&
142
27.5k
           
getHeader()->getFileClass() == ELF::ELFCLASS64440
;
143
27.5k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::isMipsELF64() const
Line
Count
Source
140
3.22k
  bool isMipsELF64() const {
141
3.22k
    return getHeader()->e_machine == ELF::EM_MIPS &&
142
3.22k
           
getHeader()->getFileClass() == ELF::ELFCLASS64543
;
143
3.22k
  }
144
145
35.1k
  bool isMips64EL() const {
146
35.1k
    return isMipsELF64() &&
147
35.1k
           
getHeader()->getDataEncoding() == ELF::ELFDATA2LSB772
;
148
35.1k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::isMips64EL() const
Line
Count
Source
145
6.09k
  bool isMips64EL() const {
146
6.09k
    return isMipsELF64() &&
147
6.09k
           
getHeader()->getDataEncoding() == ELF::ELFDATA2LSB0
;
148
6.09k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::isMips64EL() const
Line
Count
Source
145
1.75k
  bool isMips64EL() const {
146
1.75k
    return isMipsELF64() &&
147
1.75k
           
getHeader()->getDataEncoding() == ELF::ELFDATA2LSB0
;
148
1.75k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::isMips64EL() const
Line
Count
Source
145
24.9k
  bool isMips64EL() const {
146
24.9k
    return isMipsELF64() &&
147
24.9k
           
getHeader()->getDataEncoding() == ELF::ELFDATA2LSB348
;
148
24.9k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::isMips64EL() const
Line
Count
Source
145
2.39k
  bool isMips64EL() const {
146
2.39k
    return isMipsELF64() &&
147
2.39k
           
getHeader()->getDataEncoding() == ELF::ELFDATA2LSB424
;
148
2.39k
  }
149
150
  Expected<Elf_Shdr_Range> sections() const;
151
152
  Expected<Elf_Dyn_Range> dynamicEntries() const;
153
154
  Expected<const uint8_t *> toMappedAddr(uint64_t VAddr) const;
155
156
199k
  Expected<Elf_Sym_Range> symbols(const Elf_Shdr *Sec) const {
157
199k
    if (!Sec)
158
20.4k
      return makeArrayRef<Elf_Sym>(nullptr, nullptr);
159
178k
    return getSectionContentsAsArray<Elf_Sym>(Sec);
160
178k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::symbols(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*) const
Line
Count
Source
156
30.4k
  Expected<Elf_Sym_Range> symbols(const Elf_Shdr *Sec) const {
157
30.4k
    if (!Sec)
158
7.81k
      return makeArrayRef<Elf_Sym>(nullptr, nullptr);
159
22.5k
    return getSectionContentsAsArray<Elf_Sym>(Sec);
160
22.5k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::symbols(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*) const
Line
Count
Source
156
3.86k
  Expected<Elf_Sym_Range> symbols(const Elf_Shdr *Sec) const {
157
3.86k
    if (!Sec)
158
861
      return makeArrayRef<Elf_Sym>(nullptr, nullptr);
159
3.00k
    return getSectionContentsAsArray<Elf_Sym>(Sec);
160
3.00k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::symbols(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*) const
Line
Count
Source
156
162k
  Expected<Elf_Sym_Range> symbols(const Elf_Shdr *Sec) const {
157
162k
    if (!Sec)
158
11.0k
      return makeArrayRef<Elf_Sym>(nullptr, nullptr);
159
150k
    return getSectionContentsAsArray<Elf_Sym>(Sec);
160
150k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::symbols(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*) const
Line
Count
Source
156
2.76k
  Expected<Elf_Sym_Range> symbols(const Elf_Shdr *Sec) const {
157
2.76k
    if (!Sec)
158
666
      return makeArrayRef<Elf_Sym>(nullptr, nullptr);
159
2.10k
    return getSectionContentsAsArray<Elf_Sym>(Sec);
160
2.10k
  }
161
162
2.36k
  Expected<Elf_Rela_Range> relas(const Elf_Shdr *Sec) const {
163
2.36k
    return getSectionContentsAsArray<Elf_Rela>(Sec);
164
2.36k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::relas(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*) const
Line
Count
Source
162
93
  Expected<Elf_Rela_Range> relas(const Elf_Shdr *Sec) const {
163
93
    return getSectionContentsAsArray<Elf_Rela>(Sec);
164
93
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::relas(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*) const
Line
Count
Source
162
70
  Expected<Elf_Rela_Range> relas(const Elf_Shdr *Sec) const {
163
70
    return getSectionContentsAsArray<Elf_Rela>(Sec);
164
70
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::relas(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*) const
Line
Count
Source
162
2.00k
  Expected<Elf_Rela_Range> relas(const Elf_Shdr *Sec) const {
163
2.00k
    return getSectionContentsAsArray<Elf_Rela>(Sec);
164
2.00k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::relas(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*) const
Line
Count
Source
162
199
  Expected<Elf_Rela_Range> relas(const Elf_Shdr *Sec) const {
163
199
    return getSectionContentsAsArray<Elf_Rela>(Sec);
164
199
  }
165
166
732
  Expected<Elf_Rel_Range> rels(const Elf_Shdr *Sec) const {
167
732
    return getSectionContentsAsArray<Elf_Rel>(Sec);
168
732
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::rels(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*) const
Line
Count
Source
166
567
  Expected<Elf_Rel_Range> rels(const Elf_Shdr *Sec) const {
167
567
    return getSectionContentsAsArray<Elf_Rel>(Sec);
168
567
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::rels(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*) const
Line
Count
Source
166
117
  Expected<Elf_Rel_Range> rels(const Elf_Shdr *Sec) const {
167
117
    return getSectionContentsAsArray<Elf_Rel>(Sec);
168
117
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::rels(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*) const
Line
Count
Source
166
41
  Expected<Elf_Rel_Range> rels(const Elf_Shdr *Sec) const {
167
41
    return getSectionContentsAsArray<Elf_Rel>(Sec);
168
41
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::rels(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*) const
Line
Count
Source
166
7
  Expected<Elf_Rel_Range> rels(const Elf_Shdr *Sec) const {
167
7
    return getSectionContentsAsArray<Elf_Rel>(Sec);
168
7
  }
169
170
15
  Expected<Elf_Relr_Range> relrs(const Elf_Shdr *Sec) const {
171
15
    return getSectionContentsAsArray<Elf_Relr>(Sec);
172
15
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::relrs(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*) const
Line
Count
Source
170
7
  Expected<Elf_Relr_Range> relrs(const Elf_Shdr *Sec) const {
171
7
    return getSectionContentsAsArray<Elf_Relr>(Sec);
172
7
  }
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::relrs(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*) const
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::relrs(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*) const
Line
Count
Source
170
8
  Expected<Elf_Relr_Range> relrs(const Elf_Shdr *Sec) const {
171
8
    return getSectionContentsAsArray<Elf_Relr>(Sec);
172
8
  }
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::relrs(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*) const
173
174
  Expected<std::vector<Elf_Rela>> decode_relrs(Elf_Relr_Range relrs) const;
175
176
  Expected<std::vector<Elf_Rela>> android_relas(const Elf_Shdr *Sec) const;
177
178
  /// Iterate over program header table.
179
9.23k
  Expected<Elf_Phdr_Range> program_headers() const {
180
9.23k
    if (getHeader()->e_phnum && 
getHeader()->e_phentsize != sizeof(Elf_Phdr)6.73k
)
181
2
      return createError("invalid e_phentsize: " +
182
2
                         Twine(getHeader()->e_phentsize));
183
9.23k
    if (getHeader()->e_phoff +
184
9.23k
            (getHeader()->e_phnum * getHeader()->e_phentsize) >
185
9.23k
        getBufSize())
186
3
      return createError("program headers are longer than binary of size " +
187
3
                         Twine(getBufSize()) + ": e_phoff = 0x" +
188
3
                         Twine::utohexstr(getHeader()->e_phoff) +
189
3
                         ", e_phnum = " + Twine(getHeader()->e_phnum) +
190
3
                         ", e_phentsize = " + Twine(getHeader()->e_phentsize));
191
9.23k
    auto *Begin =
192
9.23k
        reinterpret_cast<const Elf_Phdr *>(base() + getHeader()->e_phoff);
193
9.23k
    return makeArrayRef(Begin, Begin + getHeader()->e_phnum);
194
9.23k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::program_headers() const
Line
Count
Source
179
1.40k
  Expected<Elf_Phdr_Range> program_headers() const {
180
1.40k
    if (getHeader()->e_phnum && 
getHeader()->e_phentsize != sizeof(Elf_Phdr)856
)
181
0
      return createError("invalid e_phentsize: " +
182
0
                         Twine(getHeader()->e_phentsize));
183
1.40k
    if (getHeader()->e_phoff +
184
1.40k
            (getHeader()->e_phnum * getHeader()->e_phentsize) >
185
1.40k
        getBufSize())
186
0
      return createError("program headers are longer than binary of size " +
187
0
                         Twine(getBufSize()) + ": e_phoff = 0x" +
188
0
                         Twine::utohexstr(getHeader()->e_phoff) +
189
0
                         ", e_phnum = " + Twine(getHeader()->e_phnum) +
190
0
                         ", e_phentsize = " + Twine(getHeader()->e_phentsize));
191
1.40k
    auto *Begin =
192
1.40k
        reinterpret_cast<const Elf_Phdr *>(base() + getHeader()->e_phoff);
193
1.40k
    return makeArrayRef(Begin, Begin + getHeader()->e_phnum);
194
1.40k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::program_headers() const
Line
Count
Source
179
461
  Expected<Elf_Phdr_Range> program_headers() const {
180
461
    if (getHeader()->e_phnum && 
getHeader()->e_phentsize != sizeof(Elf_Phdr)338
)
181
0
      return createError("invalid e_phentsize: " +
182
0
                         Twine(getHeader()->e_phentsize));
183
461
    if (getHeader()->e_phoff +
184
461
            (getHeader()->e_phnum * getHeader()->e_phentsize) >
185
461
        getBufSize())
186
0
      return createError("program headers are longer than binary of size " +
187
0
                         Twine(getBufSize()) + ": e_phoff = 0x" +
188
0
                         Twine::utohexstr(getHeader()->e_phoff) +
189
0
                         ", e_phnum = " + Twine(getHeader()->e_phnum) +
190
0
                         ", e_phentsize = " + Twine(getHeader()->e_phentsize));
191
461
    auto *Begin =
192
461
        reinterpret_cast<const Elf_Phdr *>(base() + getHeader()->e_phoff);
193
461
    return makeArrayRef(Begin, Begin + getHeader()->e_phnum);
194
461
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::program_headers() const
Line
Count
Source
179
7.08k
  Expected<Elf_Phdr_Range> program_headers() const {
180
7.08k
    if (getHeader()->e_phnum && 
getHeader()->e_phentsize != sizeof(Elf_Phdr)5.34k
)
181
2
      return createError("invalid e_phentsize: " +
182
2
                         Twine(getHeader()->e_phentsize));
183
7.07k
    if (getHeader()->e_phoff +
184
7.07k
            (getHeader()->e_phnum * getHeader()->e_phentsize) >
185
7.07k
        getBufSize())
186
3
      return createError("program headers are longer than binary of size " +
187
3
                         Twine(getBufSize()) + ": e_phoff = 0x" +
188
3
                         Twine::utohexstr(getHeader()->e_phoff) +
189
3
                         ", e_phnum = " + Twine(getHeader()->e_phnum) +
190
3
                         ", e_phentsize = " + Twine(getHeader()->e_phentsize));
191
7.07k
    auto *Begin =
192
7.07k
        reinterpret_cast<const Elf_Phdr *>(base() + getHeader()->e_phoff);
193
7.07k
    return makeArrayRef(Begin, Begin + getHeader()->e_phnum);
194
7.07k
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::program_headers() const
Line
Count
Source
179
288
  Expected<Elf_Phdr_Range> program_headers() const {
180
288
    if (getHeader()->e_phnum && 
getHeader()->e_phentsize != sizeof(Elf_Phdr)192
)
181
0
      return createError("invalid e_phentsize: " +
182
0
                         Twine(getHeader()->e_phentsize));
183
288
    if (getHeader()->e_phoff +
184
288
            (getHeader()->e_phnum * getHeader()->e_phentsize) >
185
288
        getBufSize())
186
0
      return createError("program headers are longer than binary of size " +
187
0
                         Twine(getBufSize()) + ": e_phoff = 0x" +
188
0
                         Twine::utohexstr(getHeader()->e_phoff) +
189
0
                         ", e_phnum = " + Twine(getHeader()->e_phnum) +
190
0
                         ", e_phentsize = " + Twine(getHeader()->e_phentsize));
191
288
    auto *Begin =
192
288
        reinterpret_cast<const Elf_Phdr *>(base() + getHeader()->e_phoff);
193
288
    return makeArrayRef(Begin, Begin + getHeader()->e_phnum);
194
288
  }
195
196
  /// Get an iterator over notes in a program header.
197
  ///
198
  /// The program header must be of type \c PT_NOTE.
199
  ///
200
  /// \param Phdr the program header to iterate over.
201
  /// \param Err [out] an error to support fallible iteration, which should
202
  ///  be checked after iteration ends.
203
13
  Elf_Note_Iterator notes_begin(const Elf_Phdr &Phdr, Error &Err) const {
204
13
    assert(Phdr.p_type == ELF::PT_NOTE && "Phdr is not of type PT_NOTE");
205
13
    ErrorAsOutParameter ErrAsOutParam(&Err);
206
13
    if (Phdr.p_offset + Phdr.p_filesz > getBufSize()) {
207
4
      Err = createError("PT_NOTE header has invalid offset (0x" +
208
4
                        Twine::utohexstr(Phdr.p_offset) + ") or size (0x" +
209
4
                        Twine::utohexstr(Phdr.p_filesz) + ")");
210
4
      return Elf_Note_Iterator(Err);
211
4
    }
212
9
    return Elf_Note_Iterator(base() + Phdr.p_offset, Phdr.p_filesz, Err);
213
9
  }
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::notes_begin(llvm::object::Elf_Phdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const&, llvm::Error&) const
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::notes_begin(llvm::object::Elf_Phdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const&, llvm::Error&) const
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::notes_begin(llvm::object::Elf_Phdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const&, llvm::Error&) const
Line
Count
Source
203
13
  Elf_Note_Iterator notes_begin(const Elf_Phdr &Phdr, Error &Err) const {
204
13
    assert(Phdr.p_type == ELF::PT_NOTE && "Phdr is not of type PT_NOTE");
205
13
    ErrorAsOutParameter ErrAsOutParam(&Err);
206
13
    if (Phdr.p_offset + Phdr.p_filesz > getBufSize()) {
207
4
      Err = createError("PT_NOTE header has invalid offset (0x" +
208
4
                        Twine::utohexstr(Phdr.p_offset) + ") or size (0x" +
209
4
                        Twine::utohexstr(Phdr.p_filesz) + ")");
210
4
      return Elf_Note_Iterator(Err);
211
4
    }
212
9
    return Elf_Note_Iterator(base() + Phdr.p_offset, Phdr.p_filesz, Err);
213
9
  }
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::notes_begin(llvm::object::Elf_Phdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const&, llvm::Error&) const
214
215
  /// Get an iterator over notes in a section.
216
  ///
217
  /// The section must be of type \c SHT_NOTE.
218
  ///
219
  /// \param Shdr the section to iterate over.
220
  /// \param Err [out] an error to support fallible iteration, which should
221
  ///  be checked after iteration ends.
222
91
  Elf_Note_Iterator notes_begin(const Elf_Shdr &Shdr, Error &Err) const {
223
91
    assert(Shdr.sh_type == ELF::SHT_NOTE && "Shdr is not of type SHT_NOTE");
224
91
    ErrorAsOutParameter ErrAsOutParam(&Err);
225
91
    if (Shdr.sh_offset + Shdr.sh_size > getBufSize()) {
226
4
      Err = createError("SHT_NOTE section " + getSecIndexForError(this, &Shdr) +
227
4
                        " has invalid offset (0x" +
228
4
                        Twine::utohexstr(Shdr.sh_offset) + ") or size (0x" +
229
4
                        Twine::utohexstr(Shdr.sh_size) + ")");
230
4
      return Elf_Note_Iterator(Err);
231
4
    }
232
87
    return Elf_Note_Iterator(base() + Shdr.sh_offset, Shdr.sh_size, Err);
233
87
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::notes_begin(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const&, llvm::Error&) const
Line
Count
Source
222
3
  Elf_Note_Iterator notes_begin(const Elf_Shdr &Shdr, Error &Err) const {
223
3
    assert(Shdr.sh_type == ELF::SHT_NOTE && "Shdr is not of type SHT_NOTE");
224
3
    ErrorAsOutParameter ErrAsOutParam(&Err);
225
3
    if (Shdr.sh_offset + Shdr.sh_size > getBufSize()) {
226
0
      Err = createError("SHT_NOTE section " + getSecIndexForError(this, &Shdr) +
227
0
                        " has invalid offset (0x" +
228
0
                        Twine::utohexstr(Shdr.sh_offset) + ") or size (0x" +
229
0
                        Twine::utohexstr(Shdr.sh_size) + ")");
230
0
      return Elf_Note_Iterator(Err);
231
0
    }
232
3
    return Elf_Note_Iterator(base() + Shdr.sh_offset, Shdr.sh_size, Err);
233
3
  }
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::notes_begin(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const&, llvm::Error&) const
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::notes_begin(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const&, llvm::Error&) const
Line
Count
Source
222
88
  Elf_Note_Iterator notes_begin(const Elf_Shdr &Shdr, Error &Err) const {
223
88
    assert(Shdr.sh_type == ELF::SHT_NOTE && "Shdr is not of type SHT_NOTE");
224
88
    ErrorAsOutParameter ErrAsOutParam(&Err);
225
88
    if (Shdr.sh_offset + Shdr.sh_size > getBufSize()) {
226
4
      Err = createError("SHT_NOTE section " + getSecIndexForError(this, &Shdr) +
227
4
                        " has invalid offset (0x" +
228
4
                        Twine::utohexstr(Shdr.sh_offset) + ") or size (0x" +
229
4
                        Twine::utohexstr(Shdr.sh_size) + ")");
230
4
      return Elf_Note_Iterator(Err);
231
4
    }
232
84
    return Elf_Note_Iterator(base() + Shdr.sh_offset, Shdr.sh_size, Err);
233
84
  }
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::notes_begin(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const&, llvm::Error&) const
234
235
  /// Get the end iterator for notes.
236
104
  Elf_Note_Iterator notes_end() const {
237
104
    return Elf_Note_Iterator();
238
104
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::notes_end() const
Line
Count
Source
236
3
  Elf_Note_Iterator notes_end() const {
237
3
    return Elf_Note_Iterator();
238
3
  }
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::notes_end() const
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::notes_end() const
Line
Count
Source
236
101
  Elf_Note_Iterator notes_end() const {
237
101
    return Elf_Note_Iterator();
238
101
  }
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::notes_end() const
239
240
  /// Get an iterator range over notes of a program header.
241
  ///
242
  /// The program header must be of type \c PT_NOTE.
243
  ///
244
  /// \param Phdr the program header to iterate over.
245
  /// \param Err [out] an error to support fallible iteration, which should
246
  ///  be checked after iteration ends.
247
  iterator_range<Elf_Note_Iterator> notes(const Elf_Phdr &Phdr,
248
13
                                          Error &Err) const {
249
13
    return make_range(notes_begin(Phdr, Err), notes_end());
250
13
  }
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::notes(llvm::object::Elf_Phdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const&, llvm::Error&) const
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::notes(llvm::object::Elf_Phdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const&, llvm::Error&) const
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::notes(llvm::object::Elf_Phdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const&, llvm::Error&) const
Line
Count
Source
248
13
                                          Error &Err) const {
249
13
    return make_range(notes_begin(Phdr, Err), notes_end());
250
13
  }
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::notes(llvm::object::Elf_Phdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const&, llvm::Error&) const
251
252
  /// Get an iterator range over notes of a section.
253
  ///
254
  /// The section must be of type \c SHT_NOTE.
255
  ///
256
  /// \param Shdr the section to iterate over.
257
  /// \param Err [out] an error to support fallible iteration, which should
258
  ///  be checked after iteration ends.
259
  iterator_range<Elf_Note_Iterator> notes(const Elf_Shdr &Shdr,
260
91
                                          Error &Err) const {
261
91
    return make_range(notes_begin(Shdr, Err), notes_end());
262
91
  }
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::notes(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const&, llvm::Error&) const
Line
Count
Source
260
3
                                          Error &Err) const {
261
3
    return make_range(notes_begin(Shdr, Err), notes_end());
262
3
  }
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::notes(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const&, llvm::Error&) const
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::notes(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const&, llvm::Error&) const
Line
Count
Source
260
88
                                          Error &Err) const {
261
88
    return make_range(notes_begin(Shdr, Err), notes_end());
262
88
  }
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::notes(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const&, llvm::Error&) const
263
264
  Expected<StringRef> getSectionStringTable(Elf_Shdr_Range Sections) const;
265
  Expected<uint32_t> getSectionIndex(const Elf_Sym *Sym, Elf_Sym_Range Syms,
266
                                     ArrayRef<Elf_Word> ShndxTable) const;
267
  Expected<const Elf_Shdr *> getSection(const Elf_Sym *Sym,
268
                                        const Elf_Shdr *SymTab,
269
                                        ArrayRef<Elf_Word> ShndxTable) const;
270
  Expected<const Elf_Shdr *> getSection(const Elf_Sym *Sym,
271
                                        Elf_Sym_Range Symtab,
272
                                        ArrayRef<Elf_Word> ShndxTable) const;
273
  Expected<const Elf_Shdr *> getSection(uint32_t Index) const;
274
  Expected<const Elf_Shdr *> getSection(const StringRef SectionName) const;
275
276
  Expected<const Elf_Sym *> getSymbol(const Elf_Shdr *Sec,
277
                                      uint32_t Index) const;
278
279
  Expected<StringRef> getSectionName(const Elf_Shdr *Section) const;
280
  Expected<StringRef> getSectionName(const Elf_Shdr *Section,
281
                                     StringRef DotShstrtab) const;
282
  template <typename T>
283
  Expected<ArrayRef<T>> getSectionContentsAsArray(const Elf_Shdr *Sec) const;
284
  Expected<ArrayRef<uint8_t>> getSectionContents(const Elf_Shdr *Sec) const;
285
};
286
287
using ELF32LEFile = ELFFile<ELF32LE>;
288
using ELF64LEFile = ELFFile<ELF64LE>;
289
using ELF32BEFile = ELFFile<ELF32BE>;
290
using ELF64BEFile = ELFFile<ELF64BE>;
291
292
template <class ELFT>
293
inline Expected<const typename ELFT::Shdr *>
294
676k
getSection(typename ELFT::ShdrRange Sections, uint32_t Index) {
295
676k
  if (Index >= Sections.size())
296
4
    return createError("invalid section index: " + Twine(Index));
297
676k
  return &Sections[Index];
298
676k
}
llvm::Expected<llvm::object::ELFType<(llvm::support::endianness)1, false>::Shdr const*> llvm::object::getSection<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::object::ELFType<(llvm::support::endianness)1, false>::ShdrRange, unsigned int)
Line
Count
Source
294
127k
getSection(typename ELFT::ShdrRange Sections, uint32_t Index) {
295
127k
  if (Index >= Sections.size())
296
0
    return createError("invalid section index: " + Twine(Index));
297
127k
  return &Sections[Index];
298
127k
}
llvm::Expected<llvm::object::ELFType<(llvm::support::endianness)0, false>::Shdr const*> llvm::object::getSection<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::object::ELFType<(llvm::support::endianness)0, false>::ShdrRange, unsigned int)
Line
Count
Source
294
14.6k
getSection(typename ELFT::ShdrRange Sections, uint32_t Index) {
295
14.6k
  if (Index >= Sections.size())
296
0
    return createError("invalid section index: " + Twine(Index));
297
14.6k
  return &Sections[Index];
298
14.6k
}
llvm::Expected<llvm::object::ELFType<(llvm::support::endianness)1, true>::Shdr const*> llvm::object::getSection<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::object::ELFType<(llvm::support::endianness)1, true>::ShdrRange, unsigned int)
Line
Count
Source
294
523k
getSection(typename ELFT::ShdrRange Sections, uint32_t Index) {
295
523k
  if (Index >= Sections.size())
296
4
    return createError("invalid section index: " + Twine(Index));
297
523k
  return &Sections[Index];
298
523k
}
llvm::Expected<llvm::object::ELFType<(llvm::support::endianness)0, true>::Shdr const*> llvm::object::getSection<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::object::ELFType<(llvm::support::endianness)0, true>::ShdrRange, unsigned int)
Line
Count
Source
294
10.6k
getSection(typename ELFT::ShdrRange Sections, uint32_t Index) {
295
10.6k
  if (Index >= Sections.size())
296
0
    return createError("invalid section index: " + Twine(Index));
297
10.6k
  return &Sections[Index];
298
10.6k
}
299
300
template <class ELFT>
301
inline Expected<uint32_t>
302
getExtendedSymbolTableIndex(const typename ELFT::Sym *Sym,
303
                            const typename ELFT::Sym *FirstSym,
304
5.52k
                            ArrayRef<typename ELFT::Word> ShndxTable) {
305
5.52k
  assert(Sym->st_shndx == ELF::SHN_XINDEX);
306
5.52k
  unsigned Index = Sym - FirstSym;
307
5.52k
  if (Index >= ShndxTable.size())
308
1
    return createError(
309
1
        "extended symbol index (" + Twine(Index) +
310
1
        ") is past the end of the SHT_SYMTAB_SHNDX section of size " +
311
1
        Twine(ShndxTable.size()));
312
5.52k
313
5.52k
  // The size of the table was checked in getSHNDXTable.
314
5.52k
  return ShndxTable[Index];
315
5.52k
}
llvm::Expected<unsigned int> llvm::object::getExtendedSymbolTableIndex<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::object::ELFType<(llvm::support::endianness)1, false>::Sym const*, llvm::object::ELFType<(llvm::support::endianness)1, false>::Sym const*, llvm::ArrayRef<llvm::object::ELFType<(llvm::support::endianness)1, false>::Word>)
Line
Count
Source
304
2
                            ArrayRef<typename ELFT::Word> ShndxTable) {
305
2
  assert(Sym->st_shndx == ELF::SHN_XINDEX);
306
2
  unsigned Index = Sym - FirstSym;
307
2
  if (Index >= ShndxTable.size())
308
0
    return createError(
309
0
        "extended symbol index (" + Twine(Index) +
310
0
        ") is past the end of the SHT_SYMTAB_SHNDX section of size " +
311
0
        Twine(ShndxTable.size()));
312
2
313
2
  // The size of the table was checked in getSHNDXTable.
314
2
  return ShndxTable[Index];
315
2
}
Unexecuted instantiation: llvm::Expected<unsigned int> llvm::object::getExtendedSymbolTableIndex<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::object::ELFType<(llvm::support::endianness)0, false>::Sym const*, llvm::object::ELFType<(llvm::support::endianness)0, false>::Sym const*, llvm::ArrayRef<llvm::object::ELFType<(llvm::support::endianness)0, false>::Word>)
llvm::Expected<unsigned int> llvm::object::getExtendedSymbolTableIndex<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::object::ELFType<(llvm::support::endianness)1, true>::Sym const*, llvm::object::ELFType<(llvm::support::endianness)1, true>::Sym const*, llvm::ArrayRef<llvm::object::ELFType<(llvm::support::endianness)1, true>::Word>)
Line
Count
Source
304
5.52k
                            ArrayRef<typename ELFT::Word> ShndxTable) {
305
5.52k
  assert(Sym->st_shndx == ELF::SHN_XINDEX);
306
5.52k
  unsigned Index = Sym - FirstSym;
307
5.52k
  if (Index >= ShndxTable.size())
308
1
    return createError(
309
1
        "extended symbol index (" + Twine(Index) +
310
1
        ") is past the end of the SHT_SYMTAB_SHNDX section of size " +
311
1
        Twine(ShndxTable.size()));
312
5.52k
313
5.52k
  // The size of the table was checked in getSHNDXTable.
314
5.52k
  return ShndxTable[Index];
315
5.52k
}
Unexecuted instantiation: llvm::Expected<unsigned int> llvm::object::getExtendedSymbolTableIndex<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::object::ELFType<(llvm::support::endianness)0, true>::Sym const*, llvm::object::ELFType<(llvm::support::endianness)0, true>::Sym const*, llvm::ArrayRef<llvm::object::ELFType<(llvm::support::endianness)0, true>::Word>)
316
317
template <class ELFT>
318
Expected<uint32_t>
319
ELFFile<ELFT>::getSectionIndex(const Elf_Sym *Sym, Elf_Sym_Range Syms,
320
125k
                               ArrayRef<Elf_Word> ShndxTable) const {
321
125k
  uint32_t Index = Sym->st_shndx;
322
125k
  if (Index == ELF::SHN_XINDEX) {
323
268
    auto ErrorOrIndex = getExtendedSymbolTableIndex<ELFT>(
324
268
        Sym, Syms.begin(), ShndxTable);
325
268
    if (!ErrorOrIndex)
326
0
      return ErrorOrIndex.takeError();
327
268
    return *ErrorOrIndex;
328
268
  }
329
125k
  if (Index == ELF::SHN_UNDEF || 
Index >= ELF::SHN_LORESERVE118k
)
330
8.51k
    return 0;
331
116k
  return Index;
332
116k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSectionIndex(llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*, llvm::ArrayRef<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > >, llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)1, 1ul> >) const
Line
Count
Source
320
13.8k
                               ArrayRef<Elf_Word> ShndxTable) const {
321
13.8k
  uint32_t Index = Sym->st_shndx;
322
13.8k
  if (Index == ELF::SHN_XINDEX) {
323
0
    auto ErrorOrIndex = getExtendedSymbolTableIndex<ELFT>(
324
0
        Sym, Syms.begin(), ShndxTable);
325
0
    if (!ErrorOrIndex)
326
0
      return ErrorOrIndex.takeError();
327
0
    return *ErrorOrIndex;
328
0
  }
329
13.8k
  if (Index == ELF::SHN_UNDEF || 
Index >= ELF::SHN_LORESERVE12.6k
)
330
1.39k
    return 0;
331
12.4k
  return Index;
332
12.4k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSectionIndex(llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*, llvm::ArrayRef<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > >, llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)0, 1ul> >) const
Line
Count
Source
320
2.03k
                               ArrayRef<Elf_Word> ShndxTable) const {
321
2.03k
  uint32_t Index = Sym->st_shndx;
322
2.03k
  if (Index == ELF::SHN_XINDEX) {
323
0
    auto ErrorOrIndex = getExtendedSymbolTableIndex<ELFT>(
324
0
        Sym, Syms.begin(), ShndxTable);
325
0
    if (!ErrorOrIndex)
326
0
      return ErrorOrIndex.takeError();
327
0
    return *ErrorOrIndex;
328
0
  }
329
2.03k
  if (Index == ELF::SHN_UNDEF || 
Index >= ELF::SHN_LORESERVE1.58k
)
330
484
    return 0;
331
1.55k
  return Index;
332
1.55k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSectionIndex(llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*, llvm::ArrayRef<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > >, llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)1, 1ul> >) const
Line
Count
Source
320
98.1k
                               ArrayRef<Elf_Word> ShndxTable) const {
321
98.1k
  uint32_t Index = Sym->st_shndx;
322
98.1k
  if (Index == ELF::SHN_XINDEX) {
323
268
    auto ErrorOrIndex = getExtendedSymbolTableIndex<ELFT>(
324
268
        Sym, Syms.begin(), ShndxTable);
325
268
    if (!ErrorOrIndex)
326
0
      return ErrorOrIndex.takeError();
327
268
    return *ErrorOrIndex;
328
268
  }
329
97.8k
  if (Index == ELF::SHN_UNDEF || 
Index >= ELF::SHN_LORESERVE93.0k
)
330
6.30k
    return 0;
331
91.5k
  return Index;
332
91.5k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSectionIndex(llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*, llvm::ArrayRef<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > >, llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)0, 1ul> >) const
Line
Count
Source
320
11.4k
                               ArrayRef<Elf_Word> ShndxTable) const {
321
11.4k
  uint32_t Index = Sym->st_shndx;
322
11.4k
  if (Index == ELF::SHN_XINDEX) {
323
0
    auto ErrorOrIndex = getExtendedSymbolTableIndex<ELFT>(
324
0
        Sym, Syms.begin(), ShndxTable);
325
0
    if (!ErrorOrIndex)
326
0
      return ErrorOrIndex.takeError();
327
0
    return *ErrorOrIndex;
328
0
  }
329
11.4k
  if (Index == ELF::SHN_UNDEF || 
Index >= ELF::SHN_LORESERVE11.1k
)
330
332
    return 0;
331
11.1k
  return Index;
332
11.1k
}
333
334
template <class ELFT>
335
Expected<const typename ELFT::Shdr *>
336
ELFFile<ELFT>::getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
337
36.6k
                          ArrayRef<Elf_Word> ShndxTable) const {
338
36.6k
  auto SymsOrErr = symbols(SymTab);
339
36.6k
  if (!SymsOrErr)
340
0
    return SymsOrErr.takeError();
341
36.6k
  return getSection(Sym, *SymsOrErr, ShndxTable);
342
36.6k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSection(llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*, llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*, llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)1, 1ul> >) const
Line
Count
Source
337
11.1k
                          ArrayRef<Elf_Word> ShndxTable) const {
338
11.1k
  auto SymsOrErr = symbols(SymTab);
339
11.1k
  if (!SymsOrErr)
340
0
    return SymsOrErr.takeError();
341
11.1k
  return getSection(Sym, *SymsOrErr, ShndxTable);
342
11.1k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSection(llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*, llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*, llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)0, 1ul> >) const
Line
Count
Source
337
1.20k
                          ArrayRef<Elf_Word> ShndxTable) const {
338
1.20k
  auto SymsOrErr = symbols(SymTab);
339
1.20k
  if (!SymsOrErr)
340
0
    return SymsOrErr.takeError();
341
1.20k
  return getSection(Sym, *SymsOrErr, ShndxTable);
342
1.20k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSection(llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*, llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*, llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)1, 1ul> >) const
Line
Count
Source
337
23.2k
                          ArrayRef<Elf_Word> ShndxTable) const {
338
23.2k
  auto SymsOrErr = symbols(SymTab);
339
23.2k
  if (!SymsOrErr)
340
0
    return SymsOrErr.takeError();
341
23.2k
  return getSection(Sym, *SymsOrErr, ShndxTable);
342
23.2k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSection(llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*, llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*, llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)0, 1ul> >) const
Line
Count
Source
337
920
                          ArrayRef<Elf_Word> ShndxTable) const {
338
920
  auto SymsOrErr = symbols(SymTab);
339
920
  if (!SymsOrErr)
340
0
    return SymsOrErr.takeError();
341
920
  return getSection(Sym, *SymsOrErr, ShndxTable);
342
920
}
343
344
template <class ELFT>
345
Expected<const typename ELFT::Shdr *>
346
ELFFile<ELFT>::getSection(const Elf_Sym *Sym, Elf_Sym_Range Symbols,
347
36.6k
                          ArrayRef<Elf_Word> ShndxTable) const {
348
36.6k
  auto IndexOrErr = getSectionIndex(Sym, Symbols, ShndxTable);
349
36.6k
  if (!IndexOrErr)
350
0
    return IndexOrErr.takeError();
351
36.6k
  uint32_t Index = *IndexOrErr;
352
36.6k
  if (Index == 0)
353
2.62k
    return nullptr;
354
33.9k
  return getSection(Index);
355
33.9k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSection(llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*, llvm::ArrayRef<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > >, llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)1, 1ul> >) const
Line
Count
Source
347
11.1k
                          ArrayRef<Elf_Word> ShndxTable) const {
348
11.1k
  auto IndexOrErr = getSectionIndex(Sym, Symbols, ShndxTable);
349
11.1k
  if (!IndexOrErr)
350
0
    return IndexOrErr.takeError();
351
11.1k
  uint32_t Index = *IndexOrErr;
352
11.1k
  if (Index == 0)
353
620
    return nullptr;
354
10.5k
  return getSection(Index);
355
10.5k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSection(llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*, llvm::ArrayRef<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > >, llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)0, 1ul> >) const
Line
Count
Source
347
1.20k
                          ArrayRef<Elf_Word> ShndxTable) const {
348
1.20k
  auto IndexOrErr = getSectionIndex(Sym, Symbols, ShndxTable);
349
1.20k
  if (!IndexOrErr)
350
0
    return IndexOrErr.takeError();
351
1.20k
  uint32_t Index = *IndexOrErr;
352
1.20k
  if (Index == 0)
353
130
    return nullptr;
354
1.07k
  return getSection(Index);
355
1.07k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSection(llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*, llvm::ArrayRef<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > >, llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)1, 1ul> >) const
Line
Count
Source
347
23.2k
                          ArrayRef<Elf_Word> ShndxTable) const {
348
23.2k
  auto IndexOrErr = getSectionIndex(Sym, Symbols, ShndxTable);
349
23.2k
  if (!IndexOrErr)
350
0
    return IndexOrErr.takeError();
351
23.2k
  uint32_t Index = *IndexOrErr;
352
23.2k
  if (Index == 0)
353
1.80k
    return nullptr;
354
21.4k
  return getSection(Index);
355
21.4k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSection(llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*, llvm::ArrayRef<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > >, llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)0, 1ul> >) const
Line
Count
Source
347
920
                          ArrayRef<Elf_Word> ShndxTable) const {
348
920
  auto IndexOrErr = getSectionIndex(Sym, Symbols, ShndxTable);
349
920
  if (!IndexOrErr)
350
0
    return IndexOrErr.takeError();
351
920
  uint32_t Index = *IndexOrErr;
352
920
  if (Index == 0)
353
72
    return nullptr;
354
848
  return getSection(Index);
355
848
}
356
357
template <class ELFT>
358
Expected<const typename ELFT::Sym *>
359
6
ELFFile<ELFT>::getSymbol(const Elf_Shdr *Sec, uint32_t Index) const {
360
6
  auto SymsOrErr = symbols(Sec);
361
6
  if (!SymsOrErr)
362
0
    return SymsOrErr.takeError();
363
6
364
6
  Elf_Sym_Range Symbols = *SymsOrErr;
365
6
  if (Index >= Symbols.size())
366
1
    return createError("unable to get symbol from section " +
367
1
                       getSecIndexForError(this, Sec) +
368
1
                       ": invalid symbol index (" + Twine(Index) + ")");
369
5
  return &Symbols[Index];
370
5
}
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSymbol(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*, unsigned int) const
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSymbol(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*, unsigned int) const
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSymbol(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*, unsigned int) const
Line
Count
Source
359
6
ELFFile<ELFT>::getSymbol(const Elf_Shdr *Sec, uint32_t Index) const {
360
6
  auto SymsOrErr = symbols(Sec);
361
6
  if (!SymsOrErr)
362
0
    return SymsOrErr.takeError();
363
6
364
6
  Elf_Sym_Range Symbols = *SymsOrErr;
365
6
  if (Index >= Symbols.size())
366
1
    return createError("unable to get symbol from section " +
367
1
                       getSecIndexForError(this, Sec) +
368
1
                       ": invalid symbol index (" + Twine(Index) + ")");
369
5
  return &Symbols[Index];
370
5
}
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSymbol(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*, unsigned int) const
371
372
template <class ELFT>
373
template <typename T>
374
Expected<ArrayRef<T>>
375
1.69M
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
1.69M
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 11.51M
)
377
1
    return createError("section " + getSecIndexForError(this, Sec) +
378
1
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
1.69M
380
1.69M
  uintX_t Offset = Sec->sh_offset;
381
1.69M
  uintX_t Size = Sec->sh_size;
382
1.69M
383
1.69M
  if (Size % sizeof(T))
384
1
    return createError("section " + getSecIndexForError(this, Sec) +
385
1
                       " has an invalid sh_size (" + Twine(Size) +
386
1
                       ") which is not a multiple of its sh_entsize (" +
387
1
                       Twine(Sec->sh_entsize) + ")");
388
1.69M
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
1.69M
      Offset + Size > Buf.size())
390
5
    return createError("section " + getSecIndexForError(this, Sec) +
391
5
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
5
                       ") + sh_size (0x" + Twine(Size) +
393
5
                       ") that cannot be represented");
394
1.69M
395
1.69M
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
1.69M
399
1.69M
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
1.69M
  return makeArrayRef(Start, Size / sizeof(T));
401
1.69M
}
llvm::Expected<llvm::ArrayRef<char> > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSectionContentsAsArray<char>(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*) const
Line
Count
Source
375
27.6k
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
27.6k
  if (Sec->sh_entsize != sizeof(T) && sizeof(T) != 1)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
27.6k
380
27.6k
  uintX_t Offset = Sec->sh_offset;
381
27.6k
  uintX_t Size = Sec->sh_size;
382
27.6k
383
27.6k
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
27.6k
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
27.6k
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
27.6k
395
27.6k
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
27.6k
399
27.6k
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
27.6k
  return makeArrayRef(Start, Size / sizeof(T));
401
27.6k
}
llvm::Expected<llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)1, 1ul> > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSectionContentsAsArray<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)1, 1ul> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*) const
Line
Count
Source
375
13
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
13
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
13
380
13
  uintX_t Offset = Sec->sh_offset;
381
13
  uintX_t Size = Sec->sh_size;
382
13
383
13
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
13
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
13
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
13
395
13
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
13
399
13
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
13
  return makeArrayRef(Start, Size / sizeof(T));
401
13
}
llvm::Expected<llvm::ArrayRef<llvm::object::Elf_Dyn_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSectionContentsAsArray<llvm::object::Elf_Dyn_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*) const
Line
Count
Source
375
66
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
66
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
66
380
66
  uintX_t Offset = Sec->sh_offset;
381
66
  uintX_t Size = Sec->sh_size;
382
66
383
66
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
66
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
66
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
66
395
66
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
66
399
66
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
66
  return makeArrayRef(Start, Size / sizeof(T));
401
66
}
llvm::Expected<llvm::ArrayRef<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSectionContentsAsArray<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*) const
Line
Count
Source
375
22.5k
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
22.5k
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
22.5k
380
22.5k
  uintX_t Offset = Sec->sh_offset;
381
22.5k
  uintX_t Size = Sec->sh_size;
382
22.5k
383
22.5k
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
22.5k
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
22.5k
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
22.5k
395
22.5k
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
22.5k
399
22.5k
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
22.5k
  return makeArrayRef(Start, Size / sizeof(T));
401
22.5k
}
llvm::Expected<llvm::ArrayRef<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, true> > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSectionContentsAsArray<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, true> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*) const
Line
Count
Source
375
93
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
93
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
93
380
93
  uintX_t Offset = Sec->sh_offset;
381
93
  uintX_t Size = Sec->sh_size;
382
93
383
93
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
93
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
93
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
93
395
93
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
93
399
93
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
93
  return makeArrayRef(Start, Size / sizeof(T));
401
93
}
llvm::Expected<llvm::ArrayRef<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, false> > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSectionContentsAsArray<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, false> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*) const
Line
Count
Source
375
567
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
567
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
567
380
567
  uintX_t Offset = Sec->sh_offset;
381
567
  uintX_t Size = Sec->sh_size;
382
567
383
567
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
567
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
567
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
567
395
567
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
567
399
567
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
567
  return makeArrayRef(Start, Size / sizeof(T));
401
567
}
llvm::Expected<llvm::ArrayRef<unsigned char> > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSectionContentsAsArray<unsigned char>(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*) const
Line
Count
Source
375
4.37k
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
4.37k
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 14.35k
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
4.37k
380
4.37k
  uintX_t Offset = Sec->sh_offset;
381
4.37k
  uintX_t Size = Sec->sh_size;
382
4.37k
383
4.37k
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
4.37k
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
4.37k
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
4.37k
395
4.37k
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
4.37k
399
4.37k
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
4.37k
  return makeArrayRef(Start, Size / sizeof(T));
401
4.37k
}
llvm::Expected<llvm::ArrayRef<char> > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSectionContentsAsArray<char>(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*) const
Line
Count
Source
375
4.70k
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
4.70k
  if (Sec->sh_entsize != sizeof(T) && sizeof(T) != 1)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
4.70k
380
4.70k
  uintX_t Offset = Sec->sh_offset;
381
4.70k
  uintX_t Size = Sec->sh_size;
382
4.70k
383
4.70k
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
4.70k
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
4.70k
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
4.70k
395
4.70k
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
4.70k
399
4.70k
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
4.70k
  return makeArrayRef(Start, Size / sizeof(T));
401
4.70k
}
Unexecuted instantiation: llvm::Expected<llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)0, 1ul> > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSectionContentsAsArray<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)0, 1ul> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*) const
llvm::Expected<llvm::ArrayRef<llvm::object::Elf_Dyn_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSectionContentsAsArray<llvm::object::Elf_Dyn_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*) const
Line
Count
Source
375
30
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
30
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
30
380
30
  uintX_t Offset = Sec->sh_offset;
381
30
  uintX_t Size = Sec->sh_size;
382
30
383
30
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
30
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
30
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
30
395
30
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
30
399
30
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
30
  return makeArrayRef(Start, Size / sizeof(T));
401
30
}
llvm::Expected<llvm::ArrayRef<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSectionContentsAsArray<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*) const
Line
Count
Source
375
3.00k
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
3.00k
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
3.00k
380
3.00k
  uintX_t Offset = Sec->sh_offset;
381
3.00k
  uintX_t Size = Sec->sh_size;
382
3.00k
383
3.00k
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
3.00k
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
3.00k
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
3.00k
395
3.00k
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
3.00k
399
3.00k
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
3.00k
  return makeArrayRef(Start, Size / sizeof(T));
401
3.00k
}
llvm::Expected<llvm::ArrayRef<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, true> > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSectionContentsAsArray<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, true> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*) const
Line
Count
Source
375
70
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
70
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
70
380
70
  uintX_t Offset = Sec->sh_offset;
381
70
  uintX_t Size = Sec->sh_size;
382
70
383
70
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
70
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
70
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
70
395
70
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
70
399
70
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
70
  return makeArrayRef(Start, Size / sizeof(T));
401
70
}
llvm::Expected<llvm::ArrayRef<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, false> > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSectionContentsAsArray<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, false> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*) const
Line
Count
Source
375
117
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
117
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
117
380
117
  uintX_t Offset = Sec->sh_offset;
381
117
  uintX_t Size = Sec->sh_size;
382
117
383
117
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
117
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
117
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
117
395
117
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
117
399
117
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
117
  return makeArrayRef(Start, Size / sizeof(T));
401
117
}
llvm::Expected<llvm::ArrayRef<unsigned char> > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSectionContentsAsArray<unsigned char>(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*) const
Line
Count
Source
375
1.69k
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
1.69k
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 11.69k
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
1.69k
380
1.69k
  uintX_t Offset = Sec->sh_offset;
381
1.69k
  uintX_t Size = Sec->sh_size;
382
1.69k
383
1.69k
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
1.69k
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
1.69k
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
1.69k
395
1.69k
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
1.69k
399
1.69k
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
1.69k
  return makeArrayRef(Start, Size / sizeof(T));
401
1.69k
}
llvm::Expected<llvm::ArrayRef<char> > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSectionContentsAsArray<char>(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*) const
Line
Count
Source
375
670k
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
670k
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 1670k
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
670k
380
670k
  uintX_t Offset = Sec->sh_offset;
381
670k
  uintX_t Size = Sec->sh_size;
382
670k
383
670k
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
670k
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
670k
      Offset + Size > Buf.size())
390
2
    return createError("section " + getSecIndexForError(this, Sec) +
391
2
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
2
                       ") + sh_size (0x" + Twine(Size) +
393
2
                       ") that cannot be represented");
394
670k
395
670k
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
670k
399
670k
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
670k
  return makeArrayRef(Start, Size / sizeof(T));
401
670k
}
llvm::Expected<llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)1, 1ul> > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSectionContentsAsArray<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)1, 1ul> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*) const
Line
Count
Source
375
171
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
171
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
171
380
171
  uintX_t Offset = Sec->sh_offset;
381
171
  uintX_t Size = Sec->sh_size;
382
171
383
171
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
171
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
171
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
171
395
171
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
171
399
171
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
171
  return makeArrayRef(Start, Size / sizeof(T));
401
171
}
llvm::Expected<llvm::ArrayRef<llvm::object::Elf_Dyn_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSectionContentsAsArray<llvm::object::Elf_Dyn_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*) const
Line
Count
Source
375
303
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
303
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
303
380
303
  uintX_t Offset = Sec->sh_offset;
381
303
  uintX_t Size = Sec->sh_size;
382
303
383
303
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
303
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
303
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
303
395
303
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
303
399
303
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
303
  return makeArrayRef(Start, Size / sizeof(T));
401
303
}
llvm::Expected<llvm::ArrayRef<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSectionContentsAsArray<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*) const
Line
Count
Source
375
150k
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
150k
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
1
    return createError("section " + getSecIndexForError(this, Sec) +
378
1
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
150k
380
150k
  uintX_t Offset = Sec->sh_offset;
381
150k
  uintX_t Size = Sec->sh_size;
382
150k
383
150k
  if (Size % sizeof(T))
384
1
    return createError("section " + getSecIndexForError(this, Sec) +
385
1
                       " has an invalid sh_size (" + Twine(Size) +
386
1
                       ") which is not a multiple of its sh_entsize (" +
387
1
                       Twine(Sec->sh_entsize) + ")");
388
150k
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
150k
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
150k
395
150k
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
150k
399
150k
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
150k
  return makeArrayRef(Start, Size / sizeof(T));
401
150k
}
llvm::Expected<llvm::ArrayRef<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, true> > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSectionContentsAsArray<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, true> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*) const
Line
Count
Source
375
2.00k
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
2.00k
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
2.00k
380
2.00k
  uintX_t Offset = Sec->sh_offset;
381
2.00k
  uintX_t Size = Sec->sh_size;
382
2.00k
383
2.00k
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
2.00k
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
2.00k
      Offset + Size > Buf.size())
390
1
    return createError("section " + getSecIndexForError(this, Sec) +
391
1
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
1
                       ") + sh_size (0x" + Twine(Size) +
393
1
                       ") that cannot be represented");
394
2.00k
395
2.00k
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
2.00k
399
2.00k
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
2.00k
  return makeArrayRef(Start, Size / sizeof(T));
401
2.00k
}
llvm::Expected<llvm::ArrayRef<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, false> > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSectionContentsAsArray<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, false> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*) const
Line
Count
Source
375
41
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
41
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
41
380
41
  uintX_t Offset = Sec->sh_offset;
381
41
  uintX_t Size = Sec->sh_size;
382
41
383
41
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
41
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
41
      Offset + Size > Buf.size())
390
1
    return createError("section " + getSecIndexForError(this, Sec) +
391
1
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
1
                       ") + sh_size (0x" + Twine(Size) +
393
1
                       ") that cannot be represented");
394
40
395
40
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
40
399
40
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
40
  return makeArrayRef(Start, Size / sizeof(T));
401
40
}
llvm::Expected<llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned long long, (llvm::support::endianness)1, 1ul> > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSectionContentsAsArray<llvm::support::detail::packed_endian_specific_integral<unsigned long long, (llvm::support::endianness)1, 1ul> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*) const
Line
Count
Source
375
8
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
8
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
8
380
8
  uintX_t Offset = Sec->sh_offset;
381
8
  uintX_t Size = Sec->sh_size;
382
8
383
8
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
8
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
8
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
8
395
8
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
8
399
8
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
8
  return makeArrayRef(Start, Size / sizeof(T));
401
8
}
llvm::Expected<llvm::ArrayRef<unsigned char> > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSectionContentsAsArray<unsigned char>(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*) const
Line
Count
Source
375
800k
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
800k
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 1800k
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
800k
380
800k
  uintX_t Offset = Sec->sh_offset;
381
800k
  uintX_t Size = Sec->sh_size;
382
800k
383
800k
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
800k
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
800k
      Offset + Size > Buf.size())
390
1
    return createError("section " + getSecIndexForError(this, Sec) +
391
1
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
1
                       ") + sh_size (0x" + Twine(Size) +
393
1
                       ") that cannot be represented");
394
800k
395
800k
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
800k
399
800k
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
800k
  return makeArrayRef(Start, Size / sizeof(T));
401
800k
}
llvm::Expected<llvm::ArrayRef<char> > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSectionContentsAsArray<char>(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*) const
Line
Count
Source
375
3.67k
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
3.67k
  if (Sec->sh_entsize != sizeof(T) && sizeof(T) != 1)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
3.67k
380
3.67k
  uintX_t Offset = Sec->sh_offset;
381
3.67k
  uintX_t Size = Sec->sh_size;
382
3.67k
383
3.67k
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
3.67k
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
3.67k
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
3.67k
395
3.67k
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
3.67k
399
3.67k
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
3.67k
  return makeArrayRef(Start, Size / sizeof(T));
401
3.67k
}
llvm::Expected<llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)0, 1ul> > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSectionContentsAsArray<llvm::support::detail::packed_endian_specific_integral<unsigned int, (llvm::support::endianness)0, 1ul> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*) const
Line
Count
Source
375
1
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
1
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
1
380
1
  uintX_t Offset = Sec->sh_offset;
381
1
  uintX_t Size = Sec->sh_size;
382
1
383
1
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
1
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
1
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
1
395
1
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
1
399
1
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
1
  return makeArrayRef(Start, Size / sizeof(T));
401
1
}
llvm::Expected<llvm::ArrayRef<llvm::object::Elf_Dyn_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSectionContentsAsArray<llvm::object::Elf_Dyn_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*) const
Line
Count
Source
375
15
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
15
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
15
380
15
  uintX_t Offset = Sec->sh_offset;
381
15
  uintX_t Size = Sec->sh_size;
382
15
383
15
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
15
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
15
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
15
395
15
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
15
399
15
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
15
  return makeArrayRef(Start, Size / sizeof(T));
401
15
}
llvm::Expected<llvm::ArrayRef<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSectionContentsAsArray<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*) const
Line
Count
Source
375
2.10k
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
2.10k
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
2.10k
380
2.10k
  uintX_t Offset = Sec->sh_offset;
381
2.10k
  uintX_t Size = Sec->sh_size;
382
2.10k
383
2.10k
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
2.10k
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
2.10k
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
2.10k
395
2.10k
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
2.10k
399
2.10k
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
2.10k
  return makeArrayRef(Start, Size / sizeof(T));
401
2.10k
}
llvm::Expected<llvm::ArrayRef<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, true> > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSectionContentsAsArray<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, true> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*) const
Line
Count
Source
375
199
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
199
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
199
380
199
  uintX_t Offset = Sec->sh_offset;
381
199
  uintX_t Size = Sec->sh_size;
382
199
383
199
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
199
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
199
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
199
395
199
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
199
399
199
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
199
  return makeArrayRef(Start, Size / sizeof(T));
401
199
}
llvm::Expected<llvm::ArrayRef<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, false> > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSectionContentsAsArray<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, false> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*) const
Line
Count
Source
375
7
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
7
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 10
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
7
380
7
  uintX_t Offset = Sec->sh_offset;
381
7
  uintX_t Size = Sec->sh_size;
382
7
383
7
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
7
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
7
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
7
395
7
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
7
399
7
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
7
  return makeArrayRef(Start, Size / sizeof(T));
401
7
}
Unexecuted instantiation: llvm::Expected<llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned long long, (llvm::support::endianness)0, 1ul> > > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSectionContentsAsArray<llvm::support::detail::packed_endian_specific_integral<unsigned long long, (llvm::support::endianness)0, 1ul> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*) const
llvm::Expected<llvm::ArrayRef<unsigned char> > llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSectionContentsAsArray<unsigned char>(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*) const
Line
Count
Source
375
840
ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr *Sec) const {
376
840
  if (Sec->sh_entsize != sizeof(T) && 
sizeof(T) != 1780
)
377
0
    return createError("section " + getSecIndexForError(this, Sec) +
378
0
                       " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
379
840
380
840
  uintX_t Offset = Sec->sh_offset;
381
840
  uintX_t Size = Sec->sh_size;
382
840
383
840
  if (Size % sizeof(T))
384
0
    return createError("section " + getSecIndexForError(this, Sec) +
385
0
                       " has an invalid sh_size (" + Twine(Size) +
386
0
                       ") which is not a multiple of its sh_entsize (" +
387
0
                       Twine(Sec->sh_entsize) + ")");
388
840
  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
389
840
      Offset + Size > Buf.size())
390
0
    return createError("section " + getSecIndexForError(this, Sec) +
391
0
                       " has a sh_offset (0x" + Twine::utohexstr(Offset) +
392
0
                       ") + sh_size (0x" + Twine(Size) +
393
0
                       ") that cannot be represented");
394
840
395
840
  if (Offset % alignof(T))
396
0
    // TODO: this error is untested.
397
0
    return createError("unaligned data");
398
840
399
840
  const T *Start = reinterpret_cast<const T *>(base() + Offset);
400
840
  return makeArrayRef(Start, Size / sizeof(T));
401
840
}
402
403
template <class ELFT>
404
Expected<ArrayRef<uint8_t>>
405
341k
ELFFile<ELFT>::getSectionContents(const Elf_Shdr *Sec) const {
406
341k
  return getSectionContentsAsArray<uint8_t>(Sec);
407
341k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSectionContents(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*) const
Line
Count
Source
405
2.49k
ELFFile<ELFT>::getSectionContents(const Elf_Shdr *Sec) const {
406
2.49k
  return getSectionContentsAsArray<uint8_t>(Sec);
407
2.49k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSectionContents(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*) const
Line
Count
Source
405
1.12k
ELFFile<ELFT>::getSectionContents(const Elf_Shdr *Sec) const {
406
1.12k
  return getSectionContentsAsArray<uint8_t>(Sec);
407
1.12k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSectionContents(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*) const
Line
Count
Source
405
337k
ELFFile<ELFT>::getSectionContents(const Elf_Shdr *Sec) const {
406
337k
  return getSectionContentsAsArray<uint8_t>(Sec);
407
337k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSectionContents(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*) const
Line
Count
Source
405
528
ELFFile<ELFT>::getSectionContents(const Elf_Shdr *Sec) const {
406
528
  return getSectionContentsAsArray<uint8_t>(Sec);
407
528
}
408
409
template <class ELFT>
410
6.10k
StringRef ELFFile<ELFT>::getRelocationTypeName(uint32_t Type) const {
411
6.10k
  return getELFRelocationTypeName(getHeader()->e_machine, Type);
412
6.10k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getRelocationTypeName(unsigned int) const
Line
Count
Source
410
1.77k
StringRef ELFFile<ELFT>::getRelocationTypeName(uint32_t Type) const {
411
1.77k
  return getELFRelocationTypeName(getHeader()->e_machine, Type);
412
1.77k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getRelocationTypeName(unsigned int) const
Line
Count
Source
410
431
StringRef ELFFile<ELFT>::getRelocationTypeName(uint32_t Type) const {
411
431
  return getELFRelocationTypeName(getHeader()->e_machine, Type);
412
431
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getRelocationTypeName(unsigned int) const
Line
Count
Source
410
2.83k
StringRef ELFFile<ELFT>::getRelocationTypeName(uint32_t Type) const {
411
2.83k
  return getELFRelocationTypeName(getHeader()->e_machine, Type);
412
2.83k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getRelocationTypeName(unsigned int) const
Line
Count
Source
410
1.07k
StringRef ELFFile<ELFT>::getRelocationTypeName(uint32_t Type) const {
411
1.07k
  return getELFRelocationTypeName(getHeader()->e_machine, Type);
412
1.07k
}
413
414
template <class ELFT>
415
void ELFFile<ELFT>::getRelocationTypeName(uint32_t Type,
416
5.68k
                                          SmallVectorImpl<char> &Result) const {
417
5.68k
  if (!isMipsELF64()) {
418
5.47k
    StringRef Name = getRelocationTypeName(Type);
419
5.47k
    Result.append(Name.begin(), Name.end());
420
5.47k
  } else {
421
211
    // The Mips N64 ABI allows up to three operations to be specified per
422
211
    // relocation record. Unfortunately there's no easy way to test for the
423
211
    // presence of N64 ELFs as they have no special flag that identifies them
424
211
    // as being N64. We can safely assume at the moment that all Mips
425
211
    // ELFCLASS64 ELFs are N64. New Mips64 ABIs should provide enough
426
211
    // information to disambiguate between old vs new ABIs.
427
211
    uint8_t Type1 = (Type >> 0) & 0xFF;
428
211
    uint8_t Type2 = (Type >> 8) & 0xFF;
429
211
    uint8_t Type3 = (Type >> 16) & 0xFF;
430
211
431
211
    // Concat all three relocation type names.
432
211
    StringRef Name = getRelocationTypeName(Type1);
433
211
    Result.append(Name.begin(), Name.end());
434
211
435
211
    Name = getRelocationTypeName(Type2);
436
211
    Result.append(1, '/');
437
211
    Result.append(Name.begin(), Name.end());
438
211
439
211
    Name = getRelocationTypeName(Type3);
440
211
    Result.append(1, '/');
441
211
    Result.append(Name.begin(), Name.end());
442
211
  }
443
5.68k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getRelocationTypeName(unsigned int, llvm::SmallVectorImpl<char>&) const
Line
Count
Source
416
1.77k
                                          SmallVectorImpl<char> &Result) const {
417
1.77k
  if (!isMipsELF64()) {
418
1.77k
    StringRef Name = getRelocationTypeName(Type);
419
1.77k
    Result.append(Name.begin(), Name.end());
420
1.77k
  } else {
421
0
    // The Mips N64 ABI allows up to three operations to be specified per
422
0
    // relocation record. Unfortunately there's no easy way to test for the
423
0
    // presence of N64 ELFs as they have no special flag that identifies them
424
0
    // as being N64. We can safely assume at the moment that all Mips
425
0
    // ELFCLASS64 ELFs are N64. New Mips64 ABIs should provide enough
426
0
    // information to disambiguate between old vs new ABIs.
427
0
    uint8_t Type1 = (Type >> 0) & 0xFF;
428
0
    uint8_t Type2 = (Type >> 8) & 0xFF;
429
0
    uint8_t Type3 = (Type >> 16) & 0xFF;
430
0
431
0
    // Concat all three relocation type names.
432
0
    StringRef Name = getRelocationTypeName(Type1);
433
0
    Result.append(Name.begin(), Name.end());
434
0
435
0
    Name = getRelocationTypeName(Type2);
436
0
    Result.append(1, '/');
437
0
    Result.append(Name.begin(), Name.end());
438
0
439
0
    Name = getRelocationTypeName(Type3);
440
0
    Result.append(1, '/');
441
0
    Result.append(Name.begin(), Name.end());
442
0
  }
443
1.77k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getRelocationTypeName(unsigned int, llvm::SmallVectorImpl<char>&) const
Line
Count
Source
416
431
                                          SmallVectorImpl<char> &Result) const {
417
431
  if (!isMipsELF64()) {
418
431
    StringRef Name = getRelocationTypeName(Type);
419
431
    Result.append(Name.begin(), Name.end());
420
431
  } else {
421
0
    // The Mips N64 ABI allows up to three operations to be specified per
422
0
    // relocation record. Unfortunately there's no easy way to test for the
423
0
    // presence of N64 ELFs as they have no special flag that identifies them
424
0
    // as being N64. We can safely assume at the moment that all Mips
425
0
    // ELFCLASS64 ELFs are N64. New Mips64 ABIs should provide enough
426
0
    // information to disambiguate between old vs new ABIs.
427
0
    uint8_t Type1 = (Type >> 0) & 0xFF;
428
0
    uint8_t Type2 = (Type >> 8) & 0xFF;
429
0
    uint8_t Type3 = (Type >> 16) & 0xFF;
430
0
431
0
    // Concat all three relocation type names.
432
0
    StringRef Name = getRelocationTypeName(Type1);
433
0
    Result.append(Name.begin(), Name.end());
434
0
435
0
    Name = getRelocationTypeName(Type2);
436
0
    Result.append(1, '/');
437
0
    Result.append(Name.begin(), Name.end());
438
0
439
0
    Name = getRelocationTypeName(Type3);
440
0
    Result.append(1, '/');
441
0
    Result.append(Name.begin(), Name.end());
442
0
  }
443
431
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getRelocationTypeName(unsigned int, llvm::SmallVectorImpl<char>&) const
Line
Count
Source
416
2.64k
                                          SmallVectorImpl<char> &Result) const {
417
2.64k
  if (!isMipsELF64()) {
418
2.55k
    StringRef Name = getRelocationTypeName(Type);
419
2.55k
    Result.append(Name.begin(), Name.end());
420
2.55k
  } else {
421
92
    // The Mips N64 ABI allows up to three operations to be specified per
422
92
    // relocation record. Unfortunately there's no easy way to test for the
423
92
    // presence of N64 ELFs as they have no special flag that identifies them
424
92
    // as being N64. We can safely assume at the moment that all Mips
425
92
    // ELFCLASS64 ELFs are N64. New Mips64 ABIs should provide enough
426
92
    // information to disambiguate between old vs new ABIs.
427
92
    uint8_t Type1 = (Type >> 0) & 0xFF;
428
92
    uint8_t Type2 = (Type >> 8) & 0xFF;
429
92
    uint8_t Type3 = (Type >> 16) & 0xFF;
430
92
431
92
    // Concat all three relocation type names.
432
92
    StringRef Name = getRelocationTypeName(Type1);
433
92
    Result.append(Name.begin(), Name.end());
434
92
435
92
    Name = getRelocationTypeName(Type2);
436
92
    Result.append(1, '/');
437
92
    Result.append(Name.begin(), Name.end());
438
92
439
92
    Name = getRelocationTypeName(Type3);
440
92
    Result.append(1, '/');
441
92
    Result.append(Name.begin(), Name.end());
442
92
  }
443
2.64k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getRelocationTypeName(unsigned int, llvm::SmallVectorImpl<char>&) const
Line
Count
Source
416
834
                                          SmallVectorImpl<char> &Result) const {
417
834
  if (!isMipsELF64()) {
418
715
    StringRef Name = getRelocationTypeName(Type);
419
715
    Result.append(Name.begin(), Name.end());
420
715
  } else {
421
119
    // The Mips N64 ABI allows up to three operations to be specified per
422
119
    // relocation record. Unfortunately there's no easy way to test for the
423
119
    // presence of N64 ELFs as they have no special flag that identifies them
424
119
    // as being N64. We can safely assume at the moment that all Mips
425
119
    // ELFCLASS64 ELFs are N64. New Mips64 ABIs should provide enough
426
119
    // information to disambiguate between old vs new ABIs.
427
119
    uint8_t Type1 = (Type >> 0) & 0xFF;
428
119
    uint8_t Type2 = (Type >> 8) & 0xFF;
429
119
    uint8_t Type3 = (Type >> 16) & 0xFF;
430
119
431
119
    // Concat all three relocation type names.
432
119
    StringRef Name = getRelocationTypeName(Type1);
433
119
    Result.append(Name.begin(), Name.end());
434
119
435
119
    Name = getRelocationTypeName(Type2);
436
119
    Result.append(1, '/');
437
119
    Result.append(Name.begin(), Name.end());
438
119
439
119
    Name = getRelocationTypeName(Type3);
440
119
    Result.append(1, '/');
441
119
    Result.append(Name.begin(), Name.end());
442
119
  }
443
834
}
444
445
template <class ELFT>
446
16
uint32_t ELFFile<ELFT>::getRelativeRelocationType() const {
447
16
  return getELFRelativeRelocationType(getHeader()->e_machine);
448
16
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getRelativeRelocationType() const
Line
Count
Source
446
4
uint32_t ELFFile<ELFT>::getRelativeRelocationType() const {
447
4
  return getELFRelativeRelocationType(getHeader()->e_machine);
448
4
}
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getRelativeRelocationType() const
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getRelativeRelocationType() const
Line
Count
Source
446
12
uint32_t ELFFile<ELFT>::getRelativeRelocationType() const {
447
12
  return getELFRelativeRelocationType(getHeader()->e_machine);
448
12
}
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getRelativeRelocationType() const
449
450
template <class ELFT>
451
Expected<const typename ELFT::Sym *>
452
ELFFile<ELFT>::getRelocationSymbol(const Elf_Rel *Rel,
453
4.67k
                                   const Elf_Shdr *SymTab) const {
454
4.67k
  uint32_t Index = Rel->getSymbol(isMips64EL());
455
4.67k
  if (Index == 0)
456
1.09k
    return nullptr;
457
3.57k
  return getEntry<Elf_Sym>(SymTab, Index);
458
3.57k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getRelocationSymbol(llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, false> const*, llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*) const
Line
Count
Source
453
1.48k
                                   const Elf_Shdr *SymTab) const {
454
1.48k
  uint32_t Index = Rel->getSymbol(isMips64EL());
455
1.48k
  if (Index == 0)
456
394
    return nullptr;
457
1.08k
  return getEntry<Elf_Sym>(SymTab, Index);
458
1.08k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getRelocationSymbol(llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, false> const*, llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*) const
Line
Count
Source
453
348
                                   const Elf_Shdr *SymTab) const {
454
348
  uint32_t Index = Rel->getSymbol(isMips64EL());
455
348
  if (Index == 0)
456
151
    return nullptr;
457
197
  return getEntry<Elf_Sym>(SymTab, Index);
458
197
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getRelocationSymbol(llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, false> const*, llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*) const
Line
Count
Source
453
2.08k
                                   const Elf_Shdr *SymTab) const {
454
2.08k
  uint32_t Index = Rel->getSymbol(isMips64EL());
455
2.08k
  if (Index == 0)
456
456
    return nullptr;
457
1.62k
  return getEntry<Elf_Sym>(SymTab, Index);
458
1.62k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getRelocationSymbol(llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, false> const*, llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*) const
Line
Count
Source
453
760
                                   const Elf_Shdr *SymTab) const {
454
760
  uint32_t Index = Rel->getSymbol(isMips64EL());
455
760
  if (Index == 0)
456
95
    return nullptr;
457
665
  return getEntry<Elf_Sym>(SymTab, Index);
458
665
}
459
460
template <class ELFT>
461
Expected<StringRef>
462
661k
ELFFile<ELFT>::getSectionStringTable(Elf_Shdr_Range Sections) const {
463
661k
  uint32_t Index = getHeader()->e_shstrndx;
464
661k
  if (Index == ELF::SHN_XINDEX)
465
457k
    Index = Sections[0].sh_link;
466
661k
467
661k
  if (!Index) // no section string table.
468
5
    return "";
469
661k
  // TODO: Test a case when the sh_link of the section with index 0 is broken.
470
661k
  if (Index >= Sections.size())
471
1
    return createError("section header string table index " + Twine(Index) +
472
1
                       " does not exist");
473
661k
  return getStringTable(&Sections[Index]);
474
661k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSectionStringTable(llvm::ArrayRef<llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > >) const
Line
Count
Source
462
11.1k
ELFFile<ELFT>::getSectionStringTable(Elf_Shdr_Range Sections) const {
463
11.1k
  uint32_t Index = getHeader()->e_shstrndx;
464
11.1k
  if (Index == ELF::SHN_XINDEX)
465
0
    Index = Sections[0].sh_link;
466
11.1k
467
11.1k
  if (!Index) // no section string table.
468
4
    return "";
469
11.1k
  // TODO: Test a case when the sh_link of the section with index 0 is broken.
470
11.1k
  if (Index >= Sections.size())
471
0
    return createError("section header string table index " + Twine(Index) +
472
0
                       " does not exist");
473
11.1k
  return getStringTable(&Sections[Index]);
474
11.1k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSectionStringTable(llvm::ArrayRef<llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > >) const
Line
Count
Source
462
3.41k
ELFFile<ELFT>::getSectionStringTable(Elf_Shdr_Range Sections) const {
463
3.41k
  uint32_t Index = getHeader()->e_shstrndx;
464
3.41k
  if (Index == ELF::SHN_XINDEX)
465
0
    Index = Sections[0].sh_link;
466
3.41k
467
3.41k
  if (!Index) // no section string table.
468
0
    return "";
469
3.41k
  // TODO: Test a case when the sh_link of the section with index 0 is broken.
470
3.41k
  if (Index >= Sections.size())
471
0
    return createError("section header string table index " + Twine(Index) +
472
0
                       " does not exist");
473
3.41k
  return getStringTable(&Sections[Index]);
474
3.41k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSectionStringTable(llvm::ArrayRef<llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > >) const
Line
Count
Source
462
644k
ELFFile<ELFT>::getSectionStringTable(Elf_Shdr_Range Sections) const {
463
644k
  uint32_t Index = getHeader()->e_shstrndx;
464
644k
  if (Index == ELF::SHN_XINDEX)
465
457k
    Index = Sections[0].sh_link;
466
644k
467
644k
  if (!Index) // no section string table.
468
1
    return "";
469
644k
  // TODO: Test a case when the sh_link of the section with index 0 is broken.
470
644k
  if (Index >= Sections.size())
471
1
    return createError("section header string table index " + Twine(Index) +
472
1
                       " does not exist");
473
644k
  return getStringTable(&Sections[Index]);
474
644k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSectionStringTable(llvm::ArrayRef<llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > >) const
Line
Count
Source
462
2.49k
ELFFile<ELFT>::getSectionStringTable(Elf_Shdr_Range Sections) const {
463
2.49k
  uint32_t Index = getHeader()->e_shstrndx;
464
2.49k
  if (Index == ELF::SHN_XINDEX)
465
0
    Index = Sections[0].sh_link;
466
2.49k
467
2.49k
  if (!Index) // no section string table.
468
0
    return "";
469
2.49k
  // TODO: Test a case when the sh_link of the section with index 0 is broken.
470
2.49k
  if (Index >= Sections.size())
471
0
    return createError("section header string table index " + Twine(Index) +
472
0
                       " does not exist");
473
2.49k
  return getStringTable(&Sections[Index]);
474
2.49k
}
475
476
785k
template <class ELFT> ELFFile<ELFT>::ELFFile(StringRef Object) : Buf(Object) {}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::ELFFile(llvm::StringRef)
Line
Count
Source
476
9.13k
template <class ELFT> ELFFile<ELFT>::ELFFile(StringRef Object) : Buf(Object) {}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::ELFFile(llvm::StringRef)
Line
Count
Source
476
4.33k
template <class ELFT> ELFFile<ELFT>::ELFFile(StringRef Object) : Buf(Object) {}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::ELFFile(llvm::StringRef)
Line
Count
Source
476
760k
template <class ELFT> ELFFile<ELFT>::ELFFile(StringRef Object) : Buf(Object) {}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::ELFFile(llvm::StringRef)
Line
Count
Source
476
12.3k
template <class ELFT> ELFFile<ELFT>::ELFFile(StringRef Object) : Buf(Object) {}
477
478
template <class ELFT>
479
785k
Expected<ELFFile<ELFT>> ELFFile<ELFT>::create(StringRef Object) {
480
785k
  if (sizeof(Elf_Ehdr) > Object.size())
481
1
    return createError("invalid buffer: the size (" + Twine(Object.size()) +
482
1
                       ") is smaller than an ELF header (" +
483
1
                       Twine(sizeof(Elf_Ehdr)) + ")");
484
785k
  return ELFFile(Object);
485
785k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::create(llvm::StringRef)
Line
Count
Source
479
9.13k
Expected<ELFFile<ELFT>> ELFFile<ELFT>::create(StringRef Object) {
480
9.13k
  if (sizeof(Elf_Ehdr) > Object.size())
481
0
    return createError("invalid buffer: the size (" + Twine(Object.size()) +
482
0
                       ") is smaller than an ELF header (" +
483
0
                       Twine(sizeof(Elf_Ehdr)) + ")");
484
9.13k
  return ELFFile(Object);
485
9.13k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::create(llvm::StringRef)
Line
Count
Source
479
4.33k
Expected<ELFFile<ELFT>> ELFFile<ELFT>::create(StringRef Object) {
480
4.33k
  if (sizeof(Elf_Ehdr) > Object.size())
481
0
    return createError("invalid buffer: the size (" + Twine(Object.size()) +
482
0
                       ") is smaller than an ELF header (" +
483
0
                       Twine(sizeof(Elf_Ehdr)) + ")");
484
4.33k
  return ELFFile(Object);
485
4.33k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::create(llvm::StringRef)
Line
Count
Source
479
760k
Expected<ELFFile<ELFT>> ELFFile<ELFT>::create(StringRef Object) {
480
760k
  if (sizeof(Elf_Ehdr) > Object.size())
481
1
    return createError("invalid buffer: the size (" + Twine(Object.size()) +
482
1
                       ") is smaller than an ELF header (" +
483
1
                       Twine(sizeof(Elf_Ehdr)) + ")");
484
760k
  return ELFFile(Object);
485
760k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::create(llvm::StringRef)
Line
Count
Source
479
12.3k
Expected<ELFFile<ELFT>> ELFFile<ELFT>::create(StringRef Object) {
480
12.3k
  if (sizeof(Elf_Ehdr) > Object.size())
481
0
    return createError("invalid buffer: the size (" + Twine(Object.size()) +
482
0
                       ") is smaller than an ELF header (" +
483
0
                       Twine(sizeof(Elf_Ehdr)) + ")");
484
12.3k
  return ELFFile(Object);
485
12.3k
}
486
487
template <class ELFT>
488
1.53M
Expected<typename ELFT::ShdrRange> ELFFile<ELFT>::sections() const {
489
1.53M
  const uintX_t SectionTableOffset = getHeader()->e_shoff;
490
1.53M
  if (SectionTableOffset == 0)
491
84
    return ArrayRef<Elf_Shdr>();
492
1.53M
493
1.53M
  if (getHeader()->e_shentsize != sizeof(Elf_Shdr))
494
1
    return createError("invalid e_shentsize in ELF header: " +
495
1
                       Twine(getHeader()->e_shentsize));
496
1.53M
497
1.53M
  const uint64_t FileSize = Buf.size();
498
1.53M
  if (SectionTableOffset + sizeof(Elf_Shdr) > FileSize)
499
3
    return createError(
500
3
        "section header table goes past the end of the file: e_shoff = 0x" +
501
3
        Twine::utohexstr(SectionTableOffset));
502
1.53M
503
1.53M
  // Invalid address alignment of section headers
504
1.53M
  if (SectionTableOffset & (alignof(Elf_Shdr) - 1))
505
0
    // TODO: this error is untested.
506
0
    return createError("invalid alignment of section headers");
507
1.53M
508
1.53M
  const Elf_Shdr *First =
509
1.53M
      reinterpret_cast<const Elf_Shdr *>(base() + SectionTableOffset);
510
1.53M
511
1.53M
  uintX_t NumSections = getHeader()->e_shnum;
512
1.53M
  if (NumSections == 0)
513
719k
    NumSections = First->sh_size;
514
1.53M
515
1.53M
  if (NumSections > UINT64_MAX / sizeof(Elf_Shdr))
516
0
    // TODO: this error is untested.
517
0
    return createError("section table goes past the end of file");
518
1.53M
519
1.53M
  const uint64_t SectionTableSize = NumSections * sizeof(Elf_Shdr);
520
1.53M
521
1.53M
  // Section table goes past end of file!
522
1.53M
  if (SectionTableOffset + SectionTableSize > FileSize)
523
1
    return createError("section table goes past the end of file");
524
1.53M
525
1.53M
  return makeArrayRef(First, NumSections);
526
1.53M
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::sections() const
Line
Count
Source
488
197k
Expected<typename ELFT::ShdrRange> ELFFile<ELFT>::sections() const {
489
197k
  const uintX_t SectionTableOffset = getHeader()->e_shoff;
490
197k
  if (SectionTableOffset == 0)
491
0
    return ArrayRef<Elf_Shdr>();
492
197k
493
197k
  if (getHeader()->e_shentsize != sizeof(Elf_Shdr))
494
0
    return createError("invalid e_shentsize in ELF header: " +
495
0
                       Twine(getHeader()->e_shentsize));
496
197k
497
197k
  const uint64_t FileSize = Buf.size();
498
197k
  if (SectionTableOffset + sizeof(Elf_Shdr) > FileSize)
499
0
    return createError(
500
0
        "section header table goes past the end of the file: e_shoff = 0x" +
501
0
        Twine::utohexstr(SectionTableOffset));
502
197k
503
197k
  // Invalid address alignment of section headers
504
197k
  if (SectionTableOffset & (alignof(Elf_Shdr) - 1))
505
0
    // TODO: this error is untested.
506
0
    return createError("invalid alignment of section headers");
507
197k
508
197k
  const Elf_Shdr *First =
509
197k
      reinterpret_cast<const Elf_Shdr *>(base() + SectionTableOffset);
510
197k
511
197k
  uintX_t NumSections = getHeader()->e_shnum;
512
197k
  if (NumSections == 0)
513
0
    NumSections = First->sh_size;
514
197k
515
197k
  if (NumSections > UINT64_MAX / sizeof(Elf_Shdr))
516
0
    // TODO: this error is untested.
517
0
    return createError("section table goes past the end of file");
518
197k
519
197k
  const uint64_t SectionTableSize = NumSections * sizeof(Elf_Shdr);
520
197k
521
197k
  // Section table goes past end of file!
522
197k
  if (SectionTableOffset + SectionTableSize > FileSize)
523
0
    return createError("section table goes past the end of file");
524
197k
525
197k
  return makeArrayRef(First, NumSections);
526
197k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::sections() const
Line
Count
Source
488
25.5k
Expected<typename ELFT::ShdrRange> ELFFile<ELFT>::sections() const {
489
25.5k
  const uintX_t SectionTableOffset = getHeader()->e_shoff;
490
25.5k
  if (SectionTableOffset == 0)
491
0
    return ArrayRef<Elf_Shdr>();
492
25.5k
493
25.5k
  if (getHeader()->e_shentsize != sizeof(Elf_Shdr))
494
0
    return createError("invalid e_shentsize in ELF header: " +
495
0
                       Twine(getHeader()->e_shentsize));
496
25.5k
497
25.5k
  const uint64_t FileSize = Buf.size();
498
25.5k
  if (SectionTableOffset + sizeof(Elf_Shdr) > FileSize)
499
0
    return createError(
500
0
        "section header table goes past the end of the file: e_shoff = 0x" +
501
0
        Twine::utohexstr(SectionTableOffset));
502
25.5k
503
25.5k
  // Invalid address alignment of section headers
504
25.5k
  if (SectionTableOffset & (alignof(Elf_Shdr) - 1))
505
0
    // TODO: this error is untested.
506
0
    return createError("invalid alignment of section headers");
507
25.5k
508
25.5k
  const Elf_Shdr *First =
509
25.5k
      reinterpret_cast<const Elf_Shdr *>(base() + SectionTableOffset);
510
25.5k
511
25.5k
  uintX_t NumSections = getHeader()->e_shnum;
512
25.5k
  if (NumSections == 0)
513
0
    NumSections = First->sh_size;
514
25.5k
515
25.5k
  if (NumSections > UINT64_MAX / sizeof(Elf_Shdr))
516
0
    // TODO: this error is untested.
517
0
    return createError("section table goes past the end of file");
518
25.5k
519
25.5k
  const uint64_t SectionTableSize = NumSections * sizeof(Elf_Shdr);
520
25.5k
521
25.5k
  // Section table goes past end of file!
522
25.5k
  if (SectionTableOffset + SectionTableSize > FileSize)
523
0
    return createError("section table goes past the end of file");
524
25.5k
525
25.5k
  return makeArrayRef(First, NumSections);
526
25.5k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::sections() const
Line
Count
Source
488
1.28M
Expected<typename ELFT::ShdrRange> ELFFile<ELFT>::sections() const {
489
1.28M
  const uintX_t SectionTableOffset = getHeader()->e_shoff;
490
1.28M
  if (SectionTableOffset == 0)
491
84
    return ArrayRef<Elf_Shdr>();
492
1.28M
493
1.28M
  if (getHeader()->e_shentsize != sizeof(Elf_Shdr))
494
1
    return createError("invalid e_shentsize in ELF header: " +
495
1
                       Twine(getHeader()->e_shentsize));
496
1.28M
497
1.28M
  const uint64_t FileSize = Buf.size();
498
1.28M
  if (SectionTableOffset + sizeof(Elf_Shdr) > FileSize)
499
3
    return createError(
500
3
        "section header table goes past the end of the file: e_shoff = 0x" +
501
3
        Twine::utohexstr(SectionTableOffset));
502
1.28M
503
1.28M
  // Invalid address alignment of section headers
504
1.28M
  if (SectionTableOffset & (alignof(Elf_Shdr) - 1))
505
0
    // TODO: this error is untested.
506
0
    return createError("invalid alignment of section headers");
507
1.28M
508
1.28M
  const Elf_Shdr *First =
509
1.28M
      reinterpret_cast<const Elf_Shdr *>(base() + SectionTableOffset);
510
1.28M
511
1.28M
  uintX_t NumSections = getHeader()->e_shnum;
512
1.28M
  if (NumSections == 0)
513
719k
    NumSections = First->sh_size;
514
1.28M
515
1.28M
  if (NumSections > UINT64_MAX / sizeof(Elf_Shdr))
516
0
    // TODO: this error is untested.
517
0
    return createError("section table goes past the end of file");
518
1.28M
519
1.28M
  const uint64_t SectionTableSize = NumSections * sizeof(Elf_Shdr);
520
1.28M
521
1.28M
  // Section table goes past end of file!
522
1.28M
  if (SectionTableOffset + SectionTableSize > FileSize)
523
1
    return createError("section table goes past the end of file");
524
1.28M
525
1.28M
  return makeArrayRef(First, NumSections);
526
1.28M
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::sections() const
Line
Count
Source
488
18.9k
Expected<typename ELFT::ShdrRange> ELFFile<ELFT>::sections() const {
489
18.9k
  const uintX_t SectionTableOffset = getHeader()->e_shoff;
490
18.9k
  if (SectionTableOffset == 0)
491
0
    return ArrayRef<Elf_Shdr>();
492
18.9k
493
18.9k
  if (getHeader()->e_shentsize != sizeof(Elf_Shdr))
494
0
    return createError("invalid e_shentsize in ELF header: " +
495
0
                       Twine(getHeader()->e_shentsize));
496
18.9k
497
18.9k
  const uint64_t FileSize = Buf.size();
498
18.9k
  if (SectionTableOffset + sizeof(Elf_Shdr) > FileSize)
499
0
    return createError(
500
0
        "section header table goes past the end of the file: e_shoff = 0x" +
501
0
        Twine::utohexstr(SectionTableOffset));
502
18.9k
503
18.9k
  // Invalid address alignment of section headers
504
18.9k
  if (SectionTableOffset & (alignof(Elf_Shdr) - 1))
505
0
    // TODO: this error is untested.
506
0
    return createError("invalid alignment of section headers");
507
18.9k
508
18.9k
  const Elf_Shdr *First =
509
18.9k
      reinterpret_cast<const Elf_Shdr *>(base() + SectionTableOffset);
510
18.9k
511
18.9k
  uintX_t NumSections = getHeader()->e_shnum;
512
18.9k
  if (NumSections == 0)
513
0
    NumSections = First->sh_size;
514
18.9k
515
18.9k
  if (NumSections > UINT64_MAX / sizeof(Elf_Shdr))
516
0
    // TODO: this error is untested.
517
0
    return createError("section table goes past the end of file");
518
18.9k
519
18.9k
  const uint64_t SectionTableSize = NumSections * sizeof(Elf_Shdr);
520
18.9k
521
18.9k
  // Section table goes past end of file!
522
18.9k
  if (SectionTableOffset + SectionTableSize > FileSize)
523
0
    return createError("section table goes past the end of file");
524
18.9k
525
18.9k
  return makeArrayRef(First, NumSections);
526
18.9k
}
527
528
template <class ELFT>
529
template <typename T>
530
Expected<const T *> ELFFile<ELFT>::getEntry(uint32_t Section,
531
250k
                                            uint32_t Entry) const {
532
250k
  auto SecOrErr = getSection(Section);
533
250k
  if (!SecOrErr)
534
0
    return SecOrErr.takeError();
535
250k
  return getEntry<T>(*SecOrErr, Entry);
536
250k
}
llvm::Expected<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getEntry<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > >(unsigned int, unsigned int) const
Line
Count
Source
531
57.4k
                                            uint32_t Entry) const {
532
57.4k
  auto SecOrErr = getSection(Section);
533
57.4k
  if (!SecOrErr)
534
0
    return SecOrErr.takeError();
535
57.4k
  return getEntry<T>(*SecOrErr, Entry);
536
57.4k
}
llvm::Expected<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, false> const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getEntry<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, false> >(unsigned int, unsigned int) const
Line
Count
Source
531
2.81k
                                            uint32_t Entry) const {
532
2.81k
  auto SecOrErr = getSection(Section);
533
2.81k
  if (!SecOrErr)
534
0
    return SecOrErr.takeError();
535
2.81k
  return getEntry<T>(*SecOrErr, Entry);
536
2.81k
}
llvm::Expected<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, true> const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getEntry<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, true> >(unsigned int, unsigned int) const
Line
Count
Source
531
1.99k
                                            uint32_t Entry) const {
532
1.99k
  auto SecOrErr = getSection(Section);
533
1.99k
  if (!SecOrErr)
534
0
    return SecOrErr.takeError();
535
1.99k
  return getEntry<T>(*SecOrErr, Entry);
536
1.99k
}
llvm::Expected<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getEntry<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > >(unsigned int, unsigned int) const
Line
Count
Source
531
5.56k
                                            uint32_t Entry) const {
532
5.56k
  auto SecOrErr = getSection(Section);
533
5.56k
  if (!SecOrErr)
534
0
    return SecOrErr.takeError();
535
5.56k
  return getEntry<T>(*SecOrErr, Entry);
536
5.56k
}
llvm::Expected<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, false> const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getEntry<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, false> >(unsigned int, unsigned int) const
Line
Count
Source
531
1.03k
                                            uint32_t Entry) const {
532
1.03k
  auto SecOrErr = getSection(Section);
533
1.03k
  if (!SecOrErr)
534
0
    return SecOrErr.takeError();
535
1.03k
  return getEntry<T>(*SecOrErr, Entry);
536
1.03k
}
llvm::Expected<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, true> const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getEntry<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, true> >(unsigned int, unsigned int) const
Line
Count
Source
531
668
                                            uint32_t Entry) const {
532
668
  auto SecOrErr = getSection(Section);
533
668
  if (!SecOrErr)
534
0
    return SecOrErr.takeError();
535
668
  return getEntry<T>(*SecOrErr, Entry);
536
668
}
llvm::Expected<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getEntry<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > >(unsigned int, unsigned int) const
Line
Count
Source
531
141k
                                            uint32_t Entry) const {
532
141k
  auto SecOrErr = getSection(Section);
533
141k
  if (!SecOrErr)
534
0
    return SecOrErr.takeError();
535
141k
  return getEntry<T>(*SecOrErr, Entry);
536
141k
}
llvm::Expected<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, false> const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getEntry<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, false> >(unsigned int, unsigned int) const
Line
Count
Source
531
256
                                            uint32_t Entry) const {
532
256
  auto SecOrErr = getSection(Section);
533
256
  if (!SecOrErr)
534
0
    return SecOrErr.takeError();
535
256
  return getEntry<T>(*SecOrErr, Entry);
536
256
}
llvm::Expected<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, true> const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getEntry<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, true> >(unsigned int, unsigned int) const
Line
Count
Source
531
34.6k
                                            uint32_t Entry) const {
532
34.6k
  auto SecOrErr = getSection(Section);
533
34.6k
  if (!SecOrErr)
534
0
    return SecOrErr.takeError();
535
34.6k
  return getEntry<T>(*SecOrErr, Entry);
536
34.6k
}
llvm::Expected<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getEntry<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > >(unsigned int, unsigned int) const
Line
Count
Source
531
3.51k
                                            uint32_t Entry) const {
532
3.51k
  auto SecOrErr = getSection(Section);
533
3.51k
  if (!SecOrErr)
534
0
    return SecOrErr.takeError();
535
3.51k
  return getEntry<T>(*SecOrErr, Entry);
536
3.51k
}
llvm::Expected<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, false> const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getEntry<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, false> >(unsigned int, unsigned int) const
Line
Count
Source
531
138
                                            uint32_t Entry) const {
532
138
  auto SecOrErr = getSection(Section);
533
138
  if (!SecOrErr)
534
0
    return SecOrErr.takeError();
535
138
  return getEntry<T>(*SecOrErr, Entry);
536
138
}
llvm::Expected<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, true> const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getEntry<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, true> >(unsigned int, unsigned int) const
Line
Count
Source
531
1.32k
                                            uint32_t Entry) const {
532
1.32k
  auto SecOrErr = getSection(Section);
533
1.32k
  if (!SecOrErr)
534
0
    return SecOrErr.takeError();
535
1.32k
  return getEntry<T>(*SecOrErr, Entry);
536
1.32k
}
537
538
template <class ELFT>
539
template <typename T>
540
Expected<const T *> ELFFile<ELFT>::getEntry(const Elf_Shdr *Section,
541
254k
                                            uint32_t Entry) const {
542
254k
  if (sizeof(T) != Section->sh_entsize)
543
0
    // TODO: this error is untested.
544
0
    return createError("invalid sh_entsize");
545
254k
  size_t Pos = Section->sh_offset + Entry * sizeof(T);
546
254k
  if (Pos + sizeof(T) > Buf.size())
547
1
    return createError("unable to access section " +
548
1
                       getSecIndexForError(this, Section) + " data at 0x" +
549
1
                       Twine::utohexstr(Pos) +
550
1
                       ": offset goes past the end of file");
551
254k
  return reinterpret_cast<const T *>(base() + Pos);
552
254k
}
llvm::Expected<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getEntry<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*, unsigned int) const
Line
Count
Source
541
58.5k
                                            uint32_t Entry) const {
542
58.5k
  if (sizeof(T) != Section->sh_entsize)
543
0
    // TODO: this error is untested.
544
0
    return createError("invalid sh_entsize");
545
58.5k
  size_t Pos = Section->sh_offset + Entry * sizeof(T);
546
58.5k
  if (Pos + sizeof(T) > Buf.size())
547
0
    return createError("unable to access section " +
548
0
                       getSecIndexForError(this, Section) + " data at 0x" +
549
0
                       Twine::utohexstr(Pos) +
550
0
                       ": offset goes past the end of file");
551
58.5k
  return reinterpret_cast<const T *>(base() + Pos);
552
58.5k
}
llvm::Expected<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getEntry<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*, unsigned int) const
Line
Count
Source
541
5.76k
                                            uint32_t Entry) const {
542
5.76k
  if (sizeof(T) != Section->sh_entsize)
543
0
    // TODO: this error is untested.
544
0
    return createError("invalid sh_entsize");
545
5.76k
  size_t Pos = Section->sh_offset + Entry * sizeof(T);
546
5.76k
  if (Pos + sizeof(T) > Buf.size())
547
0
    return createError("unable to access section " +
548
0
                       getSecIndexForError(this, Section) + " data at 0x" +
549
0
                       Twine::utohexstr(Pos) +
550
0
                       ": offset goes past the end of file");
551
5.76k
  return reinterpret_cast<const T *>(base() + Pos);
552
5.76k
}
llvm::Expected<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getEntry<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*, unsigned int) const
Line
Count
Source
541
143k
                                            uint32_t Entry) const {
542
143k
  if (sizeof(T) != Section->sh_entsize)
543
0
    // TODO: this error is untested.
544
0
    return createError("invalid sh_entsize");
545
143k
  size_t Pos = Section->sh_offset + Entry * sizeof(T);
546
143k
  if (Pos + sizeof(T) > Buf.size())
547
1
    return createError("unable to access section " +
548
1
                       getSecIndexForError(this, Section) + " data at 0x" +
549
1
                       Twine::utohexstr(Pos) +
550
1
                       ": offset goes past the end of file");
551
143k
  return reinterpret_cast<const T *>(base() + Pos);
552
143k
}
llvm::Expected<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getEntry<llvm::object::Elf_Sym_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*, unsigned int) const
Line
Count
Source
541
4.18k
                                            uint32_t Entry) const {
542
4.18k
  if (sizeof(T) != Section->sh_entsize)
543
0
    // TODO: this error is untested.
544
0
    return createError("invalid sh_entsize");
545
4.18k
  size_t Pos = Section->sh_offset + Entry * sizeof(T);
546
4.18k
  if (Pos + sizeof(T) > Buf.size())
547
0
    return createError("unable to access section " +
548
0
                       getSecIndexForError(this, Section) + " data at 0x" +
549
0
                       Twine::utohexstr(Pos) +
550
0
                       ": offset goes past the end of file");
551
4.18k
  return reinterpret_cast<const T *>(base() + Pos);
552
4.18k
}
llvm::Expected<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, false> const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getEntry<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, false> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*, unsigned int) const
Line
Count
Source
541
2.81k
                                            uint32_t Entry) const {
542
2.81k
  if (sizeof(T) != Section->sh_entsize)
543
0
    // TODO: this error is untested.
544
0
    return createError("invalid sh_entsize");
545
2.81k
  size_t Pos = Section->sh_offset + Entry * sizeof(T);
546
2.81k
  if (Pos + sizeof(T) > Buf.size())
547
0
    return createError("unable to access section " +
548
0
                       getSecIndexForError(this, Section) + " data at 0x" +
549
0
                       Twine::utohexstr(Pos) +
550
0
                       ": offset goes past the end of file");
551
2.81k
  return reinterpret_cast<const T *>(base() + Pos);
552
2.81k
}
llvm::Expected<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, true> const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getEntry<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, true> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*, unsigned int) const
Line
Count
Source
541
1.99k
                                            uint32_t Entry) const {
542
1.99k
  if (sizeof(T) != Section->sh_entsize)
543
0
    // TODO: this error is untested.
544
0
    return createError("invalid sh_entsize");
545
1.99k
  size_t Pos = Section->sh_offset + Entry * sizeof(T);
546
1.99k
  if (Pos + sizeof(T) > Buf.size())
547
0
    return createError("unable to access section " +
548
0
                       getSecIndexForError(this, Section) + " data at 0x" +
549
0
                       Twine::utohexstr(Pos) +
550
0
                       ": offset goes past the end of file");
551
1.99k
  return reinterpret_cast<const T *>(base() + Pos);
552
1.99k
}
llvm::Expected<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, false> const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getEntry<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, false> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*, unsigned int) const
Line
Count
Source
541
1.03k
                                            uint32_t Entry) const {
542
1.03k
  if (sizeof(T) != Section->sh_entsize)
543
0
    // TODO: this error is untested.
544
0
    return createError("invalid sh_entsize");
545
1.03k
  size_t Pos = Section->sh_offset + Entry * sizeof(T);
546
1.03k
  if (Pos + sizeof(T) > Buf.size())
547
0
    return createError("unable to access section " +
548
0
                       getSecIndexForError(this, Section) + " data at 0x" +
549
0
                       Twine::utohexstr(Pos) +
550
0
                       ": offset goes past the end of file");
551
1.03k
  return reinterpret_cast<const T *>(base() + Pos);
552
1.03k
}
llvm::Expected<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, true> const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getEntry<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, true> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*, unsigned int) const
Line
Count
Source
541
668
                                            uint32_t Entry) const {
542
668
  if (sizeof(T) != Section->sh_entsize)
543
0
    // TODO: this error is untested.
544
0
    return createError("invalid sh_entsize");
545
668
  size_t Pos = Section->sh_offset + Entry * sizeof(T);
546
668
  if (Pos + sizeof(T) > Buf.size())
547
0
    return createError("unable to access section " +
548
0
                       getSecIndexForError(this, Section) + " data at 0x" +
549
0
                       Twine::utohexstr(Pos) +
550
0
                       ": offset goes past the end of file");
551
668
  return reinterpret_cast<const T *>(base() + Pos);
552
668
}
llvm::Expected<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, false> const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getEntry<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, false> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*, unsigned int) const
Line
Count
Source
541
256
                                            uint32_t Entry) const {
542
256
  if (sizeof(T) != Section->sh_entsize)
543
0
    // TODO: this error is untested.
544
0
    return createError("invalid sh_entsize");
545
256
  size_t Pos = Section->sh_offset + Entry * sizeof(T);
546
256
  if (Pos + sizeof(T) > Buf.size())
547
0
    return createError("unable to access section " +
548
0
                       getSecIndexForError(this, Section) + " data at 0x" +
549
0
                       Twine::utohexstr(Pos) +
550
0
                       ": offset goes past the end of file");
551
256
  return reinterpret_cast<const T *>(base() + Pos);
552
256
}
llvm::Expected<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, true> const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getEntry<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, true> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*, unsigned int) const
Line
Count
Source
541
34.6k
                                            uint32_t Entry) const {
542
34.6k
  if (sizeof(T) != Section->sh_entsize)
543
0
    // TODO: this error is untested.
544
0
    return createError("invalid sh_entsize");
545
34.6k
  size_t Pos = Section->sh_offset + Entry * sizeof(T);
546
34.6k
  if (Pos + sizeof(T) > Buf.size())
547
0
    return createError("unable to access section " +
548
0
                       getSecIndexForError(this, Section) + " data at 0x" +
549
0
                       Twine::utohexstr(Pos) +
550
0
                       ": offset goes past the end of file");
551
34.6k
  return reinterpret_cast<const T *>(base() + Pos);
552
34.6k
}
llvm::Expected<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, false> const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getEntry<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, false> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*, unsigned int) const
Line
Count
Source
541
138
                                            uint32_t Entry) const {
542
138
  if (sizeof(T) != Section->sh_entsize)
543
0
    // TODO: this error is untested.
544
0
    return createError("invalid sh_entsize");
545
138
  size_t Pos = Section->sh_offset + Entry * sizeof(T);
546
138
  if (Pos + sizeof(T) > Buf.size())
547
0
    return createError("unable to access section " +
548
0
                       getSecIndexForError(this, Section) + " data at 0x" +
549
0
                       Twine::utohexstr(Pos) +
550
0
                       ": offset goes past the end of file");
551
138
  return reinterpret_cast<const T *>(base() + Pos);
552
138
}
llvm::Expected<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, true> const*> llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getEntry<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, true> >(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*, unsigned int) const
Line
Count
Source
541
1.32k
                                            uint32_t Entry) const {
542
1.32k
  if (sizeof(T) != Section->sh_entsize)
543
0
    // TODO: this error is untested.
544
0
    return createError("invalid sh_entsize");
545
1.32k
  size_t Pos = Section->sh_offset + Entry * sizeof(T);
546
1.32k
  if (Pos + sizeof(T) > Buf.size())
547
0
    return createError("unable to access section " +
548
0
                       getSecIndexForError(this, Section) + " data at 0x" +
549
0
                       Twine::utohexstr(Pos) +
550
0
                       ": offset goes past the end of file");
551
1.32k
  return reinterpret_cast<const T *>(base() + Pos);
552
1.32k
}
553
554
template <class ELFT>
555
Expected<const typename ELFT::Shdr *>
556
667k
ELFFile<ELFT>::getSection(uint32_t Index) const {
557
667k
  auto TableOrErr = sections();
558
667k
  if (!TableOrErr)
559
0
    return TableOrErr.takeError();
560
667k
  return object::getSection<ELFT>(*TableOrErr, Index);
561
667k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSection(unsigned int) const
Line
Count
Source
556
125k
ELFFile<ELFT>::getSection(uint32_t Index) const {
557
125k
  auto TableOrErr = sections();
558
125k
  if (!TableOrErr)
559
0
    return TableOrErr.takeError();
560
125k
  return object::getSection<ELFT>(*TableOrErr, Index);
561
125k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSection(unsigned int) const
Line
Count
Source
556
14.1k
ELFFile<ELFT>::getSection(uint32_t Index) const {
557
14.1k
  auto TableOrErr = sections();
558
14.1k
  if (!TableOrErr)
559
0
    return TableOrErr.takeError();
560
14.1k
  return object::getSection<ELFT>(*TableOrErr, Index);
561
14.1k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSection(unsigned int) const
Line
Count
Source
556
517k
ELFFile<ELFT>::getSection(uint32_t Index) const {
557
517k
  auto TableOrErr = sections();
558
517k
  if (!TableOrErr)
559
0
    return TableOrErr.takeError();
560
517k
  return object::getSection<ELFT>(*TableOrErr, Index);
561
517k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSection(unsigned int) const
Line
Count
Source
556
9.99k
ELFFile<ELFT>::getSection(uint32_t Index) const {
557
9.99k
  auto TableOrErr = sections();
558
9.99k
  if (!TableOrErr)
559
0
    return TableOrErr.takeError();
560
9.99k
  return object::getSection<ELFT>(*TableOrErr, Index);
561
9.99k
}
562
563
template <class ELFT>
564
Expected<const typename ELFT::Shdr *>
565
0
ELFFile<ELFT>::getSection(const StringRef SectionName) const {
566
0
  auto TableOrErr = sections();
567
0
  if (!TableOrErr)
568
0
    return TableOrErr.takeError();
569
0
  for (auto &Sec : *TableOrErr) {
570
0
    auto SecNameOrErr = getSectionName(&Sec);
571
0
    if (!SecNameOrErr)
572
0
      return SecNameOrErr.takeError();
573
0
    if (*SecNameOrErr == SectionName)
574
0
      return &Sec;
575
0
  }
576
0
  // TODO: this error is untested.
577
0
  return createError("invalid section name");
578
0
}
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSection(llvm::StringRef) const
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSection(llvm::StringRef) const
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSection(llvm::StringRef) const
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSection(llvm::StringRef) const
579
580
template <class ELFT>
581
Expected<StringRef>
582
706k
ELFFile<ELFT>::getStringTable(const Elf_Shdr *Section) const {
583
706k
  if (Section->sh_type != ELF::SHT_STRTAB)
584
15
    return createError("invalid sh_type for string table section " +
585
15
                       getSecIndexForError(this, Section) +
586
15
                       ": expected SHT_STRTAB, but got " +
587
15
                       object::getELFSectionTypeName(getHeader()->e_machine,
588
15
                                                     Section->sh_type));
589
706k
  auto V = getSectionContentsAsArray<char>(Section);
590
706k
  if (!V)
591
2
    return V.takeError();
592
706k
  ArrayRef<char> Data = *V;
593
706k
  if (Data.empty())
594
1
    // TODO: this error is untested.
595
1
    return createError("empty string table");
596
706k
  if (Data.back() != '\0')
597
2
    return createError(object::getELFSectionTypeName(getHeader()->e_machine,
598
2
                                                     Section->sh_type) +
599
2
                       " string table section " +
600
2
                       getSecIndexForError(this, Section) +
601
2
                       " is non-null terminated");
602
706k
  return StringRef(Data.begin(), Data.size());
603
706k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getStringTable(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*) const
Line
Count
Source
582
27.6k
ELFFile<ELFT>::getStringTable(const Elf_Shdr *Section) const {
583
27.6k
  if (Section->sh_type != ELF::SHT_STRTAB)
584
0
    return createError("invalid sh_type for string table section " +
585
0
                       getSecIndexForError(this, Section) +
586
0
                       ": expected SHT_STRTAB, but got " +
587
0
                       object::getELFSectionTypeName(getHeader()->e_machine,
588
0
                                                     Section->sh_type));
589
27.6k
  auto V = getSectionContentsAsArray<char>(Section);
590
27.6k
  if (!V)
591
0
    return V.takeError();
592
27.6k
  ArrayRef<char> Data = *V;
593
27.6k
  if (Data.empty())
594
0
    // TODO: this error is untested.
595
0
    return createError("empty string table");
596
27.6k
  if (Data.back() != '\0')
597
0
    return createError(object::getELFSectionTypeName(getHeader()->e_machine,
598
0
                                                     Section->sh_type) +
599
0
                       " string table section " +
600
0
                       getSecIndexForError(this, Section) +
601
0
                       " is non-null terminated");
602
27.6k
  return StringRef(Data.begin(), Data.size());
603
27.6k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getStringTable(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*) const
Line
Count
Source
582
4.70k
ELFFile<ELFT>::getStringTable(const Elf_Shdr *Section) const {
583
4.70k
  if (Section->sh_type != ELF::SHT_STRTAB)
584
0
    return createError("invalid sh_type for string table section " +
585
0
                       getSecIndexForError(this, Section) +
586
0
                       ": expected SHT_STRTAB, but got " +
587
0
                       object::getELFSectionTypeName(getHeader()->e_machine,
588
0
                                                     Section->sh_type));
589
4.70k
  auto V = getSectionContentsAsArray<char>(Section);
590
4.70k
  if (!V)
591
0
    return V.takeError();
592
4.70k
  ArrayRef<char> Data = *V;
593
4.70k
  if (Data.empty())
594
0
    // TODO: this error is untested.
595
0
    return createError("empty string table");
596
4.70k
  if (Data.back() != '\0')
597
0
    return createError(object::getELFSectionTypeName(getHeader()->e_machine,
598
0
                                                     Section->sh_type) +
599
0
                       " string table section " +
600
0
                       getSecIndexForError(this, Section) +
601
0
                       " is non-null terminated");
602
4.70k
  return StringRef(Data.begin(), Data.size());
603
4.70k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getStringTable(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*) const
Line
Count
Source
582
670k
ELFFile<ELFT>::getStringTable(const Elf_Shdr *Section) const {
583
670k
  if (Section->sh_type != ELF::SHT_STRTAB)
584
15
    return createError("invalid sh_type for string table section " +
585
15
                       getSecIndexForError(this, Section) +
586
15
                       ": expected SHT_STRTAB, but got " +
587
15
                       object::getELFSectionTypeName(getHeader()->e_machine,
588
15
                                                     Section->sh_type));
589
670k
  auto V = getSectionContentsAsArray<char>(Section);
590
670k
  if (!V)
591
2
    return V.takeError();
592
670k
  ArrayRef<char> Data = *V;
593
670k
  if (Data.empty())
594
1
    // TODO: this error is untested.
595
1
    return createError("empty string table");
596
670k
  if (Data.back() != '\0')
597
2
    return createError(object::getELFSectionTypeName(getHeader()->e_machine,
598
2
                                                     Section->sh_type) +
599
2
                       " string table section " +
600
2
                       getSecIndexForError(this, Section) +
601
2
                       " is non-null terminated");
602
670k
  return StringRef(Data.begin(), Data.size());
603
670k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getStringTable(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*) const
Line
Count
Source
582
3.67k
ELFFile<ELFT>::getStringTable(const Elf_Shdr *Section) const {
583
3.67k
  if (Section->sh_type != ELF::SHT_STRTAB)
584
0
    return createError("invalid sh_type for string table section " +
585
0
                       getSecIndexForError(this, Section) +
586
0
                       ": expected SHT_STRTAB, but got " +
587
0
                       object::getELFSectionTypeName(getHeader()->e_machine,
588
0
                                                     Section->sh_type));
589
3.67k
  auto V = getSectionContentsAsArray<char>(Section);
590
3.67k
  if (!V)
591
0
    return V.takeError();
592
3.67k
  ArrayRef<char> Data = *V;
593
3.67k
  if (Data.empty())
594
0
    // TODO: this error is untested.
595
0
    return createError("empty string table");
596
3.67k
  if (Data.back() != '\0')
597
0
    return createError(object::getELFSectionTypeName(getHeader()->e_machine,
598
0
                                                     Section->sh_type) +
599
0
                       " string table section " +
600
0
                       getSecIndexForError(this, Section) +
601
0
                       " is non-null terminated");
602
3.67k
  return StringRef(Data.begin(), Data.size());
603
3.67k
}
604
605
template <class ELFT>
606
Expected<ArrayRef<typename ELFT::Word>>
607
45
ELFFile<ELFT>::getSHNDXTable(const Elf_Shdr &Section) const {
608
45
  auto SectionsOrErr = sections();
609
45
  if (!SectionsOrErr)
610
0
    return SectionsOrErr.takeError();
611
45
  return getSHNDXTable(Section, *SectionsOrErr);
612
45
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSHNDXTable(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const&) const
Line
Count
Source
607
4
ELFFile<ELFT>::getSHNDXTable(const Elf_Shdr &Section) const {
608
4
  auto SectionsOrErr = sections();
609
4
  if (!SectionsOrErr)
610
0
    return SectionsOrErr.takeError();
611
4
  return getSHNDXTable(Section, *SectionsOrErr);
612
4
}
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSHNDXTable(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const&) const
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSHNDXTable(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const&) const
Line
Count
Source
607
41
ELFFile<ELFT>::getSHNDXTable(const Elf_Shdr &Section) const {
608
41
  auto SectionsOrErr = sections();
609
41
  if (!SectionsOrErr)
610
0
    return SectionsOrErr.takeError();
611
41
  return getSHNDXTable(Section, *SectionsOrErr);
612
41
}
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSHNDXTable(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const&) const
613
614
template <class ELFT>
615
Expected<ArrayRef<typename ELFT::Word>>
616
ELFFile<ELFT>::getSHNDXTable(const Elf_Shdr &Section,
617
50
                             Elf_Shdr_Range Sections) const {
618
50
  assert(Section.sh_type == ELF::SHT_SYMTAB_SHNDX);
619
50
  auto VOrErr = getSectionContentsAsArray<Elf_Word>(&Section);
620
50
  if (!VOrErr)
621
0
    return VOrErr.takeError();
622
50
  ArrayRef<Elf_Word> V = *VOrErr;
623
50
  auto SymTableOrErr = object::getSection<ELFT>(Sections, Section.sh_link);
624
50
  if (!SymTableOrErr)
625
0
    return SymTableOrErr.takeError();
626
50
  const Elf_Shdr &SymTable = **SymTableOrErr;
627
50
  if (SymTable.sh_type != ELF::SHT_SYMTAB &&
628
50
      
SymTable.sh_type != ELF::SHT_DYNSYM4
)
629
0
    // TODO: this error is untested.
630
0
    return createError("invalid sh_type");
631
50
  if (V.size() != (SymTable.sh_size / sizeof(Elf_Sym)))
632
1
    return createError("SHT_SYMTAB_SHNDX section has sh_size (" +
633
1
                       Twine(SymTable.sh_size) +
634
1
                       ") which is not equal to the number of symbols (" +
635
1
                       Twine(V.size()) + ")");
636
49
  return V;
637
49
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSHNDXTable(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const&, llvm::ArrayRef<llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > >) const
Line
Count
Source
617
4
                             Elf_Shdr_Range Sections) const {
618
4
  assert(Section.sh_type == ELF::SHT_SYMTAB_SHNDX);
619
4
  auto VOrErr = getSectionContentsAsArray<Elf_Word>(&Section);
620
4
  if (!VOrErr)
621
0
    return VOrErr.takeError();
622
4
  ArrayRef<Elf_Word> V = *VOrErr;
623
4
  auto SymTableOrErr = object::getSection<ELFT>(Sections, Section.sh_link);
624
4
  if (!SymTableOrErr)
625
0
    return SymTableOrErr.takeError();
626
4
  const Elf_Shdr &SymTable = **SymTableOrErr;
627
4
  if (SymTable.sh_type != ELF::SHT_SYMTAB &&
628
4
      SymTable.sh_type != ELF::SHT_DYNSYM)
629
0
    // TODO: this error is untested.
630
0
    return createError("invalid sh_type");
631
4
  if (V.size() != (SymTable.sh_size / sizeof(Elf_Sym)))
632
0
    return createError("SHT_SYMTAB_SHNDX section has sh_size (" +
633
0
                       Twine(SymTable.sh_size) +
634
0
                       ") which is not equal to the number of symbols (" +
635
0
                       Twine(V.size()) + ")");
636
4
  return V;
637
4
}
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSHNDXTable(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const&, llvm::ArrayRef<llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > >) const
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSHNDXTable(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const&, llvm::ArrayRef<llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > >) const
Line
Count
Source
617
46
                             Elf_Shdr_Range Sections) const {
618
46
  assert(Section.sh_type == ELF::SHT_SYMTAB_SHNDX);
619
46
  auto VOrErr = getSectionContentsAsArray<Elf_Word>(&Section);
620
46
  if (!VOrErr)
621
0
    return VOrErr.takeError();
622
46
  ArrayRef<Elf_Word> V = *VOrErr;
623
46
  auto SymTableOrErr = object::getSection<ELFT>(Sections, Section.sh_link);
624
46
  if (!SymTableOrErr)
625
0
    return SymTableOrErr.takeError();
626
46
  const Elf_Shdr &SymTable = **SymTableOrErr;
627
46
  if (SymTable.sh_type != ELF::SHT_SYMTAB &&
628
46
      
SymTable.sh_type != ELF::SHT_DYNSYM0
)
629
0
    // TODO: this error is untested.
630
0
    return createError("invalid sh_type");
631
46
  if (V.size() != (SymTable.sh_size / sizeof(Elf_Sym)))
632
1
    return createError("SHT_SYMTAB_SHNDX section has sh_size (" +
633
1
                       Twine(SymTable.sh_size) +
634
1
                       ") which is not equal to the number of symbols (" +
635
1
                       Twine(V.size()) + ")");
636
45
  return V;
637
45
}
Unexecuted instantiation: llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSHNDXTable(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const&, llvm::ArrayRef<llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > >) const
638
639
template <class ELFT>
640
Expected<StringRef>
641
5.10k
ELFFile<ELFT>::getStringTableForSymtab(const Elf_Shdr &Sec) const {
642
5.10k
  auto SectionsOrErr = sections();
643
5.10k
  if (!SectionsOrErr)
644
0
    return SectionsOrErr.takeError();
645
5.10k
  return getStringTableForSymtab(Sec, *SectionsOrErr);
646
5.10k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getStringTableForSymtab(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const&) const
Line
Count
Source
641
1.26k
ELFFile<ELFT>::getStringTableForSymtab(const Elf_Shdr &Sec) const {
642
1.26k
  auto SectionsOrErr = sections();
643
1.26k
  if (!SectionsOrErr)
644
0
    return SectionsOrErr.takeError();
645
1.26k
  return getStringTableForSymtab(Sec, *SectionsOrErr);
646
1.26k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getStringTableForSymtab(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const&) const
Line
Count
Source
641
250
ELFFile<ELFT>::getStringTableForSymtab(const Elf_Shdr &Sec) const {
642
250
  auto SectionsOrErr = sections();
643
250
  if (!SectionsOrErr)
644
0
    return SectionsOrErr.takeError();
645
250
  return getStringTableForSymtab(Sec, *SectionsOrErr);
646
250
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getStringTableForSymtab(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const&) const
Line
Count
Source
641
3.05k
ELFFile<ELFT>::getStringTableForSymtab(const Elf_Shdr &Sec) const {
642
3.05k
  auto SectionsOrErr = sections();
643
3.05k
  if (!SectionsOrErr)
644
0
    return SectionsOrErr.takeError();
645
3.05k
  return getStringTableForSymtab(Sec, *SectionsOrErr);
646
3.05k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getStringTableForSymtab(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const&) const
Line
Count
Source
641
540
ELFFile<ELFT>::getStringTableForSymtab(const Elf_Shdr &Sec) const {
642
540
  auto SectionsOrErr = sections();
643
540
  if (!SectionsOrErr)
644
0
    return SectionsOrErr.takeError();
645
540
  return getStringTableForSymtab(Sec, *SectionsOrErr);
646
540
}
647
648
template <class ELFT>
649
Expected<StringRef>
650
ELFFile<ELFT>::getStringTableForSymtab(const Elf_Shdr &Sec,
651
9.14k
                                       Elf_Shdr_Range Sections) const {
652
9.14k
653
9.14k
  if (Sec.sh_type != ELF::SHT_SYMTAB && 
Sec.sh_type != ELF::SHT_DYNSYM1.71k
)
654
0
    // TODO: this error is untested.
655
0
    return createError(
656
0
        "invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM");
657
9.14k
  auto SectionOrErr = object::getSection<ELFT>(Sections, Sec.sh_link);
658
9.14k
  if (!SectionOrErr)
659
3
    return SectionOrErr.takeError();
660
9.14k
  return getStringTable(*SectionOrErr);
661
9.14k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getStringTableForSymtab(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const&, llvm::ArrayRef<llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > >) const
Line
Count
Source
651
1.79k
                                       Elf_Shdr_Range Sections) const {
652
1.79k
653
1.79k
  if (Sec.sh_type != ELF::SHT_SYMTAB && 
Sec.sh_type != ELF::SHT_DYNSYM296
)
654
0
    // TODO: this error is untested.
655
0
    return createError(
656
0
        "invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM");
657
1.79k
  auto SectionOrErr = object::getSection<ELFT>(Sections, Sec.sh_link);
658
1.79k
  if (!SectionOrErr)
659
0
    return SectionOrErr.takeError();
660
1.79k
  return getStringTable(*SectionOrErr);
661
1.79k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getStringTableForSymtab(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const&, llvm::ArrayRef<llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > >) const
Line
Count
Source
651
491
                                       Elf_Shdr_Range Sections) const {
652
491
653
491
  if (Sec.sh_type != ELF::SHT_SYMTAB && 
Sec.sh_type != ELF::SHT_DYNSYM148
)
654
0
    // TODO: this error is untested.
655
0
    return createError(
656
0
        "invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM");
657
491
  auto SectionOrErr = object::getSection<ELFT>(Sections, Sec.sh_link);
658
491
  if (!SectionOrErr)
659
0
    return SectionOrErr.takeError();
660
491
  return getStringTable(*SectionOrErr);
661
491
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getStringTableForSymtab(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const&, llvm::ArrayRef<llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > >) const
Line
Count
Source
651
6.16k
                                       Elf_Shdr_Range Sections) const {
652
6.16k
653
6.16k
  if (Sec.sh_type != ELF::SHT_SYMTAB && 
Sec.sh_type != ELF::SHT_DYNSYM1.20k
)
654
0
    // TODO: this error is untested.
655
0
    return createError(
656
0
        "invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM");
657
6.16k
  auto SectionOrErr = object::getSection<ELFT>(Sections, Sec.sh_link);
658
6.16k
  if (!SectionOrErr)
659
3
    return SectionOrErr.takeError();
660
6.16k
  return getStringTable(*SectionOrErr);
661
6.16k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getStringTableForSymtab(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const&, llvm::ArrayRef<llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > >) const
Line
Count
Source
651
693
                                       Elf_Shdr_Range Sections) const {
652
693
653
693
  if (Sec.sh_type != ELF::SHT_SYMTAB && 
Sec.sh_type != ELF::SHT_DYNSYM64
)
654
0
    // TODO: this error is untested.
655
0
    return createError(
656
0
        "invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM");
657
693
  auto SectionOrErr = object::getSection<ELFT>(Sections, Sec.sh_link);
658
693
  if (!SectionOrErr)
659
0
    return SectionOrErr.takeError();
660
693
  return getStringTable(*SectionOrErr);
661
693
}
662
663
template <class ELFT>
664
Expected<StringRef>
665
658k
ELFFile<ELFT>::getSectionName(const Elf_Shdr *Section) const {
666
658k
  auto SectionsOrErr = sections();
667
658k
  if (!SectionsOrErr)
668
0
    return SectionsOrErr.takeError();
669
658k
  auto Table = getSectionStringTable(*SectionsOrErr);
670
658k
  if (!Table)
671
6
    return Table.takeError();
672
658k
  return getSectionName(Section, *Table);
673
658k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSectionName(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*) const
Line
Count
Source
665
10.6k
ELFFile<ELFT>::getSectionName(const Elf_Shdr *Section) const {
666
10.6k
  auto SectionsOrErr = sections();
667
10.6k
  if (!SectionsOrErr)
668
0
    return SectionsOrErr.takeError();
669
10.6k
  auto Table = getSectionStringTable(*SectionsOrErr);
670
10.6k
  if (!Table)
671
0
    return Table.takeError();
672
10.6k
  return getSectionName(Section, *Table);
673
10.6k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSectionName(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*) const
Line
Count
Source
665
3.20k
ELFFile<ELFT>::getSectionName(const Elf_Shdr *Section) const {
666
3.20k
  auto SectionsOrErr = sections();
667
3.20k
  if (!SectionsOrErr)
668
0
    return SectionsOrErr.takeError();
669
3.20k
  auto Table = getSectionStringTable(*SectionsOrErr);
670
3.20k
  if (!Table)
671
0
    return Table.takeError();
672
3.20k
  return getSectionName(Section, *Table);
673
3.20k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSectionName(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*) const
Line
Count
Source
665
641k
ELFFile<ELFT>::getSectionName(const Elf_Shdr *Section) const {
666
641k
  auto SectionsOrErr = sections();
667
641k
  if (!SectionsOrErr)
668
0
    return SectionsOrErr.takeError();
669
641k
  auto Table = getSectionStringTable(*SectionsOrErr);
670
641k
  if (!Table)
671
6
    return Table.takeError();
672
641k
  return getSectionName(Section, *Table);
673
641k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSectionName(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*) const
Line
Count
Source
665
2.35k
ELFFile<ELFT>::getSectionName(const Elf_Shdr *Section) const {
666
2.35k
  auto SectionsOrErr = sections();
667
2.35k
  if (!SectionsOrErr)
668
0
    return SectionsOrErr.takeError();
669
2.35k
  auto Table = getSectionStringTable(*SectionsOrErr);
670
2.35k
  if (!Table)
671
0
    return Table.takeError();
672
2.35k
  return getSectionName(Section, *Table);
673
2.35k
}
674
675
template <class ELFT>
676
Expected<StringRef> ELFFile<ELFT>::getSectionName(const Elf_Shdr *Section,
677
1.46M
                                                  StringRef DotShstrtab) const {
678
1.46M
  uint32_t Offset = Section->sh_name;
679
1.46M
  if (Offset == 0)
680
5.80k
    return StringRef();
681
1.45M
  if (Offset >= DotShstrtab.size())
682
29
    return createError("a section " + getSecIndexForError(this, Section) +
683
29
                       " has an invalid sh_name (0x" +
684
29
                       Twine::utohexstr(Offset) +
685
29
                       ") offset which goes past the end of the "
686
29
                       "section name string table");
687
1.45M
  return StringRef(DotShstrtab.data() + Offset);
688
1.45M
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getSectionName(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false> > const*, llvm::StringRef) const
Line
Count
Source
677
14.4k
                                                  StringRef DotShstrtab) const {
678
14.4k
  uint32_t Offset = Section->sh_name;
679
14.4k
  if (Offset == 0)
680
982
    return StringRef();
681
13.4k
  if (Offset >= DotShstrtab.size())
682
28
    return createError("a section " + getSecIndexForError(this, Section) +
683
28
                       " has an invalid sh_name (0x" +
684
28
                       Twine::utohexstr(Offset) +
685
28
                       ") offset which goes past the end of the "
686
28
                       "section name string table");
687
13.4k
  return StringRef(DotShstrtab.data() + Offset);
688
13.4k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getSectionName(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false> > const*, llvm::StringRef) const
Line
Count
Source
677
4.87k
                                                  StringRef DotShstrtab) const {
678
4.87k
  uint32_t Offset = Section->sh_name;
679
4.87k
  if (Offset == 0)
680
264
    return StringRef();
681
4.60k
  if (Offset >= DotShstrtab.size())
682
0
    return createError("a section " + getSecIndexForError(this, Section) +
683
0
                       " has an invalid sh_name (0x" +
684
0
                       Twine::utohexstr(Offset) +
685
0
                       ") offset which goes past the end of the "
686
0
                       "section name string table");
687
4.60k
  return StringRef(DotShstrtab.data() + Offset);
688
4.60k
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getSectionName(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true> > const*, llvm::StringRef) const
Line
Count
Source
677
1.44M
                                                  StringRef DotShstrtab) const {
678
1.44M
  uint32_t Offset = Section->sh_name;
679
1.44M
  if (Offset == 0)
680
4.38k
    return StringRef();
681
1.43M
  if (Offset >= DotShstrtab.size())
682
1
    return createError("a section " + getSecIndexForError(this, Section) +
683
1
                       " has an invalid sh_name (0x" +
684
1
                       Twine::utohexstr(Offset) +
685
1
                       ") offset which goes past the end of the "
686
1
                       "section name string table");
687
1.43M
  return StringRef(DotShstrtab.data() + Offset);
688
1.43M
}
llvm::object::ELFFile<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getSectionName(llvm::object::Elf_Shdr_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true> > const*, llvm::StringRef) const
Line
Count
Source
677
3.19k
                                                  StringRef DotShstrtab) const {
678
3.19k
  uint32_t Offset = Section->sh_name;
679
3.19k
  if (Offset == 0)
680
175
    return StringRef();
681
3.01k
  if (Offset >= DotShstrtab.size())
682
0
    return createError("a section " + getSecIndexForError(this, Section) +
683
0
                       " has an invalid sh_name (0x" +
684
0
                       Twine::utohexstr(Offset) +
685
0
                       ") offset which goes past the end of the "
686
0
                       "section name string table");
687
3.01k
  return StringRef(DotShstrtab.data() + Offset);
688
3.01k
}
689
690
/// This function returns the hash value for a symbol in the .dynsym section
691
/// Name of the API remains consistent as specified in the libelf
692
/// REF : http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#hash
693
inline unsigned hashSysV(StringRef SymbolName) {
694
  unsigned h = 0, g;
695
  for (char C : SymbolName) {
696
    h = (h << 4) + C;
697
    g = h & 0xf0000000L;
698
    if (g != 0)
699
      h ^= g >> 24;
700
    h &= ~g;
701
  }
702
  return h;
703
}
704
705
} // end namespace object
706
} // end namespace llvm
707
708
#endif // LLVM_OBJECT_ELF_H