How does llvm IR use functions in libc, such as open socket, etc. is there a specific example,How does llvm IR use functions in libc, such as open socket, etc. is there a specific example,How does llvm IR use functions in libc, such as open socket, etc. is there a specific example,How does llvm IR use functions in libc, such as open socket, etc. is there a specific example
Asked
Active
Viewed 360 times
1 Answers
1
LLVM IR allows calls to functions by name. Just like in C the function must be declared. In LLVM IR, the syntax looks like:
;; Sample declaration of a function in libc.
declare i32 @strlen(i8*)
;; Test code using it.
define i32 @test(i8* %a, i8* %b) {
%A = call i32 @strlen(i8* %a)
%B = call i32 @strlen(i8* %b)
%c = add i32 %A, %B
ret i32 %c
}
You can always take a look at the textual LLVM IR generated by clang for any given C code. clang -S -emit-llvm client.c -o client.ll -O1
to produce client.ll with light optimization.

Nick Lewycky
- 1,182
- 6
- 14