Index: clang/CMakeLists.txt =================================================================== --- clang/CMakeLists.txt +++ clang/CMakeLists.txt @@ -681,7 +681,7 @@ -DDYLD_LIBRARY_PATH=${LLVM_LIBRARY_OUTPUT_INTDIR}) elseif(NOT WIN32) add_dependencies(clang-bootstrap-deps llvm-ar llvm-ranlib) - if(NOT BOOTSTRAP_LLVM_ENABLE_LLD AND LLVM_BINUTILS_INCDIR) + if(NOT BOOTSTRAP_LLVM_ENABLE_LLD) add_dependencies(clang-bootstrap-deps LLVMgold) endif() set(${CLANG_STAGE}_AR -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar) @@ -721,7 +721,6 @@ CLANG_VERSION_PATCHLEVEL CLANG_VENDOR LLVM_VERSION_SUFFIX - LLVM_BINUTILS_INCDIR CLANG_REPOSITORY_STRING CMAKE_C_COMPILER_LAUNCHER CMAKE_CXX_COMPILER_LAUNCHER Index: clang/docs/ThinLTO.rst =================================================================== --- clang/docs/ThinLTO.rst +++ clang/docs/ThinLTO.rst @@ -94,11 +94,9 @@ .. code-block:: console - /usr/bin/ld: error: /path/to/clang/bin/../lib/LLVMgold.so: could not load plugin library: /path/to/clang/bin/../lib/LLVMgold.so: cannot open shared object file: No such file or directory + /usr/bin/ld: fatal error: cannot use --plugin: /usr/bin/ld was compiled without plugin support -Then either gold was not configured with plugins enabled, or clang -was not built with ``-DLLVM_BINUTILS_INCDIR`` set properly. See -the instructions for the +Then gold was not configured with plugins enabled. See the instructions for the `LLVM gold plugin `_. Controlling Backend Parallelism Index: compiler-rt/test/cfi/CMakeLists.txt =================================================================== --- compiler-rt/test/cfi/CMakeLists.txt +++ compiler-rt/test/cfi/CMakeLists.txt @@ -69,11 +69,7 @@ sanstats ) if(LLVM_ENABLE_PIC) - if(LLVM_BINUTILS_INCDIR) - list(APPEND CFI_TEST_DEPS - LLVMgold - ) - endif() + list(APPEND CFI_TEST_DEPS LLVMgold) if(APPLE) list(APPEND CFI_TEST_DEPS LTO Index: compiler-rt/test/safestack/CMakeLists.txt =================================================================== --- compiler-rt/test/safestack/CMakeLists.txt +++ compiler-rt/test/safestack/CMakeLists.txt @@ -7,10 +7,7 @@ # Some tests require LTO, so add a dependency on the relevant LTO plugin. if(LLVM_ENABLE_PIC) - if(LLVM_BINUTILS_INCDIR) - list(APPEND SAFESTACK_TEST_DEPS - LLVMgold - ) + list(APPEND SAFESTACK_TEST_DEPS LLVMgold) endif() if(APPLE) list(APPEND SAFESTACK_TEST_DEPS Index: llvm/cmake/config-ix.cmake =================================================================== --- llvm/cmake/config-ix.cmake +++ llvm/cmake/config-ix.cmake @@ -597,8 +597,6 @@ endif() find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold ${LLVM_DEFAULT_TARGET_TRIPLE}-ld ld DOC "The gold linker") -set(LLVM_BINUTILS_INCDIR "" CACHE PATH - "PATH to binutils/include containing plugin-api.h for gold plugin.") if(CMAKE_GENERATOR MATCHES "Ninja") execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} --version Index: llvm/docs/GoldPlugin.rst =================================================================== --- llvm/docs/GoldPlugin.rst +++ llvm/docs/GoldPlugin.rst @@ -64,10 +64,6 @@ to automatically install the newly built gold as the default linker with ``make install``. -* Build the LLVMgold plugin. Run CMake with - ``-DLLVM_BINUTILS_INCDIR=/path/to/binutils/include``. The correct include - path will contain the file ``plugin-api.h``. - Usage ===== @@ -175,11 +171,3 @@ The environment variable settings may work for non-autotooled projects too, but you may need to set the ``LD`` environment variable as well. - -Licensing -========= - -Gold is licensed under the GPLv3. LLVMgold uses the interface file -``plugin-api.h`` from gold which means that the resulting ``LLVMgold.so`` -binary is also GPLv3. This can still be used to link non-GPLv3 programs -just as much as gold could without the plugin. Index: llvm/include/llvm/LTO/Plugin.h =================================================================== --- /dev/null +++ llvm/include/llvm/LTO/Plugin.h @@ -0,0 +1,272 @@ +//===-Plugin.h - LLVM LTO Plugin API -------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file declares data types and functions used to support LLVMgold plugin. +// These definitions must be in sync with GNU binutils' plugin-api.h header. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LTO_PLUGIN_H +#define LLVM_LTO_PLUGIN_H + +namespace llvm { +namespace lto { + +enum ld_plugin_status { + LDPS_OK, + LDPS_NO_SYMS, + LDPS_BAD_HANDLE, + LDPS_ERR, +}; + +enum ld_plugin_api_version { + LD_PLUGIN_API_VERSION = 1, +}; + +enum ld_plugin_output_file_type { + LDPO_REL, + LDPO_EXEC, + LDPO_DYN, + LDPO_PIE, +}; + +struct ld_plugin_input_file { + const char *name; + int fd; + uint64_t offset; + uint64_t filesize; + void *handle; +}; + +struct ld_plugin_symbol { + char *name; + char *version; +#if __BIG_ENDIAN__ + char unused; + char section_kind; + char symbol_type; + char def; +#else + char def; + char symbol_type; + char section_kind; + char unused; +#endif + int visibility; + uint64_t size; + char *comdat_key; + int resolution; +}; + +struct ld_plugin_section { + const void *handle; + unsigned int shndx; +}; + +enum ld_plugin_symbol_kind { + LDPK_DEF, + LDPK_WEAKDEF, + LDPK_UNDEF, + LDPK_WEAKUNDEF, + LDPK_COMMON, +}; + +enum ld_plugin_symbol_visibility { + LDPV_DEFAULT, + LDPV_PROTECTED, + LDPV_INTERNAL, + LDPV_HIDDEN, +}; + +enum ld_plugin_symbol_type { + LDST_UNKNOWN, + LDST_FUNCTION, + LDST_VARIABLE, +}; + +enum ld_plugin_symbol_section_kind { + LDSSK_DEFAULT, + LDSSK_BSS, +}; + +enum ld_plugin_symbol_resolution { + LDPR_UNKNOWN, + LDPR_UNDEF, + LDPR_PREVAILING_DEF, + LDPR_PREVAILING_DEF_IRONLY, + LDPR_PREEMPTED_REG, + LDPR_PREEMPTED_IR, + LDPR_RESOLVED_IR, + LDPR_RESOLVED_EXEC, + LDPR_RESOLVED_DYN, + LDPR_PREVAILING_DEF_IRONLY_EXP, +}; + +typedef ld_plugin_status (*ld_plugin_claim_file_handler)( + const ld_plugin_input_file *file, int *claimed); + +typedef ld_plugin_status (*ld_plugin_all_symbols_read_handler)(); + +typedef ld_plugin_status (*ld_plugin_cleanup_handler)(); + +typedef ld_plugin_status (*ld_plugin_register_claim_file)( + ld_plugin_claim_file_handler handler); + +typedef ld_plugin_status (*ld_plugin_register_all_symbols_read)( + ld_plugin_all_symbols_read_handler handler); + +typedef ld_plugin_status (*ld_plugin_register_cleanup)( + ld_plugin_cleanup_handler handler); + +typedef ld_plugin_status (*ld_plugin_add_symbols)(void *handle, int nsyms, + const ld_plugin_symbol *syms); + +typedef ld_plugin_status (*ld_plugin_get_input_file)( + const void *handle, ld_plugin_input_file *file); + +typedef ld_plugin_status (*ld_plugin_get_view)(const void *handle, + const void **viewp); + +typedef ld_plugin_status (*ld_plugin_release_input_file)(const void *handle); + +typedef ld_plugin_status (*ld_plugin_get_symbols)(const void *handle, int nsyms, + ld_plugin_symbol *syms); + +typedef ld_plugin_status (*ld_plugin_add_input_file)(const char *pathname); + +typedef ld_plugin_status (*ld_plugin_add_input_library)(const char *libname); + +typedef ld_plugin_status (*ld_plugin_set_extra_library_path)(const char *path); + +typedef ld_plugin_status (*ld_plugin_message)(int level, const char *format, + ...); + +typedef ld_plugin_status (*ld_plugin_get_input_section_count)( + const void *handle, unsigned int *count); + +typedef ld_plugin_status (*ld_plugin_get_input_section_type)( + const ld_plugin_section section, unsigned int *type); + +typedef ld_plugin_status (*ld_plugin_get_input_section_name)( + const ld_plugin_section section, char **section_name_ptr); + +typedef ld_plugin_status (*ld_plugin_get_input_section_contents)( + const ld_plugin_section section, const unsigned char **section_contents, + size_t *len); + +typedef ld_plugin_status (*ld_plugin_update_section_order)( + const ld_plugin_section *section_list, unsigned int num_sections); + +typedef ld_plugin_status (*ld_plugin_allow_section_ordering)(); + +typedef ld_plugin_status (*ld_plugin_allow_unique_segment_for_sections)(); + +typedef ld_plugin_status (*ld_plugin_unique_segment_for_sections)( + const char *segment_name, uint64_t segment_flags, + uint64_t segment_alignment, const ld_plugin_section *section_list, + unsigned int num_sections); + +typedef ld_plugin_status (*ld_plugin_get_input_section_alignment)( + const ld_plugin_section section, unsigned int *addralign); + +typedef ld_plugin_status (*ld_plugin_get_input_section_size)( + const ld_plugin_section section, uint64_t *secsize); + +typedef ld_plugin_status (*ld_plugin_new_input_handler)( + const ld_plugin_input_file *file); + +typedef ld_plugin_status (*ld_plugin_register_new_input)( + ld_plugin_new_input_handler handler); + +typedef ld_plugin_status (*ld_plugin_get_wrap_symbols)( + uint64_t *num_symbols, const char ***wrap_symbol_list); + +enum ld_plugin_level { + LDPL_INFO, + LDPL_WARNING, + LDPL_ERROR, + LDPL_FATAL, +}; + +enum ld_plugin_tag { + LDPT_NULL, + LDPT_API_VERSION, + LDPT_GOLD_VERSION, + LDPT_LINKER_OUTPUT, + LDPT_OPTION, + LDPT_REGISTER_CLAIM_FILE_HOOK, + LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK, + LDPT_REGISTER_CLEANUP_HOOK, + LDPT_ADD_SYMBOLS, + LDPT_GET_SYMBOLS, + LDPT_ADD_INPUT_FILE, + LDPT_MESSAGE, + LDPT_GET_INPUT_FILE, + LDPT_RELEASE_INPUT_FILE, + LDPT_ADD_INPUT_LIBRARY, + LDPT_OUTPUT_NAME, + LDPT_SET_EXTRA_LIBRARY_PATH, + LDPT_GNU_LD_VERSION, + LDPT_GET_VIEW, + LDPT_GET_INPUT_SECTION_COUNT, + LDPT_GET_INPUT_SECTION_TYPE, + LDPT_GET_INPUT_SECTION_NAME, + LDPT_GET_INPUT_SECTION_CONTENTS, + LDPT_UPDATE_SECTION_ORDER, + LDPT_ALLOW_SECTION_ORDERING, + LDPT_GET_SYMBOLS_V2, + LDPT_ALLOW_UNIQUE_SEGMENT_FOR_SECTIONS, + LDPT_UNIQUE_SEGMENT_FOR_SECTIONS, + LDPT_GET_SYMBOLS_V3, + LDPT_GET_INPUT_SECTION_ALIGNMENT, + LDPT_GET_INPUT_SECTION_SIZE, + LDPT_REGISTER_NEW_INPUT_HOOK, + LDPT_GET_WRAP_SYMBOLS, + LDPT_ADD_SYMBOLS_V2, +}; + +struct ld_plugin_tv { + ld_plugin_tag tv_tag; + + union { + int tv_val; + const char *tv_string; + ld_plugin_register_claim_file tv_register_claim_file; + ld_plugin_register_all_symbols_read tv_register_all_symbols_read; + ld_plugin_register_cleanup tv_register_cleanup; + ld_plugin_add_symbols tv_add_symbols; + ld_plugin_get_symbols tv_get_symbols; + ld_plugin_add_input_file tv_add_input_file; + ld_plugin_message tv_message; + ld_plugin_get_input_file tv_get_input_file; + ld_plugin_get_view tv_get_view; + ld_plugin_release_input_file tv_release_input_file; + ld_plugin_add_input_library tv_add_input_library; + ld_plugin_set_extra_library_path tv_set_extra_library_path; + ld_plugin_get_input_section_count tv_get_input_section_count; + ld_plugin_get_input_section_type tv_get_input_section_type; + ld_plugin_get_input_section_name tv_get_input_section_name; + ld_plugin_get_input_section_contents tv_get_input_section_contents; + ld_plugin_update_section_order tv_update_section_order; + ld_plugin_allow_section_ordering tv_allow_section_ordering; + ld_plugin_allow_unique_segment_for_sections + tv_allow_unique_segment_for_sections; + ld_plugin_unique_segment_for_sections tv_unique_segment_for_sections; + ld_plugin_get_input_section_alignment tv_get_input_section_alignment; + ld_plugin_get_input_section_size tv_get_input_section_size; + ld_plugin_register_new_input tv_register_new_input; + ld_plugin_get_wrap_symbols tv_get_wrap_symbols; + } tv_u; +}; + +typedef ld_plugin_status (*ld_plugin_onload)(ld_plugin_tv *tv); + +} // namespace lto +} // namespace llvm + +#endif Index: llvm/tools/gold/CMakeLists.txt =================================================================== --- llvm/tools/gold/CMakeLists.txt +++ llvm/tools/gold/CMakeLists.txt @@ -1,8 +1,6 @@ set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/gold.exports) -if( LLVM_ENABLE_PIC AND LLVM_BINUTILS_INCDIR ) - include_directories( ${LLVM_BINUTILS_INCDIR} ) - +if (LLVM_ENABLE_PIC) set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} Linker Index: llvm/tools/gold/gold-plugin.cpp =================================================================== --- llvm/tools/gold/gold-plugin.cpp +++ llvm/tools/gold/gold-plugin.cpp @@ -20,6 +20,7 @@ #include "llvm/IR/Constants.h" #include "llvm/IR/DiagnosticPrinter.h" #include "llvm/LTO/LTO.h" +#include "llvm/LTO/Plugin.h" #include "llvm/Object/Error.h" #include "llvm/Remarks/HotnessThresholdParser.h" #include "llvm/Support/CachePruning.h" @@ -35,7 +36,6 @@ #include "llvm/Support/raw_ostream.h" #include #include -#include #include #include #include