Attached is the working version of LD64-97.17 (source code + PPC64 binary with PPC32/PPC64 libcrypto dylib already built for convenience). I've labelled it "Version A" to differentiate it from future revisions.
Please let me know if you encounter any bugs in LD (or typos in my post) and I will be happy to try and correct them. Below are my build instructions, but
TL;DR - If anyone reading this wants to skip ahead and use LD +ppc64, I've included pre-compiled binaries for convenience, which you can simply use by unzipping the archive and then copying ld
to /usr/local/bin
and libcrypto-64.dylib
to /usr/local/lib
.
(and if you want to use my binaries but want to rename them or don't want to put them in /usr/local, you may need to run install_name_tool on libcrypto - e.g. install_name_tool -id /opt/local/lib/libcrypto-64.dylib libcrypto-64.dylib ; install_name_tool -change /usr/local/libcrypto-64.dylib /opt/local/lib/libcrypto-64.dylib ld-ppc64 - where '/opt/local/lib/libcrypto-64.dylib' is whatever name or path you want to move libcrypto).
0. Perl 5.10 or later (Tiger-only pre-requisite)
Before you can install OpenSSL 1.1.1w on Tiger, you need to update Perl to at least 5.10. I'm personally using 5.40 and provide instructions below for those who are also using Tiger:
Bash:
# Download Perl 5.40 or use wget as below:
wget https://www.cpan.org/src/5.0/perl-5.40.1.tar.gz .
tar -zxvf https://www.cpan.org/src/5.0/perl-5.40.1.tar.gz
cd perl-5.40.1
########
# Then patch cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Darwin.pm by removing the following line:
# $self->{CCFLAGS} .= " -Wno-error=implicit-function-declaration";
# Then patch dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Platform/darwin.pm by removing the following line:
# $cf->{ccflags} .= ($cf->{ccflags} ? ' ' : '').'-Wno-error=implicit-function-declaration';
########
./Configure -des -Dprefix=/usr/local/
make && make test
sudo make install
1. OpenSSL 1.1.1w pre-requisite
To build LD 97, you need a working PPC64 version of libcrypto.
To compile yourself, you need to first download the source code for OpenSSL 1.1.1w and then apply mpsuzuki's workarounds for OS X 10.3-10.5 -
https://github.com/openssl/openssl/issues/19684 , as well as one minor fix to the test suite, described below:
One of the OpenSSL tests which fails on PPC64 (../test/recipes/04-test_bioprint.t) since it uses the 32-bit SIZE_MAX variable in the system's openssl/bio.h instead of the one in its own architecture-independent SIZE_MAX in interals/numbers.h. To fix the test, you need to add the following lines to the file test/bioprinttest.c just before the line #include "internal/numbers.h":
C:
...
#ifdef SIZE_MAX
#undef SIZE_MAX
#endif
#include "internal/numbers.h"
...
Please also note ../test/recipes/80-test_ssl_old.t may fail on Tiger, since the test relies on compiling against your existing OpenSSL installation, which is on Tiger is only 32-bit PowerPC, and you are building 64-bit PowerPC code which can only link against 64-bit PowerPC (or FAT PowerPC) libraries.
To build OpenSSL 1.1.1w yourself, after making the above modifications, the commands I used from the Terminal in the openssl-1-1-1w-64 directory were:
Bash:
cd openssl-1.1.1w-64
./Configure darwin8-ppc64-cc --prefix=/usr/local --openssldir=/usr/local no-asm
make depend && make
(If you are building on Leopard, you may wish to change the prefixes and try "darwin64-ppc-cc" istead of "darwin8-ppc64-cc". You could try without the "no-asm" on Leopard, but I it definitely breaks most of the tests on Tiger if you don't use the "no-asm" for PPC64 builds.)
Now that you are done building, you could now run "sudo make install"; however, the libraries you have just built are only compatible with 64-bit PowerPC programs. If you wish to link or use the libraries with other programs (perhaps existing ones), then I would recommend instead building FAT OpenSSL libraries, which are compatible with both 32-bit and 64-bit PowerPC code. This is easy to do and can be accomplished with the following commands in the Terminal (assuming you are still in your openssl-1-1-1w-64 directory):
Bash:
cd ..
cp -rp openssl-1.1.1w-64 openssl-1.1.1w-32
cd openssl-1.1.1w-32/
make clean
./Configure darwin8-ppc-cc --prefix=/usr/local --openssldir=/usr/local no-asm
make depend && make
cd ..
lipo -create ./openssl-1.1.1w-32/libcrypto.1.1.dylib openssl-1.1.1w-64/libcrypto.1.1.dylib -output libcrypto.1.1.dylib
# Although only libcrypt is required by LD 97, if you want make the other OpenSSL libraries compatible with both PPC32 & PPC64, which is a good idea:
lipo -create openssl-1.1.1w-32/libssl.1.1.dylib openssl-1.1.1w-64/libssl.1.1.dylib -output libssl.1.1.dylib
cp libcrypto.1.1.dylib openssl-1.1.1w-64/
cp libssl.1.1.dylib openssl-1.1.1w-64/
# Engine DYLIB's
lipo -create openssl-1.1.1w-32/engines/capi.dylib openssl-1.1.1w-64/engines/capi.dylib -output capi.dylib
lipo -create openssl-1.1.1w-32/engines/dasync.dylib openssl-1.1.1w-64/engines/dasync.dylib -output dasync.dylib
lipo -create openssl-1.1.1w-32/engines/ossltest.dylib openssl-1.1.1w-64/engines/ossltest.dylib -output ossltest.dylib
lipo -create openssl-1.1.1w-32/engines/padlock.dylib openssl-1.1.1w-64/engines/padlock.dylib -output padlock.dylib
cp capi.dylib openssl-1.1.1w-64/engines/
cp dasync.dylib openssl-1.1.1w-64/engines/
cp ossltest.dylib openssl-1.1.1w-64/engines/
cp padlock.dylib openssl-1.1.1w-64/engines/
# Static libraries
lipo -create openssl-1.1.1w-32/libssl.a openssl-1.1.1w-64/libssl.a -output libssl.a
lipo -create openssl-1.1.1w-32/libcrypto.a openssl-1.1.1w-64/libcyrpto.a -output libcrypto.a
lipo -create openssl-1.1.1w-32/apps/libapps.a openssl-1.1.1w-64/apps/libapps.a -output libapps.a
lipo -create openssl-1.1.1w-32/test/libtestutil.a openssl-1.1.1w-64/test/libtestutil.a -output libtestutil.a
cp libssl.a openssl-1.1.1w-64/
cp libcrypto.a openssl-1.1.1w-64/
cp libapps.a openssl-1.1.1w-64/apps/
cp libtestutil.a openssl-1.1.1w-64/test/
cd openssl-1.1.1w-64/
sudo make install
2. CCTools, DYLD and LibUnwind headers
The ZIP file contains versions of these headers already patched using all of the MacPorts patches. I don't recall making any other changes, but if you want to be sure, you can always diff the include sub-directories (as these are the only ones used by LD 97). However, please note that I've only included the headers and not the full contents of the cctools, dyld and libunwind directories, just to cut down on space and not exceed the MacRumors file upload size limit. Please further note that the MacPorts distfiles no longer has version 5.0.2 of libunwind, but this can easily be found on LLVM's website (the patches and Portfile are still available at the time of this writing).
3. Compiling LD64-97.17
This is where I've made the majority of any changes. I started by applying all of the the LD 97 patches and modifications specified in the Portfile by hand. It needed a couple of minor changes to get it compiling on GCC 4.0 which can be diff'd. However, I discovered that one of the Portfile modifications breaks PPC64 (PPC32 needs some the registers specified as rax, rbx, ..., which PPC64 on Tiger needs specified as __rax, ...) So, I made the code conditionally compile one was for PPC32 and another for PPC64, using #ifdef _ARCH_PPC64.
I haven't tested this on Leopard, but if you notice any bugs, let me know, and I can use #if statements to ensure it compiles and works properly on both systems.
Accidentally along the way, I found a nasty surprise in the Makefile provided by MacPorts, where it uses PREFIX=/usr as the default. Hence, if you don't provide PREFIX for make install, it will clobber your installed /usr/bin/ld and related manpages. So, I changed the default PREFIX to /usr/local to prevent such mishaps for other people.
My build command for LD 97.17 was as follow:
Code:
gnumake PREFIX=/usr/local OTHER_LDFLAGS="-g -arch ppc64" OTHER_LDFLAGS_LD64="/usr/local/lib/libcrypto.1.1.dylib" OTHER_CFLAGS="-g -arch ppc64" OTHER_CXXFLAGS="-g -arch ppc64 -I../cctools-cctools-949.0.1/include -I../libunwind-5.0.2.src/include -I../dyld-dyld-655.1.1/include" && sudo gnumake install PREFIX=/usr/local
Note that in the above example, I've used libcrytpo.1.1.dylib; but, if you prefer to use the version I've already compiled (which I've named libcrypto-64.dylib to avoid potential conflicts with local installs and TigerBrew), just change the above line to:
Code:
gnumake PREFIX=/usr/local OTHER_LDFLAGS="-g -arch ppc64" OTHER_LDFLAGS_LD64="/usr/local/lib/libcrypto-64.dylib" OTHER_CFLAGS="-g -arch ppc64" OTHER_CXXFLAGS="-g -arch ppc64 -I../cctools-cctools-949.0.1/include -I../libunwind-5.0.2.src/include -I../dyld-dyld-655.1.1/include" && sudo gnumake install PREFIX=/usr/local
4. Note about LD64 97.17 on Tiger with GCC 4.0
While LD64 97.17 works well most of the time in the testing I've done (including TenFourKit's WebCore), it does fail with a Bus Error on one test, which is when I've tried to use LD64 91.17 to build itself (!).
However, this error occurs regardless of whether you use a 32-bit PowerPC binary or a 64-bit PowerPC binary version of LD64 97.17 to compile itself (nor whether you attempt to compile LD as 32-bit or 64-bit). So, the bug does not seem to have anything to do with PPC32 vs. PPC64.
As well, I have not tested it on Leopard nor other versions of GCC 4.0 so this may be Tiger or a GCC 4.0 specific bug.
From the cursory debugging I've done, this seems to be an issue in the LD source code where an "Atom" object is generated without creating an "fSection" variable. According to GDB, the crash occurs when the getAddress() method calls fSection->getBaseAddress() on the NULL fSection pointer.
I haven't quite tracked down where in the code this rogue "Atom" object is being generated, but the object LD is processing at the time of the crash is the debug symbol: ___keymgr_dwarf2_register_sections
Otherwise, LD seems to work well on other code I've tested, and it is certainly worth giving LD64 97.17 a try on Leopard (in case the bug is Tiger-only) or if you need to build something which would benefit from having the 64-bit address space (like WebKit).
In the meantime, I will continue to slowly search for an answer to the Atom bug, and of course would appreciate any advice if you may have some insight into the cause of the bug.