Skip to content

Commit c8166cb

Browse files
committed
Refine descriptions and enhance clarity
1 parent e9af091 commit c8166cb

File tree

1 file changed

+20
-33
lines changed

1 file changed

+20
-33
lines changed

_posts/2024-10-14-out-of-process-execution-for-clangrepl_gsoc_final_blog.md

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,12 @@ Mentors: Vassil Vassilev and Matheus Izvekov
2020

2121
### **Project Overview**
2222

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.
2824

29-
Despite its benefits, Clang-Repl had certain limitations:
25+
However, Clang-Repl did have a few drawbacks:
3026

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.
3529

3630
### **Out-Of-Process Execution**
3731

@@ -71,48 +65,41 @@ To support Clang-Repl’s out-of-process execution, I contributed several improv
7165

7266
#### **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)
7367

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`.
8069

8170
#### **Push-Request Model for ELF Initializers** [#102846](https://github.com/llvm/llvm-project/pull/102846)
8271

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
8674
lacked the ability to `register`, `deregister`, or `retain` these initializers.
8775
This led to issues when re-running `dlopen` because, once `rt_getInitializers`
8876
was invoked, the initializers were erased, making subsequent executions impossible.
8977

9078
To address this, I introduced the following functions:
9179

92-
- **`__orc_rt_elfnix_register_init_sections`**: Registers ELF initializer sections.
93-
- **`__orc_rt_elfnix_register_jitdylib`**: Registers JITDylib-specific initializers.
80+
- **`__orc_rt_elfnix_register_init_sections`**: Registers the ELF initializer's for the JITDylib.
9481

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.
9987

10088
---
10189

10290
### **Additional Improvements**
10391

10492
#### **Auto-loading Dynamic Libraries in ORC JIT** [#109913](https://github.com/llvm/llvm-project/pull/109913) (On-going)
10593

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.
11199

112100
#### **Refactor `dlupdate`** [#110491](https://github.com/llvm/llvm-project/pull/110491)
113101

114-
I refactored the `dlupdate` function to remove the mode argument, simplifying the
115-
function's interface.
102+
This change refactors the `dlupdate` function by removing the `mode` argument simplifying the function's interface.
116103

117104
---
118105

@@ -127,7 +114,7 @@ function's interface.
127114

128115
### **Result**
129116

130-
With these changes, `clang-repl` now supports out-of-process execution. You can run it using the following command:
117+
With these changes, `clang-repl` now supports out-of-process execution. We can run it using the following command:
131118

132119
```bash
133120
clang-repl --oop-executor=path/to/llvm-jitlink-executor --orc-runtime=path/to/liborc_rt.a

0 commit comments

Comments
 (0)