Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Older xcode versions, like 3.1.4? #50

Open
snigel opened this issue Oct 14, 2015 · 37 comments
Open

Older xcode versions, like 3.1.4? #50

snigel opened this issue Oct 14, 2015 · 37 comments

Comments

@snigel
Copy link

snigel commented Oct 14, 2015

Hello,
I want to crosscompile for PPC, which means 10.5 / Leopard.
Firstly I couldn't install libxml2-devel, but that was a simple fix, the name in Ubuntu is libxml2-dev.

I'm using "method 3" since method 1 and 2 only supports 4.3 or later.
The second problem was to package the SDK (xcode314_2809_developerdvd.dmg)

sudo tools/mount_xcode_image.sh xcode314_2809_developerdvd.dmg
modprobe hfsplus
tmp dir: /tmp/Fi9gD7pOE
chmod 777 /tmp/Fi9gD7pOE
/home/snigel/crosscompile/osxcross/xcode314_2809_developerdvd.dmg: cannot determine HFS partition

The error message comes from the script mount_xcode_image.sh, not from dmg2img
https://github.com/tpoechtrager/osxcross/blob/master/tools/mount_xcode_image.sh

PARTITION=$(dmg2img -l $XCODEDMG | grep 'disk image (Apple_HFS ' |
awk '{printf "%d", $2}')

case $PARTITION in
''|[!0-9])
echo "$XCODEDMG: cannot determine HFS partition"
exit 1 ;;
esac

echo "HFS partition: $PARTITION"

Running dmg2img on its own yields the following, which looks sane to me:

$dmg2img -l xcode314_2809_developerdvd.dmg
dmg2img v1.6.5 (c) vu1tur (to@vu1tur.eu.org)
xcode314_2809_developerdvd.dmg --> (partition list)
partition 0: Driver Descriptor Map (DDM : 0)
partition 1: (Apple_Free : 1)
partition 2: Apple (Apple_partition_map : 2)
partition 3: Macintosh (Apple_Driver_ATAPI : 3)
partition 4: (Apple_Free : 4)
partition 5: Mac_OS_X (Apple_HFS : 5)
partition 6: (Apple_Free : 6)

I guess the script should have picked partition 5, so I hardcoded the script to use partition 5 and continued.

sudo tools/mount_xcode_image.sh xcode314_2809_developerdvd.dmg
modprobe hfsplus
tmp dir: /tmp/Kb13dijhR
chmod 777 /tmp/Kb13dijhR
/home/snigel/crosscompile/osxcross/xcode314_2809_developerdvd.dmg: cannot determine HFS partition
HFS partition:
dmg2img -p 5 -i /home/snigel/crosscompile/osxcross/xcode314_2809_developerdvd.dmg -o xcode.img &>dmg2img.log
mkdir -m 777 mnt
cd mnt
mount -o loop -t hfsplus ../xcode.img /tmp/Kb13dijhR/mnt

mounted the xcode image to: /tmp/Kb13dijhR/mnt

now run (not as root):
XCODEDIR=/tmp/Kb13dijhR/mnt ./tools/gen_sdk_package.sh

once you are done with gen_sdk_package.sh, run:
umount -l /tmp/Kb13dijhR/mnt && rm -rf /tmp/Kb13dijhR

Okay, that stepped went through, let's continue.

snigel@ubuntu:~/crosscompile/osxcross$ XCODEDIR=/tmp/Kb13dijhR/mnt ./tools/gen_sdk_package.sh
found Xcode: /tmp/Kb13dijhR/mnt
packaging MacOSX10.3.9 SDK (this may take several minutes) ...
packaging MacOSX10.4.Universal SDK (this may take several minutes) ...
packaging MacOSX10.5 SDK (this may take several minutes) ...

-rw-r--r-- 1 snigel snigel 28M Oct 14 13:54 MacOSX10.3.9.pkg
-rw-r--r-- 1 snigel snigel 35M Oct 14 13:54 MacOSX10.4.Universal.pkg
-rw-r--r-- 1 snigel snigel 47M Oct 14 13:54 MacOSX10.5.pkg

I ran into troubles trying to unmount, couldn't with or without sudo.

snigel@ubuntu:~/crosscompile/osxcross$ umount -l /tmp/Kb13dijhR/mnt && rm -rf /tmp/Kb13dijhR
umount: /tmp/Kb13dijhR/mnt: umount failed: Operation not permitted

snigel@ubuntu:~/crosscompile/osxcross$ sudo umount -l /tmp/Kb13dijhR/mnt && rm -rf >/tmp/Kb13dijhR
rm: cannot remove ‘/tmp/Kb13dijhR’: Operation not permitted

File is still there:

~/crosscompile/osxcross$ ls -al /tmp | grep Kb
drwxrwxrwx 2 root root 4096 Oct 14 13:55 Kb13dijhR

Let's ignore the unmount and try to build.

UNATTENDED=1 ./build.sh
no SDK found in tarballs/. please see README.md

Let's look in tarballs

ls -1 tarballs/
cctools-870-ld64-134.9_46e5f8b.tar.xz
cctools-870-ld64-242_9372d4c.tar.xz
xar-1.5.2.tar.gz

Okay, the unpacked pkg files are not there, let's move them.

mv MacOSX10.* tarballs/

Let's build again.

UNATTENDED=1 ./build.sh
tarballs/MacOSX10.4.Universal.pkg
tarballs/MacOSX10.3.9.pkg
tarballs/MacOSX10.5.pkg
more than one MacOSX SDK tarball found. please set
SDK_VERSION environment variable for the one you want
(for example: SDK_VERSION=10.x [OSX_VERSION_MIN=10.x] ./build.sh)

