1

1) Is it possible, using IRBuilder, to generate system calls independent of operation system? I have read this: http://llvm.lyngvig.org/Articles/Mapping-High-Level-Constructs-to-LLVM-IR#59 It seems like that when I generate LLVM IR and want to generate system call for e.g output to terminal, then I must tailor the LLVM IR to Linux/Windows/Mac. Or does LLVM have some interface for system calls?

2) Has this tool http://llvm.org/docs/CommandGuide/llc.html ability to do the stuff I want in 1) ?

1 Answers1

2

Absolutely not. LLVM is a compiler backend; it does not concern itself with system calls. System calls are usually employed inside the platform's C library, which implements them with a mixture of low-level C and target-specific assembly. System calls are both OS and target (CPU) dependent.

As for more materials on studying this stuff - you have my sympathy. It's not a well documented area, because 99.9% of programmers never need to operate at this level. I suggest you start picking up some basic assembly programming and go from there.

Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
  • Thank you! So what is the solution when I want to write LLVM IR for my toy language which should print "Hello world" both on Linux and Windows terminal? – Ondrej Smid Aug 15 '15 at 22:42
  • 2
    @OndrejSmid: you can invoke a standard C library function like `puts` and link the object file created from your IR with the C library. If you want to avoid the C library you'll have to implement your own wrappers for syscalls – Eli Bendersky Aug 17 '15 at 12:18
  • LLVM is not a compiler backend per se, it's the infrastructure that any compiler backend might be accounted as a part of it. – ozanmuyes Aug 03 '22 at 01:19