Skip to content

Commit

Permalink
Refactor the initialization of bytecode threading (#11378)
Browse files Browse the repository at this point in the history
Refactor the initialization of bytecode threading

Use a function `caml_init_thread_code` instead of exposing global variables
`caml_instr_table` and  `caml_instr_base`.

This should silence the GCC 12 "dangling-pointer" warning.

Fixes: #11358
  • Loading branch information
xavierleroy authored and gasche committed Sep 3, 2022
1 parent 77b164c commit 7481281
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
3 changes: 1 addition & 2 deletions runtime/caml/fix_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ void caml_set_instruction (code_t pos, opcode_t instr);
int caml_is_instruction (opcode_t instr1, opcode_t instr2);

#ifdef THREADED_CODE
extern char ** caml_instr_table;
extern char * caml_instr_base;
void caml_init_thread_code(void ** instr_table, void * instr_base);
void caml_thread_code (code_t code, asize_t len);
#endif

Expand Down
10 changes: 8 additions & 2 deletions runtime/fix_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ void caml_fixup_endianness(code_t code, asize_t len)

#ifdef THREADED_CODE

char ** caml_instr_table;
char * caml_instr_base;
static char ** caml_instr_table;
static char * caml_instr_base;

void caml_init_thread_code(void ** instr_table, void * instr_base)
{
caml_instr_table = (char **) instr_table;
caml_instr_base = (char *) instr_base;
}

static int* opcode_nargs = NULL;
int* caml_init_opcode_nargs(void)
Expand Down
7 changes: 3 additions & 4 deletions runtime/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ sp is a local copy of the global variable Caml_state->extern_sp. */
#ifdef THREADED_CODE
# define Instruct(name) lbl_##name
# if defined(ARCH_SIXTYFOUR) && !defined(ARCH_CODE32)
# define Jumptbl_base ((char *) &&lbl_ACC0)
# define Jumptbl_base &&lbl_ACC0
# else
# define Jumptbl_base ((char *) 0)
# define Jumptbl_base 0
# define jumptbl_base ((char *) 0)
# endif
# ifdef DEBUG
Expand Down Expand Up @@ -249,8 +249,7 @@ value caml_interprete(code_t prog, asize_t prog_size)

if (prog == NULL) { /* Interpreter is initializing */
#ifdef THREADED_CODE
caml_instr_table = (char **) jumptable;
caml_instr_base = Jumptbl_base;
caml_init_thread_code(jumptable, Jumptbl_base);
#endif
return Val_unit;
}
Expand Down

0 comments on commit 7481281

Please sign in to comment.