summaryrefslogtreecommitdiff
path: root/tools/lto/lto.cpp
Commit message (Collapse)AuthorAge
* Adding new LTO APIs to parse metadata nodes and extract linker options andYunzhong Gao2014-01-21
| | | | | | | | | | dependent libraries from a bitcode module. Differential Revision: http://llvm-reviews.chandlerc.com/D2343 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199759 91177308-0d34-0410-b5e6-96231b3b80d8
* [LTO] Add a hook to map LLVM diagnostics into the clients of LTO.Quentin Colombet2014-01-15
| | | | | | | | | | | | | | | | | | | | Add a hook in the C API of LTO so that clients of the code generator can set their own handler for the LLVM diagnostics. The handler is defined like this: typedef void (*lto_diagnostic_handler_t)(lto_codegen_diagnostic_severity_t severity, const char *diag, void *ctxt) - severity says how bad this is. - diag is a string that contains the diagnostic message. - ctxt is the registered context for this handler. This hook is more general than the lto_get_error_message, since this function keeps only the latest message and can only be queried when something went wrong (no warning for instance). <rdar://problem/15517596> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199338 91177308-0d34-0410-b5e6-96231b3b80d8
* Reapply "LTO: add API to set strategy for -internalize"Duncan P. N. Exon Smith2014-01-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reapply r199191, reverted in r199197 because it carelessly broke Other/link-opts.ll. The problem was that calling createInternalizePass("main") would select createInternalizePass(bool("main")) instead of createInternalizePass(ArrayRef<const char *>("main")). This commit fixes the bug. The original commit message follows. Add API to LTOCodeGenerator to specify a strategy for the -internalize pass. This is a new attempt at Bill's change in r185882, which he reverted in r188029 due to problems with the gold linker. This puts the onus on the linker to decide whether (and what) to internalize. In particular, running internalize before outputting an object file may change a 'weak' symbol into an internal one, even though that symbol could be needed by an external object file --- e.g., with arclite. This patch enables three strategies: - LTO_INTERNALIZE_FULL: the default (and the old behaviour). - LTO_INTERNALIZE_NONE: skip -internalize. - LTO_INTERNALIZE_HIDDEN: only -internalize symbols with hidden visibility. LTO_INTERNALIZE_FULL should be used when linking an executable. Outputting an object file (e.g., via ld -r) is more complicated, and depends on whether hidden symbols should be internalized. E.g., for ld -r, LTO_INTERNALIZE_NONE can be used when -keep_private_externs, and LTO_INTERNALIZE_HIDDEN can be used otherwise. However, LTO_INTERNALIZE_FULL is inappropriate, since the output object file will eventually need to link with others. lto_codegen_set_internalize_strategy() sets the strategy for subsequent calls to lto_codegen_write_merged_modules() and lto_codegen_compile*(). <rdar://problem/14334895> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199244 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r199191, "LTO: add API to set strategy for -internalize"NAKAMURA Takumi2014-01-14
| | | | | | Please update also Other/link-opts.ll, in next time. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199197 91177308-0d34-0410-b5e6-96231b3b80d8
* LTO: add API to set strategy for -internalizeDuncan P. N. Exon Smith2014-01-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add API to LTOCodeGenerator to specify a strategy for the -internalize pass. This is a new attempt at Bill's change in r185882, which he reverted in r188029 due to problems with the gold linker. This puts the onus on the linker to decide whether (and what) to internalize. In particular, running internalize before outputting an object file may change a 'weak' symbol into an internal one, even though that symbol could be needed by an external object file --- e.g., with arclite. This patch enables three strategies: - LTO_INTERNALIZE_FULL: the default (and the old behaviour). - LTO_INTERNALIZE_NONE: skip -internalize. - LTO_INTERNALIZE_HIDDEN: only -internalize symbols with hidden visibility. LTO_INTERNALIZE_FULL should be used when linking an executable. Outputting an object file (e.g., via ld -r) is more complicated, and depends on whether hidden symbols should be internalized. E.g., for ld -r, LTO_INTERNALIZE_NONE can be used when -keep_private_externs, and LTO_INTERNALIZE_HIDDEN can be used otherwise. However, LTO_INTERNALIZE_FULL is inappropriate, since the output object file will eventually need to link with others. lto_codegen_set_internalize_strategy() sets the strategy for subsequent calls to lto_codegen_write_merged_modules() and lto_codegen_compile*(). <rdar://problem/14334895> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199191 91177308-0d34-0410-b5e6-96231b3b80d8
* Re-sort #include lines again, prior to moving headers around.Chandler Carruth2014-01-13
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199080 91177308-0d34-0410-b5e6-96231b3b80d8
* Use LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN instead of the "dso list".Rafael Espindola2013-10-31
| | | | | | | | | | | | | | | | | | | | | | There are two ways one could implement hiding of linkonce_odr symbols in LTO: * LLVM tells the linker which symbols can be hidden if not used from native files. * The linker tells LLVM which symbols are not used from other object files, but will be put in the dso symbol table if present. GOLD's API is the second option. It was implemented almost 1:1 in llvm by passing the list down to internalize. LLVM already had partial support for the first option. It is also very similar to how ld64 handles hiding these symbols when *not* doing LTO. This patch then * removes the APIs for the DSO list. * marks LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN all linkonce_odr unnamed_addr global values and other linkonce_odr whose address is not used. * makes the gold plugin responsible for handling the API mismatch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193800 91177308-0d34-0410-b5e6-96231b3b80d8
* lto.h: Use lto_bool_t instead of int to restore the ABIReid Kleckner2013-10-24
| | | | | | | | | | | | This reverts commit r193255 and instead creates an lto_bool_t typedef that points to bool, _Bool, or unsigned char depending on what is available. Only recent versions of MSVC provide a stdbool.h header. Reviewers: rafael.espindola Differential Revision: http://llvm-reviews.chandlerc.com/D2019 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193377 91177308-0d34-0410-b5e6-96231b3b80d8
* llvm-c/lto.h: Avoid use of bool.NAKAMURA Takumi2013-10-23
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193255 91177308-0d34-0410-b5e6-96231b3b80d8
* Optimize linkonce_odr unnamed_addr functions during LTO.Rafael Espindola2013-10-03
| | | | | | | | | | | Generalize the API so we can distinguish symbols that are needed just for a DSO symbol table from those that are used from some native .o. The symbols that are only wanted for the dso symbol table can be dropped if llvm can prove every other dso has a copy (linkonce_odr) and the address is not important (unnamed_addr). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191922 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix option parsing in the gold plugin.Rafael Espindola2013-10-02
| | | | | | | | | This was broken when options were moved up in r191680. No test because this is specific LLVMgold.so/libLTO.so. Patch by Tom Roeder! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191829 91177308-0d34-0410-b5e6-96231b3b80d8
* Move command line options to the users of libLTO. Fixes --enable-shared build.Rafael Espindola2013-09-30
| | | | | | Patch by Richard Sandiford. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191680 91177308-0d34-0410-b5e6-96231b3b80d8
* Move LTO support library to a component, allowing it to be testedPeter Collingbourne2013-09-24
| | | | | | more reliably across platforms. Patch by Tom Roeder! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191343 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert 189297, the original commit message is following. Shuxin Yang2013-08-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ---- Add new API lto_codegen_compile_parallel(). This API is proposed by Nick Kledzik. The semantic is: -------------------------------------------------------------------------- Generate code for merged module into an array of native object files. On success returns a pointer to an array of NativeObjectFile. The count parameter returns the number of elements in the array. Each element is a pointer/length for a generated mach-o/ELF buffer. The buffer is owned by the lto_code_gen_t and will be freed when lto_codegen_dispose() is called, or lto_codegen_compile() is called again. On failure, returns NULL (check lto_get_error_message() for details). extern const struct NativeObjectFile* lto_codegen_compile_parallel(lto_code_gen_t cg, size_t *count); --------------------------------------------------------------------------- This API is currently only called on OSX platform. Linux or other Unixes using GNU gold are not supposed to call this function, because on these systems, object files are fed back to linker via disk file instead of memory buffer. In this commit, lto_codegen_compile_parallel() simply calls lto_codegen_compile() to return a single object file. In the near future, this function is the entry point for compilation with partition. Linker can blindly call this function even if partition is turned off; in this case, compiler will return only one object file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189386 91177308-0d34-0410-b5e6-96231b3b80d8
* Add new API lto_codegen_compile_parallel().Shuxin Yang2013-08-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This API is proposed by Nick Kledzik. The semantic is: -------------------------------------------------------------------------- Generate code for merged module into an array of native object files. On success returns a pointer to an array of NativeObjectFile. The count parameter returns the number of elements in the array. Each element is a pointer/length for a generated mach-o/ELF buffer. The buffer is owned by the lto_code_gen_t and will be freed when lto_codegen_dispose() is called, or lto_codegen_compile() is called again. On failure, returns NULL (check lto_get_error_message() for details). extern const struct NativeObjectFile* lto_codegen_compile_parallel(lto_code_gen_t cg, size_t *count); --------------------------------------------------------------------------- This API is currently only called on OSX platform. Linux or other Unixes using GNU gold are not supposed to call this function, because on these systems, object files are fed back to linker via disk file instead of memory buffer. In this commit, lto_codegen_compile_parallel() simply calls lto_codegen_compile() to return a single object file. In the near future, this function is the entry point for compilation with partition. Linker can blindly call this function even if partition is turned off; in this case, compiler will return only one object file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189297 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r188188 and r188200.Shuxin Yang2013-08-12
| | | | | | | | | In order to appease people (in Apple) who accuse me for committing "huge change" (?) without proper review. Thank Eric for fixing a compile-warning. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188204 91177308-0d34-0410-b5e6-96231b3b80d8
* Misc enhancements to LTO:Shuxin Yang2013-08-12
| | | | | | | | | | | | | | | | | | | | | | 1. Add some helper classes for partitions. They are designed in a way such that the top-level LTO driver will not see much difference with or without partitioning. 2. Introduce work-dir. Now all intermediate files generated during LTO phases will be saved under work-dir. User can specify the workdir via -lto-workdir=/path/to/dir. By default the work-dir will be erased before linker exit. To keep the workdir, do -lto-keep, or -lto-keep=1. TODO: Erase the workdir, if the linker exit prematurely. We are currently not able to remove directory on signal. The support routines simply ignore directory. 3. Add one new API lto_codegen_get_files_need_remove(). Linker and LTO plugin will communicate via this API about which files (including directories) need to removed before linker exit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188188 91177308-0d34-0410-b5e6-96231b3b80d8
* Change public functions of LTOCodeGenerator from ret-false-on-succ to ↵Shuxin Yang2013-08-07
| | | | | | | | | | | | ret-true-on-succ. As of this revision, all functions of LTOCodeGenerator are consistent in ret-true-on-succ. Tested on multiple OSes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187864 91177308-0d34-0410-b5e6-96231b3b80d8
* Split getOpenFile into getOpenFile and getOpenFileSlice.Rafael Espindola2013-07-23
| | | | | | | | | | | | | | | | The main observation is that we never need both the filesize and the map size. When mapping a slice of a file, it doesn't make sense to request a null terminator and that would be the only case where the filesize would be used. There are other cleanups that should be done in this area: * A client should not have to pass the size (even an explicit -1) to say if it wants a null terminator or not, so we should probably swap the argument order. * The default should be to not require a null terminator. Very few clients require this, but many end up asking for it just because it is the default. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186984 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r169656.Bill Wendling2012-12-10
| | | | | | | | | The linker will call `lto_codegen_add_must_preserve_symbol' on all globals that should be kept around. The linker will pretend that a dylib is being created. <rdar://problem/12528059> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169770 91177308-0d34-0410-b5e6-96231b3b80d8
* Add the `lto_codegen_set_export_dynamic' function.Bill Wendling2012-12-08
| | | | | | | | | | | | | | | | | | | | | | This function sets the `_exportDynamic' ivar. When that's set, we export all symbols (e.g. we don't run the internalize pass). This is equivalent to the `--export-dynamic' linker flag in GNU land: --export-dynamic When creating a dynamically linked executable, add all symbols to the dynamic symbol table. The dynamic symbol table is the set of symbols which are visible from dynamic objects at run time. If you do not use this option, the dynamic symbol table will normally contain only those symbols which are referenced by some dynamic object mentioned in the link. If you use dlopen to load a dynamic object which needs to refer back to the symbols defined by the program, rather than some other dynamic object, then you will probably need to use this option when linking the program itself. The Darwin linker will support this via the `-export_dynamic' flag. We should modify clang to support this via the `-rdynamic' flag. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169656 91177308-0d34-0410-b5e6-96231b3b80d8
* Sort the #include lines for tools/...Chandler Carruth2012-12-04
| | | | | | | | Again, tools are trickier to pick the main module header for than library source files. I've started to follow the pattern of using LLVMContext.h when it is included as a stub for program source files. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169252 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove lto_codegen_set_whole_program_optimization. It is a work in progress,Rafael Espindola2012-04-16
| | | | | | | | | so we don't want it to show up in the stable 3.1 interface. While at it, add a comment about why LTOCodeGenerator manually creates the internalize pass. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154807 91177308-0d34-0410-b5e6-96231b3b80d8
* s/lto_codegen_whole_program_optimization/lto_codegen_set_whole_program_optim ↵Bill Wendling2012-04-09
| | | | | | ization/ git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154312 91177308-0d34-0410-b5e6-96231b3b80d8
* Add a hook to turn on the internalize pass through the LTO interface.Bill Wendling2012-04-09
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154306 91177308-0d34-0410-b5e6-96231b3b80d8
* Cleanup whitespace and remove unneeded 'extern' keyword on function definitions.Bill Wendling2012-03-31
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153802 91177308-0d34-0410-b5e6-96231b3b80d8
* Cleanup whitespace. Doxygenize comments. And indent to llvm coding standards.Bill Wendling2012-03-30
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153740 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix a ton of comment typos found by codespell. Patch byChris Lattner2011-04-15
| | | | | | | | Luis Felipe Strano Moraes! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129558 91177308-0d34-0410-b5e6-96231b3b80d8
* Add a lto_codegen_compile_to_file to avoid producing a file, reading it toRafael Espindola2011-03-22
| | | | | | memory and writing it back to disk. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128108 91177308-0d34-0410-b5e6-96231b3b80d8
* Add support in the LTO library for loading an object from the middleRafael Espindola2011-03-17
| | | | | | of an file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127781 91177308-0d34-0410-b5e6-96231b3b80d8
* Switch LTO to use MC. This takes the linking of libxul.so from about 7m toRafael Espindola2011-02-24
| | | | | | 6m30. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126426 91177308-0d34-0410-b5e6-96231b3b80d8
* Don't open the file again in the gold plugin. To be able to do this, updateRafael Espindola2011-02-08
| | | | | | 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
* Do not include DataTypes.h in llvm-c/lto.h.Devang Patel2011-01-07
| | | | | | | This means avoid using uint32_t. This patch reverts r112200 and fixes original problem by fixing argument type in lto.cpp. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123038 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix prototypes.Devang Patel2010-08-26
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112200 91177308-0d34-0410-b5e6-96231b3b80d8
* Make it possible to set the cpu used for codegen.Rafael Espindola2010-08-11
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110759 91177308-0d34-0410-b5e6-96231b3b80d8
* Make it possible to set the flags passed to the assembler.Rafael Espindola2010-08-10
| | | | | | Nick, please review. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110705 91177308-0d34-0410-b5e6-96231b3b80d8
* Make it possible to set the target triple and expose that with an option in theRafael Espindola2010-08-09
| | | | | | gold plugin. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110604 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove the GCC path from libLTO. This has been superceded by setAssemblerPath.Nick Lewycky2009-08-03
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77960 91177308-0d34-0410-b5e6-96231b3b80d8
* Add newline at end of file.Duncan Sands2009-07-03
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74774 91177308-0d34-0410-b5e6-96231b3b80d8
* Maintain the old LTO API, by using the global context.Owen Anderson2009-07-02
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74678 91177308-0d34-0410-b5e6-96231b3b80d8
* Hold the LLVMContext by reference rather than by pointer.Owen Anderson2009-07-01
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74640 91177308-0d34-0410-b5e6-96231b3b80d8
* Add a pointer to the owning LLVMContext to Module. This requires threading ↵Owen Anderson2009-07-01
| | | | | | | | | | | LLVMContext through a lot of the bitcode reader and ASM parser APIs, as well as supporting it in all of the tools. Patches for Clang and LLVM-GCC to follow. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74614 91177308-0d34-0410-b5e6-96231b3b80d8
* Indentation.Evan Cheng2009-06-26
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74281 91177308-0d34-0410-b5e6-96231b3b80d8
* <rdar://problem/6940611> libLTO.dylib needs to let linker specify path to ↵Nick Kledzik2009-06-04
| | | | | | | | | | | | assembler Add lto_codegen_set_assembler_path() API which allows the linker to specify the path to the assembler tool to run. When assembler is used (instead of compiler) different command line options are used. Add LTO_API_VERSION #define so clients (linkers) can conditionalize use of new APIs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72823 91177308-0d34-0410-b5e6-96231b3b80d8
* Allow a user of libLTO to specify the full pathname of the gcc executable toNick Lewycky2009-04-30
| | | | | | | | | | run when assembling. Wire this up to the gold plugin. You can now pass --plugin-opt gcc=/foo/bar/gcc and it will run that gcc instead of looking for it on the path. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70490 91177308-0d34-0410-b5e6-96231b3b80d8
* fix dangling pointer and argv off by one errors. Add support for ↵Nick Kledzik2008-07-08
| | | | | | --disable-inlining git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53249 91177308-0d34-0410-b5e6-96231b3b80d8
* Provide a hook to set the code generation debug options to investigate lto ↵Devang Patel2008-07-03
| | | | | | failures. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53119 91177308-0d34-0410-b5e6-96231b3b80d8
* Rename new lto2 tool as lto.Devang Patel2008-06-30
| | | | | | | lto2->lto git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52912 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove old LTO interface.Devang Patel2008-06-30
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52909 91177308-0d34-0410-b5e6-96231b3b80d8
* Add CommonLinkage to lto (treated same as weak AFAICT)Dale Johannesen2008-05-16
| | | | | | | | and llvm-nm (prints as C). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51209 91177308-0d34-0410-b5e6-96231b3b80d8