Peng Yu via llvm-dev
2019-Jan-26 02:13 UTC
[llvm-dev] How does LLVM know where to resolve declared only functions?
Hi In the generated .ll file, it may have something like this. How does LLVM know where to look for the definition of printf? Is it documented somewhere? Thanks. declare i32 @printf(i8*, ...) #1 -- Regards, Peng
Jeremy Lakeman via llvm-dev
2019-Jan-26 04:27 UTC
[llvm-dev] How does LLVM know where to resolve declared only functions?
It's the linkers job to hook together functions and definitions that end up in the same binary. Your OS will then hook in functions from other binaries when your executable is loaded into memory. On Sat, 26 Jan 2019 at 12:43, Peng Yu via llvm-dev <llvm-dev at lists.llvm.org> wrote:> Hi > > In the generated .ll file, it may have something like this. How does > LLVM know where to look for the definition of printf? Is it documented > somewhere? Thanks. > > declare i32 @printf(i8*, ...) #1 > > -- > Regards, > Peng > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190126/b6bf9e57/attachment.html>
Peng Yu via llvm-dev
2019-Jan-27 01:03 UTC
[llvm-dev] How does LLVM know where to resolve declared only functions?
> It's the linkers job to hook together functions and definitions that end up in the same binary. Your OS will then hook in functions from other binaries when your executable is loaded into memory.How does it know whether it is a system function or a user-defined function? It seems that user functions have higher priorities over system functions as demonstrated by the following example. Is there any way to always use system functions for certain function calls (but not always default to system functions) when there are local functions with the same name? ==> main.c <=/* vim: set noexpandtab tabstop=2: */ #include <stdio.h> int main() { puts("Hello World!"); return 0; } ==> myputs.c <=/* vim: set noexpandtab tabstop=2: */ #include <stdio.h> int myputs(char *s) { return printf("myputs:%s\n", s); } $ ./main1.sh clang -Wall -pedantic -S -emit-llvm -c -o main.ll main.c clang -Wall -pedantic -S -emit-llvm -c -o myputs.ll myputs.c clang -Wall -pedantic -c -o main.o main.ll clang -Wall -pedantic -c -o myputs.o myputs.ll clang main.o myputs.o -o ./main.exe ./main.exe Hello World! sed -i 's/@myputs\>/@puts/g' myputs.ll clang -Wall -pedantic -c -o myputs.o myputs.ll clang main.o myputs.o -o ./main.exe ./main.exe myputs:Hello World! $ cat ./main1.sh #!/usr/bin/env bash # vim: set noexpandtab tabstop=2: set -v clang -Wall -pedantic -S -emit-llvm -c -o main.ll main.c clang -Wall -pedantic -S -emit-llvm -c -o myputs.ll myputs.c clang -Wall -pedantic -c -o main.o main.ll clang -Wall -pedantic -c -o myputs.o myputs.ll clang main.o myputs.o -o ./main.exe ./main.exe sed -i 's/@myputs\>/@puts/g' myputs.ll clang -Wall -pedantic -c -o myputs.o myputs.ll clang main.o myputs.o -o ./main.exe ./main.exe -- Regards, Peng
Reasonably Related Threads
- How does LLVM know where to resolve declared only functions?
- Is it possible to generate the IR representation with the original macro information?
- How to flatten a tree (based on list) to a certain depth?
- What does "preds" mean in a .ll file?
- Crash with core32 (syslinux-3.81-pre12-68-g4a211f6)