LTO API: add lto_module_create_from_memory_with_path.
authorManman Ren <manman.ren@gmail.com>
Mon, 10 Feb 2014 23:26:14 +0000 (23:26 +0000)
committerManman Ren <manman.ren@gmail.com>
Mon, 10 Feb 2014 23:26:14 +0000 (23:26 +0000)
This function adds an extra path argument to lto_module_create_from_memory.
The path argument will be passed to makeBuffer to make sure the MemoryBuffer
has a name and the created module has a module identifier.

This is mainly for emitting warning messages from the linker. When we emit
warning message on a module, we can use the module identifier.

rdar://15985737

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201114 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm-c/lto.h
include/llvm/LTO/LTOModule.h
lib/LTO/LTOModule.cpp
tools/lto/lto.cpp
tools/lto/lto.exports

index fbad2b568606de5a4af4f88d5083393c7c15621f..bff63ad09690d2c25483a80cbd046cd9968544f2 100644 (file)
@@ -40,7 +40,7 @@ typedef bool lto_bool_t;
  * @{
  */
 
-#define LTO_API_VERSION 8
+#define LTO_API_VERSION 9
 
 /**
  * \since prior to LTO_API_VERSION=3
@@ -175,6 +175,16 @@ lto_module_create(const char* path);
 extern lto_module_t
 lto_module_create_from_memory(const void* mem, size_t length);
 
+/**
+ * Loads an object file from memory with an extra path argument.
+ * Returns NULL on error (check lto_get_error_message() for details).
+ *
+ * \since prior to LTO_API_VERSION=9
+ */
+extern lto_module_t
+lto_module_create_from_memory_with_path(const void* mem, size_t length,
+                                        const char *path);
+
 /**
  * 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).
index c70afa4196d5b8bfbe751d739fcf2fe1029b712f..a70b71fa2ec977bcab3169ebd759c95a73695b0c 100644 (file)
@@ -100,7 +100,8 @@ public:
                                   std::string& errMsg);
   static LTOModule *makeLTOModule(const void *mem, size_t length,
                                   llvm::TargetOptions options,
-                                  std::string &errMsg);
+                                  std::string &errMsg,
+                                  llvm::StringRef path = "");
 
   /// getTargetTriple - Return the Module's target triple.
   const char *getTargetTriple() {
@@ -222,8 +223,9 @@ private:
                                   llvm::TargetOptions options,
                                   std::string &errMsg);
 
-  /// makeBuffer - Create a MemoryBuffer from a memory range.
-  static llvm::MemoryBuffer *makeBuffer(const void *mem, size_t length);
+  /// Create a MemoryBuffer from a memory range with an optional name.
+  static llvm::MemoryBuffer *makeBuffer(const void *mem, size_t length,
+                                        llvm::StringRef name = "");
 };
 
 #endif // LTO_MODULE_H
index 68b7313be7283cc709f75cc19a5d741da81b9ae8..909b92e888662000e80be0113f6d15ceb2e5bd4c 100644 (file)
@@ -128,8 +128,8 @@ LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
 
 LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length,
                                     TargetOptions options,
-                                    std::string &errMsg) {
-  OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length));
+                                    std::string &errMsg, StringRef path) {
+  OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length, path));
   if (!buffer)
     return NULL;
   return makeLTOModule(buffer.take(), options, errMsg);
@@ -186,10 +186,11 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
   return Ret;
 }
 
-/// makeBuffer - Create a MemoryBuffer from a memory range.
-MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) {
+/// Create a MemoryBuffer from a memory range with an optional name.
+MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length,
+                                    StringRef name) {
   const char *startPtr = (const char*)mem;
-  return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), "", false);
+  return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), name, false);
 }
 
 /// objcClassNameFromExpression - Get string that the data pointer points to.
index 967250acd7158c9b0cd65beb0f2d6d4c60f22ac0..d2f1ffdfa2312d2c5aac17071a6f0bd202710a48 100644 (file)
@@ -156,6 +156,17 @@ lto_module_t lto_module_create_from_memory(const void* mem, size_t length) {
   return LTOModule::makeLTOModule(mem, length, Options, sLastErrorString);
 }
 
+/// Loads an object file from memory with an extra path argument.
+/// Returns NULL on error (check lto_get_error_message() for details).
+lto_module_t lto_module_create_from_memory_with_path(const void* mem,
+                                                     size_t length,
+                                                     const char *path) {
+  lto_initialize();
+  llvm::TargetOptions Options;
+  lto_set_target_options(Options);
+  return LTOModule::makeLTOModule(mem, length, Options, sLastErrorString, path);
+}
+
 /// lto_module_dispose - Frees all memory for a module. Upon return the
 /// lto_module_t is no longer valid.
 void lto_module_dispose(lto_module_t mod) {
index 9b8dcb5f09ea62c9da4ae3967eac85c7ac95f6ea..b10ab1a3e6c00eb67d28ad9bbf2d2053a1c54627 100644 (file)
@@ -5,6 +5,7 @@ lto_module_create
 lto_module_create_from_fd
 lto_module_create_from_fd_at_offset
 lto_module_create_from_memory
+lto_module_create_from_memory_with_path
 lto_module_get_deplib
 lto_module_get_linkeropt
 lto_module_get_num_deplibs