From fa14ae7a09dab746e4812230401b734ec611d0bd Mon Sep 17 00:00:00 2001 From: tyfkda Date: Wed, 17 Jul 2024 17:38:49 +0900 Subject: [PATCH] Output label for static function --- src/as/arch/x64/ir_asm_x64.c | 26 ++++++++++++++------------ src/as/emit_elf.c | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/as/arch/x64/ir_asm_x64.c b/src/as/arch/x64/ir_asm_x64.c index b8ce28e52..57bda507f 100644 --- a/src/as/arch/x64/ir_asm_x64.c +++ b/src/as/arch/x64/ir_asm_x64.c @@ -129,34 +129,35 @@ bool resolve_relative_address(Vector **section_irs, Table *label_table, Vector * Value value = calc_expr(label_table, inst->opr[0].indirect.offset.expr); if (value.label != NULL) { LabelInfo *label_info = table_get(label_table, value.label); - if (label_info == NULL) { + if (label_info != NULL && label_info->section != sec) { + Vector *irs2 = section_irs[label_info->section]; + uintptr_t dst_start_address = irs2->len > 0 ? ((IR *)irs2->data[0])->address : 0; + UnresolvedInfo *info = malloc_or_die(sizeof(*info)); - info->kind = UNRES_EXTERN_PC32; + info->kind = UNRES_OTHER_SECTION; info->label = value.label; info->src_section = sec; info->offset = address + 3 - start_address; - info->add = value.offset - 4; + info->add = label_info->address + value.offset - dst_start_address - 4; vec_push(unresolved, info); #if XCC_TARGET_PLATFORM == XCC_PLATFORM_APPLE put_value(ir->code.buf + 3, value.offset, sizeof(int32_t)); #endif break; } - if (label_info->section != sec) { - Vector *irs2 = section_irs[label_info->section]; - uintptr_t dst_start_address = irs2->len > 0 ? ((IR *)irs2->data[0])->address : 0; - + if (label_info == NULL || label_info->flag & LF_GLOBAL) { UnresolvedInfo *info = malloc_or_die(sizeof(*info)); - info->kind = UNRES_OTHER_SECTION; + info->kind = UNRES_EXTERN_PC32; info->label = value.label; info->src_section = sec; info->offset = address + 3 - start_address; - info->add = label_info->address + value.offset - dst_start_address - 4; + info->add = value.offset - 4; vec_push(unresolved, info); #if XCC_TARGET_PLATFORM == XCC_PLATFORM_APPLE put_value(ir->code.buf + 3, value.offset, sizeof(int32_t)); #endif - break; + if (label_info == NULL) + break; } value.offset += label_info->address; } @@ -212,7 +213,7 @@ bool resolve_relative_address(Vector **section_irs, Table *label_table, Vector * Value value = calc_expr(label_table, inst->opr[0].direct.expr); if (value.label != NULL) { LabelInfo *label_info = table_get(label_table, value.label); - if (label_info == NULL) { + if (label_info == NULL || label_info->flag & LF_GLOBAL) { UnresolvedInfo *info = malloc_or_die(sizeof(*info)); info->kind = UNRES_EXTERN; info->label = value.label; @@ -220,7 +221,8 @@ bool resolve_relative_address(Vector **section_irs, Table *label_table, Vector * info->offset = address + 1 - start_address; info->add = value.offset - 4; vec_push(unresolved, info); - break; + if (label_info == NULL) + break; } value.offset += label_info->address; } diff --git a/src/as/emit_elf.c b/src/as/emit_elf.c index 41dace509..1e1f2ebd7 100644 --- a/src/as/emit_elf.c +++ b/src/as/emit_elf.c @@ -109,7 +109,7 @@ static int construct_symtab(Symtab *symtab, Table *label_table) { int bind; if (info->flag & LF_GLOBAL) { bind = STB_GLOBAL; - } else if (info->flag & LF_REFERRED) { + } else if (info->flag & LF_REFERRED || info->kind == LK_FUNC) { bind = STB_LOCAL; } else { continue;