ldc
ldc copied to clipboard
Incorrect ELF file for mips64el
If I compile for the mips64el architecture LDC creates an incorrect, 32 bit, ELF file:
$ ldc2 main.d -c --mtriple mips64-linux
$ file main.o
main.o: ELF 32-bit MSB relocatable, MIPS, N32 MIPS64 version 1 (GNU/Linux), not stripped
$ ldc2 --version
LDC - the LLVM D compiler (1.39.0):
based on DMD v2.109.1 and LLVM 17.0.6
built with LDC - the LLVM D compiler (1.39.0)
Default target: arm64-apple-darwin24.0.0
Host CPU: apple-m1
http://dlang.org - http://wiki.dlang.org/LDC
Using Clang with the same version (more less) of LLVM results in this:
$ clang -target mips64el-linux main.c -o main.o -c
$ file main.o
main.o: ELF 64-bit LSB relocatable, MIPS, MIPS64 rel2 version 1 (SYSV), not stripped
$ clang --version
clang version 17.0.1
Target: arm64-apple-darwin24.0.0
Thread model: posix
To me it looks like LDC outputs 64 bit MIPS code in a 32 bit ELF file.
MIPS is a bit weird with its ABIs AFAICT; looks like our default is off: https://github.com/ldc-developers/ldc/blob/48c1dff0466f5231619356ae33ef1a181888a1ff/driver/targetmachine.cpp#L154-L156
$ ldc2 -c ../hello.d -mtriple=mips64el-linux -mabi=n64
$ file hello.o
hello.o: ELF 64-bit LSB relocatable, MIPS, MIPS64 version 1 (GNU/Linux), not stripped
I see. Is that intentional?
I see. Is that intentional?
Don't see anything from history, looks like a typo.
Compiling with the -mabi=n64 worked for me. Would it be appropriate to make this the default?
Judging from the clang default, it seems so. Looks like n32 was intended for the 32-bit MIPS targets (which have no default ABI currently), i.e., llvm::Triple::mips[el].