authorgravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2021-02-04 20:51:53+07:00
committergravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2021-02-04 21:07:54+07:00
loge3e4af727103d90cb191f130159928d237263e1f
tree97bdfe02060616dd36221a9678e5891a0157e9d0
parent1eb2e4801448aca29471bf6f7582135ddafb15fe

stage1: set gen_frame_size alignment to work around requirement mismatch

Explicitly set the alignment requirements to 1 (i.e, mark the load as unaligned) since there are some architectures (e.g SPARCv9) which has different alignment requirements between a function pointer and usize pointer. On those architectures, not explicitly setting it will lead into @frameSize generating usize-aligned load instruction that could crash if the function pointer happens to be not usize-aligned.

1 files changed, 3 insertions(+), 1 deletions(-)

src/stage1/codegen.cpp+3-1
...@@ -4160,7 +4160,9 @@ static LLVMValueRef gen_frame_size(CodeGen *g, LLVMValueRef fn_val) {...@@ -4160,7 +4160,9 @@ static LLVMValueRef gen_frame_size(CodeGen *g, LLVMValueRef fn_val) {
4160 LLVMValueRef casted_fn_val = LLVMBuildBitCast(g->builder, fn_val, ptr_usize_llvm_type, "");4160 LLVMValueRef casted_fn_val = LLVMBuildBitCast(g->builder, fn_val, ptr_usize_llvm_type, "");
4161 LLVMValueRef negative_one = LLVMConstInt(LLVMInt32Type(), -1, true);4161 LLVMValueRef negative_one = LLVMConstInt(LLVMInt32Type(), -1, true);
4162 LLVMValueRef prefix_ptr = LLVMBuildInBoundsGEP(g->builder, casted_fn_val, &negative_one, 1, "");4162 LLVMValueRef prefix_ptr = LLVMBuildInBoundsGEP(g->builder, casted_fn_val, &negative_one, 1, "");
4163 return LLVMBuildLoad(g->builder, prefix_ptr, "");4163 LLVMValueRef load_inst = LLVMBuildLoad(g->builder, prefix_ptr, "");
4164 LLVMSetAlignment(load_inst, 1);
4165 return load_inst;
4164}4166}
41654167
4166static void gen_init_stack_trace(CodeGen *g, LLVMValueRef trace_field_ptr, LLVMValueRef addrs_field_ptr) {4168static void gen_init_stack_trace(CodeGen *g, LLVMValueRef trace_field_ptr, LLVMValueRef addrs_field_ptr) {