I did it !!!! YOU MADE MY DAY !!!!!!!!!!!!!!! -- 祝好! 甄凯 ------------------------------------------------------------------------------------------------------ 2012-04-10 ------------------------------------------------------------------------------------------------------ Name: 甄凯(ZhenKai) Homepage:http://www.renren.com/262729393 Email: zhenkaixd at 126.com or 846227103 at qq.com TEL: 15810729006(Beijing) Address: Room I-406, Central Building, Tsinghua University, Beijing, China. 100084. At 2012-04-10 19:55:04,"Duncan Sands" <baldrick at free.fr> wrote:>Hi, > >> BTW the opt command I use is *"opt -load ../../../Debug+Asserts/lib/Hello.so >> -hello <hello.bc> -o hello.bc"* > >just use hello.bc not <hello.bc> otherwise the shell will redirect input and >output. > >Ciao, Duncan. >_______________________________________________ >LLVM Developers mailing list >LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120410/83ad69da/attachment.html>
Hi, my friends I finally insert the callInst into the hello.bc file.Then I compile the hello.bc to hello.o file and the check.c to check.o file. And I think by link those to .o file togetherI can get the executable ELF file(clang hello.o check.o -o finalfile). But when I link the two objective file, it said "hello.o: In function `main': hello.bc:(.text+0x69): undefined reference to `check' clang: error: linker command failed with exit code 1 (use -v to see invocation)" What's wrong?? To make it readable I convert the .bc file into .ll file using llvm-dis. The IR code is as follow, any help? Before running the pass ; ModuleID = 'hello.bc' target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" target triple = "i386-pc-linux-gnu" @.str = private unnamed_addr constant [18 x i8] c"add result is %d\0A\00", align 1 @.str1 = private unnamed_addr constant [20 x i8] c"minus result is %d\0A\00", align 1 @str = private unnamed_addr constant [13 x i8] c"hello world!\00" define i32 @add(i32 %a, i32 %b) nounwind readnone { entry: %add = add nsw i32 %b, %a ret i32 %add } define i32 @minus(i32 %a, i32 %b) nounwind readnone { entry: %sub = sub nsw i32 %a, %b ret i32 %sub } define i32 @main() nounwind { entry: %call1 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([18 x i8]* @.str, i32 0, i32 0), i32 3) nounwind %call3 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([20 x i8]* @.str1, i32 0, i32 0), i32 1) nounwind %puts = tail call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @str, i32 0, i32 0)) ret i32 0 } declare i32 @printf(i8* nocapture, ...) nounwind declare i32 @puts(i8* nocapture) nounwind After running the pass ; ModuleID = 'newhello.bc' target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" target triple = "i386-pc-linux-gnu" @.str = private unnamed_addr constant [18 x i8] c"add result is %d\0A\00", align 1 @.str1 = private unnamed_addr constant [20 x i8] c"minus result is %d\0A\00", align 1 @str = private unnamed_addr constant [13 x i8] c"hello world!\00" define i32 @add(i32 %a, i32 %b) nounwind readnone { entry: %add = add nsw i32 %b, %a ret i32 %add } define i32 @minus(i32 %a, i32 %b) nounwind readnone { entry: %sub = sub nsw i32 %a, %b ret i32 %sub } define i32 @main() nounwind { entry: %call1 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([18 x i8]* @.str, i32 0, i32 0), i32 3) nounwind %call3 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([20 x i8]* @.str1, i32 0, i32 0), i32 1) nounwind %CallCheck = call i32 @check() %puts = tail call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @str, i32 0, i32 0)) ret i32 0 } declare i32 @printf(i8* nocapture, ...) nounwind declare i32 @puts(i8* nocapture) nounwind declare i32 @check() The original hello.c file #include <stdio.h> extern int check(); int add(int a,int b) { return a+b; } int minus(int a,int b) { return a-b; } int main() { int a=2,b=1; printf("add result is %d\n",add(a,b)); printf("minus result is %d\n",minus(a,b)); printf("hello world!\n"); return 0; } The original check.c file #include <stdio.h> void print() { printf("Check function works!\n"); } -- 祝好! 甄凯 ------------------------------------------------------------------------------------------------------ 2012-04-10 ------------------------------------------------------------------------------------------------------ Name: 甄凯(ZhenKai) Homepage:http://www.renren.com/262729393 Email: zhenkaixd at 126.com or 846227103 at qq.com TEL: 15810729006(Beijing) Address: Room I-406, Central Building, Tsinghua University, Beijing, China. 100084. At 2012-04-10 20:00:08,15102925731 <zhenkaixd at 126.com> wrote: I did it !!!! YOU MADE MY DAY !!!!!!!!!!!!!!! -- 祝好! 甄凯 ------------------------------------------------------------------------------------------------------ 2012-04-10 ------------------------------------------------------------------------------------------------------ Name: 甄凯(ZhenKai) Homepage:http://www.renren.com/262729393 Email: zhenkaixd at 126.com or 846227103 at qq.com TEL: 15810729006(Beijing) Address: Room I-406, Central Building, Tsinghua University, Beijing, China. 100084. At 2012-04-10 19:55:04,"Duncan Sands" <baldrick at free.fr> wrote:>Hi, > >> BTW the opt command I use is *"opt -load ../../../Debug+Asserts/lib/Hello.so >> -hello <hello.bc> -o hello.bc"* > >just use hello.bc not <hello.bc> otherwise the shell will redirect input and >output. > >Ciao, Duncan. >_______________________________________________ >LLVM Developers mailing list >LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120410/19517231/attachment.html>
Alexander Potapenko
2012-Apr-10 13:02 UTC
[LLVMdev] How to explain this weird phenomenon????????
Your files do not appear to implement the check() function. On Tue, Apr 10, 2012 at 4:57 PM, 15102925731 <zhenkaixd at 126.com> wrote:> Hi, my friends > > I finally insert the callInst into the hello.bc file.Then I compile the > hello.bc to hello.o file and the check.c to check.o file. And I think by > link those to .o file togetherI can get the executable ELF file(clang > hello.o check.o -o finalfile). > > But when I link the two objective file, it said > "hello.o: In function `main': > hello.bc:(.text+0x69): undefined reference to `check' > clang: error: linker command failed with exit code 1 (use -v to see > invocation)" What's wrong?? > > To make it readable I convert the .bc file into .ll file using llvm-dis. > The IR code is as follow, any help? > > Before running the pass > ; ModuleID = 'hello.bc' > target datalayout > "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" > target triple = "i386-pc-linux-gnu" > > @.str = private unnamed_addr constant [18 x i8] c"add result is %d\0A\00", > align 1 > @.str1 = private unnamed_addr constant [20 x i8] c"minus result is > %d\0A\00", align 1 > @str = private unnamed_addr constant [13 x i8] c"hello world!\00" > > define i32 @add(i32 %a, i32 %b) nounwind readnone { > entry: > %add = add nsw i32 %b, %a > ret i32 %add > } > > define i32 @minus(i32 %a, i32 %b) nounwind readnone { > entry: > %sub = sub nsw i32 %a, %b > ret i32 %sub > } > > define i32 @main() nounwind { > entry: > %call1 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([18 > x i8]* @.str, i32 0, i32 0), i32 3) nounwind > %call3 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([20 > x i8]* @.str1, i32 0, i32 0), i32 1) nounwind > %puts = tail call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @str, > i32 0, i32 0)) > ret i32 0 > } > > declare i32 @printf(i8* nocapture, ...) nounwind > > declare i32 @puts(i8* nocapture) nounwind > After running the pass > ; ModuleID = 'newhello.bc' > target datalayout > "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" > target triple = "i386-pc-linux-gnu" > > @.str = private unnamed_addr constant [18 x i8] c"add result is %d\0A\00", > align 1 > @.str1 = private unnamed_addr constant [20 x i8] c"minus result is > %d\0A\00", align 1 > @str = private unnamed_addr constant [13 x i8] c"hello world!\00" > > define i32 @add(i32 %a, i32 %b) nounwind readnone { > entry: > %add = add nsw i32 %b, %a > ret i32 %add > } > > define i32 @minus(i32 %a, i32 %b) nounwind readnone { > entry: > %sub = sub nsw i32 %a, %b > ret i32 %sub > } > > define i32 @main() nounwind { > entry: > %call1 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([18 > x i8]* @.str, i32 0, i32 0), i32 3) nounwind > %call3 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([20 > x i8]* @.str1, i32 0, i32 0), i32 1) nounwind > %CallCheck = call i32 @check() > %puts = tail call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @str, > i32 0, i32 0)) > ret i32 0 > } > > declare i32 @printf(i8* nocapture, ...) nounwind > > declare i32 @puts(i8* nocapture) nounwind > > declare i32 @check() > The original hello.c file > #include <stdio.h> > extern int check(); > int add(int a,int b) > { > return a+b; > } > > int minus(int a,int b) > { > return a-b; > } > int main() > { > int a=2,b=1; > printf("add result is %d\n",add(a,b)); > printf("minus result is %d\n",minus(a,b)); > printf("hello world!\n"); > return 0; > } > The original check.c file > #include <stdio.h> > void print() > { > printf("Check function works!\n"); > > } > -- > 祝好! > > 甄凯 > ------------------------------------------------------------------------------------------------------ > 2012-04-10 > ------------------------------------------------------------------------------------------------------ > Name: 甄凯(ZhenKai) > Homepage:http://www.renren.com/262729393 > Email: zhenkaixd at 126.com or 846227103 at qq.com > TEL: 15810729006(Beijing) > Address: Room I-406, Central Building, Tsinghua University, Beijing, China. > 100084. > > At 2012-04-10 20:00:08,15102925731 <zhenkaixd at 126.com> wrote: > > I did it !!!! > YOU MADE MY DAY !!!!!!!!!!!!!!! > > -- > 祝好! > > 甄凯 > ------------------------------------------------------------------------------------------------------ > 2012-04-10 > ------------------------------------------------------------------------------------------------------ > Name: 甄凯(ZhenKai) > Homepage:http://www.renren.com/262729393 > Email: zhenkaixd at 126.com or 846227103 at qq.com > TEL: 15810729006(Beijing) > Address: Room I-406, Central Building, Tsinghua University, Beijing, China. > 100084. > > > At 2012-04-10 19:55:04,"Duncan Sands" <baldrick at free.fr> wrote: >>Hi, >> >>> BTW the opt command I use is *"opt -load ../../../Debug+Asserts/lib/Hello.so >>> -hello <hello.bc> -o hello.bc"* >> >>just use hello.bc not <hello.bc> otherwise the shell will redirect input and >>output. >> >>Ciao, Duncan. >>_______________________________________________ >>LLVM Developers mailing list >>LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >>http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > > > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-- Alexander Potapenko Software Engineer Google Moscow
Hi 15102925731,> But when I link the two objective file, it said > "hello.o: In function `main': > hello.bc:(.text+0x69): undefined reference to `check' > clang: error: linker command failed with exit code 1 (use -v to see invocation)" > What's wrong??...> declare i32 @check()...> *The original check.c file* > #include <stdio.h> > void print()Should be called check not print.> { > printf("Check function works!\n"); > }Ciao, Duncan.
Reasonably Related Threads
- [LLVMdev] How to explain this weird phenomenon????????
- [LLVMdev] How to explain this weird phenomenon????????
- [LLVMdev] How to explain this weird phenomenon????????
- [LLVMdev] How to explain this weird phenomenon????????
- [LLVMdev] How to compile a linux module into .bc file using clang or llvm command?