I'm trying to implement a codegen (I seek for assembler listing only, not a binary code) for custom architecture which doesn't have hardware implementation of integer division. I use clang frontend and get symbols like __divsi3 in my assembler listing. I see an implementation of __divsi3 in compiler_rt library of LLVM. How could I use this?
Asked
Active
Viewed 1,042 times
1
-
You can adapt the code from [this answer](http://stackoverflow.com/a/7709021/968261). – Alexey Frunze Sep 29 '12 at 08:38
-
I don't ask for algorithm of division, but for a way of using standard library function. – Artem Pelenitsyn Sep 29 '12 at 09:12
-
Then I don't understand your question. Can you elaborate it or provide an example of what you want? – Alexey Frunze Sep 29 '12 at 09:14
-
I suppose you should compile libcompile_rt into bitcode and then substitute calls like __divsi3 with their code. – arrowd Sep 30 '12 at 13:21
1 Answers
2
You'll use your new compiler to compile the appropriate functions in compiler-rt that your processor is missing. Then include the compiler-rt library at link time so the unresolved symbol can be resolved.
__divsi3 is just a simple C function that uses simpler operations to perform the division that your architecture doesn't support.

Richard Pennington
- 19,673
- 4
- 43
- 72
-
Sounds reasonable, thank you. The only gotcha I have, is that I have no control on linkage, my codegen just generates asm. And I'm not sure that the current setting allows for multi-file linkage. I have to elaborate on asm-to-bin tool documentation — whether it can link multiple asm files. – Artem Pelenitsyn Sep 30 '12 at 18:11
-
1No problem. Just compile the compiler-rt files to bitcode, use llvm-link to link the rt objects with your application code bitcode, and then run the result through your code generator. – Richard Pennington Sep 30 '12 at 18:18
-
I found necessary linker option. But I have another problem now: how to told LLVM to add an external declaration for the function which implements integer division… – Artem Pelenitsyn Oct 01 '12 at 05:52