Let's try again

UNATTENDED=1 SDK_VERSION=10.5 ./build.sh
Lots of output from compiler...
testing o32-clang ... works
testing o64-clang ... works
testing o32-clang++ ... works
testing o64-clang++ ... works
Do not forget to add
/home/snigel/crosscompile/osxcross/target/bin
to your PATH variable.
All done! Now you can use o32-clang(++) and o64-clang(++) like a normal compiler.

Time to compile gcc 4.2.1 (which is what Leopard/10.5 uses).

GCC_VERSION=4.2.1 ENABLE_FORTRAN=1 ./build_gcc.sh.
Lots of compiler output...
xgcc: error trying to exec '/usr/bin/libtool': execvp: No such file or directory
libgcc.mk:780: recipe for target 'libgcc_s.dylib' failed
make[3]: *** [libgcc_s.dylib] Error 1
make[3]: Leaving directory '/home/snigel/crosscompile/osxcross/build/gcc-4.2.1/build/gcc'
Makefile:1541: recipe for target 'stmp-multilib' failed
make[2]: *** [stmp-multilib] Error 2
rm gfortran.pod
make[2]: Leaving directory '/home/snigel/crosscompile/osxcross/build/gcc-4.2.1/build/gcc'
Makefile:4306: recipe for target 'all-gcc' failed
make[1]: *** [all-gcc] Error 2
make[1]: Leaving directory '/home/snigel/crosscompile/osxcross/build/gcc-4.2.1/build'
Makefile:648: recipe for target 'all' failed
make: *** [all] Error 2

exiting with abnormal exit code (2)
run 'OCDEBUG=1 ./build_gcc.sh' to enable debug messages
removing stale locks...
if it is happening the first time, then just re-run the script

Okay, let's install libtool and retry.

sudo apt-get install libtool-bin

Ouch, a rerun causes it to restart from the beginning.

UNATTENDED=1 SDK_VERSION=10.5 ./build.sh
Lots of compiler output, redoing everything from scratch...
libtool: unrecognized option -dynamic' libtool: Trylibtool --help' for more information.
libgcc.mk:780: recipe for target 'libgcc_s.dylib' failed
make[3]: *** [libgcc_s.dylib] Error 1
make[3]: Leaving directory '/home/snigel/crosscompile/osxcross/build/gcc-4.2.1/build/gcc'
Makefile:1541: recipe for target 'stmp-multilib' failed
make[2]: *** [stmp-multilib] Error 2
rm gfortran.pod
make[2]: Leaving directory '/home/snigel/crosscompile/osxcross/build/gcc-4.2.1/build/gcc'
Makefile:4306: recipe for target 'all-gcc' failed
make[1]: *** [all-gcc] Error 2
make[1]: Leaving directory '/home/snigel/crosscompile/osxcross/build/gcc-4.2.1/build'
Makefile:648: recipe for target 'all' failed
make: *** [all] Error 2

exiting with abnormal exit code (2)
run 'OCDEBUG=1 ./build_gcc.sh' to enable debug messages
removing stale locks...
if it is happening the first time, then just re-run the script

Perhaps I'm using the wrong libtool.
Homebrew/legacy-homebrew#28442

Let's look if I have another libtool

find . -iname libtool
./build/cctools-870-ld64-242_9372d4c/cctools/misc/libtool
./build/cctools-870-ld64-242_9372d4c/cctools/libtool

Okay, how well does these handle "-dynamic" then?

./build/cctools-870-ld64-242_9372d4c/cctools/libtool -dynamic
Usage: /home/snigel/crosscompile/osxcross/build/cctools-870-ld64-242_9372d4c/cctools/libtool >[OPTION]... [MODE-ARG]...
Try 'libtool --help' for more information.
libtool: error: unrecognised option: '-dynamic'

and

