Skip to content

Commit

Permalink
Output label for static function
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed Jul 23, 2024
1 parent 5ed37f4 commit fa14ae7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions src/as/arch/x64/ir_asm_x64.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -212,15 +213,16 @@ 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;
info->src_section = sec;
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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/as/emit_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fa14ae7

Please sign in to comment.