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
This commit is contained in:
Mariusz Ceier 2021-05-19 11:07:39 -04:00 committed by Nico Weber
parent 66963bf381
commit 9383e9c1e6
18 changed files with 43 additions and 36 deletions

View File

@ -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})

View File

@ -48,6 +48,7 @@ add_lld_library(lldMachO2
LINK_LIBS
lldCommon
${LLVM_PTHREAD_LIB}
${XAR_LIB}
DEPENDS
MachOOptionsTableGen

View File

@ -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<const char *> 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

View File

@ -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 <sys/mman.h>
#endif
#ifdef HAVE_LIBXAR
#ifdef LLVM_HAVE_LIBXAR
#include <fcntl.h>
#include <xar/xar.h>
#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 {

View File

@ -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(

View File

@ -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@

View File

@ -20,7 +20,7 @@ target_link_libraries(lld
lldWasm
)
if(HAVE_LIBXAR)
if(LLVM_HAVE_LIBXAR)
target_link_libraries(lld PRIVATE ${XAR_LIB})
endif()

View File

@ -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()

View File

@ -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@

View File

@ -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 <termios.h> header file. */
#cmakedefine HAVE_TERMIOS_H ${HAVE_TERMIOS_H}

View File

@ -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

View File

@ -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

View File

@ -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@

View File

@ -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()

View File

@ -53,7 +53,7 @@
#include <cstring>
#include <system_error>
#ifdef HAVE_LIBXAR
#ifdef LLVM_HAVE_LIBXAR
extern "C" {
#include <xar/xar.h>
}
@ -184,7 +184,7 @@ typedef std::pair<uint64_t, DiceRef> DiceTableEntry;
typedef std::vector<DiceTableEntry> 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())

View File

@ -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) {

View File

@ -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 {

View File

@ -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) {