I noticed that the open projects lists porting glibc to LLVM. I was
wondering if anyone was working on this currently. If no one is on it,
does anyone have an idea of how nasty this would be to do? I'd like to
have LLVM output to a new ISA, it'd be great if all I had to do was
proxy system calls like read and write in my architectural simulator.
I noticed that the open projects lists porting glibc to LLVM. I was
wondering if anyone was working on this currently. If no one is on
it, does anyone have an idea of how nasty this would be to do?
You'd just have to make glibc compile using llvm-gcc... It may need
some minor tweaks to be accepted as LLVM-valid code. It may show that
there are some bugs in llvm-gcc (if it cannot handle glibc due to an
internal error) or it might work, but it may not be necessarily verified
to be correct. So in response to your question, the nastiness is waiting
to be discovered.
To the best of my knowledge, this is not being done right now.
I'd like to have LLVM output to a new ISA, it'd be great if all I had
to do was proxy system calls like read and write in my architectural
simulator.
Note that compiling glibc with LLVM does not give you a solution to THIS
problem: you'd still have to write a new backend for your ISA. There is
currently a Sparc backend and an X86 backend. Depending on how similar
your architecture is to one or the other, you might be able to leverage
existing code. Take a look at llvm/lib/Target/{Sparc,X86}, though the
X86 target codebase is smaller.
Also note that having glibc compiled by LLVM isn't a prerequisite for
your new ISA, as long as you either emulate the library calls or you
have it compiled in some other manner for your target architecture.
Note that compiling glibc with LLVM does not give you a solution to THIS
problem: you'd still have to write a new backend for your ISA. There is
currently a Sparc backend and an X86 backend. Depending on how similar
your architecture is to one or the other, you might be able to leverage
existing code. Take a look at llvm/lib/Target/{Sparc,X86}, though the
X86 target codebase is smaller.
Yeah, that's the easy part. My ISA is going to have a near 1:1 mapping to
LLVM bytecode.
Also note that having glibc compiled by LLVM isn't a prerequisite for
your new ISA, as long as you either emulate the library calls or you
have it compiled in some other manner for your target architecture.
The nasty thing about this, is that from my experience SPECInt spends a
considerable amount of time in standard library calls (esp. the memory and
string manipulation functions). I think I'll try playing around with glibc
for a bit. At worst I'll end up adding a compatibility mode and hand-code
some of the common simple ones (memcpy, memset, etc.). Thanks for your help.
You're approach makes sense, and nobody is working on that project yet.
You're right that having to provide tons of library calls will both be a
pain, and will skew any numbers...
Things to look out for:
You will basically want to treat LLVM as a "new" target in glibc, so there
may be some "porting" that needs to be done. Basically glibc has a large
amount of "generic" code (written in C), then some arch specific optimized
code (often written in asm). You do not want to get the asm versions
obviously, so you'll either want to tell the configure process that you're
using some generic target or some new one.
Good luck, let me know if you run into any problems!
-Chris