或者,您可以尝试从llvm-gcc发出LLVM IR的 text 表示形式,并通过llvm-as进行组装.类似这样的东西:llvm-gcc -emit-llvm -S foo.c -o foo.llllvm-as foo.ll -o foo.bcllc foo.ll -o foo.S等I'm trying to run the following example to Compile, Assemble and Disassemble an small program using the LLVM tool chain.My intention is to learn how it works so in further tries I could do some performance test by changing and/or reordering the assmbly's instructions.To start with, I first get the bite code of a dummy program: % llvm-gcc -O3 -emit-llvm hello.c -c -o hello.bcOnce I have the bite code, i try to use the llvm-dis utility to take a look at the LLVM assembly code and llc to compile the program back to native assembly using the LLC code generator (just for the shake of trying): % llvm-dis < hello.bc | less % llc hello.bc -o hello.sBut in both cases I get the following error: llvm-dis: Invalid MODULE_CODE_GLOBALVAR recordAny ideas on how to solve this problem?I've googled and I haven't found a solution. I have also tried to use otool -tV helloBut the output is not compatible with llvm. Instead of getting the following assembly format: .section __TEXT,__text,regular,pure_instructions.globl _main.align 4, 0x90 _main: Leh_func_begin1:pushq %rbp Ltmp0:movq %rsp, %rbp Ltmp1:subq $16, %rsp Ltmp2:leaq L_.str(%rip), %raxI get: __TEXT,__text) sectionstart:0000000100000eb0 pushq $0x000000000100000eb2 movq %rsp,%rbp0000000100000eb5 andq $0xf0,%rsp0000000100000eb9 movq 0x08(%rbp),%rdi0000000100000ebd leaq 0x10(%rbp),%rsi0000000100000ec1 movl %edi,%edx0000000100000ec3 addl $0x01,%edxWhich is not valid for me as I cat compile the latter assembly with for example: % gcc hello.s -o hello.nativeThanks in advance. 解决方案 Make sure your llvm-gcc's version match the version of LLVM you installed - the binary IR format changes quite fast and is not backward compatible across several version.Alternatively, you might try to emit text representation of LLVM IR out of llvm-gcc and assemble it through llvm-as.Something like this:llvm-gcc -emit-llvm -S foo.c -o foo.llllvm-as foo.ll -o foo.bcllc foo.ll -o foo.Setc. 这篇关于使用LLVM工具链进行编译,组装和反汇编的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-06 08:31