From 7481281708b3db0ea409f476b76ceb8a1b8c0c4a Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Fri, 1 Jul 2022 17:14:44 +0200 Subject: [PATCH 1/2] Refactor the initialization of bytecode threading (#11378) 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 --- runtime/caml/fix_code.h | 3 +-- runtime/fix_code.c | 10 ++++++++-- runtime/interp.c | 7 +++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/runtime/caml/fix_code.h b/runtime/caml/fix_code.h index 83c393a17dc2..2eafaa814bba 100644 --- a/runtime/caml/fix_code.h +++ b/runtime/caml/fix_code.h @@ -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 diff --git a/runtime/fix_code.c b/runtime/fix_code.c index aa059be5dfd7..558401986708 100644 --- a/runtime/fix_code.c +++ b/runtime/fix_code.c @@ -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) diff --git a/runtime/interp.c b/runtime/interp.c index a59811c87d86..e6700994bc98 100644 --- a/runtime/interp.c +++ b/runtime/interp.c @@ -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 @@ -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; } From bb79e82f6d16008ced7e7613a7e96bae92a202c6 Mon Sep 17 00:00:00 2001 From: Gabriel Scherer Date: Sat, 3 Sep 2022 10:36:05 +0200 Subject: [PATCH 2/2] Changes --- Changes | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Changes b/Changes index 6210cee91f65..bfd99672dbc3 100644 --- a/Changes +++ b/Changes @@ -12,6 +12,10 @@ OCaml 4.12, maintenance version code or an OCaml thread stops. (Xavier Leroy, review by David Allsopp, Florian Angeletti and Damien Doligez) +- #11358, #11378: Refactor the initialization of bytecode threading. + This avoids a "dangling pointer" warning of GCC 12.1. + (Xavier Leroy, report by Armaël Guéneau, review by Gabriel Scherer) + OCaml 4.12.1 (24 September 2021) --------------------------------