Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect ELF file for mips64el #4721

Open
jacob-carlborg opened this issue Aug 5, 2024 · 5 comments
Open

Incorrect ELF file for mips64el #4721

jacob-carlborg opened this issue Aug 5, 2024 · 5 comments

Comments

@jacob-carlborg
Copy link
Contributor

jacob-carlborg commented Aug 5, 2024

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.

@kinke
Copy link
Member

kinke commented Aug 5, 2024

MIPS is a bit weird with its ABIs AFAICT; looks like our default is off:

case llvm::Triple::mips64:
case llvm::Triple::mips64el:
return "n32";

$ 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

@jacob-carlborg
Copy link
Contributor Author

I see. Is that intentional?

@JohanEngelen
Copy link
Member

I see. Is that intentional?

Don't see anything from history, looks like a typo.

@kinke kinke changed the title Incorrect EFL file for mips64el Incorrect ELF file for mips64el Aug 5, 2024
@jacob-carlborg
Copy link
Contributor Author

Compiling with the -mabi=n64 worked for me. Would it be appropriate to make this the default?

@kinke
Copy link
Member

kinke commented Aug 7, 2024

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].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants