Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 1 | //===-- gold-plugin.cpp - Plugin to gold for Link Time Optimization ------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This is a gold plugin for LLVM. It provides an LLVM implementation of the |
| 11 | // interface described in http://gcc.gnu.org/wiki/whopr/driver . |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "plugin-api.h" |
| 16 | |
| 17 | #include "llvm-c/lto.h" |
| 18 | |
| 19 | #include "llvm/Support/raw_ostream.h" |
Jeffrey Yasskin | ed1c0ff | 2009-07-01 18:11:20 +0000 | [diff] [blame^] | 20 | #include "llvm/System/Errno.h" |
Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 21 | #include "llvm/System/Path.h" |
Rafael Espindola | 42de34f | 2009-06-15 10:14:18 +0000 | [diff] [blame] | 22 | #include "llvm/System/Program.h" |
Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 23 | |
Torok Edwin | 6cbbdfd | 2009-02-04 21:00:02 +0000 | [diff] [blame] | 24 | #include <cerrno> |
Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 25 | #include <cstdlib> |
| 26 | #include <cstring> |
Nick Lewycky | ca42862 | 2009-02-22 22:15:44 +0000 | [diff] [blame] | 27 | #include <fstream> |
Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 28 | #include <list> |
| 29 | #include <vector> |
| 30 | |
| 31 | using namespace llvm; |
| 32 | |
| 33 | namespace { |
| 34 | ld_plugin_status discard_message(int level, const char *format, ...) { |
| 35 | // Die loudly. Recent versions of Gold pass ld_plugin_message as the first |
| 36 | // callback in the transfer vector. This should never be called. |
| 37 | abort(); |
| 38 | } |
| 39 | |
| 40 | ld_plugin_add_symbols add_symbols = NULL; |
| 41 | ld_plugin_get_symbols get_symbols = NULL; |
| 42 | ld_plugin_add_input_file add_input_file = NULL; |
| 43 | ld_plugin_message message = discard_message; |
| 44 | |
| 45 | int api_version = 0; |
| 46 | int gold_version = 0; |
| 47 | |
Nick Lewycky | ca42862 | 2009-02-22 22:15:44 +0000 | [diff] [blame] | 48 | bool generate_api_file = false; |
Nick Lewycky | a9b9032 | 2009-06-07 00:50:45 +0000 | [diff] [blame] | 49 | const char *as_path = NULL; |
Nick Lewycky | ca42862 | 2009-02-22 22:15:44 +0000 | [diff] [blame] | 50 | |
Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 51 | struct claimed_file { |
| 52 | lto_module_t M; |
| 53 | void *handle; |
| 54 | std::vector<ld_plugin_symbol> syms; |
| 55 | }; |
| 56 | |
| 57 | lto_codegen_model output_type = LTO_CODEGEN_PIC_MODEL_STATIC; |
| 58 | std::list<claimed_file> Modules; |
| 59 | std::vector<sys::Path> Cleanup; |
| 60 | } |
| 61 | |
| 62 | ld_plugin_status claim_file_hook(const ld_plugin_input_file *file, |
| 63 | int *claimed); |
| 64 | ld_plugin_status all_symbols_read_hook(void); |
| 65 | ld_plugin_status cleanup_hook(void); |
| 66 | |
| 67 | extern "C" ld_plugin_status onload(ld_plugin_tv *tv); |
| 68 | ld_plugin_status onload(ld_plugin_tv *tv) { |
| 69 | // We're given a pointer to the first transfer vector. We read through them |
| 70 | // until we find one where tv_tag == LDPT_NULL. The REGISTER_* tagged values |
| 71 | // contain pointers to functions that we need to call to register our own |
| 72 | // hooks. The others are addresses of functions we can use to call into gold |
| 73 | // for services. |
| 74 | |
| 75 | bool registeredClaimFile = false; |
| 76 | bool registeredAllSymbolsRead = false; |
| 77 | bool registeredCleanup = false; |
| 78 | |
| 79 | for (; tv->tv_tag != LDPT_NULL; ++tv) { |
| 80 | switch (tv->tv_tag) { |
| 81 | case LDPT_API_VERSION: |
| 82 | api_version = tv->tv_u.tv_val; |
| 83 | break; |
| 84 | case LDPT_GOLD_VERSION: // major * 100 + minor |
| 85 | gold_version = tv->tv_u.tv_val; |
| 86 | break; |
| 87 | case LDPT_LINKER_OUTPUT: |
| 88 | switch (tv->tv_u.tv_val) { |
| 89 | case LDPO_REL: // .o |
| 90 | case LDPO_DYN: // .so |
| 91 | output_type = LTO_CODEGEN_PIC_MODEL_DYNAMIC; |
| 92 | break; |
| 93 | case LDPO_EXEC: // .exe |
| 94 | output_type = LTO_CODEGEN_PIC_MODEL_STATIC; |
| 95 | break; |
| 96 | default: |
| 97 | (*message)(LDPL_ERROR, "Unknown output file type %d", |
| 98 | tv->tv_u.tv_val); |
| 99 | return LDPS_ERR; |
| 100 | } |
| 101 | // TODO: add an option to disable PIC. |
| 102 | //output_type = LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC; |
| 103 | break; |
| 104 | case LDPT_OPTION: |
Nick Lewycky | ca42862 | 2009-02-22 22:15:44 +0000 | [diff] [blame] | 105 | if (strcmp("generate-api-file", tv->tv_u.tv_string) == 0) { |
| 106 | generate_api_file = true; |
Nick Lewycky | a9b9032 | 2009-06-07 00:50:45 +0000 | [diff] [blame] | 107 | } else if (strncmp("as=", tv->tv_u.tv_string, 3) == 0) { |
| 108 | if (as_path) { |
| 109 | (*message)(LDPL_WARNING, "Path to as specified twice. " |
| 110 | "Discarding %s", tv->tv_u.tv_string); |
| 111 | } else { |
| 112 | as_path = strdup(tv->tv_u.tv_string + 3); |
| 113 | } |
Nick Lewycky | ca42862 | 2009-02-22 22:15:44 +0000 | [diff] [blame] | 114 | } else { |
| 115 | (*message)(LDPL_WARNING, "Ignoring flag %s", tv->tv_u.tv_string); |
| 116 | } |
Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 117 | break; |
| 118 | case LDPT_REGISTER_CLAIM_FILE_HOOK: { |
| 119 | ld_plugin_register_claim_file callback; |
| 120 | callback = tv->tv_u.tv_register_claim_file; |
| 121 | |
| 122 | if ((*callback)(claim_file_hook) != LDPS_OK) |
| 123 | return LDPS_ERR; |
| 124 | |
| 125 | registeredClaimFile = true; |
| 126 | } break; |
| 127 | case LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK: { |
| 128 | ld_plugin_register_all_symbols_read callback; |
| 129 | callback = tv->tv_u.tv_register_all_symbols_read; |
| 130 | |
| 131 | if ((*callback)(all_symbols_read_hook) != LDPS_OK) |
| 132 | return LDPS_ERR; |
| 133 | |
| 134 | registeredAllSymbolsRead = true; |
| 135 | } break; |
| 136 | case LDPT_REGISTER_CLEANUP_HOOK: { |
| 137 | ld_plugin_register_cleanup callback; |
| 138 | callback = tv->tv_u.tv_register_cleanup; |
| 139 | |
| 140 | if ((*callback)(cleanup_hook) != LDPS_OK) |
| 141 | return LDPS_ERR; |
| 142 | |
| 143 | registeredCleanup = true; |
| 144 | } break; |
| 145 | case LDPT_ADD_SYMBOLS: |
| 146 | add_symbols = tv->tv_u.tv_add_symbols; |
| 147 | break; |
| 148 | case LDPT_GET_SYMBOLS: |
| 149 | get_symbols = tv->tv_u.tv_get_symbols; |
| 150 | break; |
| 151 | case LDPT_ADD_INPUT_FILE: |
| 152 | add_input_file = tv->tv_u.tv_add_input_file; |
| 153 | break; |
| 154 | case LDPT_MESSAGE: |
| 155 | message = tv->tv_u.tv_message; |
| 156 | break; |
| 157 | default: |
| 158 | break; |
| 159 | } |
| 160 | } |
| 161 | |
Rafael Espindola | 98c507e | 2009-02-18 08:30:15 +0000 | [diff] [blame] | 162 | if (!registeredClaimFile) { |
Rafael Espindola | 6210a94 | 2009-02-18 17:49:06 +0000 | [diff] [blame] | 163 | (*message)(LDPL_ERROR, "register_claim_file not passed to LLVMgold."); |
| 164 | return LDPS_ERR; |
| 165 | } |
Rafael Espindola | 98c507e | 2009-02-18 08:30:15 +0000 | [diff] [blame] | 166 | if (!add_symbols) { |
Rafael Espindola | 6210a94 | 2009-02-18 17:49:06 +0000 | [diff] [blame] | 167 | (*message)(LDPL_ERROR, "add_symbols not passed to LLVMgold."); |
| 168 | return LDPS_ERR; |
| 169 | } |
Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 170 | |
| 171 | return LDPS_OK; |
| 172 | } |
| 173 | |
| 174 | /// claim_file_hook - called by gold to see whether this file is one that |
| 175 | /// our plugin can handle. We'll try to open it and register all the symbols |
| 176 | /// with add_symbol if possible. |
| 177 | ld_plugin_status claim_file_hook(const ld_plugin_input_file *file, |
| 178 | int *claimed) { |
Torok Edwin | 3e5a0d8 | 2009-02-04 17:39:30 +0000 | [diff] [blame] | 179 | void *buf = NULL; |
Torok Edwin | 3e5a0d8 | 2009-02-04 17:39:30 +0000 | [diff] [blame] | 180 | if (file->offset) { |
Nick Lewycky | c1da886 | 2009-02-05 04:14:23 +0000 | [diff] [blame] | 181 | // Gold has found what might be IR part-way inside of a file, such as |
| 182 | // an .a archive. |
Torok Edwin | 3e5a0d8 | 2009-02-04 17:39:30 +0000 | [diff] [blame] | 183 | if (lseek(file->fd, file->offset, SEEK_SET) == -1) { |
Nick Lewycky | 0df91b2 | 2009-02-07 03:15:01 +0000 | [diff] [blame] | 184 | (*message)(LDPL_ERROR, |
Torok Edwin | 3e5a0d8 | 2009-02-04 17:39:30 +0000 | [diff] [blame] | 185 | "Failed to seek to archive member of %s at offset %d: %s\n", |
| 186 | file->name, |
Jeffrey Yasskin | ed1c0ff | 2009-07-01 18:11:20 +0000 | [diff] [blame^] | 187 | file->offset, sys::StrError(errno).c_str()); |
Torok Edwin | 3e5a0d8 | 2009-02-04 17:39:30 +0000 | [diff] [blame] | 188 | return LDPS_ERR; |
| 189 | } |
| 190 | buf = malloc(file->filesize); |
| 191 | if (!buf) { |
Nick Lewycky | 0df91b2 | 2009-02-07 03:15:01 +0000 | [diff] [blame] | 192 | (*message)(LDPL_ERROR, |
Torok Edwin | 3e5a0d8 | 2009-02-04 17:39:30 +0000 | [diff] [blame] | 193 | "Failed to allocate buffer for archive member of size: %d\n", |
| 194 | file->filesize); |
| 195 | return LDPS_ERR; |
| 196 | } |
| 197 | if (read(file->fd, buf, file->filesize) != file->filesize) { |
Nick Lewycky | 0df91b2 | 2009-02-07 03:15:01 +0000 | [diff] [blame] | 198 | (*message)(LDPL_ERROR, |
| 199 | "Failed to read archive member of %s at offset %d: %s\n", |
Torok Edwin | 3e5a0d8 | 2009-02-04 17:39:30 +0000 | [diff] [blame] | 200 | file->name, |
Nick Lewycky | 0df91b2 | 2009-02-07 03:15:01 +0000 | [diff] [blame] | 201 | file->offset, |
Jeffrey Yasskin | ed1c0ff | 2009-07-01 18:11:20 +0000 | [diff] [blame^] | 202 | sys::StrError(errno).c_str()); |
Nick Lewycky | 0df91b2 | 2009-02-07 03:15:01 +0000 | [diff] [blame] | 203 | free(buf); |
Torok Edwin | 3e5a0d8 | 2009-02-04 17:39:30 +0000 | [diff] [blame] | 204 | return LDPS_ERR; |
| 205 | } |
Nick Lewycky | 0df91b2 | 2009-02-07 03:15:01 +0000 | [diff] [blame] | 206 | if (!lto_module_is_object_file_in_memory(buf, file->filesize)) { |
| 207 | free(buf); |
Torok Edwin | 3e5a0d8 | 2009-02-04 17:39:30 +0000 | [diff] [blame] | 208 | return LDPS_OK; |
Nick Lewycky | 0df91b2 | 2009-02-07 03:15:01 +0000 | [diff] [blame] | 209 | } |
Torok Edwin | 3e5a0d8 | 2009-02-04 17:39:30 +0000 | [diff] [blame] | 210 | } else if (!lto_module_is_object_file(file->name)) |
Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 211 | return LDPS_OK; |
| 212 | |
| 213 | *claimed = 1; |
| 214 | Modules.resize(Modules.size() + 1); |
| 215 | claimed_file &cf = Modules.back(); |
| 216 | |
Nick Lewycky | c1da886 | 2009-02-05 04:14:23 +0000 | [diff] [blame] | 217 | cf.M = buf ? lto_module_create_from_memory(buf, file->filesize) : |
| 218 | lto_module_create(file->name); |
Nick Lewycky | ea97aa6 | 2009-02-06 01:58:34 +0000 | [diff] [blame] | 219 | free(buf); |
Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 220 | if (!cf.M) { |
| 221 | (*message)(LDPL_ERROR, "Failed to create LLVM module: %s", |
| 222 | lto_get_error_message()); |
| 223 | return LDPS_ERR; |
| 224 | } |
| 225 | cf.handle = file->handle; |
| 226 | unsigned sym_count = lto_module_get_num_symbols(cf.M); |
| 227 | cf.syms.reserve(sym_count); |
| 228 | |
| 229 | for (unsigned i = 0; i != sym_count; ++i) { |
| 230 | lto_symbol_attributes attrs = lto_module_get_symbol_attribute(cf.M, i); |
| 231 | if ((attrs & LTO_SYMBOL_SCOPE_MASK) == LTO_SYMBOL_SCOPE_INTERNAL) |
| 232 | continue; |
| 233 | |
| 234 | cf.syms.push_back(ld_plugin_symbol()); |
| 235 | ld_plugin_symbol &sym = cf.syms.back(); |
| 236 | sym.name = const_cast<char *>(lto_module_get_symbol_name(cf.M, i)); |
| 237 | sym.version = NULL; |
| 238 | |
| 239 | int scope = attrs & LTO_SYMBOL_SCOPE_MASK; |
| 240 | switch (scope) { |
| 241 | case LTO_SYMBOL_SCOPE_HIDDEN: |
| 242 | sym.visibility = LDPV_HIDDEN; |
| 243 | break; |
| 244 | case LTO_SYMBOL_SCOPE_PROTECTED: |
| 245 | sym.visibility = LDPV_PROTECTED; |
| 246 | break; |
| 247 | case 0: // extern |
| 248 | case LTO_SYMBOL_SCOPE_DEFAULT: |
| 249 | sym.visibility = LDPV_DEFAULT; |
| 250 | break; |
| 251 | default: |
| 252 | (*message)(LDPL_ERROR, "Unknown scope attribute: %d", scope); |
| 253 | return LDPS_ERR; |
| 254 | } |
| 255 | |
| 256 | int definition = attrs & LTO_SYMBOL_DEFINITION_MASK; |
| 257 | switch (definition) { |
| 258 | case LTO_SYMBOL_DEFINITION_REGULAR: |
| 259 | sym.def = LDPK_DEF; |
| 260 | break; |
| 261 | case LTO_SYMBOL_DEFINITION_UNDEFINED: |
| 262 | sym.def = LDPK_UNDEF; |
| 263 | break; |
| 264 | case LTO_SYMBOL_DEFINITION_TENTATIVE: |
| 265 | sym.def = LDPK_COMMON; |
| 266 | break; |
| 267 | case LTO_SYMBOL_DEFINITION_WEAK: |
| 268 | sym.def = LDPK_WEAKDEF; |
| 269 | break; |
Rafael Espindola | 7431af0 | 2009-04-24 16:55:21 +0000 | [diff] [blame] | 270 | case LTO_SYMBOL_DEFINITION_WEAKUNDEF: |
| 271 | sym.def = LDPK_WEAKUNDEF; |
| 272 | break; |
Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 273 | default: |
| 274 | (*message)(LDPL_ERROR, "Unknown definition attribute: %d", definition); |
| 275 | return LDPS_ERR; |
| 276 | } |
| 277 | |
| 278 | // LLVM never emits COMDAT. |
| 279 | sym.size = 0; |
| 280 | sym.comdat_key = NULL; |
| 281 | |
| 282 | sym.resolution = LDPR_UNKNOWN; |
| 283 | } |
| 284 | |
| 285 | cf.syms.reserve(cf.syms.size()); |
| 286 | |
| 287 | if (!cf.syms.empty()) { |
| 288 | if ((*add_symbols)(cf.handle, cf.syms.size(), &cf.syms[0]) != LDPS_OK) { |
| 289 | (*message)(LDPL_ERROR, "Unable to add symbols!"); |
| 290 | return LDPS_ERR; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | return LDPS_OK; |
| 295 | } |
| 296 | |
| 297 | /// all_symbols_read_hook - gold informs us that all symbols have been read. |
| 298 | /// At this point, we use get_symbols to see if any of our definitions have |
| 299 | /// been overridden by a native object file. Then, perform optimization and |
| 300 | /// codegen. |
| 301 | ld_plugin_status all_symbols_read_hook(void) { |
| 302 | lto_code_gen_t cg = lto_codegen_create(); |
| 303 | |
| 304 | for (std::list<claimed_file>::iterator I = Modules.begin(), |
| 305 | E = Modules.end(); I != E; ++I) |
| 306 | lto_codegen_add_module(cg, I->M); |
| 307 | |
Nick Lewycky | ca42862 | 2009-02-22 22:15:44 +0000 | [diff] [blame] | 308 | std::ofstream api_file; |
| 309 | if (generate_api_file) { |
| 310 | api_file.open("apifile.txt", std::ofstream::out | std::ofstream::trunc); |
| 311 | if (!api_file.is_open()) { |
| 312 | (*message)(LDPL_FATAL, "Unable to open apifile.txt for writing."); |
| 313 | abort(); |
| 314 | } |
| 315 | } |
| 316 | |
Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 317 | // If we don't preserve any symbols, libLTO will assume that all symbols are |
| 318 | // needed. Keep all symbols unless we're producing a final executable. |
| 319 | if (output_type == LTO_CODEGEN_PIC_MODEL_STATIC) { |
| 320 | bool anySymbolsPreserved = false; |
| 321 | for (std::list<claimed_file>::iterator I = Modules.begin(), |
| 322 | E = Modules.end(); I != E; ++I) { |
| 323 | (*get_symbols)(I->handle, I->syms.size(), &I->syms[0]); |
| 324 | for (unsigned i = 0, e = I->syms.size(); i != e; i++) { |
Nick Lewycky | e0afaa3 | 2009-02-15 22:49:17 +0000 | [diff] [blame] | 325 | if (I->syms[i].resolution == LDPR_PREVAILING_DEF || |
| 326 | (I->syms[i].def == LDPK_COMMON && |
| 327 | I->syms[i].resolution == LDPR_RESOLVED_IR)) { |
Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 328 | lto_codegen_add_must_preserve_symbol(cg, I->syms[i].name); |
| 329 | anySymbolsPreserved = true; |
Nick Lewycky | ca42862 | 2009-02-22 22:15:44 +0000 | [diff] [blame] | 330 | |
| 331 | if (generate_api_file) |
| 332 | api_file << I->syms[i].name << "\n"; |
Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
Nick Lewycky | ca42862 | 2009-02-22 22:15:44 +0000 | [diff] [blame] | 337 | if (generate_api_file) |
| 338 | api_file.close(); |
| 339 | |
Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 340 | if (!anySymbolsPreserved) { |
| 341 | // This entire file is unnecessary! |
| 342 | lto_codegen_dispose(cg); |
| 343 | return LDPS_OK; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | lto_codegen_set_pic_model(cg, output_type); |
| 348 | lto_codegen_set_debug_model(cg, LTO_DEBUG_MODEL_DWARF); |
Rafael Espindola | 42de34f | 2009-06-15 10:14:18 +0000 | [diff] [blame] | 349 | if (as_path) { |
| 350 | sys::Path p = sys::Program::FindProgramByName(as_path); |
| 351 | lto_codegen_set_assembler_path(cg, p.c_str()); |
| 352 | } |
Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 353 | |
| 354 | size_t bufsize = 0; |
| 355 | const char *buffer = static_cast<const char *>(lto_codegen_compile(cg, |
| 356 | &bufsize)); |
| 357 | |
| 358 | std::string ErrMsg; |
| 359 | |
| 360 | sys::Path uniqueObjPath("/tmp/llvmgold.o"); |
| 361 | if (uniqueObjPath.createTemporaryFileOnDisk(true, &ErrMsg)) { |
| 362 | (*message)(LDPL_ERROR, "%s", ErrMsg.c_str()); |
| 363 | return LDPS_ERR; |
| 364 | } |
| 365 | raw_fd_ostream *objFile = new raw_fd_ostream(uniqueObjPath.c_str(), true, |
| 366 | ErrMsg); |
| 367 | if (!ErrMsg.empty()) { |
| 368 | delete objFile; |
| 369 | (*message)(LDPL_ERROR, "%s", ErrMsg.c_str()); |
| 370 | return LDPS_ERR; |
| 371 | } |
| 372 | |
| 373 | objFile->write(buffer, bufsize); |
| 374 | objFile->close(); |
| 375 | |
| 376 | lto_codegen_dispose(cg); |
Nick Lewycky | 3e62b2d | 2009-02-03 07:13:24 +0000 | [diff] [blame] | 377 | |
| 378 | if ((*add_input_file)(const_cast<char*>(uniqueObjPath.c_str())) != LDPS_OK) { |
| 379 | (*message)(LDPL_ERROR, "Unable to add .o file to the link."); |
| 380 | (*message)(LDPL_ERROR, "File left behind in: %s", uniqueObjPath.c_str()); |
| 381 | return LDPS_ERR; |
| 382 | } |
| 383 | |
| 384 | Cleanup.push_back(uniqueObjPath); |
| 385 | |
| 386 | return LDPS_OK; |
| 387 | } |
| 388 | |
| 389 | ld_plugin_status cleanup_hook(void) { |
| 390 | std::string ErrMsg; |
| 391 | |
| 392 | for (int i = 0, e = Cleanup.size(); i != e; ++i) |
| 393 | if (Cleanup[i].eraseFromDisk(false, &ErrMsg)) |
| 394 | (*message)(LDPL_ERROR, "Failed to delete '%s': %s", Cleanup[i].c_str(), |
| 395 | ErrMsg.c_str()); |
| 396 | |
| 397 | return LDPS_OK; |
| 398 | } |