1

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?

4
  • You can adapt the code from this answer. Commented Sep 29, 2012 at 8:38
  • I don't ask for algorithm of division, but for a way of using standard library function. Commented Sep 29, 2012 at 9:12
  • Then I don't understand your question. Can you elaborate it or provide an example of what you want? Commented Sep 29, 2012 at 9:14
  • I suppose you should compile libcompile_rt into bitcode and then substitute calls like __divsi3 with their code. Commented Sep 30, 2012 at 13:21

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
No 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.
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…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.