Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-09

Debugging a darwin cross-compiler

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Brad Campbell

G'day all,

Still on the trail of the serial unit issue. Think I have it working (it's working perfectly on OSX PPC and all my variants of Linux) but I can't seem to generate valid OSX Intel binaries.

I've got a working cross compile setup where I can generate fully functional linux/win32/OSX-PPC binaries and they all work beautifully, but while all the open darwin tools tell me my OSX-Intel binaries are ok, when I actually put them on an Intel Mac and try to run them all I get is :

-bash: ./hello: cannot execute binary file

If I compile it with

fpc -Tdarwin -Ppowerpc hello.pas

It works perfectly (under Rosetta of course), but with

fpc -Tdarwin -Pi386 hello.pas

I get the above result.

My cross compilers were generated with the same command line, substituting i386 for powerpc when required, and my X86_64, Win32 and OSX-PPC compilers work perfectly.

The MacOS SDK is MacOSX10.4u.sdk which is a universal binary SDK.

I'm at a loss as to how to proceed to debug this one..

I'm in the process of downloading a native 2.2.2 compiler on my Intel Mac so I can do some comparisons of the asm/objects as I have no idea what to do next.

i386-darwin-lipo hello -detailed_info
input file hello is not a fat file
Non-fat file: hello is architecture: i386

file hello
hello: Mach-O executable i386

fpc -i
Free Pascal Compiler version 2.2.3

Compiler Date : 2008/09/24
Compiler CPU Target: i386

Supported targets:
GO32 V2 DOS extender
Linux for i386
OS/2
Win32 for i386
FreeBSD/ELF for i386
Solaris for i386 (under development)
Beos for i386 (under development)
NetBSD for i386 (under development)
Netware for i386(clib)
WDOSX DOS extender
OpenBSD for i386 (under development)
OS/2 via EMX
Watcom compatible DOS extenders
Netware for i386(libc)
WinCE for i386
Linux for x64_6432
Darwin for i386
Symbian OS for i386

Supported CPU instruction sets:
386
PENTIUM
PENTIUM2
PENTIUM3
PENTIUM4
PENTIUMM

Supported FPU instruction sets:
X87
SSE
SSE2
SSE3

Supported Optimizations:
REGVAR
UNCERTAIN
STACKFRAME
PEEPHOLE
ASMCSE
LOOPUNROLL
TAILREC

I'll keep at it, but I'd appreciate any pointers from anyone who has done this before.

Regards,
Brad

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.
Jonas Maebe
to Brad Campbell
Brad Campbell wrote 11 lines
Still on the trail of the serial unit issue. Think I have it working (it's working perfectly on OSX PPC and all my variants of Linux) but I can't seem to generate valid OSX Intel binaries. I've got a working cross compile setup where I can generate fully functional linux/win32/OSX-PPC binaries and they all work beautifully, but while all the open darwin tools tell me my OSX- Intel binaries are ok, when I actually put them on an Intel Mac and try to run them all I get is : -bash: ./hello: cannot execute binary file

Open Darwin and Mac OS X/i386 are not entirely equivalent. I've seen these kind of results in the past from people who tried this. I don't know what the actual difference or workaround is. Maybe it works if you can compile cctools from http://www.opensource.apple.com/darwinsource/DevToolsJun2008/

At least when building those on a native Mac OS X, you end up with cctools that produce binaries which also run on Mac OS X.

Jonas

Brad Campbell
to Jonas Maebe
Jonas Maebe wrote 23 lines
On 24 Sep 2008, at 14:51, Brad Campbell wrote: > Still on the trail of the serial unit issue. Think I have it working > (it's working perfectly on OSX PPC and all my variants of Linux) but I > can't seem to generate valid OSX Intel binaries. > > I've got a working cross compile setup where I can generate fully > functional linux/win32/OSX-PPC binaries and they all work beautifully, > but while all the open darwin tools tell me my OSX-Intel binaries are > ok, when I actually put them on an Intel Mac and try to run them all I > get is : > > -bash: ./hello: cannot execute binary file Open Darwin and Mac OS X/i386 are not entirely equivalent. I've seen these kind of results in the past from people who tried this. I don't know what the actual difference or workaround is. Maybe it works if you can compile cctools from http://www.opensource.apple.com/darwinsource/DevToolsJun2008/ At least when building those on a native Mac OS X, you end up with cctools that produce binaries which also run on Mac OS X.

Yeah, it certainly has to do with the linker and assembler.

I've copied the .o files across from my linux compiler box and tried to link them with the OSX tools and it has failed with unknown stabs sections in system.o. I've tried to cross compile the compiler/rtl with -gw rather than -gs and it fails to assemble/link with unknown sections. So it's certainly a problem with the odcctools/ccutils tools. (Mine are dated 13/04/2006!)

For now, I've figured out how to make the PPC binaries work "properly" on Intel OSX under Rosetta (tcflush was hanging).. so I'll work around it and use PPC binaries for now, but I'd love to be able to properly cross compile for OSX Intel in addition to OSX PPC (which works _perfectly_), so I'll keep at the linker issues until I get it solved.

Apple have bolloxed cctools _so_ badly they just won't compile on anything other than OSX..

Looks like I can compile everything *except* OSX-Intel binaries on my devel box, then I actually have to reboot into OSX to compile the OSX-Intel Binaries... ugh.. thanks Apple..

I really appreciate the help, I'm _way_ outa my comfort zone here.

Brad

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.
Brad Campbell
to Brad Campbell: Still on the trail of the serial unit issue. Think I have it working (it's working…
Brad Campbell wrote 14 lines
G'day all, Still on the trail of the serial unit issue. Think I have it working (it's working perfectly on OSX PPC and all my variants of Linux) but I can't seem to generate valid OSX Intel binaries. I've got a working cross compile setup where I can generate fully functional linux/win32/OSX-PPC binaries and they all work beautifully, but while all the open darwin tools tell me my OSX-Intel binaries are ok, when I actually put them on an Intel Mac and try to run them all I get is : -bash: ./hello: cannot execute binary file

Just a headsup. This looks like a linker problem. I managed to hack up a linker that works from an iPhone SDK toolkit I found floating around and I can now cross-compile OSX i386 binaries from my Linux box.

Many many thanks for the pointers!

Regards,
Brad

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.