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

C Compiler Problem #70

Open
i4cy opened this issue Mar 20, 2018 · 7 comments
Open

C Compiler Problem #70

i4cy opened this issue Mar 20, 2018 · 7 comments

Comments

@i4cy
Copy link

i4cy commented Mar 20, 2018

Has anyone been able to build using cc and then run an executable from within LiteBSD?

/* Hello world program, hello.c. */
#include <stdio.h>
main()
{
printf("hello world\n");
}

Compiling "hello.c" gives the following linker editor error.
$ cc hello.c
ld: multiple definition of symbol __divdi3
error: ld terminated with status 1

/* Null program, null.c. */
main()
{
}

Compiling "null.c" gives no compile/linker error, but causes a memory runtime error.
$ cc null.c
$ ./a.out
sh: ./a.out: Cannot allocate memory

Any ideas?

@ibara
Copy link
Collaborator

ibara commented Mar 20, 2018

The toolchain support was never completed. The most robust piece is going to be the assembler. As you see, pcc is able to compile C code down to MIPS assembly, but the pcc backend almost certainly suffers from a number of hidden bugs that I just never got around to fixing when I created the MIPSel pcc backend. The linker is probably the weakest link: Serge heroically got the ELFtoolchain linker to support mips32, but I have no idea how reliable the ELFtoolchain linker is. Upstream ELFtoolchain ld is almost certainly dead since FreeBSD adopted the LLVM ld.

@sergev
Copy link
Owner

sergev commented Mar 20, 2018

There is a bug in linker: I tried to fix it, but something is still wrong with %hi/%lo relocation.

@i4cy
Copy link
Author

i4cy commented Mar 21, 2018

Thanks for the replies.

Was there any reason why the original BSD C compiler (cc) could not be ported in much the same way as other utility programs have been ported? It might have only been pre ANSI C, but it works. Forgive me for the lack of knowledge regarding the details of this project.

@ibara
Copy link
Collaborator

ibara commented Mar 21, 2018

The original BSD C compiler is pcc.
Also, you know that in order to port a compiler, you have to write a backend, right? As in, the part that outputs actual assembly code. The pre-modern version of pcc did not have a MIPS backend. The current, maintained version does so that's why we use that one. Modern pcc also has the benefit of being a C99 compiler with some C11 support.

@i4cy
Copy link
Author

i4cy commented Mar 22, 2018

Ah thanks for the explanation. I presumed the original BSD had already been ported to work on MIPS by UC or AT&T. Clearly there was much more work involved than I appreciated in converting to PIC32.

@neozeed
Copy link

neozeed commented May 4, 2019

For what it's worth, PCC had support for the MIPS

http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/pcc/mips/

@ibara
Copy link
Collaborator

ibara commented May 4, 2019

pcc has support for MIPS. You're looking at the wrong repository. pcc can be found here: http://pcc.ludd.ltu.se/
GitHub mirror: https://github.com/arnoldrobbins/pcc-revived
However, MIPS support is not (and may never be, without interested parties getting involved) finished; you cannot compile more than a simple true(1) program for MIPS with pcc.

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

4 participants