[libcxx-commits] [PATCH] D62770: [libcxx] Use libtool when merging archives on Apple platforms
Petr Hosek via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Fri May 31 23:33:45 PDT 2019
phosek created this revision.
phosek added reviewers: beanz, ldionne.
Herald added subscribers: libcxx-commits, dexonsmith, christof, mgorny.
Herald added a reviewer: EricWF.
ar doesn't produce correct results when used for linking static
archives on Apple platforms, so instead use libtool -static which is
the official way to build static archives on those platforms.
Repository:
rCXX libc++
https://reviews.llvm.org/D62770
Files:
libcxx/src/CMakeLists.txt
libcxx/utils/merge_archives.py
libcxxabi/src/CMakeLists.txt
Index: libcxxabi/src/CMakeLists.txt
===================================================================
--- libcxxabi/src/CMakeLists.txt
+++ libcxxabi/src/CMakeLists.txt
@@ -226,6 +226,10 @@
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_static")
endif()
+ if (APPLE)
+ set(MERGE_ARCHIVES_LIBTOOL "--use-libtool" "--libtool" "${CMAKE_LIBTOOL}")
+ endif()
+
# Merge the the libc++abi.a and libunwind.a into one.
if(LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
add_custom_command(TARGET cxxabi_static POST_BUILD
@@ -235,6 +239,7 @@
--ar "${CMAKE_AR}"
"$<TARGET_LINKER_FILE:cxxabi_static>"
"$<TARGET_LINKER_FILE:unwind_static>"
+ ${MERGE_ARCHIVES_LIBTOOL}
WORKING_DIRECTORY ${LIBCXXABI_BUILD_DIR}
)
endif()
Index: libcxx/utils/merge_archives.py
===================================================================
--- libcxx/utils/merge_archives.py
+++ libcxx/utils/merge_archives.py
@@ -97,6 +97,12 @@
'--ar', dest='ar_exe', required=False,
help='The ar executable to use, finds \'ar\' in the path if not given',
type=str, action='store')
+ parser.add_argument(
+ '-l', '--use-libtool', dest='use_libtool', action='store_true', default=False)
+ parser.add_argument(
+ '--libtool', dest='libtool_exe', required=False,
+ help='The libtool executable to use, finds \'libtool\' in the path if not given',
+ type=str, action='store')
parser.add_argument(
'archives', metavar='archives', nargs='+',
help='The archives to merge')
@@ -109,6 +115,13 @@
if not ar_exe:
print_and_exit("failed to find 'ar' executable")
+ if args.use_libtool:
+ libtool_exe = args.libtool_exe
+ if not libtool_exe:
+ libtool_exe = distutils.spawn.find_executable('libtool')
+ if not libtool_exe:
+ print_and_exit("failed to find 'libtool' executable")
+
if len(args.archives) < 2:
print_and_exit('fewer than 2 inputs provided')
archives = [find_and_diagnose_missing(ar, args.search_paths)
@@ -127,8 +140,13 @@
out = execute_command_verbose([ar_exe, 't', arc])
files.extend(out.splitlines())
- execute_command_verbose([ar_exe, 'rcs', args.output] + files,
- cwd=temp_directory_root, verbose=args.verbose)
+ if args.use_libtool:
+ files = [f for f in files if not f.startswith('__.SYMDEF')]
+ execute_command_verbose([libtool_exe, '-static', '-o', args.output] + files,
+ cwd=temp_directory_root, verbose=args.verbose)
+ else:
+ execute_command_verbose([ar_exe, 'rcs', args.output] + files,
+ cwd=temp_directory_root, verbose=args.verbose)
if __name__ == '__main__':
Index: libcxx/src/CMakeLists.txt
===================================================================
--- libcxx/src/CMakeLists.txt
+++ libcxx/src/CMakeLists.txt
@@ -375,6 +375,9 @@
set(MERGE_ARCHIVES_ABI_TARGET
"${CMAKE_STATIC_LIBRARY_PREFIX}${LIBCXX_CXX_STATIC_ABI_LIBRARY}${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif()
+ if (APPLE)
+ set(MERGE_ARCHIVES_LIBTOOL "--use-libtool" "--libtool" "${CMAKE_LIBTOOL}")
+ endif()
add_custom_command(TARGET cxx_static POST_BUILD
COMMAND
${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/merge_archives.py
@@ -384,6 +387,7 @@
"$<TARGET_LINKER_FILE:cxx_static>"
"${MERGE_ARCHIVES_ABI_TARGET}"
"${MERGE_ARCHIVES_SEARCH_PATHS}"
+ ${MERGE_ARCHIVES_LIBTOOL}
WORKING_DIRECTORY ${LIBCXX_BUILD_DIR}
)
endif()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62770.202537.patch
Type: text/x-patch
Size: 3678 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190601/72cd085a/attachment.bin>
More information about the libcxx-commits
mailing list