~mcf/cproc#62: 
Build musl libc

Current blockers:

  • long double (#3)
  • Inline asm (#5)
  • Weak references
  • Hidden visibility
Status
REPORTED
Submitter
~mcf
Assigned to
No-one
Submitted
5 years ago
Updated
3 months ago
Labels
No labels applied.

~tekk 3 years ago

The makefile now uses -fPIC by default as well.

~mcf 3 years ago

It only uses -fPIC when it detects that the compiler enables it by default. Since cproc is using gcc as a preprocessor, if gcc is built with --enable-default-pie it defines __PIC__ by default, which is not correct since qbe doesn't generate position-independent code.

I pushed a couple of commits to fix this. Now, you should be able to do CC=cproc ./configure --target=x86_64-linux-musl && make -k lib/libc.a to see all the errors.

There are only a handful of unique errors, but these are all major features that need support from QBE (apart from _Complex maybe):

$ make -k lib/libc.a 2>&1 | grep -e error: -e cproc-qbe: | sort -u
./arch/x86_64/atomic_arch.h:3:2: error: inline assembly is not yet supported
./arch/x86_64/syscall_arch.h:6:2: error: inline assembly is not yet supported
./include/complex.h:16:8: error: _Complex is not yet supported
cproc-qbe: long double is not yet supported
src/network/if_nameindex.c:95:52: error: VLAs are not yet supported
src/process/execl.c:12:20: error: VLAs are not yet supported
src/process/execle.c:12:20: error: VLAs are not yet supported
src/process/execlp.c:12:20: error: VLAs are not yet supported
src/process/execvp.c:29:15: error: VLAs are not yet supported
src/search/lsearch.c:6:17: error: VLAs are not yet supported
src/string/explicit_bzero.c:6:2: error: inline assembly is not yet supported
$

~zyedidia 3 months ago

I did some more digging on this, stubbing out inline asm blocks and other problems to try to get as much compiling as possible. I have documented below the issues that I ran into. In the end I did get every object file to compile, though I didn't fill in the assembly functions that the final library will attempt to link with, and some of the hacks that were employed to get it to build are incorrect.

  • inline assembly is not yet supported

    • unresolved; continued by marking inline asm functions as extern
  • src/aio/aio.c:230:16: error: volatile store is not yet supported

    • unresolved; continued by removing volatile with -Dvolatile=
  • ./include/complex.h:16:8: error: _Complex is not yet supported

    • unresolved; continued by removing _Complex with -D_Complex=
  • cproc-qbe: long double is not yet supported

    • unresolved; continued by marking long double as double in cproc source code
  • src/ipc/semctl.c:27:41: error: va_arg with non-scalar type is not yet supported

    • unresolved; continued by commenting the line out (!)
  • src/legacy/ftw.c:7:33: error: base types of pointer assignment must be compatible or void

    • resolved with corrected type cast
  • src/malloc/mallocng/malloc.c:9:77: error: unexpected ';' at top-level

    • resolved by removing the ';'
  • src/process/posix_spawn.c:151:46: error: operands of conditional operator must have compatible types

    • resolved with corrected type cast
  • src/thread/__syscall_cp.c:12:38: error: function '__syscall_cp_c' redeclared with incompatible type

    • unresolved; this appears to be an issue with __typeof, which is used to declare a function alias with a weak attribute. Continued by commenting out.
  • src/thread/pthread_cancel.c:23:1: error: function '__syscall_cp_c' redeclared with incompatible type

    • unresolved; these are redefinitions using hidden, where the prototype isn't the same as the real definition. Continued by commenting out.

My changes are here. To build, first configure with CFLAGS="-Dvolatile= -D_Complex=" CC=cproc ./configure --target=x86_64-linux-musl, then go to cproc's source code and set typeldouble = FLTTYPE(TYPELDOUBLE, 8), and then run make lib/libc.a.

Register here or Log in to comment, or comment via email.