summaryrefslogtreecommitdiff
path: root/tools/gold
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2011-03-17 00:36:11 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2011-03-17 00:36:11 +0000
commitf21b1058a194f411000bdd8000a8b675a7874056 (patch)
tree1d9ae970a490bdd64c51e774a31db3487dd211ff /tools/gold
parentd02c8b6cc1d07bfe37fc055eefdac21b1c9303cb (diff)
downloadllvm-f21b1058a194f411000bdd8000a8b675a7874056.tar.gz
llvm-f21b1058a194f411000bdd8000a8b675a7874056.tar.bz2
llvm-f21b1058a194f411000bdd8000a8b675a7874056.tar.xz
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
Diffstat (limited to 'tools/gold')
-rw-r--r--tools/gold/gold-plugin.cpp41
1 files changed, 4 insertions, 37 deletions
diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp
index e959d9566b..7aa8c9109f 100644
--- a/tools/gold/gold-plugin.cpp
+++ b/tools/gold/gold-plugin.cpp
@@ -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);