llvm.org GIT mirror llvm / f3fc8c9
LTO API: add lto_module_create_from_memory_with_path. 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 Manman Ren 5 years ago
5 changed file(s) with 34 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
9999 std::string& errMsg);
100100 static LTOModule *makeLTOModule(const void *mem, size_t length,
101101 llvm::TargetOptions options,
102 std::string &errMsg);
102 std::string &errMsg,
103 llvm::StringRef path = "");
103104
104105 /// getTargetTriple - Return the Module's target triple.
105106 const char *getTargetTriple() {
221222 llvm::TargetOptions options,
222223 std::string &errMsg);
223224
224 /// makeBuffer - Create a MemoryBuffer from a memory range.
225 static llvm::MemoryBuffer *makeBuffer(const void *mem, size_t length);
225 /// Create a MemoryBuffer from a memory range with an optional name.
226 static llvm::MemoryBuffer *makeBuffer(const void *mem, size_t length,
227 llvm::StringRef name = "");
226228 };
227229
228230 #endif // LTO_MODULE_H
3939 * @{
4040 */
4141
42 #define LTO_API_VERSION 8
42 #define LTO_API_VERSION 9
4343
4444 /**
4545 * \since prior to LTO_API_VERSION=3
175175 lto_module_create_from_memory(const void* mem, size_t length);
176176
177177 /**
178 * Loads an object file from memory with an extra path argument.
179 * Returns NULL on error (check lto_get_error_message() for details).
180 *
181 * \since prior to LTO_API_VERSION=9
182 */
183 extern lto_module_t
184 lto_module_create_from_memory_with_path(const void* mem, size_t length,
185 const char *path);
186
187 /**
178188 * Loads an object file from disk. The seek point of fd is not preserved.
179189 * Returns NULL on error (check lto_get_error_message() for details).
180190 *
127127
128128 LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length,
129129 TargetOptions options,
130 std::string &errMsg) {
131 OwningPtr buffer(makeBuffer(mem, length));
130 std::string &errMsg, StringRef path) {
131 OwningPtr buffer(makeBuffer(mem, length, path));
132132 if (!buffer)
133133 return NULL;
134134 return makeLTOModule(buffer.take(), options, errMsg);
185185 return Ret;
186186 }
187187
188 /// makeBuffer - Create a MemoryBuffer from a memory range.
189 MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) {
188 /// Create a MemoryBuffer from a memory range with an optional name.
189 MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length,
190 StringRef name) {
190191 const char *startPtr = (const char*)mem;
191 return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), "", false);
192 return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), name, false);
192193 }
193194
194195 /// objcClassNameFromExpression - Get string that the data pointer points to.
155155 return LTOModule::makeLTOModule(mem, length, Options, sLastErrorString);
156156 }
157157
158 /// Loads an object file from memory with an extra path argument.
159 /// Returns NULL on error (check lto_get_error_message() for details).
160 lto_module_t lto_module_create_from_memory_with_path(const void* mem,
161 size_t length,
162 const char *path) {
163 lto_initialize();
164 llvm::TargetOptions Options;
165 lto_set_target_options(Options);
166 return LTOModule::makeLTOModule(mem, length, Options, sLastErrorString, path);
167 }
168
158169 /// lto_module_dispose - Frees all memory for a module. Upon return the
159170 /// lto_module_t is no longer valid.
160171 void lto_module_dispose(lto_module_t mod) {
44 lto_module_create_from_fd
55 lto_module_create_from_fd_at_offset
66 lto_module_create_from_memory
7 lto_module_create_from_memory_with_path
78 lto_module_get_deplib
89 lto_module_get_linkeropt
910 lto_module_get_num_deplibs