diff options
| author | Andrea Corallo | 2021-02-18 21:45:50 +0100 |
|---|---|---|
| committer | Andrea Corallo | 2021-02-18 21:55:01 +0100 |
| commit | 185121da6978553d538d37d6d0e67dc52e13311f (patch) | |
| tree | ee03984ee706a5f065ea0509d0ca6039efd1fdb5 /src/comp.c | |
| parent | f92bb788a073c6b3ca7f188e0edea714598193fd (diff) | |
| download | emacs-185121da6978553d538d37d6d0e67dc52e13311f.tar.gz emacs-185121da6978553d538d37d6d0e67dc52e13311f.zip | |
* Add assertion guarding against emitting a relocation array overflow
* src/comp.c (reloc_array_t): New type.
(comp_t, imm_reloc_t): Make use of 'reloc_array_t'.
(obj_to_reloc): Add an assertion not to overflow relocation
arrays.
(emit_lisp_obj_reloc_lval, emit_limple_insn)
(declare_imported_data_relocs): Make use of 'reloc_array_t'.
Diffstat (limited to 'src/comp.c')
| -rw-r--r-- | src/comp.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/comp.c b/src/comp.c index 5e951610302..f3a3e5556f2 100644 --- a/src/comp.c +++ b/src/comp.c | |||
| @@ -488,6 +488,11 @@ enum cast_kind_of_type | |||
| 488 | kind_pointer | 488 | kind_pointer |
| 489 | }; | 489 | }; |
| 490 | 490 | ||
| 491 | typedef struct { | ||
| 492 | EMACS_INT len; | ||
| 493 | gcc_jit_rvalue *r_val; | ||
| 494 | } reloc_array_t; | ||
| 495 | |||
| 491 | /* C side of the compiler context. */ | 496 | /* C side of the compiler context. */ |
| 492 | 497 | ||
| 493 | typedef struct { | 498 | typedef struct { |
| @@ -583,11 +588,11 @@ typedef struct { | |||
| 583 | Lisp_Object imported_funcs_h; /* subr_name -> gcc_jit_field *reloc_field. */ | 588 | Lisp_Object imported_funcs_h; /* subr_name -> gcc_jit_field *reloc_field. */ |
| 584 | Lisp_Object emitter_dispatcher; | 589 | Lisp_Object emitter_dispatcher; |
| 585 | /* Synthesized struct holding data relocs. */ | 590 | /* Synthesized struct holding data relocs. */ |
| 586 | gcc_jit_rvalue *data_relocs; | 591 | reloc_array_t data_relocs; |
| 587 | /* Same as before but can't go in pure space. */ | 592 | /* Same as before but can't go in pure space. */ |
| 588 | gcc_jit_rvalue *data_relocs_impure; | 593 | reloc_array_t data_relocs_impure; |
| 589 | /* Same as before but content does not survive load phase. */ | 594 | /* Same as before but content does not survive load phase. */ |
| 590 | gcc_jit_rvalue *data_relocs_ephemeral; | 595 | reloc_array_t data_relocs_ephemeral; |
| 591 | /* Global structure holding function relocations. */ | 596 | /* Global structure holding function relocations. */ |
| 592 | gcc_jit_lvalue *func_relocs; | 597 | gcc_jit_lvalue *func_relocs; |
| 593 | gcc_jit_type *func_relocs_ptr_type; | 598 | gcc_jit_type *func_relocs_ptr_type; |
| @@ -610,7 +615,7 @@ typedef struct { | |||
| 610 | } static_obj_t; | 615 | } static_obj_t; |
| 611 | 616 | ||
| 612 | typedef struct { | 617 | typedef struct { |
| 613 | gcc_jit_rvalue *array; | 618 | reloc_array_t array; |
| 614 | gcc_jit_rvalue *idx; | 619 | gcc_jit_rvalue *idx; |
| 615 | } imm_reloc_t; | 620 | } imm_reloc_t; |
| 616 | 621 | ||
| @@ -827,7 +832,9 @@ obj_to_reloc (Lisp_Object obj) | |||
| 827 | xsignal1 (Qnative_ice, | 832 | xsignal1 (Qnative_ice, |
| 828 | build_string ("cant't find data in relocation containers")); | 833 | build_string ("cant't find data in relocation containers")); |
| 829 | assume (false); | 834 | assume (false); |
| 835 | |||
| 830 | found: | 836 | found: |
| 837 | eassert (XFIXNUM (idx) < reloc.array.len); | ||
| 831 | if (!FIXNUMP (idx)) | 838 | if (!FIXNUMP (idx)) |
| 832 | xsignal1 (Qnative_ice, | 839 | xsignal1 (Qnative_ice, |
| 833 | build_string ("inconsistent data relocation container")); | 840 | build_string ("inconsistent data relocation container")); |
| @@ -1558,7 +1565,7 @@ emit_lisp_obj_reloc_lval (Lisp_Object obj) | |||
| 1558 | imm_reloc_t reloc = obj_to_reloc (obj); | 1565 | imm_reloc_t reloc = obj_to_reloc (obj); |
| 1559 | return gcc_jit_context_new_array_access (comp.ctxt, | 1566 | return gcc_jit_context_new_array_access (comp.ctxt, |
| 1560 | NULL, | 1567 | NULL, |
| 1561 | reloc.array, | 1568 | reloc.array.r_val, |
| 1562 | reloc.idx); | 1569 | reloc.idx); |
| 1563 | } | 1570 | } |
| 1564 | 1571 | ||
| @@ -2270,7 +2277,7 @@ emit_limple_insn (Lisp_Object insn) | |||
| 2270 | gcc_jit_lvalue_as_rvalue ( | 2277 | gcc_jit_lvalue_as_rvalue ( |
| 2271 | gcc_jit_context_new_array_access (comp.ctxt, | 2278 | gcc_jit_context_new_array_access (comp.ctxt, |
| 2272 | NULL, | 2279 | NULL, |
| 2273 | reloc.array, | 2280 | reloc.array.r_val, |
| 2274 | reloc.idx))); | 2281 | reloc.idx))); |
| 2275 | } | 2282 | } |
| 2276 | else if (EQ (op, Qcomment)) | 2283 | else if (EQ (op, Qcomment)) |
| @@ -2608,18 +2615,19 @@ emit_static_object (const char *name, Lisp_Object obj) | |||
| 2608 | } | 2615 | } |
| 2609 | #pragma GCC diagnostic pop | 2616 | #pragma GCC diagnostic pop |
| 2610 | 2617 | ||
| 2611 | static gcc_jit_rvalue * | 2618 | static reloc_array_t |
| 2612 | declare_imported_data_relocs (Lisp_Object container, const char *code_symbol, | 2619 | declare_imported_data_relocs (Lisp_Object container, const char *code_symbol, |
| 2613 | const char *text_symbol) | 2620 | const char *text_symbol) |
| 2614 | { | 2621 | { |
| 2615 | /* Imported objects. */ | 2622 | /* Imported objects. */ |
| 2616 | EMACS_INT d_reloc_len = | 2623 | reloc_array_t res; |
| 2624 | res.len = | ||
| 2617 | XFIXNUM (CALL1I (hash-table-count, | 2625 | XFIXNUM (CALL1I (hash-table-count, |
| 2618 | CALL1I (comp-data-container-idx, container))); | 2626 | CALL1I (comp-data-container-idx, container))); |
| 2619 | Lisp_Object d_reloc = CALL1I (comp-data-container-l, container); | 2627 | Lisp_Object d_reloc = CALL1I (comp-data-container-l, container); |
| 2620 | d_reloc = Fvconcat (1, &d_reloc); | 2628 | d_reloc = Fvconcat (1, &d_reloc); |
| 2621 | 2629 | ||
| 2622 | gcc_jit_rvalue *reloc_struct = | 2630 | res.r_val = |
| 2623 | gcc_jit_lvalue_as_rvalue ( | 2631 | gcc_jit_lvalue_as_rvalue ( |
| 2624 | gcc_jit_context_new_global ( | 2632 | gcc_jit_context_new_global ( |
| 2625 | comp.ctxt, | 2633 | comp.ctxt, |
| @@ -2628,12 +2636,12 @@ declare_imported_data_relocs (Lisp_Object container, const char *code_symbol, | |||
| 2628 | gcc_jit_context_new_array_type (comp.ctxt, | 2636 | gcc_jit_context_new_array_type (comp.ctxt, |
| 2629 | NULL, | 2637 | NULL, |
| 2630 | comp.lisp_obj_type, | 2638 | comp.lisp_obj_type, |
| 2631 | d_reloc_len), | 2639 | res.len), |
| 2632 | code_symbol)); | 2640 | code_symbol)); |
| 2633 | 2641 | ||
| 2634 | emit_static_object (text_symbol, d_reloc); | 2642 | emit_static_object (text_symbol, d_reloc); |
| 2635 | 2643 | ||
| 2636 | return reloc_struct; | 2644 | return res; |
| 2637 | } | 2645 | } |
| 2638 | 2646 | ||
| 2639 | static void | 2647 | static void |