问题:使用atos不加-l参数时符号化失败,加-l符号化成功。
原因:系统动态库的slide值不是0x10000000
atos
atos -l 后面跟的是基地址
atos不加-l后面跟的是总偏移地址(=映射偏移+文件偏移,映射偏移是__TEXT起始地址,文件偏移是offset)
地址逻辑
symbol address = slide + stack address - load address
slide 值是 LC_SEGMENT __TEXT 中的 vmaddr 的值(大部分是0x10000000,64是0x10000000,32是0x0,系统动态库不定).
运行命令otool -arch arm64 -l "APP_BUNDLE/APP_EXECUTABLE" | grep -B 3 -A 8 -m 2 "__TEXT"可得到具体值
代码中获取映射偏移:可以获取__TEXT的起始地址,或者text_addr = (uintptr_t)header - _dyld_get_image_vmaddr_slide(i)
demo
void test(void) {
uint32_t count = _dyld_image_count();
for (int i = 0; i < count; i++) {
NSString *name = [[NSString stringWithUTF8String:_dyld_get_image_name(i)] lastPathComponent];
intptr_t vmaddr_slide = _dyld_get_image_vmaddr_slide(i);
const struct mach_header* header = _dyld_get_image_header(i);
intptr_t text_addr = (uintptr_t)header - _dyld_get_image_vmaddr_slide(i);
NSLog(@"---i:%d,name:%@,vmaddr_slide:%#lx,header:%p,text_addr:%#lx",i,name, vmaddr_slide,header,text_addr);
}
}
// 打印可知:header = text_addr + vmaddr_slide
---i:0,name:SlideTest,vmaddr_slide:0x84000,header:0x100084000,text_addr:0x100000000
---i:1,name:substitute-inserter.dylib,vmaddr_slide:0x1001c4000,header:0x1001c4000,text_addr:0
---i:2,name:Foundation,vmaddr_slide:0xab84000,header:0x18b2c7000,text_addr:0x180743000
---i:3,name:libobjc.A.dylib,vmaddr_slide:0xab84000,header:0x18ad38000,text_addr:0x1801b4000
网友评论