Thread overview
Using LDC to compile D code for the PSP (Playstation Portable)
Sep 07, 2020
pineapple
Sep 07, 2020
kinke
Sep 07, 2020
pineapple
Sep 07, 2020
pineapple
Sep 08, 2020
kinke
Sep 20, 2020
Imperatorn
Sep 20, 2020
kinke
September 07, 2020
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!
September 07, 2020
Seems like you're looking for `-mabi=eabi`, according to https://github.com/ldc-developers/ldc/blob/032b492bcbc77625866e4a86b3cbc990a74bfb7a/driver/targetmachine.cpp#L106-L118.
September 07, 2020
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

September 07, 2020
...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.
September 08, 2020
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.
September 20, 2020
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?
September 20, 2020
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.]