[llvm-dev] How to compile glibc with clang/llvm?

David Jones via llvm-dev llvm-dev at lists.llvm.org
Sun Dec 23 16:56:43 PST 2018


Is your only problem that you don't have definitions for
mmap/ftruncate/mkdir?

If so, then you don't need to compile glibc. You merely need to solve the
problem you actually have: you need a C library for your system calls.

I have no idea what operating system you are running on your target, but
the function names suggest it's Unix-like. Unix-like operating systems
typically implement system calls as a trap to the operating system using an
instruction specially built for this purpose.  To this end, the "mmap"
function in glibc merely arranges to get the arguments in the correct
registers (or possibly the stack), and then invokes the proper trap.
Perhaps 10 lines of assembly in all.

If you can figure out the calling convention for your system calls, then
you can easily write your own syscall library in assembler, for each call
you require, which you can then link in, in addition to whatever else you
are using.


On Sat, Dec 22, 2018 at 4:29 AM xuruobin via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> To whom it may concern,
>
>         Is there a way to build glibc with clang/llvm? I’m working on
> enabling llvm-cov for my compiler which is a totally new arch with a libc.a
> built from newlib. I successfully built compiler-rt but when I typed the
> command ` clang++ --target=xxx -fprofile-instr-generate -fcoverage-mapping
> foo.cc -o foo`, the linker failed because of undefined reference to
> `mmap'/`ftruncate'/`mkdir'. I found these functions are supported by glibc
> but I cannot bulid glibc with clang/llvm(configure gave me an error “These
> critical programs are missing or too old: compiler”). So I want to know how
> can I compile glibc with clang/llvm or are there some WIP patches to help
> me with this requirement?
>
> Thanks,
> Ruobin.
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181223/f6464096/attachment.html>


More information about the llvm-dev mailing list