[LLVMdev] Customize Standard C Library Using LLVM (to support llvm backend optimization)
Jonathan Roelofs
jonathan at codesourcery.com
Wed Mar 11 09:32:27 PDT 2015
On 3/11/15 10:13 AM, Chao Yan wrote:
>
> Purpose:
>
> I implemented a pass on LLVM backend that changes the output format of
> /ARM/ assembly/binary (e.g add a jump at the end of each basic block to
> eliminate fall through). By calling:
>
> |llc -march=arm somefile.bc
> |
>
> it generates expected arm assembly/binary that runs properly on arm gnu
> linux (I use qemu-arm and gem5 to simulate it). Now I want to do the
> same thing on standard c library, but here are problems.
>
>
> Problems:
>
> According to:
>
> |http://article.gmane.org/gmane.comp.compilers.llvm.devel/77025
> https://llvm.org/svn/llvm-project/llvm/tags/RELEASE_14/docs/OpenProjects.html#glibc
> |
>
> compiling glibc using llvm may not be a proper option. On the other
> hand, according to:
>
> |http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-January/047088.html
> |
>
> llvm could be able to compile newlib, thus people consider newlib as an
> alternative. However, according to:
FWIW, I build baremetal newlib for arm-eabi using clang, and it works. I
had to patch a few of the __attribute__((naked)) functions because they
were using pre-UAL asm syntax, but for the most part it "just works".
>
> |http://www.embecosm.com/appnotes/ean9/ean9-howto-newlib-1.0.html#id2711887
> |
>
> newlib intends to support binaries for bare metal (no OS) software. It
> implements only the hardware independent parts (e.g libc and libm) and
> leave a stub for each hardware dependent syscall (e.g everything in
> libgloss).
Have you considered trying musl? It's supposed to be a full replacement
for glibc.
>
> In fact I tried to compile a simple "hello world" c program using
> arm-none-eabi-gcc which was configured with "--with-newlib" option, the
> program execution ends up with segmentation faults on both qemu-arm and
> gem5.
Have you run it in a debugger to figure out *why* it is segfaulting?
Have you tried building it without your special pass?
Cheers,
Jon
>
>
> Questions:
>
> I'm not sure if the newlib is compatible with glibc. I'm wondering if I
> could use llvm to cross-compile the machine independent parts (at the
> same time change the arm output format) from newlib and use
> arm-none-linux-gnueabi-gcc to cross-compile the machine dependent parts
> from glibc and put these two parts together to generate my own standard
> c library?
>
> There might be mistakes/misunderstandings in my work. Are there any
> other possible methods that could add my changes to at least part of the
> standard c libraries, and make the program run on qemu-arm or gem5?
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
--
Jon Roelofs
jonathan at codesourcery.com
CodeSourcery / Mentor Embedded
More information about the llvm-dev
mailing list