博文

目前显示的是 七月, 2017的博文

LLVM相关技术文章收集

Chris Lattner的LLVM教程中文版: https://llvm-tutorial-cn.readthedocs.io/en/latest/chapter-1.html IBM - 使用 LLVM 框架创建一个工作编译器: https://www.ibm.com/developerworks/cn/opensource/os-createcompilerllvm1/index.html https://www.ibm.com/developerworks/cn/opensource/os-createcompilerllvm2/index.html

LLVM的类型系统(转

LLVM中的类型系统很重要!有类型,可以使得很多优化成为可能,而且不需要额外的分析。一个强类型系统可使生成的代码更容易理解,并且更容易优化和转换。 1.类型的类别 llvm有以下几种类型: integer   i1, i2, i3, ... i8, ... i16, ... i32, ... i64, ... floating point   float, double, x86_fp80, fp128, ppc_fp128 first class   integer ,  floating point ,  pointer ,  vector ,  structure ,  array ,  label ,  metadata . primitive   label ,  void ,  floating point ,  x86mmx ,  metadata . derived   array ,  function ,  pointer ,  structure ,  packed structure ,  vector ,  opaque . (第一类)first class是最重要的。指令只能产生这些类型的值。 2.原始类型(primitive types) 原始类型是llvm系统中的基础。 integer类型 整数类型是一个位宽度从1到2^23-1的整数。 语法: iN 其中N为位宽。 例子: i1 i32 i1942652 Floating Point类型 float   32-bit floating point value double   64-bit floating point value fp128   128-bit floating point value (112-bit mantissa) x86_fp80   80-bit floating point value (X8...

objc->cpp的对应关系。

通过clang可以方便地把objc的语法转成cpp: clang -rewrite-objc xxx.m 所以可以很方便的看到objc与cpp之间的对应关系。 最近主要工作在符号混淆上,但是踩到了有关selector和runtime的混淆的坑。 NSClassFromString: id obj = [[NSClassFromString(@"MyClass") alloc] init]; id obj = ((id (*)(id, SEL))(void *)objc_msgSend)((id)((id (*)(id, SEL))(void *)objc_msgSend)((id)NSClassFromString((NSString *)&__NSConstantStringImpl__var_folders_92_dfj9jsb51kj3lh2zssbw0dzm0000gn_T_1_38e0f0_mi_0), sel_registerName("alloc")), sel_registerName("init")); NSStringFromClass: NSString *obj = NSStringFromClass([MyClass class]); NSString *obj = NSStringFromClass(((Class (*)(id, SEL))(void *)objc_msgSend)((id)objc_getClass("MyClass"), sel_registerName("class"))); Selector: SEL sel = @selector(mySelector); SEL sel = sel_registerName("mySelector");