Gwinel
Gwinel

Reputation: 11

Can a libXXX.so transfer into a native code file? What ls LLVM native code looks like?

It was confused me that what is the LLVM native code look like? For example, there are two kinds of main.s, which one is native code? This one:

.file   "main.bc"
.text
.globl  main
.align  16, 0x90
.type   main,@function
main:                                   # @main
# BB#0:
subl    $12, %esp
movl    $.L.str, (%esp)
calll   puts
calll   foo
xorl    %eax, %eax
addl    $12, %esp
ret
.Ltmp0:
.size   main, .Ltmp0-main

.type   .L.str,@object          # @.str
.section    .rodata.str1.1,"aMS",@progbits,1
.L.str:
.asciz   "This is a shared library test..."
.size   .L.str, 33


.section    ".note.GNU-stack","",@progbits

or:

@.str = private unnamed_addr constant [33 x i8] c"This is a shared library test...\00", align 1

define i32 @main() nounwind {
%1 = alloca i32, align 4
store i32 0, i32* %1
%2 = call i32 @puts(i8* getelementptr inbounds ([33 x i8]* @.str, i32 0, i32 0))
call void @foo()
ret i32 0
}

declare i32 @puts(i8*)

declare void @foo()

The first one was generated by llvm-llc, and the second was by -emit-llvm -S.

If I want to use LLVM to transfer a static library or a shared library into native code, how can I do with LLVM?

Upvotes: 1

Views: 93

Answers (1)

Oak
Oak

Reputation: 26868

There is no such thing as "LLVM native code".

The first code section is in (what looks like to be) x86 assembly. These files usually get the ".s" extension, and they can be converted into object files by an assembler. LLVM's "llc" tool generates those by default, but there's nothing LLVM-specific about those files - every x86 compiler can generate them. This is also sometimes called x86 native code.

The second code section is in "LLVM bitcode" or "LLVM Intermediate Representation" (IR). This is an LLVM-specific intermediate language, and usually get the ".ll" extension. However, running "clang -emit-llvm -S" will by default generate those under ".s" extension, which might explain your confusion here.


You ask:

If I want to use LLVM to transfer a static library or a shared library into native code, how can I do with LLVM?

If you are talking about static libraries and shared libraries that are already built - e.g. ".so" or ".lib" files - then they are already in "native code", though you may want to use a disassembler if you want to get a human-friendly representation of them. If those libraries are not already built, you can use Clang to build them, just like any other compiler. If those libraries are provided in LLVM bitcode, you can use LLVM's "llc" to convert them to assembly files (though "llc" doesn't do optimizations - you need to manually run LLVM's "opt" too for that).

Upvotes: 1

Related Questions