You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2024-10-14-out-of-process-execution-for-clangrepl_gsoc_final_blog.md
+20-33Lines changed: 20 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -20,18 +20,12 @@ Mentors: Vassil Vassilev and Matheus Izvekov
20
20
21
21
### **Project Overview**
22
22
23
-
**Clang** is a widely-used compiler front-end within the **LLVM** project, capable of
24
-
compiling languages like C++. A powerful tool, **Clang-Repl**, acts as an interactive
25
-
C++ interpreter using **Just-In-Time (JIT)** compilation. It allows users to write
26
-
compile, and execute C++ code interactively, making it an invaluable resource for
27
-
learning, prototyping, and debugging.
23
+
**Clang** is a popular compiler front-end in the **LLVM** project, capable of handling languages like C++. One of its cool tools, **Clang-Repl**, is an interactive C++ interpreter using **Just-In-Time (JIT)** compilation. It lets you write, compile, and run C++ code interactively, making it super handy for learning, quick prototyping, and debugging.
28
24
29
-
Despite its benefits, Clang-Repl had certain limitations:
25
+
However, Clang-Repl did have a few drawbacks:
30
26
31
-
1.**High Resource Usage**: Running the Clang-Repl environment and JIT in the same
32
-
process consumed a lot of system resources.
33
-
2.**Instability**: If the user's code crashed, it would terminate the entire
34
-
Clang-Repl session, causing disruptions.
27
+
1.**High Resource Usage**: Running both Clang-Repl and JIT in the same process used up a lot of system resources.
28
+
2.**Instability**: If the user's code crashed, the entire Clang-Repl session would shut down, leading to interruptions.
35
29
36
30
### **Out-Of-Process Execution**
37
31
@@ -71,48 +65,41 @@ To support Clang-Repl’s out-of-process execution, I contributed several improv
71
65
72
66
#### **Incremental Initializer Execution for Mach-O and ELF**[#97441](https://github.com/llvm/llvm-project/pull/97441), [#110406](https://github.com/llvm/llvm-project/pull/110406)
73
67
74
-
The `dlupdate` function was introduced in the ORC runtime to enable the incremental
75
-
execution of newly added initializers within the REPL environment. Unlike the
76
-
traditional `dlopen` function, which handles initializers, code mapping, and library
77
-
reference counts, `dlupdate` is focused solely on executing new initializers,
78
-
ensuring that only the newly introduced sections are processed. This targeted
79
-
approach improves efficiency, especially in interactive REPL sessions like `clang-repl`.
68
+
The `dlupdate` function was added to the ORC runtime to allow for the incremental execution of new initializers in the REPL environment. Unlike the traditional `dlopen` function, which deals with everything from handling initializers to code mapping and library reference counts, `dlupdate` is all about running just the new initializers. This focused approach makes things way more efficient, especially during interactive sessions in `clang-repl`.
80
69
81
70
#### **Push-Request Model for ELF Initializers**[#102846](https://github.com/llvm/llvm-project/pull/102846)
82
71
83
-
I introduced a push-request model to manage ELF initializers within the runtime
84
-
state for each JITDylib, similar to how Mach-O and COFF handle initializers.
85
-
Previously, ELF had to request initializers every time it needed them, but
72
+
I introduced a push-request model to handle ELF initializers in the runtime state for each JITDylib, similar to how Mach-O and COFF handle initializers.
73
+
Previously, ELF had to request initializers every time `dlopen` was called, but
86
74
lacked the ability to `register`, `deregister`, or `retain` these initializers.
87
75
This led to issues when re-running `dlopen` because, once `rt_getInitializers`
88
76
was invoked, the initializers were erased, making subsequent executions impossible.
89
77
90
78
To address this, I introduced the following functions:
-**`__orc_rt_elfnix_register_init_sections`**: Registers the ELF initializer's for the JITDylib.
94
81
95
-
The push-request model effectively tracks and manages initializers for each
96
-
`JITDylib` state. By utilizing Mach-O’s `RecordSectionsTracker`, the system selectively executes only newly
97
-
registered initializers, thereby enhancing both efficiency and reliability
98
-
when working with ELF targets in `clang-repl`.
82
+
-**`__orc_rt_elfnix_register_jitdylib`**: Registers the JITDylib with the ELF runtime state.
83
+
84
+
With this push-request model, we can better track and manage initializers for each `JITDylib` state. By leveraging Mach-O’s `RecordSectionsTracker`, we only run newly registered initializers, making the system more efficient and reliable when working with ELF targets in `clang-repl`.
85
+
86
+
This update is key to enabling out-of-process execution in `clang-repl` on the ELF platform.
99
87
100
88
---
101
89
102
90
### **Additional Improvements**
103
91
104
92
#### **Auto-loading Dynamic Libraries in ORC JIT**[#109913](https://github.com/llvm/llvm-project/pull/109913) (On-going)
105
93
106
-
I added an auto-loading dynamic library feature for ORC JIT, aimed at
107
-
enhancing the efficiency of symbol resolution for both loaded and unloaded
108
-
libraries. A key component of this improvement is the global bloom filter,
109
-
which filters out symbols unlikely to be present, thereby reducing unnecessary
110
-
search attempts and speeding up lookups.
94
+
I added an auto-loading dynamic library feature to ORC JIT to speed up symbol resolution for both loaded and unloaded libraries. A key improvement is the global bloom filter, which helps skip symbols that probably aren’t there, reducing unnecessary searches and making things faster. With this update, if the JIT can't find a symbol in the loaded libraries, it will automatically search other libraries for the definition.
95
+
96
+
So, here’s how it works: when the JIT tries to resolve a symbol, it first checks the currently loaded libraries. If it finds the symbol there, it simply grabs its address using dlsym and stores it in the results. If the symbol isn’t found among the loaded libraries, the search expands to unloaded ones.
97
+
98
+
As we scan through each library, its symbol table gets added to the global bloom filter. If we go through all the possible auto-linkable libraries and still can’t find the symbol, the bloom filter gets returned as part of the result. Plus, we keep track of any symbols that the bloom filter marks as 'may-contain' but don’t actually resolve in any library, adding those to an excluded set.
0 commit comments