# 分析汇编代码中的帧槽偏移量 # 从汇编代码中提取的偏移量: # 第500个参数的参数帧槽:[sp, #7960] # 第500个参数的alloca帧槽:[x29-2000] # LowerLoadInst创建的帧槽:[x29-4000] # 计算帧槽索引和偏移量 # 假设有500个参数,500个alloca,1个load # 参数帧槽(索引 0-499) # 前8个参数:is_stack_arg = false # 第9-500个参数:is_stack_arg = true, is_callee_stack_arg = true # alloca帧槽(索引 500-999) # is_stack_arg = false # load帧槽(索引 1000) # is_stack_arg = false # 计算偏移量 num_params = 500 num_alloca = 500 # 模拟帧槽创建 slots = [] for i in range(num_params): if i < 8: slots.append((i, False, False)) # (index, is_stack_arg, is_callee_stack_arg) else: slots.append((i, True, True)) for i in range(num_alloca): slots.append((num_params + i, False, False)) slots.append((num_params + num_alloca, False, False)) # 计算偏移量 local_cursor = 0 stack_arg_cursor = 0 for index, is_stack_arg, is_callee_stack_arg in slots: if is_stack_arg: offset = stack_arg_cursor stack_arg_cursor += 8 else: local_cursor = ((local_cursor + 4 - 1) // 4) * 4 local_cursor += 4 offset = -local_cursor # 计算local_size local_size = ((local_cursor + 16 - 1) // 16) * 16 print(f"local_cursor = {local_cursor}") print(f"local_size = {local_size}") # 计算sp_offset_base sp_offset_base = local_size + 16 print(f"sp_offset_base = {sp_offset_base}") # 更新is_callee_stack_arg的偏移量 print("\n第500个参数的参数帧槽(索引 499):") index = 499 _, is_stack_arg, is_callee_stack_arg = slots[index] # 重新计算偏移量 local_cursor = 0 stack_arg_cursor = 0 for i, (idx, is_sa, is_csa) in enumerate(slots): if is_sa: offset = stack_arg_cursor stack_arg_cursor += 8 else: local_cursor = ((local_cursor + 4 - 1) // 4) * 4 local_cursor += 4 offset = -local_cursor if i == index: if is_csa: final_offset = sp_offset_base + offset else: final_offset = offset print(f" 索引 {idx}: offset = {final_offset} (is_stack_arg = {is_sa}, is_callee_stack_arg = {is_csa})") break print("\n第500个参数的alloca帧槽(索引 999):") index = 999 local_cursor = 0 stack_arg_cursor = 0 for i, (idx, is_sa, is_csa) in enumerate(slots): if is_sa: offset = stack_arg_cursor stack_arg_cursor += 8 else: local_cursor = ((local_cursor + 4 - 1) // 4) * 4 local_cursor += 4 offset = -local_cursor if i == index: if is_csa: final_offset = sp_offset_base + offset else: final_offset = offset print(f" 索引 {idx}: offset = {final_offset} (is_stack_arg = {is_sa}, is_callee_stack_arg = {is_csa})") break print("\nload帧槽(索引 1000):") index = 1000 local_cursor = 0 stack_arg_cursor = 0 for i, (idx, is_sa, is_csa) in enumerate(slots): if is_sa: offset = stack_arg_cursor stack_arg_cursor += 8 else: local_cursor = ((local_cursor + 4 - 1) // 4) * 4 local_cursor += 4 offset = -local_cursor if i == index: if is_csa: final_offset = sp_offset_base + offset else: final_offset = offset print(f" 索引 {idx}: offset = {final_offset} (is_stack_arg = {is_sa}, is_callee_stack_arg = {is_csa})") break