aboutsummaryrefslogtreecommitdiff
path: root/tools/lto
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2011-02-08 22:40:47 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2011-02-08 22:40:47 +0000
commitb4cc031a3e1306fea74c9211d50c5cde6d9a8cd5 (patch)
tree80f2d7365cd402e9040ed85abf3b06a17d59f423 /tools/lto
parent971b83b67a9812556cdb97bb58aa96fb37af458d (diff)
Don't open the file again in the gold plugin. To be able to do this, update
MemoryBuffer::getOpenFile to not close the file descriptor. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125128 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/lto')
-rw-r--r--tools/lto/LTOModule.cpp11
-rw-r--r--tools/lto/LTOModule.h3
-rw-r--r--tools/lto/lto.cpp8
-rw-r--r--tools/lto/lto.exports1
4 files changed, 23 insertions, 0 deletions
diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp
index e2ecabcc1c..ca937bf2ff 100644
--- a/tools/lto/LTOModule.cpp
+++ b/tools/lto/LTOModule.cpp
@@ -87,6 +87,17 @@ LTOModule *LTOModule::makeLTOModule(const char *path,
return makeLTOModule(buffer.get(), errMsg);
}
+LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
+ off_t size,
+ std::string &errMsg) {
+ OwningPtr<MemoryBuffer> buffer;
+ if (error_code ec = MemoryBuffer::getOpenFile(fd, path, buffer, size)) {
+ errMsg = ec.message();
+ return NULL;
+ }
+ return makeLTOModule(buffer.get(), errMsg);
+}
+
/// makeBuffer - Create a MemoryBuffer from a memory range. MemoryBuffer
/// requires the byte past end of the buffer to be a zero. We might get lucky
/// and already be that way, otherwise make a copy. Also if next byte is on a
diff --git a/tools/lto/LTOModule.h b/tools/lto/LTOModule.h
index a19acc0d73..1794d81c0a 100644
--- a/tools/lto/LTOModule.h
+++ b/tools/lto/LTOModule.h
@@ -51,6 +51,9 @@ struct LTOModule {
static LTOModule* makeLTOModule(const char* path,
std::string& errMsg);
+ static LTOModule* makeLTOModule(int fd, const char *path,
+ off_t size,
+ std::string& errMsg);
static LTOModule* makeLTOModule(const void* mem, size_t length,
std::string& errMsg);
diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp
index 75b40f4287..7d4871d925 100644
--- a/tools/lto/lto.cpp
+++ b/tools/lto/lto.cpp
@@ -91,6 +91,14 @@ lto_module_t lto_module_create(const char* path)
return LTOModule::makeLTOModule(path, 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(int fd, const char *path, off_t size)
+{
+ return LTOModule::makeLTOModule(fd, path, size, sLastErrorString);
+}
//
// loads an object file from memory
diff --git a/tools/lto/lto.exports b/tools/lto/lto.exports
index 4dbf760d38..a3740911ed 100644
--- a/tools/lto/lto.exports
+++ b/tools/lto/lto.exports
@@ -1,6 +1,7 @@
lto_get_error_message
lto_get_version
lto_module_create
+lto_module_create_from_fd
lto_module_create_from_memory
lto_module_get_num_symbols
lto_module_get_symbol_attribute