From 9383e9c1e627b49cc1c80c2e6117132734a2fba8 Mon Sep 17 00:00:00 2001 From: Mariusz Ceier Date: Wed, 19 May 2021 11:07:39 -0400 Subject: [PATCH] Fix lld macho standalone build by including llvm/Config/llvm-config.h instead of llvm/Config/config.h lld/MachO/Driver.cpp and lld/MachO/SyntheticSections.cpp include llvm/Config/config.h which doesn't exist when building standalone lld. This patch replaces llvm/Config/config.h include with llvm/Config/llvm-config.h just like it is in lld/ELF/Driver.cpp and HAVE_LIBXAR with LLVM_HAVE_LIXAR and moves LLVM_HAVE_LIBXAR from config.h to llvm-config.h Also it adds LLVM_HAVE_LIBXAR to LLVMConfig.cmake and links liblldMachO2.so with XAR_LIB if LLVM_HAVE_LIBXAR is set. Differential Revision: https://reviews.llvm.org/D102084 --- lld/CMakeLists.txt | 4 ++++ lld/MachO/CMakeLists.txt | 1 + lld/MachO/Driver.cpp | 4 ++-- lld/MachO/SyntheticSections.cpp | 8 ++++---- lld/test/CMakeLists.txt | 2 +- lld/test/lit.site.cfg.py.in | 2 +- lld/tools/lld/CMakeLists.txt | 2 +- llvm/cmake/config-ix.cmake | 4 ++-- llvm/cmake/modules/LLVMConfig.cmake.in | 2 ++ llvm/include/llvm/Config/config.h.cmake | 3 --- llvm/include/llvm/Config/llvm-config.h.cmake | 3 +++ llvm/test/CMakeLists.txt | 2 +- llvm/test/lit.site.cfg.py.in | 2 +- llvm/tools/llvm-objdump/CMakeLists.txt | 2 +- llvm/tools/llvm-objdump/MachODump.cpp | 18 +++++++++--------- llvm/utils/gn/secondary/lld/test/BUILD.gn | 4 ++-- .../llvm/include/llvm/Config/BUILD.gn | 12 ++++++------ llvm/utils/gn/secondary/llvm/test/BUILD.gn | 4 ++-- 18 files changed, 43 insertions(+), 36 deletions(-) diff --git a/lld/CMakeLists.txt b/lld/CMakeLists.txt index 48c7081dae37..2e99564f4e3e 100644 --- a/lld/CMakeLists.txt +++ b/lld/CMakeLists.txt @@ -110,6 +110,10 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) set(LLVM_INCLUDE_TESTS OFF) endif() endif() + + if(LLVM_HAVE_LIBXAR) + set(XAR_LIB xar) + endif() endif() set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/lld/MachO/CMakeLists.txt b/lld/MachO/CMakeLists.txt index cb289f142ea8..1ddf5954ff65 100644 --- a/lld/MachO/CMakeLists.txt +++ b/lld/MachO/CMakeLists.txt @@ -48,6 +48,7 @@ add_lld_library(lldMachO2 LINK_LIBS lldCommon ${LLVM_PTHREAD_LIB} + ${XAR_LIB} DEPENDS MachOOptionsTableGen diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index 6ce261cf7a54..498924db6e4c 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -31,7 +31,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/MachO.h" #include "llvm/BinaryFormat/Magic.h" -#include "llvm/Config/config.h" +#include "llvm/Config/llvm-config.h" #include "llvm/LTO/LTO.h" #include "llvm/Object/Archive.h" #include "llvm/Option/ArgList.h" @@ -992,7 +992,7 @@ bool macho::link(ArrayRef argsArr, bool canExitEarly, args.hasFlag(OPT_encryptable, OPT_no_encryption, is_contained(encryptablePlatforms, config->platform())); -#ifndef HAVE_LIBXAR +#ifndef LLVM_HAVE_LIBXAR if (config->emitBitcodeBundle) error("-bitcode_bundle unsupported because LLD wasn't built with libxar"); #endif diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp index f0070fe48e69..2b63b839c074 100644 --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -20,7 +20,7 @@ #include "lld/Common/ErrorHandler.h" #include "lld/Common/Memory.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/Config/config.h" +#include "llvm/Config/llvm-config.h" #include "llvm/Support/EndianStream.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/LEB128.h" @@ -31,7 +31,7 @@ #include #endif -#ifdef HAVE_LIBXAR +#ifdef LLVM_HAVE_LIBXAR #include #include #endif @@ -1036,7 +1036,7 @@ private: } while (0); void BitcodeBundleSection::finalize() { -#ifdef HAVE_LIBXAR +#ifdef LLVM_HAVE_LIBXAR using namespace llvm::sys::fs; CHECK_EC(createTemporaryFile("bitcode-bundle", "xar", xarPath)); @@ -1048,7 +1048,7 @@ void BitcodeBundleSection::finalize() { CHECK_EC(xar_close(xar)); file_size(xarPath, xarSize); -#endif // defined(HAVE_LIBXAR) +#endif // defined(LLVM_HAVE_LIBXAR) } void BitcodeBundleSection::writeTo(uint8_t *buf) const { diff --git a/lld/test/CMakeLists.txt b/lld/test/CMakeLists.txt index 2b7ae3d7b027..0c42427e006b 100644 --- a/lld/test/CMakeLists.txt +++ b/lld/test/CMakeLists.txt @@ -11,7 +11,7 @@ llvm_canonicalize_cmake_booleans( LLVM_ENABLE_ZLIB LLVM_ENABLE_LIBXML2 LLD_DEFAULT_LD_LLD_IS_MINGW - HAVE_LIBXAR + LLVM_HAVE_LIBXAR ) configure_lit_site_cfg( diff --git a/lld/test/lit.site.cfg.py.in b/lld/test/lit.site.cfg.py.in index 20d44da9d63f..f9f695b62434 100644 --- a/lld/test/lit.site.cfg.py.in +++ b/lld/test/lit.site.cfg.py.in @@ -15,7 +15,7 @@ config.lld_tools_dir = "@LLD_TOOLS_DIR@" config.target_triple = "@TARGET_TRIPLE@" config.python_executable = "@Python3_EXECUTABLE@" config.have_zlib = @LLVM_ENABLE_ZLIB@ -config.have_libxar = @HAVE_LIBXAR@ +config.have_libxar = @LLVM_HAVE_LIBXAR@ config.have_libxml2 = @LLVM_ENABLE_LIBXML2@ config.sizeof_void_p = @CMAKE_SIZEOF_VOID_P@ config.ld_lld_default_mingw = @LLD_DEFAULT_LD_LLD_IS_MINGW@ diff --git a/lld/tools/lld/CMakeLists.txt b/lld/tools/lld/CMakeLists.txt index 827511d35a79..738f484a97c2 100644 --- a/lld/tools/lld/CMakeLists.txt +++ b/lld/tools/lld/CMakeLists.txt @@ -20,7 +20,7 @@ target_link_libraries(lld lldWasm ) -if(HAVE_LIBXAR) +if(LLVM_HAVE_LIBXAR) target_link_libraries(lld PRIVATE ${XAR_LIB}) endif() diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake index dd16d89b7342..d4cbf37d19a2 100644 --- a/llvm/cmake/config-ix.cmake +++ b/llvm/cmake/config-ix.cmake @@ -189,8 +189,8 @@ else() set(LLVM_ENABLE_TERMINFO 0) endif() -check_library_exists(xar xar_open "" HAVE_LIBXAR) -if(HAVE_LIBXAR) +check_library_exists(xar xar_open "" LLVM_HAVE_LIBXAR) +if(LLVM_HAVE_LIBXAR) set(XAR_LIB xar) endif() diff --git a/llvm/cmake/modules/LLVMConfig.cmake.in b/llvm/cmake/modules/LLVMConfig.cmake.in index c710cbf50484..a71bef19fd0c 100644 --- a/llvm/cmake/modules/LLVMConfig.cmake.in +++ b/llvm/cmake/modules/LLVMConfig.cmake.in @@ -111,6 +111,8 @@ set(LLVM_ENABLE_SHARED_LIBS @BUILD_SHARED_LIBS@) set(LLVM_DEFAULT_EXTERNAL_LIT "@LLVM_CONFIG_DEFAULT_EXTERNAL_LIT@") set(LLVM_LIT_ARGS "@LLVM_LIT_ARGS@") +set(LLVM_HAVE_LIBXAR "@LLVM_HAVE_LIBXAR@") + if(NOT TARGET LLVMSupport) @LLVM_CONFIG_INCLUDE_EXPORTS@ @llvm_config_include_buildtree_only_exports@ diff --git a/llvm/include/llvm/Config/config.h.cmake b/llvm/include/llvm/Config/config.h.cmake index 3aff8be86fcf..c7db4a21cb13 100644 --- a/llvm/include/llvm/Config/config.h.cmake +++ b/llvm/include/llvm/Config/config.h.cmake @@ -220,9 +220,6 @@ /* Define if the setupterm() function is supported this platform. */ #cmakedefine LLVM_ENABLE_TERMINFO ${LLVM_ENABLE_TERMINFO} -/* Define if the xar_open() function is supported this platform. */ -#cmakedefine HAVE_LIBXAR ${HAVE_LIBXAR} - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_TERMIOS_H ${HAVE_TERMIOS_H} diff --git a/llvm/include/llvm/Config/llvm-config.h.cmake b/llvm/include/llvm/Config/llvm-config.h.cmake index b5fa20f789a6..9916635489e4 100644 --- a/llvm/include/llvm/Config/llvm-config.h.cmake +++ b/llvm/include/llvm/Config/llvm-config.h.cmake @@ -94,4 +94,7 @@ /* Define to 1 to enable the experimental new pass manager by default */ #cmakedefine01 LLVM_ENABLE_NEW_PASS_MANAGER +/* Define if the xar_open() function is supported on this platform. */ +#cmakedefine LLVM_HAVE_LIBXAR ${LLVM_HAVE_LIBXAR} + #endif diff --git a/llvm/test/CMakeLists.txt b/llvm/test/CMakeLists.txt index 77035899a6d9..5b3e50706fcf 100644 --- a/llvm/test/CMakeLists.txt +++ b/llvm/test/CMakeLists.txt @@ -1,6 +1,6 @@ llvm_canonicalize_cmake_booleans( BUILD_SHARED_LIBS - HAVE_LIBXAR + LLVM_HAVE_LIBXAR HAVE_OCAMLOPT HAVE_OCAML_OUNIT LLVM_ENABLE_DIA_SDK diff --git a/llvm/test/lit.site.cfg.py.in b/llvm/test/lit.site.cfg.py.in index a42ccc93800a..635b22bceaea 100644 --- a/llvm/test/lit.site.cfg.py.in +++ b/llvm/test/lit.site.cfg.py.in @@ -36,7 +36,7 @@ config.host_ldflags = '@HOST_LDFLAGS@' config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@ config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@" config.have_zlib = @LLVM_ENABLE_ZLIB@ -config.have_libxar = @HAVE_LIBXAR@ +config.have_libxar = @LLVM_HAVE_LIBXAR@ config.have_libxml2 = @LLVM_ENABLE_LIBXML2@ config.have_dia_sdk = @LLVM_ENABLE_DIA_SDK@ config.enable_ffi = @LLVM_ENABLE_FFI@ diff --git a/llvm/tools/llvm-objdump/CMakeLists.txt b/llvm/tools/llvm-objdump/CMakeLists.txt index f1323c3d584c..149bb3dc4acd 100644 --- a/llvm/tools/llvm-objdump/CMakeLists.txt +++ b/llvm/tools/llvm-objdump/CMakeLists.txt @@ -35,7 +35,7 @@ add_llvm_tool(llvm-objdump OtoolOptsTableGen ) -if(HAVE_LIBXAR) +if(LLVM_HAVE_LIBXAR) target_link_libraries(llvm-objdump PRIVATE ${XAR_LIB}) endif() diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp index 57d83110e42d..74fb685ddbfe 100644 --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -53,7 +53,7 @@ #include #include -#ifdef HAVE_LIBXAR +#ifdef LLVM_HAVE_LIBXAR extern "C" { #include } @@ -184,7 +184,7 @@ typedef std::pair DiceTableEntry; typedef std::vector DiceTable; typedef DiceTable::iterator dice_table_iterator; -#ifdef HAVE_LIBXAR +#ifdef LLVM_HAVE_LIBXAR namespace { struct ScopedXarFile { xar_t xar; @@ -211,7 +211,7 @@ struct ScopedXarIter { operator xar_iter_t() { return iter; } }; } // namespace -#endif // defined(HAVE_LIBXAR) +#endif // defined(LLVM_HAVE_LIBXAR) // This is used to search for a data in code table entry for the PC being // disassembled. The j parameter has the PC in j.first. A single data in code @@ -1697,12 +1697,12 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, StringRef DisSegName, StringRef DisSectName); static void DumpProtocolSection(MachOObjectFile *O, const char *sect, uint32_t size, uint32_t addr); -#ifdef HAVE_LIBXAR +#ifdef LLVM_HAVE_LIBXAR static void DumpBitcodeSection(MachOObjectFile *O, const char *sect, uint32_t size, bool verbose, bool PrintXarHeader, bool PrintXarFileHeaders, std::string XarMemberName); -#endif // defined(HAVE_LIBXAR) +#endif // defined(LLVM_HAVE_LIBXAR) static void DumpSectionContents(StringRef Filename, MachOObjectFile *O, bool verbose) { @@ -1773,13 +1773,13 @@ static void DumpSectionContents(StringRef Filename, MachOObjectFile *O, DumpProtocolSection(O, sect, sect_size, sect_addr); continue; } -#ifdef HAVE_LIBXAR +#ifdef LLVM_HAVE_LIBXAR if (SegName == "__LLVM" && SectName == "__bundle") { DumpBitcodeSection(O, sect, sect_size, verbose, SymbolicOperands, ArchiveHeaders, ""); continue; } -#endif // defined(HAVE_LIBXAR) +#endif // defined(LLVM_HAVE_LIBXAR) switch (section_type) { case MachO::S_REGULAR: DumpRawSectionContents(O, sect, sect_size, sect_addr); @@ -6460,7 +6460,7 @@ static void DumpProtocolSection(MachOObjectFile *O, const char *sect, } } -#ifdef HAVE_LIBXAR +#ifdef LLVM_HAVE_LIBXAR static inline void swapStruct(struct xar_header &xar) { sys::swapByteOrder(xar.magic); sys::swapByteOrder(xar.size); @@ -6823,7 +6823,7 @@ static void DumpBitcodeSection(MachOObjectFile *O, const char *sect, } } } -#endif // defined(HAVE_LIBXAR) +#endif // defined(LLVM_HAVE_LIBXAR) static void printObjcMetaData(MachOObjectFile *O, bool verbose) { if (O->is64Bit()) diff --git a/llvm/utils/gn/secondary/lld/test/BUILD.gn b/llvm/utils/gn/secondary/lld/test/BUILD.gn index 5268f2e544b6..c2e4f685955c 100644 --- a/llvm/utils/gn/secondary/lld/test/BUILD.gn +++ b/llvm/utils/gn/secondary/lld/test/BUILD.gn @@ -53,9 +53,9 @@ write_lit_cfg("lit_site_cfg") { } if (llvm_enable_libxar) { - extra_values += [ "HAVE_LIBXAR=1" ] + extra_values += [ "LLVM_HAVE_LIBXAR=1" ] } else { - extra_values += [ "HAVE_LIBXAR=0" ] # Must be 0. + extra_values += [ "LLVM_HAVE_LIBXAR=0" ] # Must be 0. } if (llvm_enable_libxml2) { diff --git a/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn b/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn index d420c1c0158c..edc2226e556d 100644 --- a/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn @@ -296,12 +296,6 @@ write_cmake_config("config") { values += [ "HAVE_LIBEDIT=" ] } - if (llvm_enable_libxar) { - values += [ "HAVE_LIBXAR=1" ] - } else { - values += [ "HAVE_LIBXAR=" ] - } - if (llvm_enable_terminfo) { values += [ "LLVM_ENABLE_TERMINFO=1" ] } else { @@ -368,6 +362,12 @@ write_cmake_config("llvm-config") { ] } + if (llvm_enable_libxar) { + values += [ "LLVM_HAVE_LIBXAR=1" ] + } else { + values += [ "LLVM_HAVE_LIBXAR=" ] + } + if (llvm_enable_threads) { values += [ "LLVM_ENABLE_THREADS=1" ] } else { diff --git a/llvm/utils/gn/secondary/llvm/test/BUILD.gn b/llvm/utils/gn/secondary/llvm/test/BUILD.gn index 5d07a79fb087..612aeaefce41 100644 --- a/llvm/utils/gn/secondary/llvm/test/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/test/BUILD.gn @@ -162,9 +162,9 @@ write_lit_config("lit_site_cfg") { } if (llvm_enable_libxar) { - extra_values += [ "HAVE_LIBXAR=1" ] + extra_values += [ "LLVM_HAVE_LIBXAR=1" ] } else { - extra_values += [ "HAVE_LIBXAR=0" ] # Must be 0. + extra_values += [ "LLVM_HAVE_LIBXAR=0" ] # Must be 0. } if (llvm_enable_dia_sdk) {