./build/cctools-870-ld64-242_9372d4c/cctools/misc/libtool -dynamic
error: ./build/cctools-870-ld64-242_9372d4c/cctools/misc/libtool: no output file specified (specify with -o output)
Usage: ./build/cctools-870-ld64-242_9372d4c/cctools/misc/libtool -static [-] file [...] [-filelist >listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: ./build/cctools-870-ld64-242_9372d4c/cctools/misc/libtool -dynamic [-] file [...] [-filelist >listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] >[-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] >[-seg_addr_table ] [-seg_addr_table_filename <file_system_path>] [-all_load] >[-noall_load]

This one clearly states dynamic. Good.
Let's remove the libtool I installed and add this to my path.

sudo apt-get remove libtool-bin
PATH=/home/snigel/crosscompile/osxcross/build/cctools-870-ld64-242_9372d4c/cctools/misc/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

Another recompile

UNATTENDED=1 SDK_VERSION=10.5 ./build.sh
Lots of compiler output...
fixlib.o: In function compile_re': /home/snigel/crosscompile/osxcross/build/gcc-4.2.1/build/build-x86_64-unknown-linux-gnu/fixincludes/../../../fixincludes/fixlib.c:194: undefined reference toxregcomp'
/home/snigel/crosscompile/osxcross/build/gcc-4.2.1/build/build-x86_64-unknown-linux-gnu/fixincludes/../../../fixincludes/fixlib.c:199: undefined reference to `xregerror'
collect2: error: ld returned 1 exit status
Makefile:106: recipe for target 'full-stamp' failed
make[2]: *** [full-stamp] Error 1
make[2]: Leaving directory '/home/snigel/crosscompile/osxcross/build/gcc-4.2.1/build/build-x86_64-unknown-linux-gnu/fixincludes'
Makefile:2566: recipe for target 'all-build-fixincludes' failed
make[1]: *** [all-build-fixincludes] Error 2
make[1]: Leaving directory '/home/snigel/crosscompile/osxcross/build/gcc-4.2.1/build'
Makefile:648: recipe for target 'all' failed
make: *** [all] Error 2

exiting with abnormal exit code (2)
run 'OCDEBUG=1 ./build_gcc.sh' to enable debug messages
removing stale locks...
if it is happening the first time, then just re-run the script

And now I'm stuck.

@tpoechtrager
Copy link
Owner

I can't really get any further either.

This is what I have so far:

Build OSXCross the usual way

SDK_VERSION=10.4 ./build.sh
eval $(osxcross-conf)

Make the SDK GCC "compatible"

cd $OSXCROSS_SDK

cd /Library
ln -sf ../System/Library/Frameworks .
cd ../usr/lib
ln -s libstdc++.6.dylib libstdc++.dylib

Create PowerPC symlinks

cd $OSXCROSS_TARGET_DIR/bin

for arch in powerpc powerpc64; do \
  for tool in $(find . -name "x86_64-*"); do \
   ln -sf $tool $(echo $tool | sed "s/x86_64-/$arch-/"); \
  done \
done

rm powerpc*-*clang*

Build GCC

cd ~/tmp

wget https://opensource.apple.com/tarballs/gcc_42/gcc_42-5577.tar.gz
tar xf gcc-42-5577.tar.gz

cd gcc-42-5577

mkdir build
cd build

CC="clang -std=gnu89 -w" \
../configure \
 --target=powerpc-apple-$OSXCROSS_TARGET \
 --prefix=$OSXCROSS_TARGET_DIR \
 --with-sysroot=$OSXCROSS_SDK \
 --with-ld=$(which powerpc-apple-$OSXCROSS_TARGET-ld) \
 --with-as=$(which powerpc-apple-$OSXCROSS_TARGET-as) \
 --enable-languages=c,c++,objc,obj-c++ \
 --enable-wchar_t=no \
 --with-gxx-include-dir=/usr/include/c++/4.0.0

make

... fails with:

/home/thomas/tmp/gcc_42-5577/build/./gcc/xgcc -B/home/thomas/tmp/gcc_42-5577/build/./gcc/ -B/data/development/osxcross-ng/target/bin/../powerpc-apple-darwin8/bin/ -B/data/development/osxcross-ng/target/bin/../powerpc-apple-darwin8/lib/ -isystem /data/development/osxcross-ng/target/bin/../powerpc-apple-darwin8/include -isystem /data/development/osxcross-ng/target/bin/../powerpc-apple-darwin8/sys-include -O2 -g -O2  -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE   -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem ./include  -I. -I. -I../../gcc -I../../gcc/. -I../../gcc/../include -I../../gcc/../libcpp/include  -I../../gcc/../libdecnumber -I../libdecnumber  -mlongcall \
  -c ../../gcc/config/darwin-crt2.c -o crt2.o
/tmp/cczpsINq.s:40:Unknown relocation type
/tmp/cczpsINq.s:42:Unknown relocation type
/tmp/cczpsINq.s:46:Unknown relocation type
/tmp/cczpsINq.s:47:Unknown relocation type
/tmp/cczpsINq.s:49:Unknown relocation type
/tmp/cczpsINq.s:56:Unknown relocation type
/tmp/cczpsINq.s:58:Unknown relocation type
/tmp/cczpsINq.s:61:Unknown relocation type
/tmp/cczpsINq.s:62:Unknown relocation type
/tmp/cczpsINq.s:75:Unknown relocation type
/tmp/cczpsINq.s:76:Unknown relocation type
/tmp/cczpsINq.s:77:Unknown relocation type
/tmp/cczpsINq.s:78:Unknown relocation type

I also tried to build gcc-42-5577 on Mac OS X, but unfortunately, Xcode doesn't come with a PowerPC assembler anymore.

Maybe I can make clang target PowerPC.

@tpoechtrager
Copy link
Owner

Just to let you know, I was able to get gcc 5.2.0 (ppc / ppc64) and clang (ppc) working.
I will setup a test branch within the next few days.

@snigel
Copy link
Author

snigel commented Oct 17, 2015

That's awesome!

@tpoechtrager
Copy link
Owner

It was a lot of work to get PowerPC working, but here we go!

git clone https://github.com/tpoechtrager/osxcross.git
git checkout ppc-test

SDK_VERSION=10.5 ./build.sh # build.sh will detect PowerPC support automatically

# If you end up with powerpc-* symlinks in target/bin, then everything went well.

POWERPC=1 ./build_gcc.sh # build ppc64/ppc gcc
./build_gcc.sh           # build x86_64/i386 gcc

I came across a lot of issues while adding ppc support, including:

  • Recent ld64 versions do not support ppc/ppc64 anymore.

    After some googling, I found a way to add back ppc/ppc64 support via
    https://github.com/michaelweiser/ld64.

    I created a ppc branch @ cctools-port for it.

  • PPC assembler brokenness.

    Fixed via https://svn.macports.org/repository/macports/trunk/dports/devel/cctools/files/PR-37520.patch.

  • Clang <= 3.5 passes '-arch powerpc' instead of '-arch ppc' to the linker.

    Fixed by adding powerpc* aliases to ld64/as.

  • Clang <= 3.4 attempts to use powerc-apple-darwinX-gcc as assembler when targeting PowerPC

    Fix: Do not use clang <= 3.4 when targeting PowerPC.

  • LD64 > 97.17 doesn't like the 10.4 SDK's crt1.o.

    Fix 1: Do not use the 10.4 SDK when you want to target ppc.
    Fix 2: Rebuild the crt blobs, the sources can be found here.

    ld: in section __TEXT,__text reloc 1: sectionForNum(4) section number not for any section file '...../crt1.o
    ... is what you'd get otherwise, not a porting bug: https://stackoverflow.com/questions/5409860/unable-to-link-ppc-after-upgrading-to-xcode-4.

    If you want to target 10.4, use the 10.5 SDK + export MACOSX_DEPLOYMENT_TARGET=10.4 instead.

  • Clang + ppc64 only works for very simple sources.

    $ ./target/bin/powerpc64-apple-darwin9-clang++ ~/tmp/test.cpp
    fatal error: error in backend: Relocation emission for MachO/PPC64 unimplemented.
    clang-3.7: error: clang frontend command failed with exit code 70 (use -v to see invocation)

    Fix: Do not use clang when targeting ppc64.

So, in conclusion... avoid the 10.4 SDK and do not use clang when targeting ppc64.


Please let me know if everything works as expected, thanks!
I can't test whether the produced binaries work or not.

@snigel
Copy link
Author

snigel commented Oct 18, 2015

This is great, I will test to build binaries. Thanks for your effort.

@snigel
Copy link
Author

snigel commented Oct 18, 2015

I had trouble producing a working binary for gcc.

git clone https://github.com/tpoechtrager/osxcross.git
cd osxcross
git checkout ppc-test
git pull
SDK_VERSION=10.5 ./build.sh
cp MacOSX10.5.pkg tarballs/
GCC_VERSION=5.2.0 ENABLE_FORTRAN=1 POWERPC=1 ./build_gcc.sh
snigel@ubuntu:~/osxcross$ oppc32-gcc
Undefined symbols for architecture ppc:
"_main", referenced from:
start in crt1.10.5.o
ld: symbol(s) not found for architecture ppc
collect2: error: ld returned 1 exit status

@tpoechtrager
Copy link
Owner

Not much of an issue, have you actually tried to compile something? ;-)

Surviving build_gcc.sh usually already means a working gcc (the cross compiler is already used to compile libgcc, libstdc++, etc.).

Simply ignore the output of gcc <no src files>. Nothing to worry about.

@tpoechtrager
Copy link
Owner

I fixed the Undefined symbols for architecture ppc: "_main", referenced from: "issue",
you now get the expected output.

$ ./target/bin/oppc64-gcc
powerpc64-apple-darwin9-gcc: fatal error: no input files
compilation terminated.

$ ./target/bin/powerpc-apple-darwin9-gcc
powerpc-apple-darwin9-gcc: fatal error: no input files
compilation terminated.

@snigel
Copy link
Author

snigel commented Oct 20, 2015

Not much of an issue, have you actually tried to compile something? ;-)

Yes, I tried to build rtorrent, but the error I got was actually not related to the compiler.
But the first thing I saw was the compiler output, ran the compiler separately and thought it was broken.

Anyhow, I'm trying to find something that I can compile and test run. Tried wget, rtorrent and curl, they fail for different reasons during the configuration phase.

So for now I just tried two simple hello world in C and in C++
iBookG4:~ snigel$ ./c.out
Hello World

iBookG4:~ snigel$ ./cpp.out
Hello, world!

I've been thinking about trying out macports, but your documentation says that macports does not support 10.5. I am running macports 2.3.4 (latest version) on my 10.5 machine though.

It also looks like there is 10.5 content in that release
http://sourceforge.net/projects/macports/files/MacPorts/2.3.4/

Tried to launch it anyway,
snigel@ubuntu:/src$ export MACOSX_DEPLOYMENT_TARGET=10.5
snigel@ubuntu:
/src$ osxcross-macports
unsupported deployment target

Sure, I can hardcode to change it, but perhaps you have more insight on why it's unsupported?

@tpoechtrager
Copy link
Owner

Yes, I tried to build rtorrent, but the error I got was actually not related to the compiler.
But the first thing I saw was the compiler output, ran the compiler separately and thought it was broken.

Anyhow, I'm trying to find something that I can compile and test run. Tried wget, rtorrent and curl, they fail for different reasons during the configuration phase.

I was able to build wget and curl.

Edit: Added missing if [ $ARCH == powerpc ].

mkdir -p $HOME/tmp/ppc-test
cd $HOME/tmp/ppc-test

# Get and extract openssl-1.0.2d, wget-1.16 and curl-7.45.0

ARCH=powerpc64
COMPILER=gcc

## OpenSSL ##

cd openssl-1.0.2d
EXTRACONFFLAGS=""
[ $COMPILER == clang ] && EXTRACONFFLAGS="no-asm"
if [ $ARCH == powerpc ]; then
  TARGET=darwin-ppc-cc
else
  TARGET=darwin64-ppc-cc
fi
./Configure $TARGET \
  --prefix=$HOME/tmp/ppc-test/$ARCH-$COMPILER $EXTRACONFFLAGS
make clean 2>/dev/null || true
# don't use -j
make install \
  CC="$ARCH-apple-darwin9-$COMPILER" \
  AR="$ARCH-apple-darwin9-ar r" \
  RANLIB="$ARCH-apple-darwin9-ranlib"
cd ..

## wget ##

cd wget-1.16
make clean 2>/dev/null || true
CC=$ARCH-apple-darwin9-$COMPILER ./configure \
  --host=$ARCH-apple-darwin9 --prefix=$HOME/tmp/ppc-test/$ARCH-$COMPILER \
  --with-ssl=openssl --with-libssl-prefix=$HOME/tmp/ppc-test/$ARCH-$COMPILER
make install -j $(nproc)
cd ..

## curl ##

cd curl-7.45.0
CC=$ARCH-apple-darwin9-$COMPILER ./configure \
  --host=powerpc-apple-darwin9 --with-ssl=$HOME/tmp/ppc-test/$ARCH-$COMPILER \
  --prefix=$HOME/tmp/ppc-test/$ARCH-$COMPILER
make install -j $(nproc)
cd ..

# Do this for gcc (powerpc/powerpc64) and clang (powerpc)

I've been thinking about trying out macports, but your documentation says that macports does not support 10.5. I am running macports 2.3.4 (latest version) on my 10.5 machine though.

There are no pre-built packages for 10.5 (anymore?).

https://packages.macports.org/<pkg>

@snigel
Copy link
Author

snigel commented Oct 21, 2015

Oh, I never use prebuilt packages with macports anyway. That's why I thought I made a great case for osxcross. Get all required sources, build them on a fast machine and transfer the binaries to my slower ppc machine.

I will try the above script for test compiles, allthough, I can only test for ppc32.

@snigel
Copy link
Author

snigel commented Oct 22, 2015

I went to /home/tmp/ppc-test and then

wget https://www.openssl.org/source/openssl-1.0.2d.tar.gz
wget http://ftp.gnu.org/gnu/wget/wget-1.16.tar.gz
wget http://curl.haxx.se/download/curl-7.45.0.tar.gz
tar zxf curl-7.45.0.tar.gz
tar zxf wget-1.16.tar.gz
tar zxf openssl-1.0.2d.tar.gz
tar: A lone zero block at 52140

I tried redownloading openssl several times from the official homepage with the same result.

This built fine, so let's change arch to something I can test:
ARCH=powerpc

This also built fine, but I saw something scroll by that didn't look right:

/home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: 1: /home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: ▒▒▒▒: not found
/home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: 1: /home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: Syntax error: Unterminated quoted string
/home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: 1: /home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: ▒▒▒▒: not found
/home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: 1: /home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: Syntax error: Unterminated quoted string
WARNING: Skipping duplicate certificate dsa-pca.pem
/home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: 1: /home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: ▒▒▒▒: not found
/home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: 1: /home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: Syntax error: Unterminated quoted string
WARNING: Skipping duplicate certificate dsa-ca.pem
/home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: 1: /home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: ▒▒▒▒: not found
/home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: 1: /home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: Syntax error: Unterminated quoted string
WARNING: Skipping duplicate certificate ca-cert.pem
final section layout:

During the build I could also see my terminal doing a visual bell, so I guess something is being outputted that shouldn't be.

Also, this is weird, why aren't all the binaries in my 32bit build?

powerpc-gcc/bin$ ls -1
curl
curl-config
powerpc64-gcc/bin$ ls -1
c_rehash
curl
curl-config
openssl
wget

Regardless I copied the powerpc-gcc directory to the ppc machine.

iBookG4:~ snigel$ ./powerpc-gcc/bin/curl
dyld: Library not loaded: /home/snigel/tmp/ppc-test/powerpc-gcc/lib/libcurl.4.dylib
  Referenced from: /Users/snigel/./powerpc-gcc/bin/curl
  Reason: Incompatible library version: curl requires version 9.0.0 or later, but libcurl.4.dylib provides version 5.0.0
Trace/BPT trap

@tpoechtrager
Copy link
Owner

Also, this is weird, why aren't all the binaries in my 32bit build?

Looks like OpenSSL and wget failed to build. Use set -ex to see what's causing the build failure.

/home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: 1: /home/snigel/tmp/ppc-test/openssl-1.0.2d/util/../apps/openssl: ▒▒▒▒: not found

What's triggering that output? make install?

Reason: Incompatible library version: curl requires version 9.0.0 or later, but libcurl.4.dylib provides version 5.0.0

Either link statically or adjust DYLD_LIBRARY_PATH.

DYLD_LIBRARY_PATH=../lib ./curl

@snigel
Copy link
Author

snigel commented Oct 23, 2015

Either link statically or adjust DYLD_LIBRARY_PATH.
Embarrassing, I misinterpreted that error message. When I pointed out DYLD_LIBRARY_PATH curl started instantly. Thanks for your patience.

I tried rerunning the script with set -ex

make[2]: Entering directory '/home/snigel/tmp/ppc-test/openssl-1.0.2d/test'
( :; LIBDEPS="${LIBDEPS:--Wl,-search_paths_first -L.. -lssl -L.. -lcrypto  }"; LDCMD="${LDCMD:-powerpc-apple-darwin9-gcc}"; LDFLAGS="${LDFLAGS:--DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch ppc -O3 -DB_ENDIAN -Wa,-force_cpusubtype_ALL -DOPENSSL_BN_ASM_MONT -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DAES_ASM -DVPAES_ASM}"; LIBPATH=`for x in $LIBDEPS; do echo $x; done | sed -e 's/^ *-L//;t' -e d | uniq`; LIBPATH=`echo $LIBPATH | sed -e 's/ /:/g'`; LD_LIBRARY_PATH=$LIBPATH:$LD_LIBRARY_PATH ${LDCMD} ${LDFLAGS} -o ${APPNAME:=constant_time_test} constant_time_test.o ${LIBDEPS} )
final section layout:
    __TEXT/__text addr=0x00001F8C, size=0x00000190, fileOffset=0x00000F8C, type=1
    __TEXT/__text_startup addr=0x0000211C, size=0x00000990, fileOffset=0x0000111C, type=1
    __TEXT/__symbol_stub1 addr=0x00002AAC, size=0x00000030, fileOffset=0x00001AAC, type=28
    __TEXT/__cstring addr=0x00002ADC, size=0x000004C8, fileOffset=0x00001ADC, type=13
    __TEXT/__const addr=0x00002FA4, size=0x0000005C, fileOffset=0x00001FA4, type=0
    __DATA/__dyld addr=0x00003000, size=0x0000001C, fileOffset=0x00002000, type=30
    __DATA/__nl_symbol_ptr addr=0x0000301C, size=0x00000008, fileOffset=0x0000201C, type=29
    __DATA/__la_symbol_ptr addr=0x00003024, size=0x0000000C, fileOffset=0x00002024, type=27
    __DATA/__const addr=0x00003030, size=0x00000004, fileOffset=0x00002030, type=0
    __DATA/__data addr=0x00003034, size=0x00000014, fileOffset=0x00002034, type=0
ld: 32-bit absolute address out of range (0x100002FD4 max is 4GB): from anon + 0x00000000 (0x00003030) to 0x100002FD4 in 'anon' from constant_time_test.o for architecture ppc
collect2: error: ld returned 1 exit status
../Makefile.shared:164: recipe for target 'link_app.' failed
make[2]: *** [link_app.] Error 1
make[2]: Leaving directory '/home/snigel/tmp/ppc-test/openssl-1.0.2d/test'
Makefile:525: recipe for target 'constant_time_test' failed
make[1]: *** [constant_time_test] Error 2
make[1]: Leaving directory '/home/snigel/tmp/ppc-test/openssl-1.0.2d/test'
Makefile:291: recipe for target 'build_tests' failed
make: *** [build_tests] Error 1

The error itself looks quite straight forward, we're out of memory range. But why, I don't think it's curl. So maybe something is still producing 64bit code somewhere.

If I comment out "make install" for openssl, the script stops at wget instead:

mv -f .deps/ftp-opie.Tpo .deps/ftp-opie.Po
powerpc-apple-darwin9-gcc -DHAVE_CONFIG_H -DSYSTEM_WGETRC=\"/home/snigel/tmp/ppc-test/powerpc-gcc/etc/wgetrc\" -DLOCALEDIR=\"/home/snigel/tmp/ppc-test/powerpc-gcc/share/locale\" -I.  -I../lib -I../lib   -g -O2 -MT openssl.o -MD -MP -MF .deps/openssl.Tpo -c -o openssl.o openssl.c
openssl.c: In function 'ssl_init':
openssl.c:195:3: warning: implicit declaration of function 'ENGINE_load_builtin_engines' [-Wimplicit-function-declaration]
   ENGINE_load_builtin_engines();
   ^
openssl.c:197:7: error: 'CONF_MFLAGS_DEFAULT_SECTION' undeclared (first use in this function)
       CONF_MFLAGS_DEFAULT_SECTION|CONF_MFLAGS_IGNORE_MISSING_FILE);
       ^
openssl.c:197:7: note: each undeclared identifier is reported only once for each function it appears in
openssl.c: In function 'ssl_check_certificate':
openssl.c:681:49: warning: implicit declaration of function 'a2i_IPADDRESS' [-Wimplicit-function-declaration]
       ASN1_OCTET_STRING *host_in_octet_string = a2i_IPADDRESS (host);
                                                 ^
openssl.c:681:49: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
Makefile:1512: recipe for target 'openssl.o' failed
make[2]: *** [openssl.o] Error 1
make[2]: *** Waiting for unfinished jobs....
mv -f .deps/utils.Tpo .deps/utils.Po
make[2]: Leaving directory '/home/snigel/tmp/ppc-test/wget-1.16/src'
Makefile:1342: recipe for target 'install-recursive' failed
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory '/home/snigel/tmp/ppc-test/wget-1.16'
Makefile:1632: recipe for target 'install' failed
make: *** [install] Error 2

So indeed it looks like both wget and curl are failing on make install.

@tpoechtrager
Copy link
Owner

Need the whole output to see what's going on.

./Configure darwin-ppc-cc --prefix=$HOME/tmp/ppc-test/powerpcc-gcc
make clean
make install CC="powerpc-apple-darwin9-gcc" AR="powerpc-apple-darwin9-ar r" RANLIB="powerpc-apple-darwin9-ranlib" &>build.log

Edit: Never mind... I am getting the same error too with gcc; clang seems to work.

I will try to add "Apple GCC" support once I am done with porting the new cctools/ld64.


Edit 2: "Apple GCC" seems to work too.

However, it will take a while until I will have a build script ready.

@snigel
Copy link
Author

snigel commented Oct 23, 2015

Is this as it should be? Both powerpc-apple-darwin9-gcc and powerpc64-apple-darwin9-gcc points to the same wrapper, with 64 in its name.

readlink $(which powerpc-apple-darwin9-gcc)
powerpc64-apple-darwin9-wrapper
readlink $(which powerpc64-apple-darwin9-gcc)
powerpc64-apple-darwin9-wrapper

On the other hand, I see no "powerpc-apple-darwin9-wrapper" existing in my file tree.

@tpoechtrager
Copy link
Owner

Yes. My wrapper passes some flags "under the hood" to the compiler.
You can see them by setting OCDEBUG to 1.

$ OCDEBUG=1 oppc32-gcc ~/tmp/test.c

There's something wrong with gcc, not with the wrapper.
I was able to compile OpenSSL with the Apple GCC and with clang.

@tpoechtrager
Copy link
Owner

You can now build an Apple GCC via:

Edit: It's APPLE_GCC=1 not APPLEGCC=1

POWERPC=1 APPLE_GCC=1 ./build_gcc.sh

I successfully built LLVM/Clang 3.4, OpenSSL, wget and curl with it.

Please do the same and let me know whether the resulting binaries work.

LLVM/Clang 3.4 configure flags:

CC=powerpc-apple-darwin9-gcc CXX=powerpc-apple-darwin9-g++ \
  ../../llvm/configure --host=powerpc-apple-darwin9 --disable-assertions --enable-optimized

Or try my binaries: http://51.254.123.149/thomas/llvm-clang-3.4-ppc32.tar.xz
(sha256: 61791e0c09cb3fd271991f1d10b8f23a12c94d84a5b2377f596e890b82457f80)

@snigel
Copy link
Author

snigel commented Nov 7, 2015

Hi, I downloaded your binaries to my ppc machine.
I could not see curl, wget or curl though?

Anyhow, I can launch some of the applications inside.
cd Release/bin
./clang
clang: error: no input files
./count
usage: ./count
./FileCheck
FileCheck: Not enough positional command line arguments specified!
Must specify at least 1 positional arguments: See: ./FileCheck -help

Should I test something specific?

@WinterMute
Copy link

I don't know if you can be bothered with supporting 10.4 for ppc but your issue may be that the 10.4u SDK needs apple gcc 4.0. My Snow Leopard machine has 4.0.1 build 5494.

@tpoechtrager
Copy link
Owner

@snigel:

No, that's enough. Thanks!

I left curl, wget and OpenSSL out because they are easy enough to build.

I will finish PowerPC support at a later time point, most things should work already though.

@WinterMute:

I think the problem is caused by ld64, not by the compiler.
LD64 > 97 seems to cause troubles. What linker version are you using on that machine?

@WinterMute
Copy link

@tpoechtrager

I have this
@(#)PROGRAM:ld PROJECT:ld64-97.17
llvm version 2.9svn, from Apple Clang 1.7 (build 77)

But trying to build anything against 10.4u SDK with gcc 4.2 fails quite badly on this machine.

@BSzili
Copy link

BSzili commented Jan 26, 2016

@tpoechtrager
I tried to build the PowerPC GCC under cygwin, but I got this error:

make[2]: *** No rule to make target 'host-cygwin.o', needed by 'libbackend.a'. Stop.

Apparently host-cygwin.c and co are missing from this version of GCC.

@tpoechtrager
Copy link
Owner

@BSzili: Is https://github.com/gcc-mirror/gcc/blob/gcc-4_2-branch/gcc/config/i386/host-cygwin.c of any help? Copy the file(s) into build/gcc/[...] then cd into build/gcc/build_* and re-run make.

@BSzili
Copy link

BSzili commented Jan 28, 2016

Thanks for the tip! Copying just that one file wasn't enough, but copying the rest of the cygwin-related ones solved the problem:

cygwin.asm
cygwin.h
cygwin1.c
cygwin2.c
host-cygwin.c
t-cygwin
x-cygwin
xm-cygwin.h

Now I'm stuck again at a different place, because it can't link libgcc:
powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_trampoline.o) has no symbols powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_ctors.o) has no symbols powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_powixf2.o) has no symbols powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_mulxc3.o) has no symbols powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_divxc3.o) has no symbols powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_fixunsxfsi.o) has no symbols powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_fixxfdi.o) has no symbols powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_fixunsxfdi.o) has no symbols powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_floatdixf.o) has no symbols powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_floatundixf.o) has no symbols /home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file: static/libgcc.a(_trampoline.o) has no symbols /home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file: static/libgcc.a(_ctors.o) has no symbols /home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file: static/libgcc.a(_powixf2.o) has no symbols /home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file: static/libgcc.a(_mulxc3.o) has no symbols /home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file: static/libgcc.a(_divxc3.o) has no symbols /home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file: static/libgcc.a(_fixunsxfsi.o) has no symbols /home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file: static/libgcc.a(_fixxfdi.o) has no symbols /home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file: static/libgcc.a(_fixunsxfdi.o) has no symbols /home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file: static/libgcc.a(_floatdixf.o) has no symbols /home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file: static/libgcc.a(_floatundixf.o) has no symbols powerpc64-apple-darwin8-ranlib -c static/libgcc.a ld: unknown/unsupported architecture name for: -arch ppc64 collect2: ld returned 1 exit status libgcc.mk:731: recipe for target 'libgcc_s.dylib' failed make[3]: *** [libgcc_s.dylib] Error 1
I copied more similar errors into a pastebin:
http://pastebin.com/YabckMBB

@tpoechtrager
Copy link
Owner

rm -rf target and re-run build.sh. I think you built the linker from
the wrong branch.

On Thu, Jan 28, 2016 at 12:25 PM, Szilárd Biró notifications@github.com
wrote:

Thanks for the tip! Copying just that one file wasn't enough, but copying
the rest of the cygwin-related ones solved the problem:

cygwin.asm
cygwin.h
cygwin1.c
cygwin2.c
host-cygwin.c
t-cygwin
x-cygwin
xm-cygwin.h

Now I'm stuck again at a different place, because it can't link libgcc:
powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_trampoline.o) has no
symbols
powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_ctors.o) has no symbols
powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_powixf2.o) has no symbols
powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_mulxc3.o) has no symbols
powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_divxc3.o) has no symbols
powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_fixunsxfsi.o) has no
symbols
powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_fixxfdi.o) has no symbols
powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_fixunsxfdi.o) has no
symbols
powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_floatdixf.o) has no
symbols
powerpc64-apple-darwin8-ranlib: file: ./libgcc.a(_floatundixf.o) has no
symbols
/home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file:
static/libgcc.a(_trampoline.o) has no symbols
/home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file:
static/libgcc.a(_ctors.o) has no symbols
/home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file:
static/libgcc.a(_powixf2.o) has no symbols
/home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file:
static/libgcc.a(_mulxc3.o) has no symbols
/home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file:
static/libgcc.a(_divxc3.o) has no symbols
/home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file:
static/libgcc.a(_fixunsxfsi.o) has no symbols
/home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file:
static/libgcc.a(_fixxfdi.o) has no symbols
/home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file:
static/libgcc.a(_fixunsxfdi.o) has no symbols
/home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file:
static/libgcc.a(_floatdixf.o) has no symbols
/home/BSzili/osxcross/target/bin/x86_64-apple-darwin8-ranlib: file:
static/libgcc.a(_floatundixf.o) has no symbols
powerpc64-apple-darwin8-ranlib -c static/libgcc.a
ld: unknown/unsupported architecture name for: -arch ppc64
collect2: ld returned 1 exit status
libgcc.mk:731: recipe for target 'libgcc_s.dylib' failed
make[3]: *** [libgcc_s.dylib] Error 1

I copied more similar errors into a pastebin:
http://pastebin.com/YabckMBB


Reply to this email directly or view it on GitHub
#50 (comment)
.

@BSzili
Copy link

BSzili commented Jan 30, 2016

I did a full rebuild, but something is still not right about the linker, because it does'nt seem to produce working executables:

...
checking for pid_t... yes
checking for library containing strerror... configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES.
Makefile:9432: recipe for target 'configure-target-libiberty' failed
make[1]: *** [configure-target-libiberty] Error 1
make[1]: Leaving directory '/home/BSzili/osxcross/build/gcc-5575.11/build_powerpc'
Makefile:652: recipe for target 'all' failed
make: *** [all] Error 2

@tpoechtrager
Copy link
Owner

Did you set MACOSX_DEPLOYMENT_TARGET? If so, unset that variable.

@BSzili
Copy link

BSzili commented Jan 31, 2016

No, I definitely didn't set MACOSX_DEPLOYMENT_TARGET. I ran these commands:

./build.sh
POWERPC=1 APPLE_GCC=1 ./build_gcc.sh

@tpoechtrager
Copy link
Owner

Please post config.log.

@BSzili
Copy link

BSzili commented Jan 31, 2016

Here it is:
http://pastebin.com/SMfX2inf

@tpoechtrager
Copy link
Owner

Hmm... what's the output of:

/home/BSzili/osxcross/build/gcc-5575.11/build_powerpc/./gcc/xgcc -B/home/BSzili/osxcross/build/gcc-5575.11/build_powerpc/./gcc/ -B/home/BSzili/osxcross/target/bin/../powerpc-apple-darwin8/bin/ -B/home/BSzili/osxcross/target/bin/../powerpc-apple-darwin8/lib/ -isystem /home/BSzili/osxcross/target/bin/../powerpc-apple-darwin8/include -isystem /home/BSzili/osxcross/target/bin/../powerpc-apple-darwin8/sys-include -c -O2 -g -O2     <testfile.c>

?

@BSzili
Copy link

BSzili commented Jan 31, 2016

I only get an error:

-bash: syntax error near unexpected token `newline'

Removing the angled brackets, it get an error about testfile.c not existing. Isn't this file supposed to be generated by the configure script during the tests?

@tpoechtrager
Copy link
Owner

echo "int main(void){return 0;}" > testfile.c

Would it be much of a hassle to set up a Linux VM for OSXCross? Cygwin is freaking slow and thus very annoying to debug.

All I get when I am trying to build the Apple GCC is:

Makefile:652: recipe for target 'all' failed
make: *** [all] Error 2
make: INTERNAL: Exiting with 7 jobserver tokens available; should be 8!

@BSzili
Copy link

BSzili commented Feb 1, 2016

I could, but that would kind of defeat the purpose of being able to compile all of my executables from the same environment. I tried compiling that simple test file, and I got and object without a hitch. I'll try to look more into why the libiberty configure script fails.

@johnsonjh
Copy link

johnsonjh commented Apr 3, 2023

Hi, just wanted to say, although the ppc branch is a bit old and a bit of a mess, I was able to use it to build a current cross-compiler for PPC and PPC64 using GCC 12.2.0, which I completely failed to do on my own for an entire day. I did end up just disabling C++ because it was giving me a problem and I don't need it, so perhaps someone might be willing to revive it if they do need it.

Your posts above (#50 (comment)) was really useful. I had duplicated a lot of work and was stumped with the ld: in section __TEXT,__text reloc 1: sectionForNum(4) section number not for any section file '...../crt1.o message, trying to use the 10.4 SDK, and searching for that found this issue. Good thing it was pretty unique.

I also have to admit, I looked at this repo while first attempting this, but I moved on quickly because I didn't see any PPC support, and didn't investigate further to find out it was in a branch!

I am getting a osxcross: warning: cannot find apple gcc intrinsic headers; please report this issue to the OSXCross project message, and only for ppc64, but I can easily work around it, and haven't investigated it yet.

Thanks so much!

@jlsantiago0
Copy link

I have submitted a PR #390 to the ppc-test branch that I used to get OS X Cross + SDK-10.5 + mainline GCC-5.5.0 to target PowerPC and PowerPC64 .

I also provided detailed documentation on how I got it all built and scripts to test building some non-trivial projects Like OpenSSL, WGet, CURL and some C++11 and C++14 programs using the toolchain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants