Skip to content

Commit 9383e9c

Browse files
Mariusz Ceiernico
authored andcommitted
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
1 parent 66963bf commit 9383e9c

File tree

18 files changed

+43
-36
lines changed

18 files changed

+43
-36
lines changed

lld/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
110110
set(LLVM_INCLUDE_TESTS OFF)
111111
endif()
112112
endif()
113+
114+
if(LLVM_HAVE_LIBXAR)
115+
set(XAR_LIB xar)
116+
endif()
113117
endif()
114118

115119
set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

lld/MachO/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ add_lld_library(lldMachO2
4848
LINK_LIBS
4949
lldCommon
5050
${LLVM_PTHREAD_LIB}
51+
${XAR_LIB}
5152

5253
DEPENDS
5354
MachOOptionsTableGen

lld/MachO/Driver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "llvm/ADT/StringRef.h"
3232
#include "llvm/BinaryFormat/MachO.h"
3333
#include "llvm/BinaryFormat/Magic.h"
34-
#include "llvm/Config/config.h"
34+
#include "llvm/Config/llvm-config.h"
3535
#include "llvm/LTO/LTO.h"
3636
#include "llvm/Object/Archive.h"
3737
#include "llvm/Option/ArgList.h"
@@ -992,7 +992,7 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
992992
args.hasFlag(OPT_encryptable, OPT_no_encryption,
993993
is_contained(encryptablePlatforms, config->platform()));
994994

995-
#ifndef HAVE_LIBXAR
995+
#ifndef LLVM_HAVE_LIBXAR
996996
if (config->emitBitcodeBundle)
997997
error("-bitcode_bundle unsupported because LLD wasn't built with libxar");
998998
#endif

lld/MachO/SyntheticSections.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "lld/Common/ErrorHandler.h"
2121
#include "lld/Common/Memory.h"
2222
#include "llvm/ADT/STLExtras.h"
23-
#include "llvm/Config/config.h"
23+
#include "llvm/Config/llvm-config.h"
2424
#include "llvm/Support/EndianStream.h"
2525
#include "llvm/Support/FileSystem.h"
2626
#include "llvm/Support/LEB128.h"
@@ -31,7 +31,7 @@
3131
#include <sys/mman.h>
3232
#endif
3333

34-
#ifdef HAVE_LIBXAR
34+
#ifdef LLVM_HAVE_LIBXAR
3535
#include <fcntl.h>
3636
#include <xar/xar.h>
3737
#endif
@@ -1036,7 +1036,7 @@ class ErrorCodeWrapper {
10361036
} while (0);
10371037

10381038
void BitcodeBundleSection::finalize() {
1039-
#ifdef HAVE_LIBXAR
1039+
#ifdef LLVM_HAVE_LIBXAR
10401040
using namespace llvm::sys::fs;
10411041
CHECK_EC(createTemporaryFile("bitcode-bundle", "xar", xarPath));
10421042

@@ -1048,7 +1048,7 @@ void BitcodeBundleSection::finalize() {
10481048
CHECK_EC(xar_close(xar));
10491049

10501050
file_size(xarPath, xarSize);
1051-
#endif // defined(HAVE_LIBXAR)
1051+
#endif // defined(LLVM_HAVE_LIBXAR)
10521052
}
10531053

10541054
void BitcodeBundleSection::writeTo(uint8_t *buf) const {

lld/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ llvm_canonicalize_cmake_booleans(
1111
LLVM_ENABLE_ZLIB
1212
LLVM_ENABLE_LIBXML2
1313
LLD_DEFAULT_LD_LLD_IS_MINGW
14-
HAVE_LIBXAR
14+
LLVM_HAVE_LIBXAR
1515
)
1616

1717
configure_lit_site_cfg(

lld/test/lit.site.cfg.py.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ config.lld_tools_dir = "@LLD_TOOLS_DIR@"
1515
config.target_triple = "@TARGET_TRIPLE@"
1616
config.python_executable = "@Python3_EXECUTABLE@"
1717
config.have_zlib = @LLVM_ENABLE_ZLIB@
18-
config.have_libxar = @HAVE_LIBXAR@
18+
config.have_libxar = @LLVM_HAVE_LIBXAR@
1919
config.have_libxml2 = @LLVM_ENABLE_LIBXML2@
2020
config.sizeof_void_p = @CMAKE_SIZEOF_VOID_P@
2121
config.ld_lld_default_mingw = @LLD_DEFAULT_LD_LLD_IS_MINGW@

lld/tools/lld/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ target_link_libraries(lld
2020
lldWasm
2121
)
2222

23-
if(HAVE_LIBXAR)
23+
if(LLVM_HAVE_LIBXAR)
2424
target_link_libraries(lld PRIVATE ${XAR_LIB})
2525
endif()
2626

llvm/cmake/config-ix.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ else()
189189
set(LLVM_ENABLE_TERMINFO 0)
190190
endif()
191191

192-
check_library_exists(xar xar_open "" HAVE_LIBXAR)
193-
if(HAVE_LIBXAR)
192+
check_library_exists(xar xar_open "" LLVM_HAVE_LIBXAR)
193+
if(LLVM_HAVE_LIBXAR)
194194
set(XAR_LIB xar)
195195
endif()
196196

llvm/cmake/modules/LLVMConfig.cmake.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ set(LLVM_ENABLE_SHARED_LIBS @BUILD_SHARED_LIBS@)
111111
set(LLVM_DEFAULT_EXTERNAL_LIT "@LLVM_CONFIG_DEFAULT_EXTERNAL_LIT@")
112112
set(LLVM_LIT_ARGS "@LLVM_LIT_ARGS@")
113113

114+
set(LLVM_HAVE_LIBXAR "@LLVM_HAVE_LIBXAR@")
115+
114116
if(NOT TARGET LLVMSupport)
115117
@LLVM_CONFIG_INCLUDE_EXPORTS@
116118
@llvm_config_include_buildtree_only_exports@

llvm/include/llvm/Config/config.h.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,6 @@
220220
/* Define if the setupterm() function is supported this platform. */
221221
#cmakedefine LLVM_ENABLE_TERMINFO ${LLVM_ENABLE_TERMINFO}
222222

223-
/* Define if the xar_open() function is supported this platform. */
224-
#cmakedefine HAVE_LIBXAR ${HAVE_LIBXAR}
225-
226223
/* Define to 1 if you have the <termios.h> header file. */
227224
#cmakedefine HAVE_TERMIOS_H ${HAVE_TERMIOS_H}
228225

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,7 @@
9494
/* Define to 1 to enable the experimental new pass manager by default */
9595
#cmakedefine01 LLVM_ENABLE_NEW_PASS_MANAGER
9696

97+
/* Define if the xar_open() function is supported on this platform. */
98+
#cmakedefine LLVM_HAVE_LIBXAR ${LLVM_HAVE_LIBXAR}
99+
97100
#endif

llvm/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
llvm_canonicalize_cmake_booleans(
22
BUILD_SHARED_LIBS
3-
HAVE_LIBXAR
3+
LLVM_HAVE_LIBXAR
44
HAVE_OCAMLOPT
55
HAVE_OCAML_OUNIT
66
LLVM_ENABLE_DIA_SDK

llvm/test/lit.site.cfg.py.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ config.host_ldflags = '@HOST_LDFLAGS@'
3636
config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@
3737
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
3838
config.have_zlib = @LLVM_ENABLE_ZLIB@
39-
config.have_libxar = @HAVE_LIBXAR@
39+
config.have_libxar = @LLVM_HAVE_LIBXAR@
4040
config.have_libxml2 = @LLVM_ENABLE_LIBXML2@
4141
config.have_dia_sdk = @LLVM_ENABLE_DIA_SDK@
4242
config.enable_ffi = @LLVM_ENABLE_FFI@

llvm/tools/llvm-objdump/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ add_llvm_tool(llvm-objdump
3535
OtoolOptsTableGen
3636
)
3737

38-
if(HAVE_LIBXAR)
38+
if(LLVM_HAVE_LIBXAR)
3939
target_link_libraries(llvm-objdump PRIVATE ${XAR_LIB})
4040
endif()
4141

llvm/tools/llvm-objdump/MachODump.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#include <cstring>
5454
#include <system_error>
5555

56-
#ifdef HAVE_LIBXAR
56+
#ifdef LLVM_HAVE_LIBXAR
5757
extern "C" {
5858
#include <xar/xar.h>
5959
}
@@ -184,7 +184,7 @@ typedef std::pair<uint64_t, DiceRef> DiceTableEntry;
184184
typedef std::vector<DiceTableEntry> DiceTable;
185185
typedef DiceTable::iterator dice_table_iterator;
186186

187-
#ifdef HAVE_LIBXAR
187+
#ifdef LLVM_HAVE_LIBXAR
188188
namespace {
189189
struct ScopedXarFile {
190190
xar_t xar;
@@ -211,7 +211,7 @@ struct ScopedXarIter {
211211
operator xar_iter_t() { return iter; }
212212
};
213213
} // namespace
214-
#endif // defined(HAVE_LIBXAR)
214+
#endif // defined(LLVM_HAVE_LIBXAR)
215215

216216
// This is used to search for a data in code table entry for the PC being
217217
// 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,
16971697
StringRef DisSegName, StringRef DisSectName);
16981698
static void DumpProtocolSection(MachOObjectFile *O, const char *sect,
16991699
uint32_t size, uint32_t addr);
1700-
#ifdef HAVE_LIBXAR
1700+
#ifdef LLVM_HAVE_LIBXAR
17011701
static void DumpBitcodeSection(MachOObjectFile *O, const char *sect,
17021702
uint32_t size, bool verbose,
17031703
bool PrintXarHeader, bool PrintXarFileHeaders,
17041704
std::string XarMemberName);
1705-
#endif // defined(HAVE_LIBXAR)
1705+
#endif // defined(LLVM_HAVE_LIBXAR)
17061706

17071707
static void DumpSectionContents(StringRef Filename, MachOObjectFile *O,
17081708
bool verbose) {
@@ -1773,13 +1773,13 @@ static void DumpSectionContents(StringRef Filename, MachOObjectFile *O,
17731773
DumpProtocolSection(O, sect, sect_size, sect_addr);
17741774
continue;
17751775
}
1776-
#ifdef HAVE_LIBXAR
1776+
#ifdef LLVM_HAVE_LIBXAR
17771777
if (SegName == "__LLVM" && SectName == "__bundle") {
17781778
DumpBitcodeSection(O, sect, sect_size, verbose, SymbolicOperands,
17791779
ArchiveHeaders, "");
17801780
continue;
17811781
}
1782-
#endif // defined(HAVE_LIBXAR)
1782+
#endif // defined(LLVM_HAVE_LIBXAR)
17831783
switch (section_type) {
17841784
case MachO::S_REGULAR:
17851785
DumpRawSectionContents(O, sect, sect_size, sect_addr);
@@ -6460,7 +6460,7 @@ static void DumpProtocolSection(MachOObjectFile *O, const char *sect,
64606460
}
64616461
}
64626462

6463-
#ifdef HAVE_LIBXAR
6463+
#ifdef LLVM_HAVE_LIBXAR
64646464
static inline void swapStruct(struct xar_header &xar) {
64656465
sys::swapByteOrder(xar.magic);
64666466
sys::swapByteOrder(xar.size);
@@ -6823,7 +6823,7 @@ static void DumpBitcodeSection(MachOObjectFile *O, const char *sect,
68236823
}
68246824
}
68256825
}
6826-
#endif // defined(HAVE_LIBXAR)
6826+
#endif // defined(LLVM_HAVE_LIBXAR)
68276827

68286828
static void printObjcMetaData(MachOObjectFile *O, bool verbose) {
68296829
if (O->is64Bit())

llvm/utils/gn/secondary/lld/test/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ write_lit_cfg("lit_site_cfg") {
5353
}
5454

5555
if (llvm_enable_libxar) {
56-
extra_values += [ "HAVE_LIBXAR=1" ]
56+
extra_values += [ "LLVM_HAVE_LIBXAR=1" ]
5757
} else {
58-
extra_values += [ "HAVE_LIBXAR=0" ] # Must be 0.
58+
extra_values += [ "LLVM_HAVE_LIBXAR=0" ] # Must be 0.
5959
}
6060

6161
if (llvm_enable_libxml2) {

llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,6 @@ write_cmake_config("config") {
296296
values += [ "HAVE_LIBEDIT=" ]
297297
}
298298

299-
if (llvm_enable_libxar) {
300-
values += [ "HAVE_LIBXAR=1" ]
301-
} else {
302-
values += [ "HAVE_LIBXAR=" ]
303-
}
304-
305299
if (llvm_enable_terminfo) {
306300
values += [ "LLVM_ENABLE_TERMINFO=1" ]
307301
} else {
@@ -368,6 +362,12 @@ write_cmake_config("llvm-config") {
368362
]
369363
}
370364

365+
if (llvm_enable_libxar) {
366+
values += [ "LLVM_HAVE_LIBXAR=1" ]
367+
} else {
368+
values += [ "LLVM_HAVE_LIBXAR=" ]
369+
}
370+
371371
if (llvm_enable_threads) {
372372
values += [ "LLVM_ENABLE_THREADS=1" ]
373373
} else {

llvm/utils/gn/secondary/llvm/test/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ write_lit_config("lit_site_cfg") {
162162
}
163163

164164
if (llvm_enable_libxar) {
165-
extra_values += [ "HAVE_LIBXAR=1" ]
165+
extra_values += [ "LLVM_HAVE_LIBXAR=1" ]
166166
} else {
167-
extra_values += [ "HAVE_LIBXAR=0" ] # Must be 0.
167+
extra_values += [ "LLVM_HAVE_LIBXAR=0" ] # Must be 0.
168168
}
169169

170170
if (llvm_enable_dia_sdk) {

0 commit comments

Comments
 (0)