jit: Add checking for dereference of void *
[official-gcc.git] / gcc / jit / notes.txt
blob26f381e4177aec31ff3809dd898d2fe39313e7c1
1 Client Code   . Generated .            libgccjit.so
2               . code      .
3               .           . JIT API  . JIT "Frontend". (libbackend.a)
4 ....................................................................................
5    │          .           .          .               .
6     ──────────────────────────>      .               .
7               .           .    │     .               .
8               .           .    V     .               .
9               .           .    ──> libgccjit.c       .
10               .           .        │ (error-checking).
11               .           .        │                 .
12               .           .        ──> jit-recording.c
13               .           .              (record API calls)
14               .           .    <───────              .
15               .           .    │     .               .
16    <───────────────────────────      .               .
17    │          .           .          .               .
18    │          .           .          .               .
19    V          .           .  gcc_jit_context_compile .
20     ──────────────────────────>      .               .
21               .           .    │ start of recording::context::compile ()
22               .           .    │     .               .
23               .           .    │ start of playback::context::compile ()
24               .           .    │   (create tempdir)  .
25               .           .    │     .               .
26               .           .    │ ACQUIRE MUTEX       .
27               .           .    │     .               .
28               .           .    V───────────────────────> toplev::main (for now)
29               .           .          .               .       │
30               .           .          .               .   (various code)
31               .           .          .               .       │
32               .           .          .               .       V
33               .           .          .    <───────────────── langhook:parse_file
34               .           .          .    │          .
35               .           .          .    │ (jit_langhook_parse_file)
36               .           .          .    │          .
37 ..........................................│..................VVVVVVVVVVVVV...
38               .           .          .    │          .       No GC in here
39               .           .          .    │ jit-playback.c
40               .           .          .    │   (playback of API calls)
41               .           .          .    ───────────────> creation of functions,
42               .           .          .               .     types, expression trees
43               .           .          .    <──────────────── etc
44               .           .          .    │(handle_locations: add locations to
45               .           .          .    │ linemap and associate them with trees)
46               .           .          .    │          .
47               .           .          .    │          .       No GC in here
48 ..........................................│..................AAAAAAAAAAAAA...
49               .           .          .    │ for each function
50               .           .          .    ──> postprocess
51               .           .          .        │      .
52               .           .          .        ────────────> cgraph_finalize_function
53               .           .          .        <────────────
54               .           .          .     <──       .
55               .           .          .    │          .
56               .           .          .    ──────────────────> (end of
57               .           .          .               .       │ langhook_parse_file)
58               .           .          .               .       │
59               .           .          .               .   (various code)
60               .           .          .               .       │
61               .           .          .               .       ↓
62               .           .          .    <───────────────── langhook:write_globals
63               .           .          .    │          .
64               .           .          .    │ (jit_langhook_write_globals)
65               .           .          .    │          .
66               .           .          .    │          .
67               .           .          .    ──────────────────> finalize_compilation_unit
68               .           .          .               .       │
69               .           .          .               .   (the middle─end and backend)
70               .           .          .               .       ↓
71               .           .    <───────────────────────────── end of toplev::main
72               .           .    │     .               .
73               .           .    V───────────────────────> toplev::finalize
74               .           .          .               . │   (purge internal state)
75               .           .    <──────────────────────── end of toplev::finalize
76               .           .    │     .               .
77               .           .    │ Convert assembler to DSO ("fake.so")
78               .           .    │     .               .
79               .           .    │ Load DSO (dlopen "fake.so")
80               .           .    │     .               .
81               .           .    │ RELEASE MUTEX       .
82               .           .    │     .               .
83               .           .    │ end of playback::context::compile ()
84               .           .    │     .               .
85               .           .    │ playback::context dtor
86               .           .     ──>  .               .
87               .           .       │ Cleanup tempdir  .
88               .           .       │   ("fake.so" is unlinked from the
89               .           .       │    filesystem at this point)
90               .           .    <──   .               .
91               .           .    │     .               .
92               .           .    │ end of recording::context::compile ()
93    <───────────────────────────      .               .
94    │          .           .          .               .
95    V          .           .  gcc_jit_result_get_code .
96     ──────────────────────────>      .               .
97               .           .    │ dlsym () within loaded DSO
98    <───────────────────────────      .               .
99    Get (void*).           .          .               .
100    │          .           .          .               .
101    │ Call it  .           .          .               .
102    ───────────────>       .          .               .
103               .    │      .          .               .
104               .    │      .          .               .
105    <───────────────       .          .               .
106    │          .           .          .               .
107 etc│          .           .          .               .
108    │          .           .          .               .
109    V          .           .  gcc_jit_result_release  .
110     ──────────────────────────>      .               .
111               .           .    │ dlclose () the loaded DSO
112               .           .    │    (code becomes uncallable)
113    <───────────────────────────      .               .
114    │          .           .          .               .