Skip to content

Commit

Permalink
ld64 with ppc
Browse files Browse the repository at this point in the history
  • Loading branch information
iains committed Jul 3, 2019
2 parents 2932bca + 08e17fc commit 6f6c04e
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ld64/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
79 changes: 79 additions & 0 deletions ld64/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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++")
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)
26 changes: 26 additions & 0 deletions ld64/src/configure.h.in
Original file line number Diff line number Diff line change
@@ -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@"
76 changes: 76 additions & 0 deletions ld64/src/ld/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions ld64/src/ld/compile_stubs.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

static const char *compile_stubs = "@COMPILE_STUBS_COMMAND@";
4 changes: 4 additions & 0 deletions ld64/src/ld/ld_vers.c.in
Original file line number Diff line number Diff line change
@@ -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@;
41 changes: 41 additions & 0 deletions ld64/src/other/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 6f6c04e

Please sign in to comment.