pcc (portable compiler)

NeXT Computer, Inc. -> Porting New Software

Title: pcc (portable compiler)
Post by: neozeed on June 18, 2008, 04:13:34 PM
I've had some minor/major sucess with this package!

The good news is that I've managed to hand walk thru bulding a hello world!

The bad news is that I have a bit more work to do, but I don't think it's impossible.

Anyways with pcc-0.99 they say it's basically C99 compliant!

Here is an example of it failing to build something:

bash-2.01# cc/pcc -S  -v j.c
pcc 0.9.9 for i386-pc-nextstep, root@albinonext Wed Jun 18 14:44:36 GMT-0600 200
8
/usr/local/libexec/pcc-cpp -v -D__PCC__=0 -D__PCC_MINOR__=9 -D__PCC_MINORMINOR__
=9 -D__NEXT__ -I/usr/local/include/pcc -D__i386__ -D__LITTLE_ENDIAN__ -S /usr/in
clude/ j.c /tmp/ctm.009979
cpp: pcc 0.9.9 for i386-pc-nextstep, root@albinonext Wed Jun 18 14:44:36 GMT-060
0 2008
/usr/local/libexec/pcc-ccom -v /tmp/ctm.009979 j.s
ccom: pcc 0.9.9 for i386-pc-nextstep, root@albinonext Wed Jun 18 14:44:36 GMT-06
00 2008
bash-2.01# cc/pcc -S j.c
bash-2.01# cat j.s
       .text
       .align 4
       .globl main
main:
       pushl %ebp
       movl %esp,%ebp
.L11:
.L13:
.L12:
       leave
       ret
bash-2.01# /lib/i386/as -arch i386 -o j.o j.s
bash-2.01# ld -arch i386 -o j -NEXTSTEP-deployment-target 3.2 -lcrt0.o -L/lib/i
386 -L/lib/i386 j.o -lsys_s
ld: Undefined symbols:
_main


Now the fix is pretty easy... it's missing the _'s from main.  Here is something more complix:



       .section .rodata
.L15:
       .ascii "hi\n\0"
       .text
       .align 4
       .globl main
main:
       pushl %ebp
       movl %esp,%ebp
.L11:
.L13:
       pushl $.L15
       call printf
       addl $4, %esp
.L12:
       leave
       ret



adding some comma's and _'s gives us this:



       .section, .rodata
.L15:
       .ascii "hi\n\0"
       .text
       .align 4
       .globl _main
_main:
       pushl %ebp
       movl %esp,%ebp
.L11:
.L13:
       pushl $.L15
       call _printf
       addl $4, %esp
.L12:
       leave
       ret


And finally:

bash-2.01# /lib/i386/as -arch i386 -o j.o j.s
bash-2.01# ld -arch i386 -o j -NEXTSTEP-deployment-target 3.2 -lcrt0.o -L/lib/i386 -L/lib/i386 j.o -lsys_s
bash-2.01# ./j
hi
bash-2.01#


I know there is more to do, but I've hand walked it thru a hello world!
And for the other archs, pcc supports:

hppa     m16c     nova     powerpc  vax
arm      i386     mips     pdp10    sparc64

So this could be a "good thing" for either the sparc/hppa NeXTSTEP as I recall that only the gcc 2.5.8 was about all that ran.
Title: Re: pcc (portable compiler)
Post by: cubist on June 18, 2008, 11:10:40 PM
Quote from: "neozeed"
I know there is more to do, but I've hand walked it thru a hello world!
Reading the builds, it looks like it uses the original 'as', 'ld' and libraries, is that correct?  No calling convention problems on x86?
Title: Re: pcc (portable compiler)
Post by: neozeed on June 18, 2008, 11:21:56 PM
Quote from: "cubist"
Quote from: "neozeed"
I know there is more to do, but I've hand walked it thru a hello world!
Reading the builds, it looks like it uses the original 'as', 'ld' and libraries, is that correct?  No calling convention problems on x86?

Yeah I've actually never built a next compatable binutils... I've tried a few times, and it never works.. I suspect I need the binutils from next/apple to get something to work... I should look again to rhapsody or even darwin for those....

But yes I was able to call printf from main.

It does have some really good viable hopes.

Go to top  Forum index