Xcoff -> pef

Thanks to a kind BeOS enthusiast whom I won’t out (they can speak up if they like), I have Fred Fish’s egcs port on my BeBox, which I’m hopeful might help unwind some of the issues with the current BeOS port of Crypto Ancienne (see Old Vintage Computing Research: Crypto Ancienne 2.0 now brings TLS 1.3 to the Internet of Old Things (except BeOS) for the gory details).

Unfortunately, it doesn’t link. Looking at the output from gcc -v shows that it actually calls mwld to do the final step to convert the XCOFF binary generated by egcs to PEF, and mwld doesn’t like XCOFF. Doing a strings on mwld shows some strings related to XCOFF, but no obvious command line options. The temporary file is called /tmp/ldhackXXXX, which implies Fish did this on purpose. Does anyone have this running, and how did you do it?


I’m not sure if it really works and helps but:

There (in the directory PEFTools) is makepef (or MakePEF) which seems to convert xcoff into pef.

1 Like

You can also use original Metrowerks PPC compiler that works on 32 bit Haiku: http://bebits.irixnet.org/beos/experimental/tools/develop_x86_ppc.zip.

I appreciate the attempts to be helpful, but I think I should be explicit at this point that I’m trying to do onboard work, not cross-compiling.

With that said, replying to both:

There (in the directory PEFTools) is makepef (or MakePEF) which seems to convert xcoff into pef.

I’m aware of Retro68, but I don’t know if this works (or if it works to generate a real BeOS executable), or if this specific piece can be built separately on BeOS.

You can also use original Metrowerks PPC compiler that works on 32 bit Haiku

I don’t have a Haiku system, and as my initial post would indicate, I already have Metrowerks on my BeBox.

I shouldn’t need to use Haiku anyway because Fish’s compiler is PPC native, so there was clearly a PPC system that this worked on at one stage.

I started to port Retro68 for BeOS PPC. You are welcome to get involved. It does “work”, but it is far from perfect. I had the basic runtime stuff in place and I can compile C code, but I suspect it is far from able to do any C++.

I have used the Fred Fish stuff… it basically used GCC to compile to XCOFF and the mwld to link XCOFF to PEF. The Retro68 tools actually do the same exact thing, but just use a more elegant solution.

1 Like

Yes, I determined that from the gcc -v output. What mwld did you use? Was it a specific version? Fred’s compiler clearly calls mwld on purpose, so there must be an mwld that can do this.

So - yes it works. Yes I have confirmed it works. But the runtime is incomplete, so it probably is far from being a real contender. But I have 100% compiled an exe on a Mac under Catalina, ftp’d it to BeOS R5 running on a PowerMac clone, and run it. See this thread for more info. This includes linking to libroot.so and also libbe.so too iirc.

It is also worth noting, you can use any Metrowerks C++ compiler that supports PEF to build BeOS apps. I have used the one that comes with Codewarrior 10 (I think?) under MacOS X Panther to make a simple graphical BeOS app (see this link.) You basically just need the libs and the headers. I could probably send you the CodeWarrior target stationary/template I made - which just creates a basic BeApp skeleton.

I appreciate this, but again, I’m trying to do this on-board, not cross-compiled. You mention you’ve used Fish’s compiler. Did you have a specific mwld that was capable of the conversion?

If you’re not sure, can you do a gcc -v and compile a little hello world with it? This is what I get.

$ gcc -v -o gcc-hello hello.c
Reading specs from /boot/apps/GeekGadgets/lib/gcc-lib/ppc-beos/egcs-2.90.27/specs
gcc version egcs-2.90.27 980315 (egcs-1.0.2 release)
 /boot/apps/GeekGadgets/lib/gcc-lib/ppc-beos/egcs-2.90.27/cpp -lang-c -v -undef
-D__GNUC__=2 -D__GNUC_MINOR__=90 -D__BEOS__ -D__POWERPC__ -D__BEOS__
-D__POWERPC__ -Asystem(beos) -Acpu(powerpc) -Amachine(powerpc)
-D__CHAR_UNSIGNED__ -D_ARCH_PPC hello.c /tmp/cc225558.i
GNU CPP version egcs-2.90.27 980315 (egcs-1.0.2 release)
#include "..." search starts here:
#include <...> search starts here:
End of search list.
 /boot/apps/GeekGadgets/lib/gcc-lib/ppc-beos/egcs-2.90.27/cc1 /tmp/cc225558.i
