LLVM: lib/Object/Object.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

20

21using namespace llvm;

22using namespace object;

23

26}

27

31}

32

35}

36

41}

42

45}

46

51}

52

55}

56

61}

62

63

64

67 char **ErrorMessage) {

68 auto maybeContext = Context ? unwrap(Context) : nullptr;

71 if (!ObjOrErr) {

73 return nullptr;

74 }

75

76 return wrap(ObjOrErr.get().release());

77}

78

80 auto Buf = unwrap(BR)->getMemoryBufferRef();

82 Buf.getBuffer(), Buf.getBufferIdentifier(),

83 false).release());

84}

85

88}

89

91 class BinaryTypeMapper final : public Binary {

92 public:

94 switch (Kind) {

129 llvm_unreachable("Marker types are not valid binary kinds!");

130 default:

132 }

133 }

134 };

135 return BinaryTypeMapper::mapBinaryTypeToLLVMBinaryType(unwrap(BR)->getType());

136}

137

139 const char *Arch,

140 size_t ArchLen,

141 char **ErrorMessage) {

142 auto universal = cast(unwrap(BR));

144 universal->getMachOObjectForArch({Arch, ArchLen}));

145 if (!ObjOrErr) {

147 return nullptr;

148 }

149 return wrap(ObjOrErr.get().release());

150}

151

153 auto OF = cast(unwrap(BR));

154 auto sections = OF->sections();

156 return nullptr;

158}

159

162 auto OF = cast(unwrap(BR));

163 return (*unwrap(SI) == OF->section_end()) ? 1 : 0;

164}

165

167 auto OF = cast(unwrap(BR));

168 auto symbols = OF->symbols();

169 if (symbols.begin() == symbols.end())

170 return nullptr;

172}

173

176 auto OF = cast(unwrap(BR));

177 return (*unwrap(SI) == OF->symbol_end()) ? 1 : 0;

178}

179

180

182 std::unique_ptr Buf(unwrap(MemBuf));

185 std::unique_ptr Obj;

186 if (!ObjOrErr) {

187

189 return nullptr;

190 }

191

193 return wrap(Ret);

194}

195

198}

199

200

205}

206

209}

210

214 return (*unwrap(SI) == OB->getBinary()->section_end()) ? 1 : 0;

215}

216

219}

220

224 if (!SecOrErr) {

225 std::string Buf;

229 }

230 *unwrap(Sect) = *SecOrErr;

231}

232

233

238}

239

242}

243

247 return (*unwrap(SI) == OB->getBinary()->symbol_end()) ? 1 : 0;

248}

249

252}

253

254

257 if (!NameOrErr)

259 return NameOrErr->data();

260}

261

263 return (*unwrap(SI))->getSize();

264}

265

268 return E->data();

269 else

271}

272

274 return (*unwrap(SI))->getAddress();

275}

276

280}

281

282

286}

287

290}

291

294 return (*unwrap(SI) == (*unwrap(Section))->relocation_end()) ? 1 : 0;

295}

296

299}

300

301

302

305 if (!Ret) {

306 std::string Buf;

310 }

311 return Ret->data();

312}

313

316 if (!Ret) {

317 std::string Buf;

321 }

322 return *Ret;

323}

324

326 return (*unwrap(SI))->getCommonSize();

327}

328

329

331 return (*unwrap(RI))->getOffset();

332}

333

337}

338

340 return (*unwrap(RI))->getType();

341}

342

343

349 return str;

350}

351

352

354 return strdup("");

355}

356

bbsections Prepares for basic block sections

This file defines counterparts of C library allocation functions defined in the namespace 'std'.

LLVMObjectFileRef wrap(const OwningBinary< ObjectFile > *OF)

OwningBinary< ObjectFile > * unwrap(LLVMObjectFileRef OF)

static StringRef getName(Value *V)

const Value * getAddress(const DbgVariableIntrinsic *DVI)

This file defines the SmallVector class.

static SymbolRef::Type getType(const Symbol *Sym)

Tagged union holding either a T or a Error.

Error takeError()

Take ownership of the stored error.

reference get()

Returns a reference to the stored T value.

static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)

Open the specified memory range as a MemoryBuffer.

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

@ ID_MachOUniversalBinary

This class is the base class for all object file types.

static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)

A raw_ostream that writes to an std::string.

uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI)

LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf)

Deprecated: Use LLVMCreateBinary instead.

LLVMSymbolIteratorRef LLVMObjectFileCopySymbolIterator(LLVMBinaryRef BR)

Retrieve a copy of the symbol iterator for this object file.

LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section, LLVMRelocationIteratorRef SI)

struct LLVMOpaqueSymbolIterator * LLVMSymbolIteratorRef

void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef SI)

void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI)

const char * LLVMGetSectionContents(LLVMSectionIteratorRef SI)

const char * LLVMGetSectionName(LLVMSectionIteratorRef SI)

uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI)

uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI)

const char * LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI)

LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef OF, LLVMSectionIteratorRef SI)

Deprecated: Use LLVMObjectFileIsSectionIteratorAtEnd instead.

uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI)

void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI)

LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef OF)

Deprecated: Use LLVMObjectFileCopySymbolIterator instead.

LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef OF)

Deprecated: Use LLVMObjectFileCopySectionIterator instead.

uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI)

LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef OF, LLVMSymbolIteratorRef SI)

Deprecated: Use LLVMObjectFileIsSymbolIteratorAtEnd instead.

LLVMBinaryType LLVMBinaryGetType(LLVMBinaryRef BR)

Retrieve the specific type of a binary.

LLVMBool LLVMObjectFileIsSectionIteratorAtEnd(LLVMBinaryRef BR, LLVMSectionIteratorRef SI)

Returns whether the given section iterator is at the end.

void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI)

LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section)

struct LLVMOpaqueSectionIterator * LLVMSectionIteratorRef

LLVMBinaryRef LLVMMachOUniversalBinaryCopyObjectForArch(LLVMBinaryRef BR, const char *Arch, size_t ArchLen, char **ErrorMessage)

void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect, LLVMSymbolIteratorRef Sym)

void LLVMDisposeBinary(LLVMBinaryRef BR)

Dispose of a binary file.

LLVMSectionIteratorRef LLVMObjectFileCopySectionIterator(LLVMBinaryRef BR)

Retrieve a copy of the section iterator for this object file.

void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef SI)

LLVMBinaryRef LLVMCreateBinary(LLVMMemoryBufferRef MemBuf, LLVMContextRef Context, char **ErrorMessage)

Create a binary file from the given memory buffer.

LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI)

void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile)

Deprecated: Use LLVMDisposeBinary instead.

LLVMBool LLVMObjectFileIsSymbolIteratorAtEnd(LLVMBinaryRef BR, LLVMSymbolIteratorRef SI)

Returns whether the given symbol iterator is at the end.

const char * LLVMGetSymbolName(LLVMSymbolIteratorRef SI)

struct LLVMOpaqueRelocationIterator * LLVMRelocationIteratorRef

struct LLVMOpaqueObjectFile * LLVMObjectFileRef

Deprecated: Use LLVMBinaryRef instead.

LLVMMemoryBufferRef LLVMBinaryCopyMemoryBuffer(LLVMBinaryRef BR)

Retrieves a copy of the memory buffer associated with this object file.

void LLVMMoveToNextSection(LLVMSectionIteratorRef SI)

LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI, LLVMSymbolIteratorRef Sym)

const char * LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI)

uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI)

@ LLVMBinaryTypeIR

LLVM IR.

@ LLVMBinaryTypeELF64B

ELF 64-bit, big endian.

@ LLVMBinaryTypeArchive

Archive file.

@ LLVMBinaryTypeMachO32B

MachO 32-bit, big endian.

@ LLVMBinaryTypeWasm

Web Assembly.

@ LLVMBinaryTypeELF64L

ELF 64-bit, little endian.

@ LLVMBinaryTypeWinRes

Windows resource (.res) file.

@ LLVMBinaryTypeMachOUniversalBinary

Mach-O Universal Binary file.

@ LLVMBinaryTypeMachO64B

MachO 64-bit, big endian.

@ LLVMBinaryTypeCOFF

COFF Object file.

@ LLVMBinaryTypeCOFFImportFile

COFF Import file.

@ LLVMBinaryTypeELF32B

ELF 32-bit, big endian.

@ LLVMBinaryTypeELF32L

ELF 32-bit, little endian.

@ LLVMBinaryTypeMachO32L

MachO 32-bit, little endian.

@ LLVMBinaryTypeMachO64L

MachO 64-bit, little endian.

@ LLVMBinaryTypeOffload

Offloading fatbinary.

struct LLVMOpaqueBinary * LLVMBinaryRef

struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef

LLVM uses a polymorphic type hierarchy which C cannot represent, therefore parameters must be passed ...

struct LLVMOpaqueContext * LLVMContextRef

The top-level container for all LLVM global data.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)

content_iterator< SectionRef > section_iterator

content_iterator< RelocationRef > relocation_iterator

Expected< std::unique_ptr< Binary > > createBinary(MemoryBufferRef Source, LLVMContext *Context=nullptr, bool InitContent=true)

Create a Binary from Source, autodetecting the file type.

This is an optimization pass for GlobalISel generic memory operations.

void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})

Log all errors (if any) in E to OS.

void report_fatal_error(Error Err, bool gen_crash_diag=true)

Report a serious error, calling any installed error handler.

LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_malloc(size_t Sz)

StringRef getTypeName()

We provide a function which tries to compute the (demangled) name of a type statically.

OutputIt copy(R &&Range, OutputIt Out)

const char * toString(DWARFSectionKind Kind)

void consumeError(Error Err)

Consume a Error without doing anything.