From 33519967787a3f5cd68057f71b5609b18fb16dfc Mon Sep 17 00:00:00 2001 From: Iain Sandoe Date: Mon, 18 May 2015 23:45:11 +0100 Subject: [PATCH 1/2] [ld64, cmake] Implementation. - Adjust version stuff to allow 3-part numbers. - Use xar shim lib when needed. - Build tools that are needed for testing - Enabled all the targets. - Revise cmake for libtapi support. --- ld64/CMakeLists.txt | 10 +++++ ld64/src/CMakeLists.txt | 81 ++++++++++++++++++++++++++++++++++ ld64/src/configure.h.in | 26 +++++++++++ ld64/src/ld/CMakeLists.txt | 76 +++++++++++++++++++++++++++++++ ld64/src/ld/compile_stubs.h.in | 2 + ld64/src/ld/ld_vers.c.in | 4 ++ ld64/src/other/CMakeLists.txt | 41 +++++++++++++++++ 7 files changed, 240 insertions(+) create mode 100644 ld64/CMakeLists.txt create mode 100644 ld64/src/CMakeLists.txt create mode 100644 ld64/src/configure.h.in create mode 100644 ld64/src/ld/CMakeLists.txt create mode 100644 ld64/src/ld/compile_stubs.h.in create mode 100644 ld64/src/ld/ld_vers.c.in create mode 100644 ld64/src/other/CMakeLists.txt diff --git a/ld64/CMakeLists.txt b/ld64/CMakeLists.txt new file mode 100644 index 0000000..c495b32 --- /dev/null +++ b/ld64/CMakeLists.txt @@ -0,0 +1,10 @@ + +set(LD64_VERSION_NUM 274.2) +set(LD64_VERSION_DBL 274.2) + +include_directories("${CMAKE_BINARY_DIR}/dyld-include") + +add_subdirectory(src) +if( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/unit-tests/CMakeLists.txt ) + add_subdirectory(unit-tests) +endif() diff --git a/ld64/src/CMakeLists.txt b/ld64/src/CMakeLists.txt new file mode 100644 index 0000000..46d7661 --- /dev/null +++ b/ld64/src/CMakeLists.txt @@ -0,0 +1,81 @@ +if(XTOOLS_LTO_SUPPORT) + add_definitions(-DLTO_SUPPORT) + set(LTO_SUPPORT_INFO "(with LLVM LTO support)") +endif() + +if(XTOOLS_BUGURL) + add_definitions(-DXTOOLS_BUGURL="${XTOOLS_BUGURL}") +endif() + +if(PACKAGE_VERSION) + add_definitions(-DPACKAGE_VERSION="${PACKAGE_VERSION}") +endif() + +if(XTOOLS_VERSION) + add_definitions(-DXTOOLS_VERSION="${XTOOLS_VERSION}") +endif() + +#include(cmake/config-ix.cmake) + +# We should figure these out somehow - but for now let's just set them to +# the same as the fallback defaults. + +SET(DEFAULT_MACOSX_MIN_VERSION "10.5") +SET(DEFAULT_IPHONEOS_MIN_VERSION "6.0") + +SET(SUPPORT_ARCH_ppc 1) +SET(SUPPORT_ARCH_ppc64 1) + +SET(SUPPORT_ARCH_i386 1) +SET(SUPPORT_ARCH_x86_64 1) +SET(SUPPORT_ARCH_x86_64h 1) + +SET(SUPPORT_ARCH_armv6 1) +SET(SUPPORT_ARCH_armv6m 1) +SET(SUPPORT_ARCH_armv7 1) +SET(SUPPORT_ARCH_armv7em 1) +SET(SUPPORT_ARCH_armv7m 1) +SET(SUPPORT_ARCH_armv7s 1) +SET(SUPPORT_ARCH_arm64 1) + +SET(LD64_SUPPORTED_TARGETS "ppc ppc64 i386 x86_64 x86_64h armv6 armv6m armv7 armv7s armv7m armv7em arm64") +configure_file ( + "${CMAKE_CURRENT_SOURCE_DIR}/configure.h.in" + "${CMAKE_BINARY_DIR}/ld64/configure.h" + ) + +# add the binary tree to the search path for include files +# so that we will find configure.h +include_directories("${CMAKE_BINARY_DIR}/ld64") + +# Set up flags. +# If we re-use components (e.g. libprunetrie) we need the libc++ stuff to +# match up. + +if (NOT XTOOLS_HAS_64BATADD) + add_definitions(-DNO_64B_ATOMIC) +endif() + +set(LD64_CXX_FLAGS) +if(XTOOLS_C_HAS_FNOCOMMON_FLAG) + set(LD64_CXX_FLAGS "-fno-common") +endif() +if(XTOOLS_CXX_HAS_STDCXX11_FLAG) + set(LD64_CXX_FLAGS "${LD64_CXX_FLAGS} -std=c++11") +endif() +if(XTOOLS_CXX_HAS_STDLIB_FLAG) + set(LD64_CXX_FLAGS "${LD64_CXX_FLAGS} -stdlib=libc++") +elseif(XTOOLS_CXX_HAS_STATICCXX_FLAG) + set(LD64_CXX_FLAGS "${LD64_CXX_FLAGS} -static-libstdc++") +endif() + +set(LD64_CXX_FLAGS "${LD64_CXX_FLAGS} -lxar") + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LD64_CXX_FLAGS} ") + +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/abstraction") + +add_subdirectory(ld) +add_subdirectory(other) + +add_library(prunetrie other/PruneTrie.cpp) diff --git a/ld64/src/configure.h.in b/ld64/src/configure.h.in new file mode 100644 index 0000000..94b5056 --- /dev/null +++ b/ld64/src/configure.h.in @@ -0,0 +1,26 @@ + +#cmakedefine DEFAULT_MACOSX_MIN_VERSION "@DEFAULT_MACOSX_MIN_VERSION@" +#cmakedefine DEFAULT_IPHONEOS_MIN_VERSION "@DEFAULT_IPHONEOS_MIN_VERSION@" + +#cmakedefine01 SUPPORT_ARCH_ppc +#cmakedefine01 SUPPORT_ARCH_ppc64 + +#cmakedefine01 SUPPORT_ARCH_i386 +#cmakedefine01 SUPPORT_ARCH_x86_64 +#cmakedefine01 SUPPORT_ARCH_x86_64h + +#cmakedefine01 SUPPORT_ARCH_armv4t +#cmakedefine01 SUPPORT_ARCH_armv6 +#cmakedefine01 SUPPORT_ARCH_armv6m +#cmakedefine01 SUPPORT_ARCH_armv7 +#cmakedefine01 SUPPORT_ARCH_armv7f +#cmakedefine01 SUPPORT_ARCH_armv7k +#cmakedefine01 SUPPORT_ARCH_armv7s +#cmakedefine01 SUPPORT_ARCH_armv7em +#cmakedefine01 SUPPORT_ARCH_armv7m +#cmakedefine01 SUPPORT_ARCH_armv8 + +#cmakedefine01 SUPPORT_ARCH_arm64 +#cmakedefine01 SUPPORT_ARCH_arm64v8 + +#define ALL_SUPPORTED_ARCHS "@LD64_SUPPORTED_TARGETS@" diff --git a/ld64/src/ld/CMakeLists.txt b/ld64/src/ld/CMakeLists.txt new file mode 100644 index 0000000..c314ff4 --- /dev/null +++ b/ld64/src/ld/CMakeLists.txt @@ -0,0 +1,76 @@ +configure_file ( + "${CMAKE_CURRENT_SOURCE_DIR}/ld_vers.c.in" + "${CMAKE_BINARY_DIR}/ld64/ld_vers.c" + ) + +set(LD64_SOURCES + Options.cpp + ld.cpp + debugline.c + InputFiles.cpp + SymbolTable.cpp + Resolver.cpp + OutputFile.cpp + Snapshot.cpp + parsers/macho_relocatable_file.cpp + parsers/archive_file.cpp + parsers/lto_file.cpp + parsers/macho_dylib_file.cpp + parsers/textstub_dylib_file.cpp + parsers/opaque_section_file.cpp + passes/stubs/stubs.cpp + passes/dtrace_dof.cpp + passes/compact_unwind.cpp + passes/got.cpp + passes/huge.cpp + passes/code_dedup.cpp + passes/branch_island.cpp + passes/branch_shim.cpp + passes/bitcode_bundle.cpp + passes/objc.cpp + passes/dylibs.cpp + passes/tlvp.cpp + passes/order.cpp + passes/order.cpp + code-sign-blobs/blob.cpp + "${CMAKE_BINARY_DIR}/ld64/ld_vers.c" + ) + +execute_process( + COMMAND cat ${CMAKE_SOURCE_DIR}/ld64/compile_stubs + OUTPUT_VARIABLE COMPILE_STUBS_COMMAND) +if (HAD_ERROR) + message(FATAL_ERROR "ld64 compile_stubs generation failed with status ${HAD_ERROR}") +endif() +string(REPLACE "\n" "\\n" COMPILE_STUBS_COMMAND ${COMPILE_STUBS_COMMAND}) +string(REPLACE "\"" "\\\"" COMPILE_STUBS_COMMAND ${COMPILE_STUBS_COMMAND}) + +configure_file ( + "${CMAKE_CURRENT_SOURCE_DIR}/compile_stubs.h.in" + "${CMAKE_BINARY_DIR}/ld64/compile_stubs.h" + ) + +if(XTOOLS_TAPI_SUPPORT) + include_directories("${XTOOLS_TAPI_PATH}/include") + message(STATUS "*LD64* including ${XTOOLS_TAPI_PATH}/include") +endif() + +include_directories("${CMAKE_CURRENT_SOURCE_DIR}") +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/parsers") + +if(XTOOLS_LTO_SUPPORT) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lLTO") +endif() + +if(XTOOLS_TAPI_SUPPORT) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -ltapi") +endif() + +add_definitions(-DLD_VERS="xtools-ld64-${LD64_VERSION_NUM}") + +add_executable(ld ${LD64_SOURCES}) +if(NOT XTOOLS_HAS_MODERNXAR) + target_link_libraries(ld xarextralib) +endif() + +install(TARGETS ld DESTINATION bin) diff --git a/ld64/src/ld/compile_stubs.h.in b/ld64/src/ld/compile_stubs.h.in new file mode 100644 index 0000000..870bbb7 --- /dev/null +++ b/ld64/src/ld/compile_stubs.h.in @@ -0,0 +1,2 @@ + +static const char *compile_stubs = "@COMPILE_STUBS_COMMAND@"; diff --git a/ld64/src/ld/ld_vers.c.in b/ld64/src/ld/ld_vers.c.in new file mode 100644 index 0000000..1d5e320 --- /dev/null +++ b/ld64/src/ld/ld_vers.c.in @@ -0,0 +1,4 @@ +const unsigned char ldVersionString[] __attribute__ ((used)) = +"xtools-@XTOOLS_VERSION@ ld (@PACKAGE_VERSION@)\nBased on Apple Inc. ld64-@LD64_VERSION_NUM@ @LTO_SUPPORT_INFO@\n"; + +const double ldVersionNumber __attribute__ ((used)) = (double)@LD64_VERSION_DBL@; diff --git a/ld64/src/other/CMakeLists.txt b/ld64/src/other/CMakeLists.txt new file mode 100644 index 0000000..0a4afa4 --- /dev/null +++ b/ld64/src/other/CMakeLists.txt @@ -0,0 +1,41 @@ + +include_directories("${CMAKE_CURRENT_SOURCE_DIR}") +include_directories("${CMAKE_SOURCE_DIR}/ld64/src/ld") + +if(XTOOLS_LTO_SUPPORT) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lLTO") +endif() + +add_definitions(-DLD_VERS="xtools-ld64-${LD64_VERSION_NUM}") +add_definitions(-DLD64_VERSION_NUM="${LD64_VERSION_NUM}") + +if(XTOOLS_BUGURL) + add_definitions(-DXTOOLS_BUGURL="${XTOOLS_BUGURL}") +endif() + +if(PACKAGE_VERSION) + add_definitions(-DPACKAGE_VERSION="${PACKAGE_VERSION}") +else() + add_definitions(-DPACKAGE_VERSION="") +endif() + +if (XTOOLS_VERSION) + add_definitions(-DXTOOLS_VERSION="${XTOOLS_VERSION}") +else() + add_definitions(-DXTOOLS_VERSION="??") +endif() + +set(OBJDUMP_SOURCES + ObjectDump.cpp + ../ld/parsers/macho_relocatable_file.cpp + ../ld/parsers/lto_file.cpp + ../ld/debugline.c + ) + +add_executable(ObjectDump ${OBJDUMP_SOURCES}) +add_executable(dyldinfo dyldinfo.cpp) +add_executable(machocheck machochecker.cpp) +add_executable(rebase rebase.cpp) +add_executable(unwinddump unwinddump.cpp) + +install(TARGETS ObjectDump dyldinfo machocheck rebase unwinddump DESTINATION bin) From 08e17fc4e9db45d1d86b71158f57601f1b405906 Mon Sep 17 00:00:00 2001 From: Iain Sandoe Date: Wed, 3 Apr 2019 08:38:09 +0100 Subject: [PATCH 2/2] [ld64, cmake] Don't force static-libstdc++ here. --- ld64/src/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/ld64/src/CMakeLists.txt b/ld64/src/CMakeLists.txt index 46d7661..1be1a5e 100644 --- a/ld64/src/CMakeLists.txt +++ b/ld64/src/CMakeLists.txt @@ -65,8 +65,6 @@ if(XTOOLS_CXX_HAS_STDCXX11_FLAG) endif() if(XTOOLS_CXX_HAS_STDLIB_FLAG) set(LD64_CXX_FLAGS "${LD64_CXX_FLAGS} -stdlib=libc++") -elseif(XTOOLS_CXX_HAS_STATICCXX_FLAG) - set(LD64_CXX_FLAGS "${LD64_CXX_FLAGS} -static-libstdc++") endif() set(LD64_CXX_FLAGS "${LD64_CXX_FLAGS} -lxar")