-fno-builtin -quiet -dumpbase hello.c -version -o /tmp/cc225558.s
GNU C version egcs-2.90.27 980315 (egcs-1.0.2 release) (ppc-beos) compiled by
GNU C version egcs-2.90.27 980315 (egcs-1.0.2 release).
In file included from hello.c:2:
warning: redefinition of `va_list'
/boot/develop/headers/posix/va_list.h:10: warning: `va_list' previously
declared here
 /boot/apps/GeekGadgets/ppc-beos/bin/as -u -mppc -o /tmp/cc2255581.o
 /boot/apps/GeekGadgets/ppc-beos/bin/ld -v -o gcc-hello -L/boot/home/config/lib
-L/boot/apps/GeekGadgets/ppc-beos/lib -L/boot/apps/GeekGadgets/lib
ppc-beos-ld-coff -v -o /tmp/ldhack320788 -L/boot/home/config/lib
-L/boot/apps/GeekGadgets/ppc-beos/lib -L/boot/apps/GeekGadgets/lib
/boot/apps/GeekGadgets/lib/gcc-lib/ppc-beos/egcs-2.90.27/libgcc.a -r
GNU ld version 2.8.1 (with BFD 2.8.1)
mwld -o gcc-hello -nodup /tmp/ldhack320788
### mwld Usage Error:
#   File '/tmp/ldhack320788' cannot be used on this target, ignoring

Errors caused tool to abort.
ld: mwld returned 1 exit status
gcc: Internal compiler error: program ld got fatal signal 1

$ mwld

Metrowerks Linker for BeOS/PPC.
Copyright 1993-1999 Metrowerks, Inc.  All rights reserved.
Version 2.2
Runtime Built: Jun  1 1999 14:02:50

mwld [options, filenames...]

Execute 'mwld -help' for more information.

The one from the standard BeOS distro works. You might need to symlink it - I don’t remember. It was probably 20 years ago when I tested it. If we can get Retro68 working you should have a much more recent gcc, and a much more modern target. Mwcc is like a lesson in pain to use with modern C/C++.

Seriously, it doesn’t - see my output above. Can you check the mwld you used it with?

I really do not want to cross-compile. Part of the intention with Crypto Ancienne is you can bring it up on very old compilers, even C89. I know folks are trying to be helpful, but I’m being very specific here on purpose. :slightly_smiling_face:

I mean - you could try the one from PR2 or R3? I don’t think it really changed all that much as MetroWerks probably only did bug fixes after R3. Be Inc maintained Be IDE, but the compiler was closed source.

I might have also done it in t steps - built all the object files and manually run the link stage. I don’t remember.

The ultimate goal is to bootstrap Retro68 for BeOS PowerPC, but we need a working compiler first to make that happen.

One thing to note - Retro68 can make PEF library imports that can be used by the gnu linker, then converted to a PEF exe… it is way farther along than Fred Fish on integration.

If you can stomach using some parts built on another platform, you might be able to use MWCC on Mac to compile the problem parts (as the compiler uses the same object format) and then glue them together in to one app under BeOS… past that, I don’t have Fred Fish anymore (if you can link me I can grab it) and when I did have it it was probably around 2001/2002, so you are asking me to rewind my brain 20 odd years :wink: :exploding_head:

I get what you are saying, but till we can port a more modern compiler to BeOS PowerPC we are all a but stuck with the MWCC and PEF legacy.

Hmm is that a script? Maybe it doesn’t generate a proper COFF binary in the first place?
Do you have objdump around to check maybe?

I interrupted it during generation and grabbed the intermediate binary, and it’s definitely COFF. My AIX system recognizes the format.

% file ldhack444927
ldhack444927: executable (RISC System/6000 V3.1) or obj module not stripped

Yeah but possibly the file isn’t properly structured or something, or maybe bad CPU id inside? Not sure it has provision for that…
Have you tried with objdump? You should be able to use a cross version, powerpc-linux-gnu-objdump on my Debian still knows about aixcoff-rs6000.
I’d have to set up my BeBox to have a look but I’m quite busy atm…

I’ll just close the loop for posterity. It indeed wanted a specific mwld and I went through the box of discs I had for the BeBox and found the CodeWarrior 3 BeOS mwld will do it. I monkeypatched the Fred Fish ld (two copies) to call this older mwld I renamed to mxld, and now it compiles and links on the BeBox.

$ gcc -o gcc-hello hello.c
In file included from hello.c:2:
/boot/apps/GeekGadgets/lib/gcc-lib/ppc-beos/egcs-2.90.27/include/stdarg.h:182: warning: redefinition of `va_list'
/boot/develop/headers/posix/va_list.h:10: warning: `va_list' previously declared here
$ ./gcc-hello
Hello world!
$ gcc --version
egcs-2.90.27 980315 (egcs-1.0.2 release)
$ uname -a
BeOS jean 5.0 1000009 BeBox unknown

I suspect I used the one from PR2, which is probably similar to the one you are using. I had PR2 and R4.5 to hand at the time I was playing about with this. All the playing I did was for sure on a Mac.