mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-28 22:20:37 +00:00
Add support in the LTO library for loading an object from the middle
of an file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127781 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d02c8b6cc1
commit
f21b1058a1
@ -127,7 +127,15 @@ lto_module_create_from_memory(const void* mem, size_t length);
|
||||
* Returns NULL on error (check lto_get_error_message() for details).
|
||||
*/
|
||||
extern lto_module_t
|
||||
lto_module_create_from_fd(int fd, const char *path, off_t size);
|
||||
lto_module_create_from_fd(int fd, const char *path, size_t file_size);
|
||||
|
||||
/**
|
||||
* Loads an object file from disk. The seek point of fd is not preserved.
|
||||
* Returns NULL on error (check lto_get_error_message() for details).
|
||||
*/
|
||||
extern lto_module_t
|
||||
lto_module_create_from_fd_at_offset(int fd, const char *path, size_t file_size,
|
||||
size_t map_size, off_t offset);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -235,46 +235,13 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file,
|
||||
if (file->offset) {
|
||||
// Gold has found what might be IR part-way inside of a file, such as
|
||||
// an .a archive.
|
||||
if (lseek(file->fd, file->offset, SEEK_SET) == -1) {
|
||||
(*message)(LDPL_ERROR,
|
||||
"Failed to seek to archive member of %s at offset %d: %s\n",
|
||||
file->name,
|
||||
file->offset, sys::StrError(errno).c_str());
|
||||
return LDPS_ERR;
|
||||
}
|
||||
void *buf = malloc(file->filesize);
|
||||
if (!buf) {
|
||||
(*message)(LDPL_ERROR,
|
||||
"Failed to allocate buffer for archive member of size: %d\n",
|
||||
file->filesize);
|
||||
return LDPS_ERR;
|
||||
}
|
||||
if (read(file->fd, buf, file->filesize) != file->filesize) {
|
||||
(*message)(LDPL_ERROR,
|
||||
"Failed to read archive member of %s at offset %d: %s\n",
|
||||
file->name,
|
||||
file->offset,
|
||||
sys::StrError(errno).c_str());
|
||||
free(buf);
|
||||
return LDPS_ERR;
|
||||
}
|
||||
if (!lto_module_is_object_file_in_memory(buf, file->filesize)) {
|
||||
free(buf);
|
||||
return LDPS_OK;
|
||||
}
|
||||
M = lto_module_create_from_memory(buf, file->filesize);
|
||||
if (!M) {
|
||||
(*message)(LDPL_ERROR, "Failed to create LLVM module: %s",
|
||||
lto_get_error_message());
|
||||
return LDPS_ERR;
|
||||
}
|
||||
free(buf);
|
||||
M = lto_module_create_from_fd_at_offset(file->fd, file->name, -1,
|
||||
file->filesize, file->offset);
|
||||
} else {
|
||||
lseek(file->fd, 0, SEEK_SET);
|
||||
M = lto_module_create_from_fd(file->fd, file->name, file->filesize);
|
||||
if (!M)
|
||||
return LDPS_OK;
|
||||
}
|
||||
if (!M)
|
||||
return LDPS_OK;
|
||||
|
||||
*claimed = 1;
|
||||
Modules.resize(Modules.size() + 1);
|
||||
|
@ -95,10 +95,19 @@ LTOModule *LTOModule::makeLTOModule(const char *path,
|
||||
}
|
||||
|
||||
LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
|
||||
off_t size,
|
||||
size_t size,
|
||||
std::string &errMsg) {
|
||||
return makeLTOModule(fd, path, size, size, 0, errMsg);
|
||||
}
|
||||
|
||||
LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
|
||||
size_t file_size,
|
||||
size_t map_size,
|
||||
off_t offset,
|
||||
std::string &errMsg) {
|
||||
OwningPtr<MemoryBuffer> buffer;
|
||||
if (error_code ec = MemoryBuffer::getOpenFile(fd, path, buffer, size)) {
|
||||
if (error_code ec = MemoryBuffer::getOpenFile(fd, path, buffer, file_size,
|
||||
map_size, offset, false)) {
|
||||
errMsg = ec.message();
|
||||
return NULL;
|
||||
}
|
||||
|
@ -52,7 +52,12 @@ struct LTOModule {
|
||||
static LTOModule* makeLTOModule(const char* path,
|
||||
std::string& errMsg);
|
||||
static LTOModule* makeLTOModule(int fd, const char *path,
|
||||
off_t size,
|
||||
size_t size,
|
||||
std::string& errMsg);
|
||||
static LTOModule* makeLTOModule(int fd, const char *path,
|
||||
size_t file_size,
|
||||
size_t map_size,
|
||||
off_t offset,
|
||||
std::string& errMsg);
|
||||
static LTOModule* makeLTOModule(const void* mem, size_t length,
|
||||
std::string& errMsg);
|
||||
|
@ -95,11 +95,24 @@ lto_module_t lto_module_create(const char* path)
|
||||
// loads an object file from disk
|
||||
// returns NULL on error (check lto_get_error_message() for details)
|
||||
//
|
||||
lto_module_t lto_module_create_from_fd(int fd, const char *path, off_t size)
|
||||
lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size)
|
||||
{
|
||||
return LTOModule::makeLTOModule(fd, path, size, sLastErrorString);
|
||||
}
|
||||
|
||||
//
|
||||
// loads an object file from disk
|
||||
// returns NULL on error (check lto_get_error_message() for details)
|
||||
//
|
||||
lto_module_t lto_module_create_from_fd_at_offset(int fd, const char *path,
|
||||
size_t file_size,
|
||||
size_t map_size,
|
||||
off_t offset)
|
||||
{
|
||||
return LTOModule::makeLTOModule(fd, path, file_size, map_size,
|
||||
offset, sLastErrorString);
|
||||
}
|
||||
|
||||
//
|
||||
// loads an object file from memory
|
||||
// returns NULL on error (check lto_get_error_message() for details)
|
||||
|
@ -2,6 +2,7 @@ lto_get_error_message
|
||||
lto_get_version
|
||||
lto_module_create
|
||||
lto_module_create_from_fd
|
||||
lto_module_create_from_fd_at_offset
|
||||
lto_module_create_from_memory
|
||||
lto_module_get_num_symbols
|
||||
lto_module_get_symbol_attribute
|
||||
|
Loading…
Reference in New Issue
Block a user