[英]How to link extern librarys in the llvm IR representation
嘿,我使用clang ++通過以下命令以IR表示形式轉換程序:
鐺++ -S -emit-llvm program.cpp
然后我用llvm傳遞給某些屬性在.ll文件中搜索。 是否有可能以這種表示形式獲得外部庫? 通常我只能從調用函數中看到名稱。
例:
#include "stdio.h"
int main(int argc, char const *argv[]) {
printf("hi");
return 0;
}
紅外線:
; ModuleID = 'main.cpp'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@.str = private unnamed_addr constant [3 x i8] c"hi\00", align 1
; Function Attrs: norecurse uwtable
define i32 @main(i32 %argc, i8** %argv) #0 {
entry:
%retval = alloca i32, align 4
%argc.addr = alloca i32, align 4
%argv.addr = alloca i8**, align 8
store i32 0, i32* %retval, align 4
store i32 %argc, i32* %argc.addr, align 4
store i8** %argv, i8*** %argv.addr, align 8
%call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0))
ret i32 0
}
declare i32 @printf(i8*, ...) #1
attributes #0 = { norecurse uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.ident = !{!0}
!0 = !{!"clang version 3.8.1 (tags/RELEASE_381/final)"}
在這種情況下,我只能看到printf函數。 有沒有辦法在表示中獲取“ stdio.h”?
stdio.h僅包含printf的聲明 ,而不包含定義。 編譯器發出LLVM IR時看不到它。
從技術上講,您可以使用LTO(包括靜態檔案庫)在IR中獲取完整程序。 但是,通常libc不是為LTO構建的,無論如何您都不會看到printf的主體。
對於嵌入式開發(固件...),LTO階段通常會看到完整程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.