2011-04-04 06:34:07 +08:00
|
|
|
//===- Object.cpp - C bindings to the object file library--------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-04-04 06:34:07 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the C bindings to the file-format-independent object
|
|
|
|
// library.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm-c/Object.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2019-04-06 05:36:50 +08:00
|
|
|
#include "llvm/IR/LLVMContext.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "llvm/Object/ObjectFile.h"
|
2019-05-26 00:47:27 +08:00
|
|
|
#include "llvm/Object/MachOUniversal.h"
|
2011-04-04 06:34:07 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace object;
|
|
|
|
|
2014-08-20 02:44:46 +08:00
|
|
|
inline OwningBinary<ObjectFile> *unwrap(LLVMObjectFileRef OF) {
|
|
|
|
return reinterpret_cast<OwningBinary<ObjectFile> *>(OF);
|
2013-04-23 06:47:22 +08:00
|
|
|
}
|
|
|
|
|
2014-08-20 02:44:46 +08:00
|
|
|
inline LLVMObjectFileRef wrap(const OwningBinary<ObjectFile> *OF) {
|
|
|
|
return reinterpret_cast<LLVMObjectFileRef>(
|
|
|
|
const_cast<OwningBinary<ObjectFile> *>(OF));
|
2013-04-23 06:47:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
|
|
|
|
return reinterpret_cast<section_iterator*>(SI);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline LLVMSectionIteratorRef
|
|
|
|
wrap(const section_iterator *SI) {
|
|
|
|
return reinterpret_cast<LLVMSectionIteratorRef>
|
|
|
|
(const_cast<section_iterator*>(SI));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline symbol_iterator *unwrap(LLVMSymbolIteratorRef SI) {
|
|
|
|
return reinterpret_cast<symbol_iterator*>(SI);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline LLVMSymbolIteratorRef
|
|
|
|
wrap(const symbol_iterator *SI) {
|
|
|
|
return reinterpret_cast<LLVMSymbolIteratorRef>
|
|
|
|
(const_cast<symbol_iterator*>(SI));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline relocation_iterator *unwrap(LLVMRelocationIteratorRef SI) {
|
|
|
|
return reinterpret_cast<relocation_iterator*>(SI);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline LLVMRelocationIteratorRef
|
|
|
|
wrap(const relocation_iterator *SI) {
|
|
|
|
return reinterpret_cast<LLVMRelocationIteratorRef>
|
|
|
|
(const_cast<relocation_iterator*>(SI));
|
|
|
|
}
|
|
|
|
|
2019-04-06 05:36:50 +08:00
|
|
|
/*--.. Operations on binary files ..........................................--*/
|
|
|
|
|
|
|
|
LLVMBinaryRef LLVMCreateBinary(LLVMMemoryBufferRef MemBuf,
|
|
|
|
LLVMContextRef Context,
|
|
|
|
char **ErrorMessage) {
|
|
|
|
auto maybeContext = Context ? unwrap(Context) : nullptr;
|
|
|
|
Expected<std::unique_ptr<Binary>> ObjOrErr(
|
|
|
|
createBinary(unwrap(MemBuf)->getMemBufferRef(), maybeContext));
|
|
|
|
if (!ObjOrErr) {
|
|
|
|
*ErrorMessage = strdup(toString(ObjOrErr.takeError()).c_str());
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return wrap(ObjOrErr.get().release());
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMemoryBufferRef LLVMBinaryCopyMemoryBuffer(LLVMBinaryRef BR) {
|
|
|
|
auto Buf = unwrap(BR)->getMemoryBufferRef();
|
|
|
|
return wrap(llvm::MemoryBuffer::getMemBuffer(
|
|
|
|
Buf.getBuffer(), Buf.getBufferIdentifier(),
|
|
|
|
/*RequiresNullTerminator*/false).release());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDisposeBinary(LLVMBinaryRef BR) {
|
|
|
|
delete unwrap(BR);
|
|
|
|
}
|
|
|
|
|
2019-04-08 02:18:42 +08:00
|
|
|
LLVMBinaryType LLVMBinaryGetType(LLVMBinaryRef BR) {
|
|
|
|
class BinaryTypeMapper final : public Binary {
|
|
|
|
public:
|
|
|
|
static LLVMBinaryType mapBinaryTypeToLLVMBinaryType(unsigned Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
case ID_Archive:
|
|
|
|
return LLVMBinaryTypeArchive;
|
|
|
|
case ID_MachOUniversalBinary:
|
|
|
|
return LLVMBinaryTypeMachOUniversalBinary;
|
|
|
|
case ID_COFFImportFile:
|
|
|
|
return LLVMBinaryTypeCOFFImportFile;
|
|
|
|
case ID_IR:
|
|
|
|
return LLVMBinaryTypeIR;
|
|
|
|
case ID_WinRes:
|
|
|
|
return LLVMBinaryTypeWinRes;
|
|
|
|
case ID_COFF:
|
|
|
|
return LLVMBinaryTypeCOFF;
|
|
|
|
case ID_ELF32L:
|
|
|
|
return LLVMBinaryTypeELF32L;
|
|
|
|
case ID_ELF32B:
|
|
|
|
return LLVMBinaryTypeELF32B;
|
|
|
|
case ID_ELF64L:
|
|
|
|
return LLVMBinaryTypeELF64L;
|
|
|
|
case ID_ELF64B:
|
|
|
|
return LLVMBinaryTypeELF64B;
|
|
|
|
case ID_MachO32L:
|
|
|
|
return LLVMBinaryTypeMachO32L;
|
|
|
|
case ID_MachO32B:
|
|
|
|
return LLVMBinaryTypeMachO32B;
|
|
|
|
case ID_MachO64L:
|
|
|
|
return LLVMBinaryTypeMachO64L;
|
|
|
|
case ID_MachO64B:
|
|
|
|
return LLVMBinaryTypeMachO64B;
|
|
|
|
case ID_Wasm:
|
|
|
|
return LLVMBinaryTypeWasm;
|
|
|
|
case ID_StartObjects:
|
|
|
|
case ID_EndObjects:
|
|
|
|
llvm_unreachable("Marker types are not valid binary kinds!");
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown binary kind!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return BinaryTypeMapper::mapBinaryTypeToLLVMBinaryType(unwrap(BR)->getType());
|
|
|
|
}
|
|
|
|
|
2019-05-26 00:47:27 +08:00
|
|
|
LLVMBinaryRef LLVMMachOUniversalBinaryCopyObjectForArch(LLVMBinaryRef BR,
|
|
|
|
const char *Arch,
|
|
|
|
size_t ArchLen,
|
|
|
|
char **ErrorMessage) {
|
|
|
|
auto universal = cast<MachOUniversalBinary>(unwrap(BR));
|
|
|
|
Expected<std::unique_ptr<ObjectFile>> ObjOrErr(
|
2019-09-19 08:02:12 +08:00
|
|
|
universal->getMachOObjectForArch({Arch, ArchLen}));
|
2019-05-26 00:47:27 +08:00
|
|
|
if (!ObjOrErr) {
|
|
|
|
*ErrorMessage = strdup(toString(ObjOrErr.takeError()).c_str());
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return wrap(ObjOrErr.get().release());
|
|
|
|
}
|
|
|
|
|
2019-04-10 05:53:31 +08:00
|
|
|
LLVMSectionIteratorRef LLVMObjectFileCopySectionIterator(LLVMBinaryRef BR) {
|
|
|
|
auto OF = cast<ObjectFile>(unwrap(BR));
|
|
|
|
auto sections = OF->sections();
|
|
|
|
if (sections.begin() == sections.end())
|
|
|
|
return nullptr;
|
|
|
|
return wrap(new section_iterator(sections.begin()));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMBool LLVMObjectFileIsSectionIteratorAtEnd(LLVMBinaryRef BR,
|
|
|
|
LLVMSectionIteratorRef SI) {
|
|
|
|
auto OF = cast<ObjectFile>(unwrap(BR));
|
|
|
|
return (*unwrap(SI) == OF->section_end()) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMSymbolIteratorRef LLVMObjectFileCopySymbolIterator(LLVMBinaryRef BR) {
|
|
|
|
auto OF = cast<ObjectFile>(unwrap(BR));
|
|
|
|
auto symbols = OF->symbols();
|
|
|
|
if (symbols.begin() == symbols.end())
|
|
|
|
return nullptr;
|
|
|
|
return wrap(new symbol_iterator(symbols.begin()));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMBool LLVMObjectFileIsSymbolIteratorAtEnd(LLVMBinaryRef BR,
|
|
|
|
LLVMSymbolIteratorRef SI) {
|
|
|
|
auto OF = cast<ObjectFile>(unwrap(BR));
|
|
|
|
return (*unwrap(SI) == OF->symbol_end()) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2011-10-22 01:50:59 +08:00
|
|
|
// ObjectFile creation
|
2011-04-04 06:34:07 +08:00
|
|
|
LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf) {
|
2014-06-24 06:00:37 +08:00
|
|
|
std::unique_ptr<MemoryBuffer> Buf(unwrap(MemBuf));
|
2016-04-07 06:14:09 +08:00
|
|
|
Expected<std::unique_ptr<ObjectFile>> ObjOrErr(
|
2014-08-20 02:44:46 +08:00
|
|
|
ObjectFile::createObjectFile(Buf->getMemBufferRef()));
|
|
|
|
std::unique_ptr<ObjectFile> Obj;
|
2016-04-07 06:14:09 +08:00
|
|
|
if (!ObjOrErr) {
|
|
|
|
// TODO: Actually report errors helpfully.
|
|
|
|
consumeError(ObjOrErr.takeError());
|
2014-09-06 05:22:09 +08:00
|
|
|
return nullptr;
|
2016-04-07 06:14:09 +08:00
|
|
|
}
|
2014-09-06 05:22:09 +08:00
|
|
|
|
|
|
|
auto *Ret = new OwningBinary<ObjectFile>(std::move(ObjOrErr.get()), std::move(Buf));
|
2014-08-20 02:44:46 +08:00
|
|
|
return wrap(Ret);
|
2011-04-04 06:34:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile) {
|
|
|
|
delete unwrap(ObjectFile);
|
|
|
|
}
|
|
|
|
|
2011-10-22 01:50:59 +08:00
|
|
|
// ObjectFile Section iterators
|
2014-08-20 02:44:46 +08:00
|
|
|
LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef OF) {
|
|
|
|
OwningBinary<ObjectFile> *OB = unwrap(OF);
|
|
|
|
section_iterator SI = OB->getBinary()->section_begin();
|
2011-10-08 03:25:32 +08:00
|
|
|
return wrap(new section_iterator(SI));
|
2011-04-04 06:34:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI) {
|
|
|
|
delete unwrap(SI);
|
|
|
|
}
|
|
|
|
|
2014-08-20 02:44:46 +08:00
|
|
|
LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef OF,
|
|
|
|
LLVMSectionIteratorRef SI) {
|
|
|
|
OwningBinary<ObjectFile> *OB = unwrap(OF);
|
|
|
|
return (*unwrap(SI) == OB->getBinary()->section_end()) ? 1 : 0;
|
2011-04-04 06:34:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMMoveToNextSection(LLVMSectionIteratorRef SI) {
|
2014-01-30 10:49:50 +08:00
|
|
|
++(*unwrap(SI));
|
2011-04-04 06:34:07 +08:00
|
|
|
}
|
|
|
|
|
2011-10-22 02:21:22 +08:00
|
|
|
void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,
|
|
|
|
LLVMSymbolIteratorRef Sym) {
|
2016-05-03 04:28:12 +08:00
|
|
|
Expected<section_iterator> SecOrErr = (*unwrap(Sym))->getSection();
|
|
|
|
if (!SecOrErr) {
|
|
|
|
std::string Buf;
|
|
|
|
raw_string_ostream OS(Buf);
|
2018-11-11 09:46:03 +08:00
|
|
|
logAllUnhandledErrors(SecOrErr.takeError(), OS);
|
2016-05-03 04:28:12 +08:00
|
|
|
OS.flush();
|
|
|
|
report_fatal_error(Buf);
|
|
|
|
}
|
2015-08-08 07:27:14 +08:00
|
|
|
*unwrap(Sect) = *SecOrErr;
|
2011-10-22 02:21:22 +08:00
|
|
|
}
|
|
|
|
|
2011-10-22 01:50:59 +08:00
|
|
|
// ObjectFile Symbol iterators
|
2014-08-20 02:44:46 +08:00
|
|
|
LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef OF) {
|
|
|
|
OwningBinary<ObjectFile> *OB = unwrap(OF);
|
|
|
|
symbol_iterator SI = OB->getBinary()->symbol_begin();
|
2011-10-22 01:50:59 +08:00
|
|
|
return wrap(new symbol_iterator(SI));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI) {
|
|
|
|
delete unwrap(SI);
|
|
|
|
}
|
|
|
|
|
2014-08-20 02:44:46 +08:00
|
|
|
LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef OF,
|
|
|
|
LLVMSymbolIteratorRef SI) {
|
|
|
|
OwningBinary<ObjectFile> *OB = unwrap(OF);
|
|
|
|
return (*unwrap(SI) == OB->getBinary()->symbol_end()) ? 1 : 0;
|
2011-10-22 01:50:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI) {
|
2014-01-30 10:49:50 +08:00
|
|
|
++(*unwrap(SI));
|
2011-10-22 01:50:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// SectionRef accessors
|
2011-04-04 06:34:07 +08:00
|
|
|
const char *LLVMGetSectionName(LLVMSectionIteratorRef SI) {
|
2019-08-14 19:10:11 +08:00
|
|
|
auto NameOrErr = (*unwrap(SI))->getName();
|
|
|
|
if (!NameOrErr)
|
|
|
|
report_fatal_error(NameOrErr.takeError());
|
|
|
|
return NameOrErr->data();
|
2011-04-04 06:34:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI) {
|
2014-10-08 23:28:58 +08:00
|
|
|
return (*unwrap(SI))->getSize();
|
2011-04-04 06:34:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI) {
|
2019-05-16 21:24:04 +08:00
|
|
|
if (Expected<StringRef> E = (*unwrap(SI))->getContents())
|
|
|
|
return E->data();
|
|
|
|
else
|
|
|
|
report_fatal_error(E.takeError());
|
2011-04-04 06:34:07 +08:00
|
|
|
}
|
2011-10-22 01:50:59 +08:00
|
|
|
|
|
|
|
uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI) {
|
2014-10-08 23:28:58 +08:00
|
|
|
return (*unwrap(SI))->getAddress();
|
2011-10-22 01:50:59 +08:00
|
|
|
}
|
|
|
|
|
2011-10-22 04:35:58 +08:00
|
|
|
LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,
|
2011-10-22 01:50:59 +08:00
|
|
|
LLVMSymbolIteratorRef Sym) {
|
2014-10-08 23:28:58 +08:00
|
|
|
return (*unwrap(SI))->containsSymbol(**unwrap(Sym));
|
2011-10-22 01:50:59 +08:00
|
|
|
}
|
|
|
|
|
2011-10-28 01:15:47 +08:00
|
|
|
// Section Relocation iterators
|
|
|
|
LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section) {
|
2014-02-11 04:24:04 +08:00
|
|
|
relocation_iterator SI = (*unwrap(Section))->relocation_begin();
|
2011-10-28 01:15:47 +08:00
|
|
|
return wrap(new relocation_iterator(SI));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef SI) {
|
|
|
|
delete unwrap(SI);
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section,
|
|
|
|
LLVMRelocationIteratorRef SI) {
|
2014-02-11 04:24:04 +08:00
|
|
|
return (*unwrap(SI) == (*unwrap(Section))->relocation_end()) ? 1 : 0;
|
2011-10-28 01:15:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef SI) {
|
2014-01-30 10:49:50 +08:00
|
|
|
++(*unwrap(SI));
|
2011-10-28 01:15:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-22 01:50:59 +08:00
|
|
|
// SymbolRef accessors
|
|
|
|
const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) {
|
2016-04-21 05:24:34 +08:00
|
|
|
Expected<StringRef> Ret = (*unwrap(SI))->getName();
|
|
|
|
if (!Ret) {
|
|
|
|
std::string Buf;
|
|
|
|
raw_string_ostream OS(Buf);
|
2018-11-11 09:46:03 +08:00
|
|
|
logAllUnhandledErrors(Ret.takeError(), OS);
|
2016-04-21 05:24:34 +08:00
|
|
|
OS.flush();
|
|
|
|
report_fatal_error(Buf);
|
|
|
|
}
|
2015-07-03 04:55:21 +08:00
|
|
|
return Ret->data();
|
2011-10-22 01:50:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI) {
|
2016-06-25 02:24:42 +08:00
|
|
|
Expected<uint64_t> Ret = (*unwrap(SI))->getAddress();
|
|
|
|
if (!Ret) {
|
|
|
|
std::string Buf;
|
|
|
|
raw_string_ostream OS(Buf);
|
2018-11-11 09:46:03 +08:00
|
|
|
logAllUnhandledErrors(Ret.takeError(), OS);
|
2016-06-25 02:24:42 +08:00
|
|
|
OS.flush();
|
|
|
|
report_fatal_error(Buf);
|
|
|
|
}
|
2015-07-04 02:19:00 +08:00
|
|
|
return *Ret;
|
2011-10-22 01:50:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI) {
|
2015-06-24 18:20:30 +08:00
|
|
|
return (*unwrap(SI))->getCommonSize();
|
2011-10-22 01:50:59 +08:00
|
|
|
}
|
|
|
|
|
2011-10-28 01:32:36 +08:00
|
|
|
// RelocationRef accessors
|
2011-11-30 01:40:10 +08:00
|
|
|
uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI) {
|
2015-06-30 07:29:12 +08:00
|
|
|
return (*unwrap(RI))->getOffset();
|
2011-11-30 01:40:10 +08:00
|
|
|
}
|
|
|
|
|
2011-10-28 01:32:36 +08:00
|
|
|
LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI) {
|
2013-06-05 09:33:53 +08:00
|
|
|
symbol_iterator ret = (*unwrap(RI))->getSymbol();
|
2011-10-28 01:32:36 +08:00
|
|
|
return wrap(new symbol_iterator(ret));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI) {
|
2015-06-30 09:53:01 +08:00
|
|
|
return (*unwrap(RI))->getType();
|
2011-10-28 01:32:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: Caller takes ownership of returned string.
|
|
|
|
const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI) {
|
|
|
|
SmallVector<char, 0> ret;
|
2015-06-30 12:08:37 +08:00
|
|
|
(*unwrap(RI))->getTypeName(ret);
|
Report fatal error in the case of out of memory
This is the second part of recommit of r325224. The previous part was
committed in r325426, which deals with C++ memory allocation. Solution
for C memory allocation involved functions `llvm::malloc` and similar.
This was a fragile solution because it caused ambiguity errors in some
cases. In this commit the new functions have names like `llvm::safe_malloc`.
The relevant part of original comment is below, updated for new function
names.
Analysis of fails in the case of out of memory errors can be tricky on
Windows. Such error emerges at the point where memory allocation function
fails, but manifests itself when null pointer is used. These two points
may be distant from each other. Besides, next runs may not exhibit
allocation error.
In some cases memory is allocated by a call to some of C allocation
functions, malloc, calloc and realloc. They are used for interoperability
with C code, when allocated object has variable size and when it is
necessary to avoid call of constructors. In many calls the result is not
checked for null pointer. To simplify checks, new functions are defined
in the namespace 'llvm': `safe_malloc`, `safe_calloc` and `safe_realloc`.
They behave as corresponding standard functions but produce fatal error if
allocation fails. This change replaces the standard functions like 'malloc'
in the cases when the result of the allocation function is not checked
for null pointer.
Finally, there are plain C code, that uses malloc and similar functions. If
the result is not checked, assert statement is added.
Differential Revision: https://reviews.llvm.org/D43010
llvm-svn: 325551
2018-02-20 13:41:26 +08:00
|
|
|
char *str = static_cast<char*>(safe_malloc(ret.size()));
|
2018-11-17 09:44:25 +08:00
|
|
|
llvm::copy(ret, str);
|
2011-10-28 01:32:36 +08:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: Caller takes ownership of returned string.
|
|
|
|
const char *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI) {
|
2015-06-03 12:48:06 +08:00
|
|
|
return strdup("");
|
2011-10-28 01:32:36 +08:00
|
|
|
}
|
|
|
|
|