www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - Using LDC to compile D code for the PSP (Playstation Portable)

reply pineapple <meapineapple gmail.com> writes:
I've been taking in interest in PSP homebrew development, and I'd 
like to be able to write some things with D. Unfortunately, I'm 
having some trouble getting things working.

I've been using the Minimalist PSPSDK for Windows and made some 
nice little C programs that run in an emulator and on my PSP 
hardware. Now I'm trying to incorporate some D code for the PSP's 
MIPS R4000 compile target. What I'm stuck on currently is how to 
get LDC to use the same ABI as the PSP libraries.

My build command looks like this:

     ldc2 --betterC --march=mipsel --mcpu=mips3 -c -of=src/main.o 
src/main.d

The linker errors I get look like this:

     psp-ld: src/main.o: warning: linking PIC files with non-PIC 
files
     psp-ld: src/main.o: linking mips:4000 module with previous 
mips:allegrex modules
     psp-ld: src/main.o: ABI mismatch: linking O32 module with 
previous EABI32 modules
     psp-ld: failed to merge target specific data of file 
src/main.o

I also get rather a lot of warnings about position-independent 
code, though I'm not sure if these are going to cause problems or 
not:

     psp-ld: C:/pspsdk/psp/sdk/lib/prxexports.o: warning: linking 
PIC files with non-PIC files
     psp-ld: C:/pspsdk/psp/sdk/lib\libpspgu.a(sceGuClear.o): 
warning: linking PIC files with non-PIC files
     psp-ld: C:/pspsdk/psp/sdk/lib\libpspgu.a(sceGuClearColor.o): 
warning: linking PIC files with non-PIC files
     psp-ld: C:/pspsdk/psp/sdk/lib\libpspgu.a(sceGuDispBuffer.o): 
warning: linking PIC files with non-PIC files
     psp-ld: C:/pspsdk/psp/sdk/lib\libpspgu.a(sceGuDisplay.o): 
warning: linking PIC files with non-PIC files
     psp-ld: C:/pspsdk/psp/sdk/lib\libpspgu.a(sceGuDrawArray.o): 
warning: linking PIC files with non-PIC files
     psp-ld: C:/pspsdk/psp/sdk/lib\libpspgu.a(sceGuDrawBuffer.o): 
warning: linking PIC files with non-PIC files
     & etc...

Can anyone help me out? Let me know what configuration I'm 
missing, or point me to where in LDC I might start hacking at if 
there is no such configuration yet?

Thanks!
Sep 07 2020
parent reply kinke <noone nowhere.com> writes:
Seems like you're looking for `-mabi=eabi`, according to 
https://github.com/ldc-developers/ldc/blob/032b492bcbc77625866e4a86b3cbc990a74bfb7a/driver/targetmachine.cpp#L106-L118.
Sep 07 2020
next sibling parent reply pineapple <meapineapple gmail.com> writes:
On Monday, 7 September 2020 at 22:33:52 UTC, kinke wrote:
 Seems like you're looking for `-mabi=eabi`, according to 
 https://github.com/ldc-developers/ldc/blob/032b492bcbc77625866e4a86b3cbc990a74bfb7a/driver/targetmachine.cpp#L106-L118.
Aha, thank you. That option wasn't showing up with --help but it was exactly what I needed Getting some new errors now, though I'm not sure how LDC's object file output could be connected to them. But the same errors don't occur when linking with a main file written in C, of course, so it must be related somehow. e:\Sync\Projects\psp\test>make clean & make rm -f test.prx test.elf src/module.o src/main.o PARAM.SFO EBOOT.PBP EBOOT.PBP psp-gcc -I. -IC:/pspsdk/psp/sdk/include -G0 -Wall -std=c99 -IC:/pspsdk/psp/include -IC:/pspsdk/lib/gcc/psp/8.2.0/include -BC:/pspsdk/lib/gcc/psp/8.2.0 -BC:/pspsdk/psp/lib -D_PSP_FW_VERSION=500 -c -o src/module.o src/module.c psp-gcc -I. -IC:/pspsdk/psp/sdk/include -G0 -Wall -std=c99 -IC:/pspsdk/psp/include -IC:/pspsdk/lib/gcc/psp/8.2.0/include -BC:/pspsdk/lib/gcc/psp/8.2.0 -BC:/pspsdk/psp/lib -I. -IC:/pspsdk/psp/sdk/include -G0 -Wall -std=c99 -IC:/pspsdk/psp/include -IC:/pspsdk/lib/gcc/psp/8.2.0/include -BC:/pspsdk/lib/gcc/psp/8.2.0 -BC:/pspsdk/psp/lib -o src/main.o src/main.s psp-ld: Dwarf Error: found dwarf version '4', this reader only handles version 2 information. C:/pspsdk/psp/lib/crt0.o: In function `_main': (.text+0x44): undefined reference to `strlen' C:/pspsdk/psp/lib/crt0.o: In function `_main': (.text+0x90): undefined reference to `atexit' C:/pspsdk/psp/lib/crt0.o: In function `_main': (.text+0xa4): undefined reference to `exit' C:/pspsdk/psp/lib/crt0.o: In function `_start': (.text+0x1b4): undefined reference to `sceKernelCreateThread' C:/pspsdk/psp/lib/crt0.o: In function `_start': (.text+0x1c4): undefined reference to `sceKernelStartThread' make: *** [src/main.o] Error 1
Sep 07 2020
next sibling parent pineapple <meapineapple gmail.com> writes:
...Actually, I think that was a fluke? I'm getting the same error 
again, in spite of the -mabi=eabi option. I'm using LDC 1.23.0 
and I am very confused.
Sep 07 2020
prev sibling parent kinke <noone nowhere.com> writes:
On Monday, 7 September 2020 at 22:47:44 UTC, pineapple wrote:
 That option wasn't showing up with --help but it was exactly 
 what I needed
Use -help-hidden for all options, as mentioned on https://wiki.dlang.org/Using_LDC. There you'll also see that there's -dwarf-version to switch to old DWARF v2 as required by your old toolchain.
Sep 08 2020
prev sibling parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Monday, 7 September 2020 at 22:33:52 UTC, kinke wrote:
 Seems like you're looking for `-mabi=eabi`, according to 
 https://github.com/ldc-developers/ldc/blob/032b492bcbc77625866e4a86b3cbc990a74bfb7a/driver/targetmachine.cpp#L106-L118.
Is this option documented?
Sep 20 2020
parent kinke <noone nowhere.com> writes:
On Sunday, 20 September 2020 at 08:25:58 UTC, Imperatorn wrote:
 On Monday, 7 September 2020 at 22:33:52 UTC, kinke wrote:
 Seems like you're looking for `-mabi=eabi`, according to 
 https://github.com/ldc-developers/ldc/blob/032b492bcbc77625866e4a86b3cbc990a74bfb7a/driver/targetmachine.cpp#L106-L118.
Is this option documented?
As mentioned, its mere presence is detectible via -help-hidden, but the help doesn't elaborate on the supported values, as it's an advanced and highly target-specific option. [I'd rather try to get rid of it and encode this stuff in the target triple, as gcc seems to use triples like `mips-linux-gnu`, `mips64-linux-gnuabin32` etc.]
Sep 20 2020