Commit 8e39bff

Browse files
authored
Merge pull request #4697 from michaliskok/genmc-llvm-dep
genmc: Build without LLVM; adjust to API changes
2 parents 5bb385d + 26bd441 commit 8e39bff

8 files changed

Lines changed: 53 additions & 80 deletions

File tree

‎src/tools/miri/genmc-sys/build.rs‎

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mod downloading {
2828
/// The GenMC repository the we get our commit from.
2929
pub(crate)constGENMC_GITHUB_URL:&str = "https://github.com/MPI-SWS/genmc.git";
3030
/// The GenMC commit we depend on. It must be available on the specified GenMC repository.
31-
pub(crate)constGENMC_COMMIT:&str = "d9527280bb99f1cef64326b1803ffd952e3880df";
31+
pub(crate)constGENMC_COMMIT:&str = "aa10ed65117c3291524efc19253b5d443a4602ac";
3232

3333
/// Ensure that a local GenMC repo is present and set to the correct commit.
3434
/// Return the path of the GenMC repo and whether the checked out commit was changed.
@@ -140,51 +140,6 @@ mod downloading {
140140
}
141141
}
142142

143-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
144-
/// The linked LLVM version is in the generated `config.h`` file, which we parse and use to link to LLVM.
145-
/// Returns c++ compiler definitions required for building with/including LLVM, and the include path for LLVM headers.
146-
fnlink_to_llvm(config_file:&Path) -> (String,String){
147-
/// Search a string for a line matching `//@VARIABLE_NAME: VARIABLE CONTENT`
148-
fnextract_value<'a>(input:&'astr,name:&str) -> Option<&'astr>{
149-
input
150-
.lines()
151-
.find_map(|line| line.strip_prefix("//@")?.strip_prefix(name)?.strip_prefix(": "))
152-
}
153-
154-
let file_content = std::fs::read_to_string(&config_file).unwrap_or_else(|err| {
155-
panic!("GenMC config file ({}) should exist, but got errror {err:?}", config_file.display())
156-
});
157-
158-
let llvm_definitions = extract_value(&file_content,"LLVM_DEFINITIONS")
159-
.expect("Config file should contain LLVM_DEFINITIONS");
160-
let llvm_include_dirs = extract_value(&file_content,"LLVM_INCLUDE_DIRS")
161-
.expect("Config file should contain LLVM_INCLUDE_DIRS");
162-
let llvm_library_dir = extract_value(&file_content,"LLVM_LIBRARY_DIR")
163-
.expect("Config file should contain LLVM_LIBRARY_DIR");
164-
let llvm_config_path = extract_value(&file_content,"LLVM_CONFIG_PATH")
165-
.expect("Config file should contain LLVM_CONFIG_PATH");
166-
167-
// Add linker search path.
168-
let lib_dir = PathBuf::from_str(llvm_library_dir).unwrap();
169-
println!("cargo::rustc-link-search=native={}", lib_dir.display());
170-
171-
// Add libraries to link.
172-
let output = std::process::Command::new(llvm_config_path)
173-
.arg("--libs")// Print the libraries to link to (space-separated list)
174-
.output()
175-
.expect("failed to execute llvm-config");
176-
let llvm_link_libs =
177-
String::try_from(output.stdout).expect("llvm-config output should be a valid string");
178-
179-
for link_lib in llvm_link_libs.trim().split(" "){
180-
let link_lib =
181-
link_lib.strip_prefix("-l").expect("Linker parameter should start with \"-l\"");
182-
println!("cargo::rustc-link-lib=dylib={link_lib}");
183-
}
184-
185-
(llvm_definitions.to_string(), llvm_include_dirs.to_string())
186-
}
187-
188143
/// Build the GenMC model checker library and the Rust-C++ interop library with cxx.rs
189144
fncompile_cpp_dependencies(genmc_path:&Path,always_configure:bool){
190145
// Give each step a separate build directory to prevent interference.
@@ -204,6 +159,7 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
204159
.always_configure(always_configure)// We force running the configure step when the GenMC commit changed.
205160
.out_dir(genmc_build_dir)
206161
.profile(GENMC_CMAKE_PROFILE)
162+
.define("BUILD_LLI","OFF")
207163
.define("GENMC_DEBUG",if enable_genmc_debug {"ON"}else{"OFF"});
208164

209165
// The actual compilation happens here:
@@ -214,19 +170,11 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
214170
println!("cargo::rustc-link-search=native={}", cmake_lib_dir.display());
215171
println!("cargo::rustc-link-lib=static={GENMC_MODEL_CHECKER}");
216172

217-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
218-
let config_file = genmc_install_dir.join("include").join("genmc").join("config.h");
219-
let(llvm_definitions, llvm_include_dirs) = link_to_llvm(&config_file);
220-
221173
// Part 2:
222174
// Compile the cxx_bridge (the link between the Rust and C++ code).
223175

224176
let genmc_include_dir = genmc_install_dir.join("include").join("genmc");
225177

226-
// FIXME(genmc,llvm): remove once LLVM dependency is removed.
227-
// These definitions are parsed into a cmake list and then printed to the config.h file, so they are ';' separated.
228-
let definitions = llvm_definitions.split(";");
229-
230178
// These are all the C++ files we need to compile, which needs to be updated if more C++ files are added to Miri.
231179
// We use absolute paths since relative paths can confuse IDEs when attempting to go-to-source on a path in a compiler error.
232180
let cpp_files_base_path = Path::new("cpp/src/");
@@ -244,16 +192,12 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
244192
if enable_genmc_debug {
245193
bridge.define("ENABLE_GENMC_DEBUG",None);
246194
}
247-
for definition in definitions {
248-
bridge.flag(definition);
249-
}
250195
bridge
251196
.opt_level(2)
252197
.debug(true)// Same settings that GenMC uses (default for cmake `RelWithDebInfo`)
253198
.warnings(false)// NOTE: enabling this produces a lot of warnings.
254199
.std("c++23")
255200
.include(genmc_include_dir)
256-
.include(llvm_include_dirs)
257201
.include("./cpp/include")
258202
.files(&cpp_files)
259203
.out_dir(interface_build_dir)

‎src/tools/miri/genmc-sys/cpp/include/MiriInterface.hpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ struct MiriGenmcShim : private GenMCDriver {
220220
autohandle_load_reset_if_none(ThreadId tid, std::optional<SVal> old_val, Ts&&... params)
221221
-> HandleResult<SVal> {
222222
constauto pos = inc_pos(tid);
223-
constauto ret = GenMCDriver::handleLoad<k>(pos, old_val, std::forward<Ts>(params)...);
223+
constauto ret =
224+
GenMCDriver::handleLoad<k>(nullptr, pos, old_val, std::forward<Ts>(params)...);
224225
// If we didn't get a value, we have to reset the index of the current thread.
225226
if (!std::holds_alternative<SVal>(ret)) {
226227
dec_pos(tid);

‎src/tools/miri/genmc-sys/cpp/include/ResultHandling.hpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
// GenMC headers:
88
#include"Verification/VerificationError.hpp"
99

10+
#include<format>
11+
#include<memory>
12+
#include<sstream>
1013
#include<string>
1114

1215
/** Information about an error, formatted as a string to avoid having to share an error enum and
1316
* printing functionality with the Rust side. */
1417
staticautoformat_error(VerificationError err) -> std::unique_ptr<std::string> {
15-
auto buf = std::string();
16-
auto s = llvm::raw_string_ostream(buf);
17-
s << err;
18+
std::stringstream s;
19+
s << std::format("{}", err);
1820
return std::make_unique<std::string>(s.str());
1921
}
2022

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/EventHandling.cpp‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
voidMiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_type) {
3636
BUG_ON(getExec().getGraph().isThreadBlocked(thread_id));
37-
GenMCDriver::handleAssume(inc_pos(thread_id), assume_type);
37+
GenMCDriver::handleAssume(nullptr, inc_pos(thread_id), assume_type);
3838
}
3939

4040
/**** Memory access handling ****/
@@ -76,6 +76,7 @@ void MiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_ty
7676
) -> StoreResult {
7777
constauto pos = inc_pos(thread_id);
7878
constauto ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::Write>(
79+
nullptr,
7980
pos,
8081
GenmcScalarExt::try_to_sval(old_val),
8182
ord,
@@ -100,7 +101,7 @@ void MiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_ty
100101

101102
voidMiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
102103
constauto pos = inc_pos(thread_id);
103-
GenMCDriver::handleFence(pos, ord, EventDeps());
104+
GenMCDriver::handleFence(nullptr, pos, ord, EventDeps());
104105
}
105106

106107
[[nodiscard]]autoMiriGenmcShim::handle_read_modify_write(
@@ -143,6 +144,7 @@ void MiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
143144

144145
constauto storePos = inc_pos(thread_id);
145146
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::FaiWrite>(
147+
nullptr,
146148
storePos,
147149
GenmcScalarExt::try_to_sval(old_val),
148150
ordering,
@@ -210,6 +212,7 @@ void MiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
210212

211213
constauto storePos = inc_pos(thread_id);
212214
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::CasWrite>(
215+
nullptr,
213216
storePos,
214217
GenmcScalarExt::try_to_sval(old_val),
215218
success_ordering,
@@ -242,6 +245,7 @@ auto MiriGenmcShim::handle_malloc(ThreadId thread_id, uint64_t size, uint64_t al
242245
constauto address_space = AddressSpace::AS_User;
243246

244247
const SVal ret_val = GenMCDriver::handleMalloc(
248+
nullptr,
245249
pos,
246250
size,
247251
alignment,
@@ -255,7 +259,7 @@ auto MiriGenmcShim::handle_malloc(ThreadId thread_id, uint64_t size, uint64_t al
255259

256260
autoMiriGenmcShim::handle_free(ThreadId thread_id, uint64_t address) -> bool {
257261
constauto pos = inc_pos(thread_id);
258-
GenMCDriver::handleFree(pos, SAddr(address), EventDeps());
262+
GenMCDriver::handleFree(nullptr, pos, SAddr(address), EventDeps());
259263
// FIXME(genmc): use returned error from `handleFree` once implemented in GenMC.
260264
returngetResult().status.has_value();
261265
}

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Exploration.cpp‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,23 @@ auto MiriGenmcShim::schedule_next(
2222
// a scheduling decision.
2323
threads_action_[curr_thread_id].kind = curr_thread_next_instr_kind;
2424

25-
if (constauto result = GenMCDriver::scheduleNext(threads_action_))
26-
return SchedulingResult { ExecutionState::Ok, static_cast<int32_t>(result.value()) };
27-
if (getExec().getGraph().isBlocked())
28-
return SchedulingResult { ExecutionState::Blocked, 0 };
29-
if (getResult().status.has_value()) // the "value" here is a `VerificationError`
30-
return SchedulingResult { ExecutionState::Error, 0 };
31-
return SchedulingResult { ExecutionState::Finished, 0 };
25+
auto result = GenMCDriver::scheduleNext(threads_action_);
26+
returnstd::visit(
27+
[](auto&& arg) {
28+
using T = std::decay_t<decltype(arg)>;
29+
ifconstexpr (std::is_same_v<T, int>)
30+
return SchedulingResult { ExecutionState::Ok, static_cast<int32_t>(arg) };
31+
elseifconstexpr (std::is_same_v<T, Blocked>)
32+
return SchedulingResult { ExecutionState::Blocked, 0 };
33+
elseifconstexpr (std::is_same_v<T, Error>)
34+
return SchedulingResult { ExecutionState::Error, 0 };
35+
elseifconstexpr (std::is_same_v<T, Finished>)
36+
return SchedulingResult { ExecutionState::Finished, 0 };
37+
else
38+
static_assert(false, "non-exhaustive visitor!");
39+
},
40+
result
41+
);
3242
}
3343

3444
/**** Execution start/end handling ****/

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Mutex.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ auto MiriGenmcShim::handle_mutex_lock(ThreadId thread_id, uint64_t address, uint
6060
constbool is_lock_acquired = *ret_val == MUTEX_UNLOCKED;
6161
if (is_lock_acquired) {
6262
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::LockCasWrite>(
63+
nullptr,
6364
inc_pos(thread_id),
6465
old_val,
6566
address,
@@ -93,6 +94,7 @@ auto MiriGenmcShim::handle_mutex_try_lock(ThreadId thread_id, uint64_t address,
9394
// a mutex to be "unlocked".
9495
constauto old_val = MUTEX_UNLOCKED;
9596
constauto load_ret = GenMCDriver::handleLoad<EventLabel::EventLabelKind::TrylockCasRead>(
97+
nullptr,
9698
++currPos,
9799
old_val,
98100
SAddr(address),
@@ -115,6 +117,7 @@ auto MiriGenmcShim::handle_mutex_try_lock(ThreadId thread_id, uint64_t address,
115117
}
116118

117119
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::TrylockCasWrite>(
120+
nullptr,
118121
++currPos,
119122
old_val,
120123
SAddr(address),
@@ -136,6 +139,7 @@ auto MiriGenmcShim::handle_mutex_unlock(ThreadId thread_id, uint64_t address, ui
136139
-> StoreResult {
137140
constauto pos = inc_pos(thread_id);
138141
constauto ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::UnlockWrite>(
142+
nullptr,
139143
pos,
140144
// As usual, we need to tell GenMC which value was stored at this location before this
141145
// atomic access, if there previously was a non-atomic initializing access. We set the

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Setup.cpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,16 @@ static auto to_genmc_verbosity_level(const LogLevel log_level) -> VerbosityLevel
147147
// that is allowed to leak and memory that is not.
148148
conf->warnUnfreedMemory = false;
149149

150-
// FIXME(genmc,error handling): This function currently exits on error, but will return an
151-
// error value in the future. The return value should be checked once this change is made.
152-
checkConfig(*conf);
150+
// Validate the config and exit if there are any errors
151+
std::vector<std::string> warnings;
152+
auto config_valid = conf->validate(warnings);
153+
for (constauto& w : warnings)
154+
WARN("{}", w);
155+
if (auto* errors = std::get_if<ConfigErrorList>(&config_valid); errors) {
156+
for (constauto& e : *errors)
157+
LOG(VerbosityLevel::Error, "{}", e);
158+
exit(EUSER);
159+
}
153160

154161
// Create the actual driver and Miri-GenMC communication shim.
155162
auto driver = std::make_unique<MiriGenmcShim>(std::move(conf), mode);

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/ThreadManagement.cpp‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ void MiriGenmcShim::handle_thread_create(ThreadId thread_id, ThreadId parent_id)
1919
// FIXME(genmc): for supporting symmetry reduction, these will need to be properly set:
2020
constunsigned fun_id = 0;
2121
const SVal arg = SVal(0);
22-
const ThreadInfo child_info = ThreadInfo { thread_id, parent_id, fun_id, arg };
22+
const ThreadInfo child_info =
23+
ThreadInfo { thread_id, parent_id, fun_id, arg, "unknown thread" };
2324

2425
// NOTE: Default memory ordering (`Release`) used here.
25-
constauto child_tid = GenMCDriver::handleThreadCreate(pos, child_info, EventDeps());
26+
constauto child_tid = GenMCDriver::handleThreadCreate(nullptr, pos, child_info, EventDeps());
2627
// Sanity check the thread id, which is the index in the `threads_action_` array.
2728
BUG_ON(child_tid != thread_id || child_tid <= 0 || child_tid != threads_action_.size());
2829
threads_action_.push_back(Action(ActionKind::Load, Event(child_tid, 0)));
@@ -33,7 +34,7 @@ void MiriGenmcShim::handle_thread_join(ThreadId thread_id, ThreadId child_id) {
3334
constauto pos = inc_pos(thread_id);
3435

3536
// NOTE: Default memory ordering (`Acquire`) used here.
36-
constauto ret = GenMCDriver::handleThreadJoin(pos, child_id, EventDeps());
37+
constauto ret = GenMCDriver::handleThreadJoin(nullptr, pos, child_id, EventDeps());
3738
// If the join failed, decrease the event index again:
3839
if (!std::holds_alternative<SVal>(ret)) {
3940
dec_pos(thread_id);
@@ -46,10 +47,10 @@ void MiriGenmcShim::handle_thread_join(ThreadId thread_id, ThreadId child_id) {
4647
voidMiriGenmcShim::handle_thread_finish(ThreadId thread_id, uint64_t ret_val) {
4748
constauto pos = inc_pos(thread_id);
4849
// NOTE: Default memory ordering (`Release`) used here.
49-
GenMCDriver::handleThreadFinish(pos, SVal(ret_val));
50+
GenMCDriver::handleThreadFinish(nullptr, pos, SVal(ret_val));
5051
}
5152

5253
voidMiriGenmcShim::handle_thread_kill(ThreadId thread_id) {
5354
constauto pos = inc_pos(thread_id);
54-
GenMCDriver::handleThreadKill(pos);
55+
GenMCDriver::handleThreadKill(nullptr, pos);
5556
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Commit 8e39bff

Browse files
authored
Merge pull request #4697 from michaliskok/genmc-llvm-dep
genmc: Build without LLVM; adjust to API changes
2 parents 5bb385d + 26bd441 commit 8e39bff

8 files changed

Lines changed: 53 additions & 80 deletions

File tree

‎src/tools/miri/genmc-sys/build.rs‎

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mod downloading {
2828
/// The GenMC repository the we get our commit from.
2929
pub(crate)constGENMC_GITHUB_URL:&str = "https://github.com/MPI-SWS/genmc.git";
3030
/// The GenMC commit we depend on. It must be available on the specified GenMC repository.
31-
pub(crate)constGENMC_COMMIT:&str = "d9527280bb99f1cef64326b1803ffd952e3880df";
31+
pub(crate)constGENMC_COMMIT:&str = "aa10ed65117c3291524efc19253b5d443a4602ac";
3232

3333
/// Ensure that a local GenMC repo is present and set to the correct commit.
3434
/// Return the path of the GenMC repo and whether the checked out commit was changed.
@@ -140,51 +140,6 @@ mod downloading {
140140
}
141141
}
142142

143-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
144-
/// The linked LLVM version is in the generated `config.h`` file, which we parse and use to link to LLVM.
145-
/// Returns c++ compiler definitions required for building with/including LLVM, and the include path for LLVM headers.
146-
fnlink_to_llvm(config_file:&Path) -> (String,String){
147-
/// Search a string for a line matching `//@VARIABLE_NAME: VARIABLE CONTENT`
148-
fnextract_value<'a>(input:&'astr,name:&str) -> Option<&'astr>{
149-
input
150-
.lines()
151-
.find_map(|line| line.strip_prefix("//@")?.strip_prefix(name)?.strip_prefix(": "))
152-
}
153-
154-
let file_content = std::fs::read_to_string(&config_file).unwrap_or_else(|err| {
155-
panic!("GenMC config file ({}) should exist, but got errror {err:?}", config_file.display())
156-
});
157-
158-
let llvm_definitions = extract_value(&file_content,"LLVM_DEFINITIONS")
159-
.expect("Config file should contain LLVM_DEFINITIONS");
160-
let llvm_include_dirs = extract_value(&file_content,"LLVM_INCLUDE_DIRS")
161-
.expect("Config file should contain LLVM_INCLUDE_DIRS");
162-
let llvm_library_dir = extract_value(&file_content,"LLVM_LIBRARY_DIR")
163-
.expect("Config file should contain LLVM_LIBRARY_DIR");
164-
let llvm_config_path = extract_value(&file_content,"LLVM_CONFIG_PATH")
165-
.expect("Config file should contain LLVM_CONFIG_PATH");
166-
167-
// Add linker search path.
168-
let lib_dir = PathBuf::from_str(llvm_library_dir).unwrap();
169-
println!("cargo::rustc-link-search=native={}", lib_dir.display());
170-
171-
// Add libraries to link.
172-
let output = std::process::Command::new(llvm_config_path)
173-
.arg("--libs")// Print the libraries to link to (space-separated list)
174-
.output()
175-
.expect("failed to execute llvm-config");
176-
let llvm_link_libs =
177-
String::try_from(output.stdout).expect("llvm-config output should be a valid string");
178-
179-
for link_lib in llvm_link_libs.trim().split(" "){
180-
let link_lib =
181-
link_lib.strip_prefix("-l").expect("Linker parameter should start with \"-l\"");
182-
println!("cargo::rustc-link-lib=dylib={link_lib}");
183-
}
184-
185-
(llvm_definitions.to_string(), llvm_include_dirs.to_string())
186-
}
187-
188143
/// Build the GenMC model checker library and the Rust-C++ interop library with cxx.rs
189144
fncompile_cpp_dependencies(genmc_path:&Path,always_configure:bool){
190145
// Give each step a separate build directory to prevent interference.
@@ -204,6 +159,7 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
204159
.always_configure(always_configure)// We force running the configure step when the GenMC commit changed.
205160
.out_dir(genmc_build_dir)
206161
.profile(GENMC_CMAKE_PROFILE)
162+
.define("BUILD_LLI","OFF")
207163
.define("GENMC_DEBUG",if enable_genmc_debug {"ON"}else{"OFF"});
208164

209165
// The actual compilation happens here:
@@ -214,19 +170,11 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
214170
println!("cargo::rustc-link-search=native={}", cmake_lib_dir.display());
215171
println!("cargo::rustc-link-lib=static={GENMC_MODEL_CHECKER}");
216172

217-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
218-
let config_file = genmc_install_dir.join("include").join("genmc").join("config.h");
219-
let(llvm_definitions, llvm_include_dirs) = link_to_llvm(&config_file);
220-
221173
// Part 2:
222174
// Compile the cxx_bridge (the link between the Rust and C++ code).
223175

224176
let genmc_include_dir = genmc_install_dir.join("include").join("genmc");
225177

226-
// FIXME(genmc,llvm): remove once LLVM dependency is removed.
227-
// These definitions are parsed into a cmake list and then printed to the config.h file, so they are ';' separated.
228-
let definitions = llvm_definitions.split(";");
229-
230178
// These are all the C++ files we need to compile, which needs to be updated if more C++ files are added to Miri.
231179
// We use absolute paths since relative paths can confuse IDEs when attempting to go-to-source on a path in a compiler error.
232180
let cpp_files_base_path = Path::new("cpp/src/");
@@ -244,16 +192,12 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
244192
if enable_genmc_debug {
245193
bridge.define("ENABLE_GENMC_DEBUG",None);
246194
}
247-
for definition in definitions {
248-
bridge.flag(definition);
249-
}
250195
bridge
251196
.opt_level(2)
252197
.debug(true)// Same settings that GenMC uses (default for cmake `RelWithDebInfo`)
253198
.warnings(false)// NOTE: enabling this produces a lot of warnings.
254199
.std("c++23")
255200
.include(genmc_include_dir)
256-
.include(llvm_include_dirs)
257201
.include("./cpp/include")
258202
.files(&cpp_files)
259203
.out_dir(interface_build_dir)

‎src/tools/miri/genmc-sys/cpp/include/MiriInterface.hpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ struct MiriGenmcShim : private GenMCDriver {
220220
autohandle_load_reset_if_none(ThreadId tid, std::optional<SVal> old_val, Ts&&... params)
221221
-> HandleResult<SVal> {
222222
constauto pos = inc_pos(tid);
223-
constauto ret = GenMCDriver::handleLoad<k>(pos, old_val, std::forward<Ts>(params)...);
223+
constauto ret =
224+
GenMCDriver::handleLoad<k>(nullptr, pos, old_val, std::forward<Ts>(params)...);
224225
// If we didn't get a value, we have to reset the index of the current thread.
225226
if (!std::holds_alternative<SVal>(ret)) {
226227
dec_pos(tid);

‎src/tools/miri/genmc-sys/cpp/include/ResultHandling.hpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
// GenMC headers:
88
#include"Verification/VerificationError.hpp"
99

10+
#include<format>
11+
#include<memory>
12+
#include<sstream>
1013
#include<string>
1114

1215
/** Information about an error, formatted as a string to avoid having to share an error enum and
1316
* printing functionality with the Rust side. */
1417
staticautoformat_error(VerificationError err) -> std::unique_ptr<std::string> {
15-
auto buf = std::string();
16-
auto s = llvm::raw_string_ostream(buf);
17-
s << err;
18+
std::stringstream s;
19+
s << std::format("{}", err);
1820
return std::make_unique<std::string>(s.str());
1921
}
2022

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/EventHandling.cpp‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
voidMiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_type) {
3636
BUG_ON(getExec().getGraph().isThreadBlocked(thread_id));
37-
GenMCDriver::handleAssume(inc_pos(thread_id), assume_type);
37+
GenMCDriver::handleAssume(nullptr, inc_pos(thread_id), assume_type);
3838
}
3939

4040
/**** Memory access handling ****/
@@ -76,6 +76,7 @@ void MiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_ty
7676
) -> StoreResult {
7777
constauto pos = inc_pos(thread_id);
7878
constauto ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::Write>(
79+
nullptr,
7980
pos,
8081
GenmcScalarExt::try_to_sval(old_val),
8182
ord,
@@ -100,7 +101,7 @@ void MiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_ty
100101

101102
voidMiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
102103
constauto pos = inc_pos(thread_id);
103-
GenMCDriver::handleFence(pos, ord, EventDeps());
104+
GenMCDriver::handleFence(nullptr, pos, ord, EventDeps());
104105
}
105106

106107
[[nodiscard]]autoMiriGenmcShim::handle_read_modify_write(
@@ -143,6 +144,7 @@ void MiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
143144

144145
constauto storePos = inc_pos(thread_id);
145146
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::FaiWrite>(
147+
nullptr,
146148
storePos,
147149
GenmcScalarExt::try_to_sval(old_val),
148150
ordering,
@@ -210,6 +212,7 @@ void MiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
210212

211213
constauto storePos = inc_pos(thread_id);
212214
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::CasWrite>(
215+
nullptr,
213216
storePos,
214217
GenmcScalarExt::try_to_sval(old_val),
215218
success_ordering,
@@ -242,6 +245,7 @@ auto MiriGenmcShim::handle_malloc(ThreadId thread_id, uint64_t size, uint64_t al
242245
constauto address_space = AddressSpace::AS_User;
243246

244247
const SVal ret_val = GenMCDriver::handleMalloc(
248+
nullptr,
245249
pos,
246250
size,
247251
alignment,
@@ -255,7 +259,7 @@ auto MiriGenmcShim::handle_malloc(ThreadId thread_id, uint64_t size, uint64_t al
255259

256260
autoMiriGenmcShim::handle_free(ThreadId thread_id, uint64_t address) -> bool {
257261
constauto pos = inc_pos(thread_id);
258-
GenMCDriver::handleFree(pos, SAddr(address), EventDeps());
262+
GenMCDriver::handleFree(nullptr, pos, SAddr(address), EventDeps());
259263
// FIXME(genmc): use returned error from `handleFree` once implemented in GenMC.
260264
returngetResult().status.has_value();
261265
}

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Exploration.cpp‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,23 @@ auto MiriGenmcShim::schedule_next(
2222
// a scheduling decision.
2323
threads_action_[curr_thread_id].kind = curr_thread_next_instr_kind;
2424

25-
if (constauto result = GenMCDriver::scheduleNext(threads_action_))
26-
return SchedulingResult { ExecutionState::Ok, static_cast<int32_t>(result.value()) };
27-
if (getExec().getGraph().isBlocked())
28-
return SchedulingResult { ExecutionState::Blocked, 0 };
29-
if (getResult().status.has_value()) // the "value" here is a `VerificationError`
30-
return SchedulingResult { ExecutionState::Error, 0 };
31-
return SchedulingResult { ExecutionState::Finished, 0 };
25+
auto result = GenMCDriver::scheduleNext(threads_action_);
26+
returnstd::visit(
27+
[](auto&& arg) {
28+
using T = std::decay_t<decltype(arg)>;
29+
ifconstexpr (std::is_same_v<T, int>)
30+
return SchedulingResult { ExecutionState::Ok, static_cast<int32_t>(arg) };
31+
elseifconstexpr (std::is_same_v<T, Blocked>)
32+
return SchedulingResult { ExecutionState::Blocked, 0 };
33+
elseifconstexpr (std::is_same_v<T, Error>)
34+
return SchedulingResult { ExecutionState::Error, 0 };
35+
elseifconstexpr (std::is_same_v<T, Finished>)
36+
return SchedulingResult { ExecutionState::Finished, 0 };
37+
else
38+
static_assert(false, "non-exhaustive visitor!");
39+
},
40+
result
41+
);
3242
}
3343

3444
/**** Execution start/end handling ****/

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Mutex.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ auto MiriGenmcShim::handle_mutex_lock(ThreadId thread_id, uint64_t address, uint
6060
constbool is_lock_acquired = *ret_val == MUTEX_UNLOCKED;
6161
if (is_lock_acquired) {
6262
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::LockCasWrite>(
63+
nullptr,
6364
inc_pos(thread_id),
6465
old_val,
6566
address,
@@ -93,6 +94,7 @@ auto MiriGenmcShim::handle_mutex_try_lock(ThreadId thread_id, uint64_t address,
9394
// a mutex to be "unlocked".
9495
constauto old_val = MUTEX_UNLOCKED;
9596
constauto load_ret = GenMCDriver::handleLoad<EventLabel::EventLabelKind::TrylockCasRead>(
97+
nullptr,
9698
++currPos,
9799
old_val,
98100
SAddr(address),
@@ -115,6 +117,7 @@ auto MiriGenmcShim::handle_mutex_try_lock(ThreadId thread_id, uint64_t address,
115117
}
116118

117119
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::TrylockCasWrite>(
120+
nullptr,
118121
++currPos,
119122
old_val,
120123
SAddr(address),
@@ -136,6 +139,7 @@ auto MiriGenmcShim::handle_mutex_unlock(ThreadId thread_id, uint64_t address, ui
136139
-> StoreResult {
137140
constauto pos = inc_pos(thread_id);
138141
constauto ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::UnlockWrite>(
142+
nullptr,
139143
pos,
140144
// As usual, we need to tell GenMC which value was stored at this location before this
141145
// atomic access, if there previously was a non-atomic initializing access. We set the

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Setup.cpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,16 @@ static auto to_genmc_verbosity_level(const LogLevel log_level) -> VerbosityLevel
147147
// that is allowed to leak and memory that is not.
148148
conf->warnUnfreedMemory = false;
149149

150-
// FIXME(genmc,error handling): This function currently exits on error, but will return an
151-
// error value in the future. The return value should be checked once this change is made.
152-
checkConfig(*conf);
150+
// Validate the config and exit if there are any errors
151+
std::vector<std::string> warnings;
152+
auto config_valid = conf->validate(warnings);
153+
for (constauto& w : warnings)
154+
WARN("{}", w);
155+
if (auto* errors = std::get_if<ConfigErrorList>(&config_valid); errors) {
156+
for (constauto& e : *errors)
157+
LOG(VerbosityLevel::Error, "{}", e);
158+
exit(EUSER);
159+
}
153160

154161
// Create the actual driver and Miri-GenMC communication shim.
155162
auto driver = std::make_unique<MiriGenmcShim>(std::move(conf), mode);

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/ThreadManagement.cpp‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ void MiriGenmcShim::handle_thread_create(ThreadId thread_id, ThreadId parent_id)
1919
// FIXME(genmc): for supporting symmetry reduction, these will need to be properly set:
2020
constunsigned fun_id = 0;
2121
const SVal arg = SVal(0);
22-
const ThreadInfo child_info = ThreadInfo { thread_id, parent_id, fun_id, arg };
22+
const ThreadInfo child_info =
23+
ThreadInfo { thread_id, parent_id, fun_id, arg, "unknown thread" };
2324

2425
// NOTE: Default memory ordering (`Release`) used here.
25-
constauto child_tid = GenMCDriver::handleThreadCreate(pos, child_info, EventDeps());
26+
constauto child_tid = GenMCDriver::handleThreadCreate(nullptr, pos, child_info, EventDeps());
2627
// Sanity check the thread id, which is the index in the `threads_action_` array.
2728
BUG_ON(child_tid != thread_id || child_tid <= 0 || child_tid != threads_action_.size());
2829
threads_action_.push_back(Action(ActionKind::Load, Event(child_tid, 0)));
@@ -33,7 +34,7 @@ void MiriGenmcShim::handle_thread_join(ThreadId thread_id, ThreadId child_id) {
3334
constauto pos = inc_pos(thread_id);
3435

3536
// NOTE: Default memory ordering (`Acquire`) used here.
36-
constauto ret = GenMCDriver::handleThreadJoin(pos, child_id, EventDeps());
37+
constauto ret = GenMCDriver::handleThreadJoin(nullptr, pos, child_id, EventDeps());
3738
// If the join failed, decrease the event index again:
3839
if (!std::holds_alternative<SVal>(ret)) {
3940
dec_pos(thread_id);
@@ -46,10 +47,10 @@ void MiriGenmcShim::handle_thread_join(ThreadId thread_id, ThreadId child_id) {
4647
voidMiriGenmcShim::handle_thread_finish(ThreadId thread_id, uint64_t ret_val) {
4748
constauto pos = inc_pos(thread_id);
4849
// NOTE: Default memory ordering (`Release`) used here.
49-
GenMCDriver::handleThreadFinish(pos, SVal(ret_val));
50+
GenMCDriver::handleThreadFinish(nullptr, pos, SVal(ret_val));
5051
}
5152

5253
voidMiriGenmcShim::handle_thread_kill(ThreadId thread_id) {
5354
constauto pos = inc_pos(thread_id);
54-
GenMCDriver::handleThreadKill(pos);
55+
GenMCDriver::handleThreadKill(nullptr, pos);
5556
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 8e39bff

Browse files
authored
Merge pull request #4697 from michaliskok/genmc-llvm-dep
genmc: Build without LLVM; adjust to API changes
2 parents 5bb385d + 26bd441 commit 8e39bff

8 files changed

Lines changed: 53 additions & 80 deletions

File tree

‎src/tools/miri/genmc-sys/build.rs‎

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mod downloading {
2828
/// The GenMC repository the we get our commit from.
2929
pub(crate)constGENMC_GITHUB_URL:&str = "https://github.com/MPI-SWS/genmc.git";
3030
/// The GenMC commit we depend on. It must be available on the specified GenMC repository.
31-
pub(crate)constGENMC_COMMIT:&str = "d9527280bb99f1cef64326b1803ffd952e3880df";
31+
pub(crate)constGENMC_COMMIT:&str = "aa10ed65117c3291524efc19253b5d443a4602ac";
3232

3333
/// Ensure that a local GenMC repo is present and set to the correct commit.
3434
/// Return the path of the GenMC repo and whether the checked out commit was changed.
@@ -140,51 +140,6 @@ mod downloading {
140140
}
141141
}
142142

143-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
144-
/// The linked LLVM version is in the generated `config.h`` file, which we parse and use to link to LLVM.
145-
/// Returns c++ compiler definitions required for building with/including LLVM, and the include path for LLVM headers.
146-
fnlink_to_llvm(config_file:&Path) -> (String,String){
147-
/// Search a string for a line matching `//@VARIABLE_NAME: VARIABLE CONTENT`
148-
fnextract_value<'a>(input:&'astr,name:&str) -> Option<&'astr>{
149-
input
150-
.lines()
151-
.find_map(|line| line.strip_prefix("//@")?.strip_prefix(name)?.strip_prefix(": "))
152-
}
153-
154-
let file_content = std::fs::read_to_string(&config_file).unwrap_or_else(|err| {
155-
panic!("GenMC config file ({}) should exist, but got errror {err:?}", config_file.display())
156-
});
157-
158-
let llvm_definitions = extract_value(&file_content,"LLVM_DEFINITIONS")
159-
.expect("Config file should contain LLVM_DEFINITIONS");
160-
let llvm_include_dirs = extract_value(&file_content,"LLVM_INCLUDE_DIRS")
161-
.expect("Config file should contain LLVM_INCLUDE_DIRS");
162-
let llvm_library_dir = extract_value(&file_content,"LLVM_LIBRARY_DIR")
163-
.expect("Config file should contain LLVM_LIBRARY_DIR");
164-
let llvm_config_path = extract_value(&file_content,"LLVM_CONFIG_PATH")
165-
.expect("Config file should contain LLVM_CONFIG_PATH");
166-
167-
// Add linker search path.
168-
let lib_dir = PathBuf::from_str(llvm_library_dir).unwrap();
169-
println!("cargo::rustc-link-search=native={}", lib_dir.display());
170-
171-
// Add libraries to link.
172-
let output = std::process::Command::new(llvm_config_path)
173-
.arg("--libs")// Print the libraries to link to (space-separated list)
174-
.output()
175-
.expect("failed to execute llvm-config");
176-
let llvm_link_libs =
177-
String::try_from(output.stdout).expect("llvm-config output should be a valid string");
178-
179-
for link_lib in llvm_link_libs.trim().split(" "){
180-
let link_lib =
181-
link_lib.strip_prefix("-l").expect("Linker parameter should start with \"-l\"");
182-
println!("cargo::rustc-link-lib=dylib={link_lib}");
183-
}
184-
185-
(llvm_definitions.to_string(), llvm_include_dirs.to_string())
186-
}
187-
188143
/// Build the GenMC model checker library and the Rust-C++ interop library with cxx.rs
189144
fncompile_cpp_dependencies(genmc_path:&Path,always_configure:bool){
190145
// Give each step a separate build directory to prevent interference.
@@ -204,6 +159,7 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
204159
.always_configure(always_configure)// We force running the configure step when the GenMC commit changed.
205160
.out_dir(genmc_build_dir)
206161
.profile(GENMC_CMAKE_PROFILE)
162+
.define("BUILD_LLI","OFF")
207163
.define("GENMC_DEBUG",if enable_genmc_debug {"ON"}else{"OFF"});
208164

209165
// The actual compilation happens here:
@@ -214,19 +170,11 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
214170
println!("cargo::rustc-link-search=native={}", cmake_lib_dir.display());
215171
println!("cargo::rustc-link-lib=static={GENMC_MODEL_CHECKER}");
216172

217-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
218-
let config_file = genmc_install_dir.join("include").join("genmc").join("config.h");
219-
let(llvm_definitions, llvm_include_dirs) = link_to_llvm(&config_file);
220-
221173
// Part 2:
222174
// Compile the cxx_bridge (the link between the Rust and C++ code).
223175

224176
let genmc_include_dir = genmc_install_dir.join("include").join("genmc");
225177

226-
// FIXME(genmc,llvm): remove once LLVM dependency is removed.
227-
// These definitions are parsed into a cmake list and then printed to the config.h file, so they are ';' separated.
228-
let definitions = llvm_definitions.split(";");
229-
230178
// These are all the C++ files we need to compile, which needs to be updated if more C++ files are added to Miri.
231179
// We use absolute paths since relative paths can confuse IDEs when attempting to go-to-source on a path in a compiler error.
232180
let cpp_files_base_path = Path::new("cpp/src/");
@@ -244,16 +192,12 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
244192
if enable_genmc_debug {
245193
bridge.define("ENABLE_GENMC_DEBUG",None);
246194
}
247-
for definition in definitions {
248-
bridge.flag(definition);
249-
}
250195
bridge
251196
.opt_level(2)
252197
.debug(true)// Same settings that GenMC uses (default for cmake `RelWithDebInfo`)
253198
.warnings(false)// NOTE: enabling this produces a lot of warnings.
254199
.std("c++23")
255200
.include(genmc_include_dir)
256-
.include(llvm_include_dirs)
257201
.include("./cpp/include")
258202
.files(&cpp_files)
259203
.out_dir(interface_build_dir)

‎src/tools/miri/genmc-sys/cpp/include/MiriInterface.hpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ struct MiriGenmcShim : private GenMCDriver {
220220
autohandle_load_reset_if_none(ThreadId tid, std::optional<SVal> old_val, Ts&&... params)
221221
-> HandleResult<SVal> {
222222
constauto pos = inc_pos(tid);
223-
constauto ret = GenMCDriver::handleLoad<k>(pos, old_val, std::forward<Ts>(params)...);
223+
constauto ret =
224+
GenMCDriver::handleLoad<k>(nullptr, pos, old_val, std::forward<Ts>(params)...);
224225
// If we didn't get a value, we have to reset the index of the current thread.
225226
if (!std::holds_alternative<SVal>(ret)) {
226227
dec_pos(tid);

‎src/tools/miri/genmc-sys/cpp/include/ResultHandling.hpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
// GenMC headers:
88
#include"Verification/VerificationError.hpp"
99

10+
#include<format>
11+
#include<memory>
12+
#include<sstream>
1013
#include<string>
1114

1215
/** Information about an error, formatted as a string to avoid having to share an error enum and
1316
* printing functionality with the Rust side. */
1417
staticautoformat_error(VerificationError err) -> std::unique_ptr<std::string> {
15-
auto buf = std::string();
16-
auto s = llvm::raw_string_ostream(buf);
17-
s << err;
18+
std::stringstream s;
19+
s << std::format("{}", err);
1820
return std::make_unique<std::string>(s.str());
1921
}
2022

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/EventHandling.cpp‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
voidMiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_type) {
3636
BUG_ON(getExec().getGraph().isThreadBlocked(thread_id));
37-
GenMCDriver::handleAssume(inc_pos(thread_id), assume_type);
37+
GenMCDriver::handleAssume(nullptr, inc_pos(thread_id), assume_type);
3838
}
3939

4040
/**** Memory access handling ****/
@@ -76,6 +76,7 @@ void MiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_ty
7676
) -> StoreResult {
7777
constauto pos = inc_pos(thread_id);
7878
constauto ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::Write>(
79+
nullptr,
7980
pos,
8081
GenmcScalarExt::try_to_sval(old_val),
8182
ord,
@@ -100,7 +101,7 @@ void MiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_ty
100101

101102
voidMiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
102103
constauto pos = inc_pos(thread_id);
103-
GenMCDriver::handleFence(pos, ord, EventDeps());
104+
GenMCDriver::handleFence(nullptr, pos, ord, EventDeps());
104105
}
105106

106107
[[nodiscard]]autoMiriGenmcShim::handle_read_modify_write(
@@ -143,6 +144,7 @@ void MiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
143144

144145
constauto storePos = inc_pos(thread_id);
145146
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::FaiWrite>(
147+
nullptr,
146148
storePos,
147149
GenmcScalarExt::try_to_sval(old_val),
148150
ordering,
@@ -210,6 +212,7 @@ void MiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
210212

211213
constauto storePos = inc_pos(thread_id);
212214
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::CasWrite>(
215+
nullptr,
213216
storePos,
214217
GenmcScalarExt::try_to_sval(old_val),
215218
success_ordering,
@@ -242,6 +245,7 @@ auto MiriGenmcShim::handle_malloc(ThreadId thread_id, uint64_t size, uint64_t al
242245
constauto address_space = AddressSpace::AS_User;
243246

244247
const SVal ret_val = GenMCDriver::handleMalloc(
248+
nullptr,
245249
pos,
246250
size,
247251
alignment,
@@ -255,7 +259,7 @@ auto MiriGenmcShim::handle_malloc(ThreadId thread_id, uint64_t size, uint64_t al
255259

256260
autoMiriGenmcShim::handle_free(ThreadId thread_id, uint64_t address) -> bool {
257261
constauto pos = inc_pos(thread_id);
258-
GenMCDriver::handleFree(pos, SAddr(address), EventDeps());
262+
GenMCDriver::handleFree(nullptr, pos, SAddr(address), EventDeps());
259263
// FIXME(genmc): use returned error from `handleFree` once implemented in GenMC.
260264
returngetResult().status.has_value();
261265
}

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Exploration.cpp‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,23 @@ auto MiriGenmcShim::schedule_next(
2222
// a scheduling decision.
2323
threads_action_[curr_thread_id].kind = curr_thread_next_instr_kind;
2424

25-
if (constauto result = GenMCDriver::scheduleNext(threads_action_))
26-
return SchedulingResult { ExecutionState::Ok, static_cast<int32_t>(result.value()) };
27-
if (getExec().getGraph().isBlocked())
28-
return SchedulingResult { ExecutionState::Blocked, 0 };
29-
if (getResult().status.has_value()) // the "value" here is a `VerificationError`
30-
return SchedulingResult { ExecutionState::Error, 0 };
31-
return SchedulingResult { ExecutionState::Finished, 0 };
25+
auto result = GenMCDriver::scheduleNext(threads_action_);
26+
returnstd::visit(
27+
[](auto&& arg) {
28+
using T = std::decay_t<decltype(arg)>;
29+
ifconstexpr (std::is_same_v<T, int>)
30+
return SchedulingResult { ExecutionState::Ok, static_cast<int32_t>(arg) };
31+
elseifconstexpr (std::is_same_v<T, Blocked>)
32+
return SchedulingResult { ExecutionState::Blocked, 0 };
33+
elseifconstexpr (std::is_same_v<T, Error>)
34+
return SchedulingResult { ExecutionState::Error, 0 };
35+
elseifconstexpr (std::is_same_v<T, Finished>)
36+
return SchedulingResult { ExecutionState::Finished, 0 };
37+
else
38+
static_assert(false, "non-exhaustive visitor!");
39+
},
40+
result
41+
);
3242
}
3343

3444
/**** Execution start/end handling ****/

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Mutex.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ auto MiriGenmcShim::handle_mutex_lock(ThreadId thread_id, uint64_t address, uint
6060
constbool is_lock_acquired = *ret_val == MUTEX_UNLOCKED;
6161
if (is_lock_acquired) {
6262
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::LockCasWrite>(
63+
nullptr,
6364
inc_pos(thread_id),
6465
old_val,
6566
address,
@@ -93,6 +94,7 @@ auto MiriGenmcShim::handle_mutex_try_lock(ThreadId thread_id, uint64_t address,
9394
// a mutex to be "unlocked".
9495
constauto old_val = MUTEX_UNLOCKED;
9596
constauto load_ret = GenMCDriver::handleLoad<EventLabel::EventLabelKind::TrylockCasRead>(
97+
nullptr,
9698
++currPos,
9799
old_val,
98100
SAddr(address),
@@ -115,6 +117,7 @@ auto MiriGenmcShim::handle_mutex_try_lock(ThreadId thread_id, uint64_t address,
115117
}
116118

117119
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::TrylockCasWrite>(
120+
nullptr,
118121
++currPos,
119122
old_val,
120123
SAddr(address),
@@ -136,6 +139,7 @@ auto MiriGenmcShim::handle_mutex_unlock(ThreadId thread_id, uint64_t address, ui
136139
-> StoreResult {
137140
constauto pos = inc_pos(thread_id);
138141
constauto ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::UnlockWrite>(
142+
nullptr,
139143
pos,
140144
// As usual, we need to tell GenMC which value was stored at this location before this
141145
// atomic access, if there previously was a non-atomic initializing access. We set the

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Setup.cpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,16 @@ static auto to_genmc_verbosity_level(const LogLevel log_level) -> VerbosityLevel
147147
// that is allowed to leak and memory that is not.
148148
conf->warnUnfreedMemory = false;
149149

150-
// FIXME(genmc,error handling): This function currently exits on error, but will return an
151-
// error value in the future. The return value should be checked once this change is made.
152-
checkConfig(*conf);
150+
// Validate the config and exit if there are any errors
151+
std::vector<std::string> warnings;
152+
auto config_valid = conf->validate(warnings);
153+
for (constauto& w : warnings)
154+
WARN("{}", w);
155+
if (auto* errors = std::get_if<ConfigErrorList>(&config_valid); errors) {
156+
for (constauto& e : *errors)
157+
LOG(VerbosityLevel::Error, "{}", e);
158+
exit(EUSER);
159+
}
153160

154161
// Create the actual driver and Miri-GenMC communication shim.
155162
auto driver = std::make_unique<MiriGenmcShim>(std::move(conf), mode);

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/ThreadManagement.cpp‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ void MiriGenmcShim::handle_thread_create(ThreadId thread_id, ThreadId parent_id)
1919
// FIXME(genmc): for supporting symmetry reduction, these will need to be properly set:
2020
constunsigned fun_id = 0;
2121
const SVal arg = SVal(0);
22-
const ThreadInfo child_info = ThreadInfo { thread_id, parent_id, fun_id, arg };
22+
const ThreadInfo child_info =
23+
ThreadInfo { thread_id, parent_id, fun_id, arg, "unknown thread" };
2324

2425
// NOTE: Default memory ordering (`Release`) used here.
25-
constauto child_tid = GenMCDriver::handleThreadCreate(pos, child_info, EventDeps());
26+
constauto child_tid = GenMCDriver::handleThreadCreate(nullptr, pos, child_info, EventDeps());
2627
// Sanity check the thread id, which is the index in the `threads_action_` array.
2728
BUG_ON(child_tid != thread_id || child_tid <= 0 || child_tid != threads_action_.size());
2829
threads_action_.push_back(Action(ActionKind::Load, Event(child_tid, 0)));
@@ -33,7 +34,7 @@ void MiriGenmcShim::handle_thread_join(ThreadId thread_id, ThreadId child_id) {
3334
constauto pos = inc_pos(thread_id);
3435

3536
// NOTE: Default memory ordering (`Acquire`) used here.
36-
constauto ret = GenMCDriver::handleThreadJoin(pos, child_id, EventDeps());
37+
constauto ret = GenMCDriver::handleThreadJoin(nullptr, pos, child_id, EventDeps());
3738
// If the join failed, decrease the event index again:
3839
if (!std::holds_alternative<SVal>(ret)) {
3940
dec_pos(thread_id);
@@ -46,10 +47,10 @@ void MiriGenmcShim::handle_thread_join(ThreadId thread_id, ThreadId child_id) {
4647
voidMiriGenmcShim::handle_thread_finish(ThreadId thread_id, uint64_t ret_val) {
4748
constauto pos = inc_pos(thread_id);
4849
// NOTE: Default memory ordering (`Release`) used here.
49-
GenMCDriver::handleThreadFinish(pos, SVal(ret_val));
50+
GenMCDriver::handleThreadFinish(nullptr, pos, SVal(ret_val));
5051
}
5152

5253
voidMiriGenmcShim::handle_thread_kill(ThreadId thread_id) {
5354
constauto pos = inc_pos(thread_id);
54-
GenMCDriver::handleThreadKill(pos);
55+
GenMCDriver::handleThreadKill(nullptr, pos);
5556
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 8e39bff

Browse files
authored
Merge pull request #4697 from michaliskok/genmc-llvm-dep
genmc: Build without LLVM; adjust to API changes
2 parents 5bb385d + 26bd441 commit 8e39bff

8 files changed

Lines changed: 53 additions & 80 deletions

File tree

‎src/tools/miri/genmc-sys/build.rs‎

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mod downloading {
2828
/// The GenMC repository the we get our commit from.
2929
pub(crate)constGENMC_GITHUB_URL:&str = "https://github.com/MPI-SWS/genmc.git";
3030
/// The GenMC commit we depend on. It must be available on the specified GenMC repository.
31-
pub(crate)constGENMC_COMMIT:&str = "d9527280bb99f1cef64326b1803ffd952e3880df";
31+
pub(crate)constGENMC_COMMIT:&str = "aa10ed65117c3291524efc19253b5d443a4602ac";
3232

3333
/// Ensure that a local GenMC repo is present and set to the correct commit.
3434
/// Return the path of the GenMC repo and whether the checked out commit was changed.
@@ -140,51 +140,6 @@ mod downloading {
140140
}
141141
}
142142

143-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
144-
/// The linked LLVM version is in the generated `config.h`` file, which we parse and use to link to LLVM.
145-
/// Returns c++ compiler definitions required for building with/including LLVM, and the include path for LLVM headers.
146-
fnlink_to_llvm(config_file:&Path) -> (String,String){
147-
/// Search a string for a line matching `//@VARIABLE_NAME: VARIABLE CONTENT`
148-
fnextract_value<'a>(input:&'astr,name:&str) -> Option<&'astr>{
149-
input
150-
.lines()
151-
.find_map(|line| line.strip_prefix("//@")?.strip_prefix(name)?.strip_prefix(": "))
152-
}
153-
154-
let file_content = std::fs::read_to_string(&config_file).unwrap_or_else(|err| {
155-
panic!("GenMC config file ({}) should exist, but got errror {err:?}", config_file.display())
156-
});
157-
158-
let llvm_definitions = extract_value(&file_content,"LLVM_DEFINITIONS")
159-
.expect("Config file should contain LLVM_DEFINITIONS");
160-
let llvm_include_dirs = extract_value(&file_content,"LLVM_INCLUDE_DIRS")
161-
.expect("Config file should contain LLVM_INCLUDE_DIRS");
162-
let llvm_library_dir = extract_value(&file_content,"LLVM_LIBRARY_DIR")
163-
.expect("Config file should contain LLVM_LIBRARY_DIR");
164-
let llvm_config_path = extract_value(&file_content,"LLVM_CONFIG_PATH")
165-
.expect("Config file should contain LLVM_CONFIG_PATH");
166-
167-
// Add linker search path.
168-
let lib_dir = PathBuf::from_str(llvm_library_dir).unwrap();
169-
println!("cargo::rustc-link-search=native={}", lib_dir.display());
170-
171-
// Add libraries to link.
172-
let output = std::process::Command::new(llvm_config_path)
173-
.arg("--libs")// Print the libraries to link to (space-separated list)
174-
.output()
175-
.expect("failed to execute llvm-config");
176-
let llvm_link_libs =
177-
String::try_from(output.stdout).expect("llvm-config output should be a valid string");
178-
179-
for link_lib in llvm_link_libs.trim().split(" "){
180-
let link_lib =
181-
link_lib.strip_prefix("-l").expect("Linker parameter should start with \"-l\"");
182-
println!("cargo::rustc-link-lib=dylib={link_lib}");
183-
}
184-
185-
(llvm_definitions.to_string(), llvm_include_dirs.to_string())
186-
}
187-
188143
/// Build the GenMC model checker library and the Rust-C++ interop library with cxx.rs
189144
fncompile_cpp_dependencies(genmc_path:&Path,always_configure:bool){
190145
// Give each step a separate build directory to prevent interference.
@@ -204,6 +159,7 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
204159
.always_configure(always_configure)// We force running the configure step when the GenMC commit changed.
205160
.out_dir(genmc_build_dir)
206161
.profile(GENMC_CMAKE_PROFILE)
162+
.define("BUILD_LLI","OFF")
207163
.define("GENMC_DEBUG",if enable_genmc_debug {"ON"}else{"OFF"});
208164

209165
// The actual compilation happens here:
@@ -214,19 +170,11 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
214170
println!("cargo::rustc-link-search=native={}", cmake_lib_dir.display());
215171
println!("cargo::rustc-link-lib=static={GENMC_MODEL_CHECKER}");
216172

217-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
218-
let config_file = genmc_install_dir.join("include").join("genmc").join("config.h");
219-
let(llvm_definitions, llvm_include_dirs) = link_to_llvm(&config_file);
220-
221173
// Part 2:
222174
// Compile the cxx_bridge (the link between the Rust and C++ code).
223175

224176
let genmc_include_dir = genmc_install_dir.join("include").join("genmc");
225177

226-
// FIXME(genmc,llvm): remove once LLVM dependency is removed.
227-
// These definitions are parsed into a cmake list and then printed to the config.h file, so they are ';' separated.
228-
let definitions = llvm_definitions.split(";");
229-
230178
// These are all the C++ files we need to compile, which needs to be updated if more C++ files are added to Miri.
231179
// We use absolute paths since relative paths can confuse IDEs when attempting to go-to-source on a path in a compiler error.
232180
let cpp_files_base_path = Path::new("cpp/src/");
@@ -244,16 +192,12 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
244192
if enable_genmc_debug {
245193
bridge.define("ENABLE_GENMC_DEBUG",None);
246194
}
247-
for definition in definitions {
248-
bridge.flag(definition);
249-
}
250195
bridge
251196
.opt_level(2)
252197
.debug(true)// Same settings that GenMC uses (default for cmake `RelWithDebInfo`)
253198
.warnings(false)// NOTE: enabling this produces a lot of warnings.
254199
.std("c++23")
255200
.include(genmc_include_dir)
256-
.include(llvm_include_dirs)
257201
.include("./cpp/include")
258202
.files(&cpp_files)
259203
.out_dir(interface_build_dir)

‎src/tools/miri/genmc-sys/cpp/include/MiriInterface.hpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ struct MiriGenmcShim : private GenMCDriver {
220220
autohandle_load_reset_if_none(ThreadId tid, std::optional<SVal> old_val, Ts&&... params)
221221
-> HandleResult<SVal> {
222222
constauto pos = inc_pos(tid);
223-
constauto ret = GenMCDriver::handleLoad<k>(pos, old_val, std::forward<Ts>(params)...);
223+
constauto ret =
224+
GenMCDriver::handleLoad<k>(nullptr, pos, old_val, std::forward<Ts>(params)...);
224225
// If we didn't get a value, we have to reset the index of the current thread.
225226
if (!std::holds_alternative<SVal>(ret)) {
226227
dec_pos(tid);

‎src/tools/miri/genmc-sys/cpp/include/ResultHandling.hpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
// GenMC headers:
88
#include"Verification/VerificationError.hpp"
99

10+
#include<format>
11+
#include<memory>
12+
#include<sstream>
1013
#include<string>
1114

1215
/** Information about an error, formatted as a string to avoid having to share an error enum and
1316
* printing functionality with the Rust side. */
1417
staticautoformat_error(VerificationError err) -> std::unique_ptr<std::string> {
15-
auto buf = std::string();
16-
auto s = llvm::raw_string_ostream(buf);
17-
s << err;
18+
std::stringstream s;
19+
s << std::format("{}", err);
1820
return std::make_unique<std::string>(s.str());
1921
}
2022

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/EventHandling.cpp‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
voidMiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_type) {
3636
BUG_ON(getExec().getGraph().isThreadBlocked(thread_id));
37-
GenMCDriver::handleAssume(inc_pos(thread_id), assume_type);
37+
GenMCDriver::handleAssume(nullptr, inc_pos(thread_id), assume_type);
3838
}
3939

4040
/**** Memory access handling ****/
@@ -76,6 +76,7 @@ void MiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_ty
7676
) -> StoreResult {
7777
constauto pos = inc_pos(thread_id);
7878
constauto ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::Write>(
79+
nullptr,
7980
pos,
8081
GenmcScalarExt::try_to_sval(old_val),
8182
ord,
@@ -100,7 +101,7 @@ void MiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_ty
100101

101102
voidMiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
102103
constauto pos = inc_pos(thread_id);
103-
GenMCDriver::handleFence(pos, ord, EventDeps());
104+
GenMCDriver::handleFence(nullptr, pos, ord, EventDeps());
104105
}
105106

106107
[[nodiscard]]autoMiriGenmcShim::handle_read_modify_write(
@@ -143,6 +144,7 @@ void MiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
143144

144145
constauto storePos = inc_pos(thread_id);
145146
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::FaiWrite>(
147+
nullptr,
146148
storePos,
147149
GenmcScalarExt::try_to_sval(old_val),
148150
ordering,
@@ -210,6 +212,7 @@ void MiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
210212

211213
constauto storePos = inc_pos(thread_id);
212214
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::CasWrite>(
215+
nullptr,
213216
storePos,
214217
GenmcScalarExt::try_to_sval(old_val),
215218
success_ordering,
@@ -242,6 +245,7 @@ auto MiriGenmcShim::handle_malloc(ThreadId thread_id, uint64_t size, uint64_t al
242245
constauto address_space = AddressSpace::AS_User;
243246

244247
const SVal ret_val = GenMCDriver::handleMalloc(
248+
nullptr,
245249
pos,
246250
size,
247251
alignment,
@@ -255,7 +259,7 @@ auto MiriGenmcShim::handle_malloc(ThreadId thread_id, uint64_t size, uint64_t al
255259

256260
autoMiriGenmcShim::handle_free(ThreadId thread_id, uint64_t address) -> bool {
257261
constauto pos = inc_pos(thread_id);
258-
GenMCDriver::handleFree(pos, SAddr(address), EventDeps());
262+
GenMCDriver::handleFree(nullptr, pos, SAddr(address), EventDeps());
259263
// FIXME(genmc): use returned error from `handleFree` once implemented in GenMC.
260264
returngetResult().status.has_value();
261265
}

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Exploration.cpp‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,23 @@ auto MiriGenmcShim::schedule_next(
2222
// a scheduling decision.
2323
threads_action_[curr_thread_id].kind = curr_thread_next_instr_kind;
2424

25-
if (constauto result = GenMCDriver::scheduleNext(threads_action_))
26-
return SchedulingResult { ExecutionState::Ok, static_cast<int32_t>(result.value()) };
27-
if (getExec().getGraph().isBlocked())
28-
return SchedulingResult { ExecutionState::Blocked, 0 };
29-
if (getResult().status.has_value()) // the "value" here is a `VerificationError`
30-
return SchedulingResult { ExecutionState::Error, 0 };
31-
return SchedulingResult { ExecutionState::Finished, 0 };
25+
auto result = GenMCDriver::scheduleNext(threads_action_);
26+
returnstd::visit(
27+
[](auto&& arg) {
28+
using T = std::decay_t<decltype(arg)>;
29+
ifconstexpr (std::is_same_v<T, int>)
30+
return SchedulingResult { ExecutionState::Ok, static_cast<int32_t>(arg) };
31+
elseifconstexpr (std::is_same_v<T, Blocked>)
32+
return SchedulingResult { ExecutionState::Blocked, 0 };
33+
elseifconstexpr (std::is_same_v<T, Error>)
34+
return SchedulingResult { ExecutionState::Error, 0 };
35+
elseifconstexpr (std::is_same_v<T, Finished>)
36+
return SchedulingResult { ExecutionState::Finished, 0 };
37+
else
38+
static_assert(false, "non-exhaustive visitor!");
39+
},
40+
result
41+
);
3242
}
3343

3444
/**** Execution start/end handling ****/

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Mutex.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ auto MiriGenmcShim::handle_mutex_lock(ThreadId thread_id, uint64_t address, uint
6060
constbool is_lock_acquired = *ret_val == MUTEX_UNLOCKED;
6161
if (is_lock_acquired) {
6262
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::LockCasWrite>(
63+
nullptr,
6364
inc_pos(thread_id),
6465
old_val,
6566
address,
@@ -93,6 +94,7 @@ auto MiriGenmcShim::handle_mutex_try_lock(ThreadId thread_id, uint64_t address,
9394
// a mutex to be "unlocked".
9495
constauto old_val = MUTEX_UNLOCKED;
9596
constauto load_ret = GenMCDriver::handleLoad<EventLabel::EventLabelKind::TrylockCasRead>(
97+
nullptr,
9698
++currPos,
9799
old_val,
98100
SAddr(address),
@@ -115,6 +117,7 @@ auto MiriGenmcShim::handle_mutex_try_lock(ThreadId thread_id, uint64_t address,
115117
}
116118

117119
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::TrylockCasWrite>(
120+
nullptr,
118121
++currPos,
119122
old_val,
120123
SAddr(address),
@@ -136,6 +139,7 @@ auto MiriGenmcShim::handle_mutex_unlock(ThreadId thread_id, uint64_t address, ui
136139
-> StoreResult {
137140
constauto pos = inc_pos(thread_id);
138141
constauto ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::UnlockWrite>(
142+
nullptr,
139143
pos,
140144
// As usual, we need to tell GenMC which value was stored at this location before this
141145
// atomic access, if there previously was a non-atomic initializing access. We set the

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Setup.cpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,16 @@ static auto to_genmc_verbosity_level(const LogLevel log_level) -> VerbosityLevel
147147
// that is allowed to leak and memory that is not.
148148
conf->warnUnfreedMemory = false;
149149

150-
// FIXME(genmc,error handling): This function currently exits on error, but will return an
151-
// error value in the future. The return value should be checked once this change is made.
152-
checkConfig(*conf);
150+
// Validate the config and exit if there are any errors
151+
std::vector<std::string> warnings;
152+
auto config_valid = conf->validate(warnings);
153+
for (constauto& w : warnings)
154+
WARN("{}", w);
155+
if (auto* errors = std::get_if<ConfigErrorList>(&config_valid); errors) {
156+
for (constauto& e : *errors)
157+
LOG(VerbosityLevel::Error, "{}", e);
158+
exit(EUSER);
159+
}
153160

154161
// Create the actual driver and Miri-GenMC communication shim.
155162
auto driver = std::make_unique<MiriGenmcShim>(std::move(conf), mode);

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/ThreadManagement.cpp‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ void MiriGenmcShim::handle_thread_create(ThreadId thread_id, ThreadId parent_id)
1919
// FIXME(genmc): for supporting symmetry reduction, these will need to be properly set:
2020
constunsigned fun_id = 0;
2121
const SVal arg = SVal(0);
22-
const ThreadInfo child_info = ThreadInfo { thread_id, parent_id, fun_id, arg };
22+
const ThreadInfo child_info =
23+
ThreadInfo { thread_id, parent_id, fun_id, arg, "unknown thread" };
2324

2425
// NOTE: Default memory ordering (`Release`) used here.
25-
constauto child_tid = GenMCDriver::handleThreadCreate(pos, child_info, EventDeps());
26+
constauto child_tid = GenMCDriver::handleThreadCreate(nullptr, pos, child_info, EventDeps());
2627
// Sanity check the thread id, which is the index in the `threads_action_` array.
2728
BUG_ON(child_tid != thread_id || child_tid <= 0 || child_tid != threads_action_.size());
2829
threads_action_.push_back(Action(ActionKind::Load, Event(child_tid, 0)));
@@ -33,7 +34,7 @@ void MiriGenmcShim::handle_thread_join(ThreadId thread_id, ThreadId child_id) {
3334
constauto pos = inc_pos(thread_id);
3435

3536
// NOTE: Default memory ordering (`Acquire`) used here.
36-
constauto ret = GenMCDriver::handleThreadJoin(pos, child_id, EventDeps());
37+
constauto ret = GenMCDriver::handleThreadJoin(nullptr, pos, child_id, EventDeps());
3738
// If the join failed, decrease the event index again:
3839
if (!std::holds_alternative<SVal>(ret)) {
3940
dec_pos(thread_id);
@@ -46,10 +47,10 @@ void MiriGenmcShim::handle_thread_join(ThreadId thread_id, ThreadId child_id) {
4647
voidMiriGenmcShim::handle_thread_finish(ThreadId thread_id, uint64_t ret_val) {
4748
constauto pos = inc_pos(thread_id);
4849
// NOTE: Default memory ordering (`Release`) used here.
49-
GenMCDriver::handleThreadFinish(pos, SVal(ret_val));
50+
GenMCDriver::handleThreadFinish(nullptr, pos, SVal(ret_val));
5051
}
5152

5253
voidMiriGenmcShim::handle_thread_kill(ThreadId thread_id) {
5354
constauto pos = inc_pos(thread_id);
54-
GenMCDriver::handleThreadKill(pos);
55+
GenMCDriver::handleThreadKill(nullptr, pos);
5556
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Commit 8e39bff

Browse files
authored
Merge pull request #4697 from michaliskok/genmc-llvm-dep
genmc: Build without LLVM; adjust to API changes
2 parents 5bb385d + 26bd441 commit 8e39bff

8 files changed

Lines changed: 53 additions & 80 deletions

File tree

‎src/tools/miri/genmc-sys/build.rs‎

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mod downloading {
2828
/// The GenMC repository the we get our commit from.
2929
pub(crate)constGENMC_GITHUB_URL:&str = "https://github.com/MPI-SWS/genmc.git";
3030
/// The GenMC commit we depend on. It must be available on the specified GenMC repository.
31-
pub(crate)constGENMC_COMMIT:&str = "d9527280bb99f1cef64326b1803ffd952e3880df";
31+
pub(crate)constGENMC_COMMIT:&str = "aa10ed65117c3291524efc19253b5d443a4602ac";
3232

3333
/// Ensure that a local GenMC repo is present and set to the correct commit.
3434
/// Return the path of the GenMC repo and whether the checked out commit was changed.
@@ -140,51 +140,6 @@ mod downloading {
140140
}
141141
}
142142

143-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
144-
/// The linked LLVM version is in the generated `config.h`` file, which we parse and use to link to LLVM.
145-
/// Returns c++ compiler definitions required for building with/including LLVM, and the include path for LLVM headers.
146-
fnlink_to_llvm(config_file:&Path) -> (String,String){
147-
/// Search a string for a line matching `//@VARIABLE_NAME: VARIABLE CONTENT`
148-
fnextract_value<'a>(input:&'astr,name:&str) -> Option<&'astr>{
149-
input
150-
.lines()
151-
.find_map(|line| line.strip_prefix("//@")?.strip_prefix(name)?.strip_prefix(": "))
152-
}
153-
154-
let file_content = std::fs::read_to_string(&config_file).unwrap_or_else(|err| {
155-
panic!("GenMC config file ({}) should exist, but got errror {err:?}", config_file.display())
156-
});
157-
158-
let llvm_definitions = extract_value(&file_content,"LLVM_DEFINITIONS")
159-
.expect("Config file should contain LLVM_DEFINITIONS");
160-
let llvm_include_dirs = extract_value(&file_content,"LLVM_INCLUDE_DIRS")
161-
.expect("Config file should contain LLVM_INCLUDE_DIRS");
162-
let llvm_library_dir = extract_value(&file_content,"LLVM_LIBRARY_DIR")
163-
.expect("Config file should contain LLVM_LIBRARY_DIR");
164-
let llvm_config_path = extract_value(&file_content,"LLVM_CONFIG_PATH")
165-
.expect("Config file should contain LLVM_CONFIG_PATH");
166-
167-
// Add linker search path.
168-
let lib_dir = PathBuf::from_str(llvm_library_dir).unwrap();
169-
println!("cargo::rustc-link-search=native={}", lib_dir.display());
170-
171-
// Add libraries to link.
172-
let output = std::process::Command::new(llvm_config_path)
173-
.arg("--libs")// Print the libraries to link to (space-separated list)
174-
.output()
175-
.expect("failed to execute llvm-config");
176-
let llvm_link_libs =
177-
String::try_from(output.stdout).expect("llvm-config output should be a valid string");
178-
179-
for link_lib in llvm_link_libs.trim().split(" "){
180-
let link_lib =
181-
link_lib.strip_prefix("-l").expect("Linker parameter should start with \"-l\"");
182-
println!("cargo::rustc-link-lib=dylib={link_lib}");
183-
}
184-
185-
(llvm_definitions.to_string(), llvm_include_dirs.to_string())
186-
}
187-
188143
/// Build the GenMC model checker library and the Rust-C++ interop library with cxx.rs
189144
fncompile_cpp_dependencies(genmc_path:&Path,always_configure:bool){
190145
// Give each step a separate build directory to prevent interference.
@@ -204,6 +159,7 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
204159
.always_configure(always_configure)// We force running the configure step when the GenMC commit changed.
205160
.out_dir(genmc_build_dir)
206161
.profile(GENMC_CMAKE_PROFILE)
162+
.define("BUILD_LLI","OFF")
207163
.define("GENMC_DEBUG",if enable_genmc_debug {"ON"}else{"OFF"});
208164

209165
// The actual compilation happens here:
@@ -214,19 +170,11 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
214170
println!("cargo::rustc-link-search=native={}", cmake_lib_dir.display());
215171
println!("cargo::rustc-link-lib=static={GENMC_MODEL_CHECKER}");
216172

217-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
218-
let config_file = genmc_install_dir.join("include").join("genmc").join("config.h");
219-
let(llvm_definitions, llvm_include_dirs) = link_to_llvm(&config_file);
220-
221173
// Part 2:
222174
// Compile the cxx_bridge (the link between the Rust and C++ code).
223175

224176
let genmc_include_dir = genmc_install_dir.join("include").join("genmc");
225177

226-
// FIXME(genmc,llvm): remove once LLVM dependency is removed.
227-
// These definitions are parsed into a cmake list and then printed to the config.h file, so they are ';' separated.
228-
let definitions = llvm_definitions.split(";");
229-
230178
// These are all the C++ files we need to compile, which needs to be updated if more C++ files are added to Miri.
231179
// We use absolute paths since relative paths can confuse IDEs when attempting to go-to-source on a path in a compiler error.
232180
let cpp_files_base_path = Path::new("cpp/src/");
@@ -244,16 +192,12 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
244192
if enable_genmc_debug {
245193
bridge.define("ENABLE_GENMC_DEBUG",None);
246194
}
247-
for definition in definitions {
248-
bridge.flag(definition);
249-
}
250195
bridge
251196
.opt_level(2)
252197
.debug(true)// Same settings that GenMC uses (default for cmake `RelWithDebInfo`)
253198
.warnings(false)// NOTE: enabling this produces a lot of warnings.
254199
.std("c++23")
255200
.include(genmc_include_dir)
256-
.include(llvm_include_dirs)
257201
.include("./cpp/include")
258202
.files(&cpp_files)
259203
.out_dir(interface_build_dir)

‎src/tools/miri/genmc-sys/cpp/include/MiriInterface.hpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ struct MiriGenmcShim : private GenMCDriver {
220220
autohandle_load_reset_if_none(ThreadId tid, std::optional<SVal> old_val, Ts&&... params)
221221
-> HandleResult<SVal> {
222222
constauto pos = inc_pos(tid);
223-
constauto ret = GenMCDriver::handleLoad<k>(pos, old_val, std::forward<Ts>(params)...);
223+
constauto ret =
224+
GenMCDriver::handleLoad<k>(nullptr, pos, old_val, std::forward<Ts>(params)...);
224225
// If we didn't get a value, we have to reset the index of the current thread.
225226
if (!std::holds_alternative<SVal>(ret)) {
226227
dec_pos(tid);

‎src/tools/miri/genmc-sys/cpp/include/ResultHandling.hpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
// GenMC headers:
88
#include"Verification/VerificationError.hpp"
99

10+
#include<format>
11+
#include<memory>
12+
#include<sstream>
1013
#include<string>
1114

1215
/** Information about an error, formatted as a string to avoid having to share an error enum and
1316
* printing functionality with the Rust side. */
1417
staticautoformat_error(VerificationError err) -> std::unique_ptr<std::string> {
15-
auto buf = std::string();
16-
auto s = llvm::raw_string_ostream(buf);
17-
s << err;
18+
std::stringstream s;
19+
s << std::format("{}", err);
1820
return std::make_unique<std::string>(s.str());
1921
}
2022

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/EventHandling.cpp‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
voidMiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_type) {
3636
BUG_ON(getExec().getGraph().isThreadBlocked(thread_id));
37-
GenMCDriver::handleAssume(inc_pos(thread_id), assume_type);
37+
GenMCDriver::handleAssume(nullptr, inc_pos(thread_id), assume_type);
3838
}
3939

4040
/**** Memory access handling ****/
@@ -76,6 +76,7 @@ void MiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_ty
7676
) -> StoreResult {
7777
constauto pos = inc_pos(thread_id);
7878
constauto ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::Write>(
79+
nullptr,
7980
pos,
8081
GenmcScalarExt::try_to_sval(old_val),
8182
ord,
@@ -100,7 +101,7 @@ void MiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_ty
100101

101102
voidMiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
102103
constauto pos = inc_pos(thread_id);
103-
GenMCDriver::handleFence(pos, ord, EventDeps());
104+
GenMCDriver::handleFence(nullptr, pos, ord, EventDeps());
104105
}
105106

106107
[[nodiscard]]autoMiriGenmcShim::handle_read_modify_write(
@@ -143,6 +144,7 @@ void MiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
143144

144145
constauto storePos = inc_pos(thread_id);
145146
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::FaiWrite>(
147+
nullptr,
146148
storePos,
147149
GenmcScalarExt::try_to_sval(old_val),
148150
ordering,
@@ -210,6 +212,7 @@ void MiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
210212

211213
constauto storePos = inc_pos(thread_id);
212214
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::CasWrite>(
215+
nullptr,
213216
storePos,
214217
GenmcScalarExt::try_to_sval(old_val),
215218
success_ordering,
@@ -242,6 +245,7 @@ auto MiriGenmcShim::handle_malloc(ThreadId thread_id, uint64_t size, uint64_t al
242245
constauto address_space = AddressSpace::AS_User;
243246

244247
const SVal ret_val = GenMCDriver::handleMalloc(
248+
nullptr,
245249
pos,
246250
size,
247251
alignment,
@@ -255,7 +259,7 @@ auto MiriGenmcShim::handle_malloc(ThreadId thread_id, uint64_t size, uint64_t al
255259

256260
autoMiriGenmcShim::handle_free(ThreadId thread_id, uint64_t address) -> bool {
257261
constauto pos = inc_pos(thread_id);
258-
GenMCDriver::handleFree(pos, SAddr(address), EventDeps());
262+
GenMCDriver::handleFree(nullptr, pos, SAddr(address), EventDeps());
259263
// FIXME(genmc): use returned error from `handleFree` once implemented in GenMC.
260264
returngetResult().status.has_value();
261265
}

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Exploration.cpp‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,23 @@ auto MiriGenmcShim::schedule_next(
2222
// a scheduling decision.
2323
threads_action_[curr_thread_id].kind = curr_thread_next_instr_kind;
2424

25-
if (constauto result = GenMCDriver::scheduleNext(threads_action_))
26-
return SchedulingResult { ExecutionState::Ok, static_cast<int32_t>(result.value()) };
27-
if (getExec().getGraph().isBlocked())
28-
return SchedulingResult { ExecutionState::Blocked, 0 };
29-
if (getResult().status.has_value()) // the "value" here is a `VerificationError`
30-
return SchedulingResult { ExecutionState::Error, 0 };
31-
return SchedulingResult { ExecutionState::Finished, 0 };
25+
auto result = GenMCDriver::scheduleNext(threads_action_);
26+
returnstd::visit(
27+
[](auto&& arg) {
28+
using T = std::decay_t<decltype(arg)>;
29+
ifconstexpr (std::is_same_v<T, int>)
30+
return SchedulingResult { ExecutionState::Ok, static_cast<int32_t>(arg) };
31+
elseifconstexpr (std::is_same_v<T, Blocked>)
32+
return SchedulingResult { ExecutionState::Blocked, 0 };
33+
elseifconstexpr (std::is_same_v<T, Error>)
34+
return SchedulingResult { ExecutionState::Error, 0 };
35+
elseifconstexpr (std::is_same_v<T, Finished>)
36+
return SchedulingResult { ExecutionState::Finished, 0 };
37+
else
38+
static_assert(false, "non-exhaustive visitor!");
39+
},
40+
result
41+
);
3242
}
3343

3444
/**** Execution start/end handling ****/

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Mutex.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ auto MiriGenmcShim::handle_mutex_lock(ThreadId thread_id, uint64_t address, uint
6060
constbool is_lock_acquired = *ret_val == MUTEX_UNLOCKED;
6161
if (is_lock_acquired) {
6262
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::LockCasWrite>(
63+
nullptr,
6364
inc_pos(thread_id),
6465
old_val,
6566
address,
@@ -93,6 +94,7 @@ auto MiriGenmcShim::handle_mutex_try_lock(ThreadId thread_id, uint64_t address,
9394
// a mutex to be "unlocked".
9495
constauto old_val = MUTEX_UNLOCKED;
9596
constauto load_ret = GenMCDriver::handleLoad<EventLabel::EventLabelKind::TrylockCasRead>(
97+
nullptr,
9698
++currPos,
9799
old_val,
98100
SAddr(address),
@@ -115,6 +117,7 @@ auto MiriGenmcShim::handle_mutex_try_lock(ThreadId thread_id, uint64_t address,
115117
}
116118

117119
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::TrylockCasWrite>(
120+
nullptr,
118121
++currPos,
119122
old_val,
120123
SAddr(address),
@@ -136,6 +139,7 @@ auto MiriGenmcShim::handle_mutex_unlock(ThreadId thread_id, uint64_t address, ui
136139
-> StoreResult {
137140
constauto pos = inc_pos(thread_id);
138141
constauto ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::UnlockWrite>(
142+
nullptr,
139143
pos,
140144
// As usual, we need to tell GenMC which value was stored at this location before this
141145
// atomic access, if there previously was a non-atomic initializing access. We set the

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Setup.cpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,16 @@ static auto to_genmc_verbosity_level(const LogLevel log_level) -> VerbosityLevel
147147
// that is allowed to leak and memory that is not.
148148
conf->warnUnfreedMemory = false;
149149

150-
// FIXME(genmc,error handling): This function currently exits on error, but will return an
151-
// error value in the future. The return value should be checked once this change is made.
152-
checkConfig(*conf);
150+
// Validate the config and exit if there are any errors
151+
std::vector<std::string> warnings;
152+
auto config_valid = conf->validate(warnings);
153+
for (constauto& w : warnings)
154+
WARN("{}", w);
155+
if (auto* errors = std::get_if<ConfigErrorList>(&config_valid); errors) {
156+
for (constauto& e : *errors)
157+
LOG(VerbosityLevel::Error, "{}", e);
158+
exit(EUSER);
159+
}
153160

154161
// Create the actual driver and Miri-GenMC communication shim.
155162
auto driver = std::make_unique<MiriGenmcShim>(std::move(conf), mode);

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/ThreadManagement.cpp‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ void MiriGenmcShim::handle_thread_create(ThreadId thread_id, ThreadId parent_id)
1919
// FIXME(genmc): for supporting symmetry reduction, these will need to be properly set:
2020
constunsigned fun_id = 0;
2121
const SVal arg = SVal(0);
22-
const ThreadInfo child_info = ThreadInfo { thread_id, parent_id, fun_id, arg };
22+
const ThreadInfo child_info =
23+
ThreadInfo { thread_id, parent_id, fun_id, arg, "unknown thread" };
2324

2425
// NOTE: Default memory ordering (`Release`) used here.
25-
constauto child_tid = GenMCDriver::handleThreadCreate(pos, child_info, EventDeps());
26+
constauto child_tid = GenMCDriver::handleThreadCreate(nullptr, pos, child_info, EventDeps());
2627
// Sanity check the thread id, which is the index in the `threads_action_` array.
2728
BUG_ON(child_tid != thread_id || child_tid <= 0 || child_tid != threads_action_.size());
2829
threads_action_.push_back(Action(ActionKind::Load, Event(child_tid, 0)));
@@ -33,7 +34,7 @@ void MiriGenmcShim::handle_thread_join(ThreadId thread_id, ThreadId child_id) {
3334
constauto pos = inc_pos(thread_id);
3435

3536
// NOTE: Default memory ordering (`Acquire`) used here.
36-
constauto ret = GenMCDriver::handleThreadJoin(pos, child_id, EventDeps());
37+
constauto ret = GenMCDriver::handleThreadJoin(nullptr, pos, child_id, EventDeps());
3738
// If the join failed, decrease the event index again:
3839
if (!std::holds_alternative<SVal>(ret)) {
3940
dec_pos(thread_id);
@@ -46,10 +47,10 @@ void MiriGenmcShim::handle_thread_join(ThreadId thread_id, ThreadId child_id) {
4647
voidMiriGenmcShim::handle_thread_finish(ThreadId thread_id, uint64_t ret_val) {
4748
constauto pos = inc_pos(thread_id);
4849
// NOTE: Default memory ordering (`Release`) used here.
49-
GenMCDriver::handleThreadFinish(pos, SVal(ret_val));
50+
GenMCDriver::handleThreadFinish(nullptr, pos, SVal(ret_val));
5051
}
5152

5253
voidMiriGenmcShim::handle_thread_kill(ThreadId thread_id) {
5354
constauto pos = inc_pos(thread_id);
54-
GenMCDriver::handleThreadKill(pos);
55+
GenMCDriver::handleThreadKill(nullptr, pos);
5556
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 8e39bff

Browse files
authored
Merge pull request #4697 from michaliskok/genmc-llvm-dep
genmc: Build without LLVM; adjust to API changes
2 parents 5bb385d + 26bd441 commit 8e39bff

8 files changed

Lines changed: 53 additions & 80 deletions

File tree

‎src/tools/miri/genmc-sys/build.rs‎

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mod downloading {
2828
/// The GenMC repository the we get our commit from.
2929
pub(crate)constGENMC_GITHUB_URL:&str = "https://github.com/MPI-SWS/genmc.git";
3030
/// The GenMC commit we depend on. It must be available on the specified GenMC repository.
31-
pub(crate)constGENMC_COMMIT:&str = "d9527280bb99f1cef64326b1803ffd952e3880df";
31+
pub(crate)constGENMC_COMMIT:&str = "aa10ed65117c3291524efc19253b5d443a4602ac";
3232

3333
/// Ensure that a local GenMC repo is present and set to the correct commit.
3434
/// Return the path of the GenMC repo and whether the checked out commit was changed.
@@ -140,51 +140,6 @@ mod downloading {
140140
}
141141
}
142142

143-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
144-
/// The linked LLVM version is in the generated `config.h`` file, which we parse and use to link to LLVM.
145-
/// Returns c++ compiler definitions required for building with/including LLVM, and the include path for LLVM headers.
146-
fnlink_to_llvm(config_file:&Path) -> (String,String){
147-
/// Search a string for a line matching `//@VARIABLE_NAME: VARIABLE CONTENT`
148-
fnextract_value<'a>(input:&'astr,name:&str) -> Option<&'astr>{
149-
input
150-
.lines()
151-
.find_map(|line| line.strip_prefix("//@")?.strip_prefix(name)?.strip_prefix(": "))
152-
}
153-
154-
let file_content = std::fs::read_to_string(&config_file).unwrap_or_else(|err| {
155-
panic!("GenMC config file ({}) should exist, but got errror {err:?}", config_file.display())
156-
});
157-
158-
let llvm_definitions = extract_value(&file_content,"LLVM_DEFINITIONS")
159-
.expect("Config file should contain LLVM_DEFINITIONS");
160-
let llvm_include_dirs = extract_value(&file_content,"LLVM_INCLUDE_DIRS")
161-
.expect("Config file should contain LLVM_INCLUDE_DIRS");
162-
let llvm_library_dir = extract_value(&file_content,"LLVM_LIBRARY_DIR")
163-
.expect("Config file should contain LLVM_LIBRARY_DIR");
164-
let llvm_config_path = extract_value(&file_content,"LLVM_CONFIG_PATH")
165-
.expect("Config file should contain LLVM_CONFIG_PATH");
166-
167-
// Add linker search path.
168-
let lib_dir = PathBuf::from_str(llvm_library_dir).unwrap();
169-
println!("cargo::rustc-link-search=native={}", lib_dir.display());
170-
171-
// Add libraries to link.
172-
let output = std::process::Command::new(llvm_config_path)
173-
.arg("--libs")// Print the libraries to link to (space-separated list)
174-
.output()
175-
.expect("failed to execute llvm-config");
176-
let llvm_link_libs =
177-
String::try_from(output.stdout).expect("llvm-config output should be a valid string");
178-
179-
for link_lib in llvm_link_libs.trim().split(" "){
180-
let link_lib =
181-
link_lib.strip_prefix("-l").expect("Linker parameter should start with \"-l\"");
182-
println!("cargo::rustc-link-lib=dylib={link_lib}");
183-
}
184-
185-
(llvm_definitions.to_string(), llvm_include_dirs.to_string())
186-
}
187-
188143
/// Build the GenMC model checker library and the Rust-C++ interop library with cxx.rs
189144
fncompile_cpp_dependencies(genmc_path:&Path,always_configure:bool){
190145
// Give each step a separate build directory to prevent interference.
@@ -204,6 +159,7 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
204159
.always_configure(always_configure)// We force running the configure step when the GenMC commit changed.
205160
.out_dir(genmc_build_dir)
206161
.profile(GENMC_CMAKE_PROFILE)
162+
.define("BUILD_LLI","OFF")
207163
.define("GENMC_DEBUG",if enable_genmc_debug {"ON"}else{"OFF"});
208164

209165
// The actual compilation happens here:
@@ -214,19 +170,11 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
214170
println!("cargo::rustc-link-search=native={}", cmake_lib_dir.display());
215171
println!("cargo::rustc-link-lib=static={GENMC_MODEL_CHECKER}");
216172

217-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
218-
let config_file = genmc_install_dir.join("include").join("genmc").join("config.h");
219-
let(llvm_definitions, llvm_include_dirs) = link_to_llvm(&config_file);
220-
221173
// Part 2:
222174
// Compile the cxx_bridge (the link between the Rust and C++ code).
223175

224176
let genmc_include_dir = genmc_install_dir.join("include").join("genmc");
225177

226-
// FIXME(genmc,llvm): remove once LLVM dependency is removed.
227-
// These definitions are parsed into a cmake list and then printed to the config.h file, so they are ';' separated.
228-
let definitions = llvm_definitions.split(";");
229-
230178
// These are all the C++ files we need to compile, which needs to be updated if more C++ files are added to Miri.
231179
// We use absolute paths since relative paths can confuse IDEs when attempting to go-to-source on a path in a compiler error.
232180
let cpp_files_base_path = Path::new("cpp/src/");
@@ -244,16 +192,12 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
244192
if enable_genmc_debug {
245193
bridge.define("ENABLE_GENMC_DEBUG",None);
246194
}
247-
for definition in definitions {
248-
bridge.flag(definition);
249-
}
250195
bridge
251196
.opt_level(2)
252197
.debug(true)// Same settings that GenMC uses (default for cmake `RelWithDebInfo`)
253198
.warnings(false)// NOTE: enabling this produces a lot of warnings.
254199
.std("c++23")
255200
.include(genmc_include_dir)
256-
.include(llvm_include_dirs)
257201
.include("./cpp/include")
258202
.files(&cpp_files)
259203
.out_dir(interface_build_dir)

‎src/tools/miri/genmc-sys/cpp/include/MiriInterface.hpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ struct MiriGenmcShim : private GenMCDriver {
220220
autohandle_load_reset_if_none(ThreadId tid, std::optional<SVal> old_val, Ts&&... params)
221221
-> HandleResult<SVal> {
222222
constauto pos = inc_pos(tid);
223-
constauto ret = GenMCDriver::handleLoad<k>(pos, old_val, std::forward<Ts>(params)...);
223+
constauto ret =
224+
GenMCDriver::handleLoad<k>(nullptr, pos, old_val, std::forward<Ts>(params)...);
224225
// If we didn't get a value, we have to reset the index of the current thread.
225226
if (!std::holds_alternative<SVal>(ret)) {
226227
dec_pos(tid);

‎src/tools/miri/genmc-sys/cpp/include/ResultHandling.hpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
// GenMC headers:
88
#include"Verification/VerificationError.hpp"
99

10+
#include<format>
11+
#include<memory>
12+
#include<sstream>
1013
#include<string>
1114

1215
/** Information about an error, formatted as a string to avoid having to share an error enum and
1316
* printing functionality with the Rust side. */
1417
staticautoformat_error(VerificationError err) -> std::unique_ptr<std::string> {
15-
auto buf = std::string();
16-
auto s = llvm::raw_string_ostream(buf);
17-
s << err;
18+
std::stringstream s;
19+
s << std::format("{}", err);
1820
return std::make_unique<std::string>(s.str());
1921
}
2022

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/EventHandling.cpp‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
voidMiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_type) {
3636
BUG_ON(getExec().getGraph().isThreadBlocked(thread_id));
37-
GenMCDriver::handleAssume(inc_pos(thread_id), assume_type);
37+
GenMCDriver::handleAssume(nullptr, inc_pos(thread_id), assume_type);
3838
}
3939

4040
/**** Memory access handling ****/
@@ -76,6 +76,7 @@ void MiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_ty
7676
) -> StoreResult {
7777
constauto pos = inc_pos(thread_id);
7878
constauto ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::Write>(
79+
nullptr,
7980
pos,
8081
GenmcScalarExt::try_to_sval(old_val),
8182
ord,
@@ -100,7 +101,7 @@ void MiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_ty
100101

101102
voidMiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
102103
constauto pos = inc_pos(thread_id);
103-
GenMCDriver::handleFence(pos, ord, EventDeps());
104+
GenMCDriver::handleFence(nullptr, pos, ord, EventDeps());
104105
}
105106

106107
[[nodiscard]]autoMiriGenmcShim::handle_read_modify_write(
@@ -143,6 +144,7 @@ void MiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
143144

144145
constauto storePos = inc_pos(thread_id);
145146
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::FaiWrite>(
147+
nullptr,
146148
storePos,
147149
GenmcScalarExt::try_to_sval(old_val),
148150
ordering,
@@ -210,6 +212,7 @@ void MiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
210212

211213
constauto storePos = inc_pos(thread_id);
212214
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::CasWrite>(
215+
nullptr,
213216
storePos,
214217
GenmcScalarExt::try_to_sval(old_val),
215218
success_ordering,
@@ -242,6 +245,7 @@ auto MiriGenmcShim::handle_malloc(ThreadId thread_id, uint64_t size, uint64_t al
242245
constauto address_space = AddressSpace::AS_User;
243246

244247
const SVal ret_val = GenMCDriver::handleMalloc(
248+
nullptr,
245249
pos,
246250
size,
247251
alignment,
@@ -255,7 +259,7 @@ auto MiriGenmcShim::handle_malloc(ThreadId thread_id, uint64_t size, uint64_t al
255259

256260
autoMiriGenmcShim::handle_free(ThreadId thread_id, uint64_t address) -> bool {
257261
constauto pos = inc_pos(thread_id);
258-
GenMCDriver::handleFree(pos, SAddr(address), EventDeps());
262+
GenMCDriver::handleFree(nullptr, pos, SAddr(address), EventDeps());
259263
// FIXME(genmc): use returned error from `handleFree` once implemented in GenMC.
260264
returngetResult().status.has_value();
261265
}

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Exploration.cpp‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,23 @@ auto MiriGenmcShim::schedule_next(
2222
// a scheduling decision.
2323
threads_action_[curr_thread_id].kind = curr_thread_next_instr_kind;
2424

25-
if (constauto result = GenMCDriver::scheduleNext(threads_action_))
26-
return SchedulingResult { ExecutionState::Ok, static_cast<int32_t>(result.value()) };
27-
if (getExec().getGraph().isBlocked())
28-
return SchedulingResult { ExecutionState::Blocked, 0 };
29-
if (getResult().status.has_value()) // the "value" here is a `VerificationError`
30-
return SchedulingResult { ExecutionState::Error, 0 };
31-
return SchedulingResult { ExecutionState::Finished, 0 };
25+
auto result = GenMCDriver::scheduleNext(threads_action_);
26+
returnstd::visit(
27+
[](auto&& arg) {
28+
using T = std::decay_t<decltype(arg)>;
29+
ifconstexpr (std::is_same_v<T, int>)
30+
return SchedulingResult { ExecutionState::Ok, static_cast<int32_t>(arg) };
31+
elseifconstexpr (std::is_same_v<T, Blocked>)
32+
return SchedulingResult { ExecutionState::Blocked, 0 };
33+
elseifconstexpr (std::is_same_v<T, Error>)
34+
return SchedulingResult { ExecutionState::Error, 0 };
35+
elseifconstexpr (std::is_same_v<T, Finished>)
36+
return SchedulingResult { ExecutionState::Finished, 0 };
37+
else
38+
static_assert(false, "non-exhaustive visitor!");
39+
},
40+
result
41+
);
3242
}
3343

3444
/**** Execution start/end handling ****/

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Mutex.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ auto MiriGenmcShim::handle_mutex_lock(ThreadId thread_id, uint64_t address, uint
6060
constbool is_lock_acquired = *ret_val == MUTEX_UNLOCKED;
6161
if (is_lock_acquired) {
6262
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::LockCasWrite>(
63+
nullptr,
6364
inc_pos(thread_id),
6465
old_val,
6566
address,
@@ -93,6 +94,7 @@ auto MiriGenmcShim::handle_mutex_try_lock(ThreadId thread_id, uint64_t address,
9394
// a mutex to be "unlocked".
9495
constauto old_val = MUTEX_UNLOCKED;
9596
constauto load_ret = GenMCDriver::handleLoad<EventLabel::EventLabelKind::TrylockCasRead>(
97+
nullptr,
9698
++currPos,
9799
old_val,
98100
SAddr(address),
@@ -115,6 +117,7 @@ auto MiriGenmcShim::handle_mutex_try_lock(ThreadId thread_id, uint64_t address,
115117
}
116118

117119
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::TrylockCasWrite>(
120+
nullptr,
118121
++currPos,
119122
old_val,
120123
SAddr(address),
@@ -136,6 +139,7 @@ auto MiriGenmcShim::handle_mutex_unlock(ThreadId thread_id, uint64_t address, ui
136139
-> StoreResult {
137140
constauto pos = inc_pos(thread_id);
138141
constauto ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::UnlockWrite>(
142+
nullptr,
139143
pos,
140144
// As usual, we need to tell GenMC which value was stored at this location before this
141145
// atomic access, if there previously was a non-atomic initializing access. We set the

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Setup.cpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,16 @@ static auto to_genmc_verbosity_level(const LogLevel log_level) -> VerbosityLevel
147147
// that is allowed to leak and memory that is not.
148148
conf->warnUnfreedMemory = false;
149149

150-
// FIXME(genmc,error handling): This function currently exits on error, but will return an
151-
// error value in the future. The return value should be checked once this change is made.
152-
checkConfig(*conf);
150+
// Validate the config and exit if there are any errors
151+
std::vector<std::string> warnings;
152+
auto config_valid = conf->validate(warnings);
153+
for (constauto& w : warnings)
154+
WARN("{}", w);
155+
if (auto* errors = std::get_if<ConfigErrorList>(&config_valid); errors) {
156+
for (constauto& e : *errors)
157+
LOG(VerbosityLevel::Error, "{}", e);
158+
exit(EUSER);
159+
}
153160

154161
// Create the actual driver and Miri-GenMC communication shim.
155162
auto driver = std::make_unique<MiriGenmcShim>(std::move(conf), mode);

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/ThreadManagement.cpp‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ void MiriGenmcShim::handle_thread_create(ThreadId thread_id, ThreadId parent_id)
1919
// FIXME(genmc): for supporting symmetry reduction, these will need to be properly set:
2020
constunsigned fun_id = 0;
2121
const SVal arg = SVal(0);
22-
const ThreadInfo child_info = ThreadInfo { thread_id, parent_id, fun_id, arg };
22+
const ThreadInfo child_info =
23+
ThreadInfo { thread_id, parent_id, fun_id, arg, "unknown thread" };
2324

2425
// NOTE: Default memory ordering (`Release`) used here.
25-
constauto child_tid = GenMCDriver::handleThreadCreate(pos, child_info, EventDeps());
26+
constauto child_tid = GenMCDriver::handleThreadCreate(nullptr, pos, child_info, EventDeps());
2627
// Sanity check the thread id, which is the index in the `threads_action_` array.
2728
BUG_ON(child_tid != thread_id || child_tid <= 0 || child_tid != threads_action_.size());
2829
threads_action_.push_back(Action(ActionKind::Load, Event(child_tid, 0)));
@@ -33,7 +34,7 @@ void MiriGenmcShim::handle_thread_join(ThreadId thread_id, ThreadId child_id) {
3334
constauto pos = inc_pos(thread_id);
3435

3536
// NOTE: Default memory ordering (`Acquire`) used here.
36-
constauto ret = GenMCDriver::handleThreadJoin(pos, child_id, EventDeps());
37+
constauto ret = GenMCDriver::handleThreadJoin(nullptr, pos, child_id, EventDeps());
3738
// If the join failed, decrease the event index again:
3839
if (!std::holds_alternative<SVal>(ret)) {
3940
dec_pos(thread_id);
@@ -46,10 +47,10 @@ void MiriGenmcShim::handle_thread_join(ThreadId thread_id, ThreadId child_id) {
4647
voidMiriGenmcShim::handle_thread_finish(ThreadId thread_id, uint64_t ret_val) {
4748
constauto pos = inc_pos(thread_id);
4849
// NOTE: Default memory ordering (`Release`) used here.
49-
GenMCDriver::handleThreadFinish(pos, SVal(ret_val));
50+
GenMCDriver::handleThreadFinish(nullptr, pos, SVal(ret_val));
5051
}
5152

5253
voidMiriGenmcShim::handle_thread_kill(ThreadId thread_id) {
5354
constauto pos = inc_pos(thread_id);
54-
GenMCDriver::handleThreadKill(pos);
55+
GenMCDriver::handleThreadKill(nullptr, pos);
5556
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 8e39bff

Browse files
authored
Merge pull request #4697 from michaliskok/genmc-llvm-dep
genmc: Build without LLVM; adjust to API changes
2 parents 5bb385d + 26bd441 commit 8e39bff

8 files changed

Lines changed: 53 additions & 80 deletions

File tree

‎src/tools/miri/genmc-sys/build.rs‎

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mod downloading {
2828
/// The GenMC repository the we get our commit from.
2929
pub(crate)constGENMC_GITHUB_URL:&str = "https://github.com/MPI-SWS/genmc.git";
3030
/// The GenMC commit we depend on. It must be available on the specified GenMC repository.
31-
pub(crate)constGENMC_COMMIT:&str = "d9527280bb99f1cef64326b1803ffd952e3880df";
31+
pub(crate)constGENMC_COMMIT:&str = "aa10ed65117c3291524efc19253b5d443a4602ac";
3232

3333
/// Ensure that a local GenMC repo is present and set to the correct commit.
3434
/// Return the path of the GenMC repo and whether the checked out commit was changed.
@@ -140,51 +140,6 @@ mod downloading {
140140
}
141141
}
142142

143-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
144-
/// The linked LLVM version is in the generated `config.h`` file, which we parse and use to link to LLVM.
145-
/// Returns c++ compiler definitions required for building with/including LLVM, and the include path for LLVM headers.
146-
fnlink_to_llvm(config_file:&Path) -> (String,String){
147-
/// Search a string for a line matching `//@VARIABLE_NAME: VARIABLE CONTENT`
148-
fnextract_value<'a>(input:&'astr,name:&str) -> Option<&'astr>{
149-
input
150-
.lines()
151-
.find_map(|line| line.strip_prefix("//@")?.strip_prefix(name)?.strip_prefix(": "))
152-
}
153-
154-
let file_content = std::fs::read_to_string(&config_file).unwrap_or_else(|err| {
155-
panic!("GenMC config file ({}) should exist, but got errror {err:?}", config_file.display())
156-
});
157-
158-
let llvm_definitions = extract_value(&file_content,"LLVM_DEFINITIONS")
159-
.expect("Config file should contain LLVM_DEFINITIONS");
160-
let llvm_include_dirs = extract_value(&file_content,"LLVM_INCLUDE_DIRS")
161-
.expect("Config file should contain LLVM_INCLUDE_DIRS");
162-
let llvm_library_dir = extract_value(&file_content,"LLVM_LIBRARY_DIR")
163-
.expect("Config file should contain LLVM_LIBRARY_DIR");
164-
let llvm_config_path = extract_value(&file_content,"LLVM_CONFIG_PATH")
165-
.expect("Config file should contain LLVM_CONFIG_PATH");
166-
167-
// Add linker search path.
168-
let lib_dir = PathBuf::from_str(llvm_library_dir).unwrap();
169-
println!("cargo::rustc-link-search=native={}", lib_dir.display());
170-
171-
// Add libraries to link.
172-
let output = std::process::Command::new(llvm_config_path)
173-
.arg("--libs")// Print the libraries to link to (space-separated list)
174-
.output()
175-
.expect("failed to execute llvm-config");
176-
let llvm_link_libs =
177-
String::try_from(output.stdout).expect("llvm-config output should be a valid string");
178-
179-
for link_lib in llvm_link_libs.trim().split(" "){
180-
let link_lib =
181-
link_lib.strip_prefix("-l").expect("Linker parameter should start with \"-l\"");
182-
println!("cargo::rustc-link-lib=dylib={link_lib}");
183-
}
184-
185-
(llvm_definitions.to_string(), llvm_include_dirs.to_string())
186-
}
187-
188143
/// Build the GenMC model checker library and the Rust-C++ interop library with cxx.rs
189144
fncompile_cpp_dependencies(genmc_path:&Path,always_configure:bool){
190145
// Give each step a separate build directory to prevent interference.
@@ -204,6 +159,7 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
204159
.always_configure(always_configure)// We force running the configure step when the GenMC commit changed.
205160
.out_dir(genmc_build_dir)
206161
.profile(GENMC_CMAKE_PROFILE)
162+
.define("BUILD_LLI","OFF")
207163
.define("GENMC_DEBUG",if enable_genmc_debug {"ON"}else{"OFF"});
208164

209165
// The actual compilation happens here:
@@ -214,19 +170,11 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
214170
println!("cargo::rustc-link-search=native={}", cmake_lib_dir.display());
215171
println!("cargo::rustc-link-lib=static={GENMC_MODEL_CHECKER}");
216172

217-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
218-
let config_file = genmc_install_dir.join("include").join("genmc").join("config.h");
219-
let(llvm_definitions, llvm_include_dirs) = link_to_llvm(&config_file);
220-
221173
// Part 2:
222174
// Compile the cxx_bridge (the link between the Rust and C++ code).
223175

224176
let genmc_include_dir = genmc_install_dir.join("include").join("genmc");
225177

226-
// FIXME(genmc,llvm): remove once LLVM dependency is removed.
227-
// These definitions are parsed into a cmake list and then printed to the config.h file, so they are ';' separated.
228-
let definitions = llvm_definitions.split(";");
229-
230178
// These are all the C++ files we need to compile, which needs to be updated if more C++ files are added to Miri.
231179
// We use absolute paths since relative paths can confuse IDEs when attempting to go-to-source on a path in a compiler error.
232180
let cpp_files_base_path = Path::new("cpp/src/");
@@ -244,16 +192,12 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
244192
if enable_genmc_debug {
245193
bridge.define("ENABLE_GENMC_DEBUG",None);
246194
}
247-
for definition in definitions {
248-
bridge.flag(definition);
249-
}
250195
bridge
251196
.opt_level(2)
252197
.debug(true)// Same settings that GenMC uses (default for cmake `RelWithDebInfo`)
253198
.warnings(false)// NOTE: enabling this produces a lot of warnings.
254199
.std("c++23")
255200
.include(genmc_include_dir)
256-
.include(llvm_include_dirs)
257201
.include("./cpp/include")
258202
.files(&cpp_files)
259203
.out_dir(interface_build_dir)

‎src/tools/miri/genmc-sys/cpp/include/MiriInterface.hpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ struct MiriGenmcShim : private GenMCDriver {
220220
autohandle_load_reset_if_none(ThreadId tid, std::optional<SVal> old_val, Ts&&... params)
221221
-> HandleResult<SVal> {
222222
constauto pos = inc_pos(tid);
223-
constauto ret = GenMCDriver::handleLoad<k>(pos, old_val, std::forward<Ts>(params)...);
223+
constauto ret =
224+
GenMCDriver::handleLoad<k>(nullptr, pos, old_val, std::forward<Ts>(params)...);
224225
// If we didn't get a value, we have to reset the index of the current thread.
225226
if (!std::holds_alternative<SVal>(ret)) {
226227
dec_pos(tid);

‎src/tools/miri/genmc-sys/cpp/include/ResultHandling.hpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
// GenMC headers:
88
#include"Verification/VerificationError.hpp"
99

10+
#include<format>
11+
#include<memory>
12+
#include<sstream>
1013
#include<string>
1114

1215
/** Information about an error, formatted as a string to avoid having to share an error enum and
1316
* printing functionality with the Rust side. */
1417
staticautoformat_error(VerificationError err) -> std::unique_ptr<std::string> {
15-
auto buf = std::string();
16-
auto s = llvm::raw_string_ostream(buf);
17-
s << err;
18+
std::stringstream s;
19+
s << std::format("{}", err);
1820
return std::make_unique<std::string>(s.str());
1921
}
2022

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/EventHandling.cpp‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
voidMiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_type) {
3636
BUG_ON(getExec().getGraph().isThreadBlocked(thread_id));
37-
GenMCDriver::handleAssume(inc_pos(thread_id), assume_type);
37+
GenMCDriver::handleAssume(nullptr, inc_pos(thread_id), assume_type);
3838
}
3939

4040
/**** Memory access handling ****/
@@ -76,6 +76,7 @@ void MiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_ty
7676
) -> StoreResult {
7777
constauto pos = inc_pos(thread_id);
7878
constauto ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::Write>(
79+
nullptr,
7980
pos,
8081
GenmcScalarExt::try_to_sval(old_val),
8182
ord,
@@ -100,7 +101,7 @@ void MiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_ty
100101

101102
voidMiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
102103
constauto pos = inc_pos(thread_id);
103-
GenMCDriver::handleFence(pos, ord, EventDeps());
104+
GenMCDriver::handleFence(nullptr, pos, ord, EventDeps());
104105
}
105106

106107
[[nodiscard]]autoMiriGenmcShim::handle_read_modify_write(
@@ -143,6 +144,7 @@ void MiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
143144

144145
constauto storePos = inc_pos(thread_id);
145146
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::FaiWrite>(
147+
nullptr,
146148
storePos,
147149
GenmcScalarExt::try_to_sval(old_val),
148150
ordering,
@@ -210,6 +212,7 @@ void MiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
210212

211213
constauto storePos = inc_pos(thread_id);
212214
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::CasWrite>(
215+
nullptr,
213216
storePos,
214217
GenmcScalarExt::try_to_sval(old_val),
215218
success_ordering,
@@ -242,6 +245,7 @@ auto MiriGenmcShim::handle_malloc(ThreadId thread_id, uint64_t size, uint64_t al
242245
constauto address_space = AddressSpace::AS_User;
243246

244247
const SVal ret_val = GenMCDriver::handleMalloc(
248+
nullptr,
245249
pos,
246250
size,
247251
alignment,
@@ -255,7 +259,7 @@ auto MiriGenmcShim::handle_malloc(ThreadId thread_id, uint64_t size, uint64_t al
255259

256260
autoMiriGenmcShim::handle_free(ThreadId thread_id, uint64_t address) -> bool {
257261
constauto pos = inc_pos(thread_id);
258-
GenMCDriver::handleFree(pos, SAddr(address), EventDeps());
262+
GenMCDriver::handleFree(nullptr, pos, SAddr(address), EventDeps());
259263
// FIXME(genmc): use returned error from `handleFree` once implemented in GenMC.
260264
returngetResult().status.has_value();
261265
}

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Exploration.cpp‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,23 @@ auto MiriGenmcShim::schedule_next(
2222
// a scheduling decision.
2323
threads_action_[curr_thread_id].kind = curr_thread_next_instr_kind;
2424

25-
if (constauto result = GenMCDriver::scheduleNext(threads_action_))
26-
return SchedulingResult { ExecutionState::Ok, static_cast<int32_t>(result.value()) };
27-
if (getExec().getGraph().isBlocked())
28-
return SchedulingResult { ExecutionState::Blocked, 0 };
29-
if (getResult().status.has_value()) // the "value" here is a `VerificationError`
30-
return SchedulingResult { ExecutionState::Error, 0 };
31-
return SchedulingResult { ExecutionState::Finished, 0 };
25+
auto result = GenMCDriver::scheduleNext(threads_action_);
26+
returnstd::visit(
27+
[](auto&& arg) {
28+
using T = std::decay_t<decltype(arg)>;
29+
ifconstexpr (std::is_same_v<T, int>)
30+
return SchedulingResult { ExecutionState::Ok, static_cast<int32_t>(arg) };
31+
elseifconstexpr (std::is_same_v<T, Blocked>)
32+
return SchedulingResult { ExecutionState::Blocked, 0 };
33+
elseifconstexpr (std::is_same_v<T, Error>)
34+
return SchedulingResult { ExecutionState::Error, 0 };
35+
elseifconstexpr (std::is_same_v<T, Finished>)
36+
return SchedulingResult { ExecutionState::Finished, 0 };
37+
else
38+
static_assert(false, "non-exhaustive visitor!");
39+
},
40+
result
41+
);
3242
}
3343

3444
/**** Execution start/end handling ****/

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Mutex.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ auto MiriGenmcShim::handle_mutex_lock(ThreadId thread_id, uint64_t address, uint
6060
constbool is_lock_acquired = *ret_val == MUTEX_UNLOCKED;
6161
if (is_lock_acquired) {
6262
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::LockCasWrite>(
63+
nullptr,
6364
inc_pos(thread_id),
6465
old_val,
6566
address,
@@ -93,6 +94,7 @@ auto MiriGenmcShim::handle_mutex_try_lock(ThreadId thread_id, uint64_t address,
9394
// a mutex to be "unlocked".
9495
constauto old_val = MUTEX_UNLOCKED;
9596
constauto load_ret = GenMCDriver::handleLoad<EventLabel::EventLabelKind::TrylockCasRead>(
97+
nullptr,
9698
++currPos,
9799
old_val,
98100
SAddr(address),
@@ -115,6 +117,7 @@ auto MiriGenmcShim::handle_mutex_try_lock(ThreadId thread_id, uint64_t address,
115117
}
116118

117119
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::TrylockCasWrite>(
120+
nullptr,
118121
++currPos,
119122
old_val,
120123
SAddr(address),
@@ -136,6 +139,7 @@ auto MiriGenmcShim::handle_mutex_unlock(ThreadId thread_id, uint64_t address, ui
136139
-> StoreResult {
137140
constauto pos = inc_pos(thread_id);
138141
constauto ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::UnlockWrite>(
142+
nullptr,
139143
pos,
140144
// As usual, we need to tell GenMC which value was stored at this location before this
141145
// atomic access, if there previously was a non-atomic initializing access. We set the

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Setup.cpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,16 @@ static auto to_genmc_verbosity_level(const LogLevel log_level) -> VerbosityLevel
147147
// that is allowed to leak and memory that is not.
148148
conf->warnUnfreedMemory = false;
149149

150-
// FIXME(genmc,error handling): This function currently exits on error, but will return an
151-
// error value in the future. The return value should be checked once this change is made.
152-
checkConfig(*conf);
150+
// Validate the config and exit if there are any errors
151+
std::vector<std::string> warnings;
152+
auto config_valid = conf->validate(warnings);
153+
for (constauto& w : warnings)
154+
WARN("{}", w);
155+
if (auto* errors = std::get_if<ConfigErrorList>(&config_valid); errors) {
156+
for (constauto& e : *errors)
157+
LOG(VerbosityLevel::Error, "{}", e);
158+
exit(EUSER);
159+
}
153160

154161
// Create the actual driver and Miri-GenMC communication shim.
155162
auto driver = std::make_unique<MiriGenmcShim>(std::move(conf), mode);

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/ThreadManagement.cpp‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ void MiriGenmcShim::handle_thread_create(ThreadId thread_id, ThreadId parent_id)
1919
// FIXME(genmc): for supporting symmetry reduction, these will need to be properly set:
2020
constunsigned fun_id = 0;
2121
const SVal arg = SVal(0);
22-
const ThreadInfo child_info = ThreadInfo { thread_id, parent_id, fun_id, arg };
22+
const ThreadInfo child_info =
23+
ThreadInfo { thread_id, parent_id, fun_id, arg, "unknown thread" };
2324

2425
// NOTE: Default memory ordering (`Release`) used here.
25-
constauto child_tid = GenMCDriver::handleThreadCreate(pos, child_info, EventDeps());
26+
constauto child_tid = GenMCDriver::handleThreadCreate(nullptr, pos, child_info, EventDeps());
2627
// Sanity check the thread id, which is the index in the `threads_action_` array.
2728
BUG_ON(child_tid != thread_id || child_tid <= 0 || child_tid != threads_action_.size());
2829
threads_action_.push_back(Action(ActionKind::Load, Event(child_tid, 0)));
@@ -33,7 +34,7 @@ void MiriGenmcShim::handle_thread_join(ThreadId thread_id, ThreadId child_id) {
3334
constauto pos = inc_pos(thread_id);
3435

3536
// NOTE: Default memory ordering (`Acquire`) used here.
36-
constauto ret = GenMCDriver::handleThreadJoin(pos, child_id, EventDeps());
37+
constauto ret = GenMCDriver::handleThreadJoin(nullptr, pos, child_id, EventDeps());
3738
// If the join failed, decrease the event index again:
3839
if (!std::holds_alternative<SVal>(ret)) {
3940
dec_pos(thread_id);
@@ -46,10 +47,10 @@ void MiriGenmcShim::handle_thread_join(ThreadId thread_id, ThreadId child_id) {
4647
voidMiriGenmcShim::handle_thread_finish(ThreadId thread_id, uint64_t ret_val) {
4748
constauto pos = inc_pos(thread_id);
4849
// NOTE: Default memory ordering (`Release`) used here.
49-
GenMCDriver::handleThreadFinish(pos, SVal(ret_val));
50+
GenMCDriver::handleThreadFinish(nullptr, pos, SVal(ret_val));
5051
}
5152

5253
voidMiriGenmcShim::handle_thread_kill(ThreadId thread_id) {
5354
constauto pos = inc_pos(thread_id);
54-
GenMCDriver::handleThreadKill(pos);
55+
GenMCDriver::handleThreadKill(nullptr, pos);
5556
}

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Commit 8e39bff

Browse files
authored
Merge pull request #4697 from michaliskok/genmc-llvm-dep
genmc: Build without LLVM; adjust to API changes
2 parents 5bb385d + 26bd441 commit 8e39bff

8 files changed

Lines changed: 53 additions & 80 deletions

File tree

‎src/tools/miri/genmc-sys/build.rs‎

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mod downloading {
2828
/// The GenMC repository the we get our commit from.
2929
pub(crate)constGENMC_GITHUB_URL:&str = "https://github.com/MPI-SWS/genmc.git";
3030
/// The GenMC commit we depend on. It must be available on the specified GenMC repository.
31-
pub(crate)constGENMC_COMMIT:&str = "d9527280bb99f1cef64326b1803ffd952e3880df";
31+
pub(crate)constGENMC_COMMIT:&str = "aa10ed65117c3291524efc19253b5d443a4602ac";
3232

3333
/// Ensure that a local GenMC repo is present and set to the correct commit.
3434
/// Return the path of the GenMC repo and whether the checked out commit was changed.
@@ -140,51 +140,6 @@ mod downloading {
140140
}
141141
}
142142

143-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
144-
/// The linked LLVM version is in the generated `config.h`` file, which we parse and use to link to LLVM.
145-
/// Returns c++ compiler definitions required for building with/including LLVM, and the include path for LLVM headers.
146-
fnlink_to_llvm(config_file:&Path) -> (String,String){
147-
/// Search a string for a line matching `//@VARIABLE_NAME: VARIABLE CONTENT`
148-
fnextract_value<'a>(input:&'astr,name:&str) -> Option<&'astr>{
149-
input
150-
.lines()
151-
.find_map(|line| line.strip_prefix("//@")?.strip_prefix(name)?.strip_prefix(": "))
152-
}
153-
154-
let file_content = std::fs::read_to_string(&config_file).unwrap_or_else(|err| {
155-
panic!("GenMC config file ({}) should exist, but got errror {err:?}", config_file.display())
156-
});
157-
158-
let llvm_definitions = extract_value(&file_content,"LLVM_DEFINITIONS")
159-
.expect("Config file should contain LLVM_DEFINITIONS");
160-
let llvm_include_dirs = extract_value(&file_content,"LLVM_INCLUDE_DIRS")
161-
.expect("Config file should contain LLVM_INCLUDE_DIRS");
162-
let llvm_library_dir = extract_value(&file_content,"LLVM_LIBRARY_DIR")
163-
.expect("Config file should contain LLVM_LIBRARY_DIR");
164-
let llvm_config_path = extract_value(&file_content,"LLVM_CONFIG_PATH")
165-
.expect("Config file should contain LLVM_CONFIG_PATH");
166-
167-
// Add linker search path.
168-
let lib_dir = PathBuf::from_str(llvm_library_dir).unwrap();
169-
println!("cargo::rustc-link-search=native={}", lib_dir.display());
170-
171-
// Add libraries to link.
172-
let output = std::process::Command::new(llvm_config_path)
173-
.arg("--libs")// Print the libraries to link to (space-separated list)
174-
.output()
175-
.expect("failed to execute llvm-config");
176-
let llvm_link_libs =
177-
String::try_from(output.stdout).expect("llvm-config output should be a valid string");
178-
179-
for link_lib in llvm_link_libs.trim().split(" "){
180-
let link_lib =
181-
link_lib.strip_prefix("-l").expect("Linker parameter should start with \"-l\"");
182-
println!("cargo::rustc-link-lib=dylib={link_lib}");
183-
}
184-
185-
(llvm_definitions.to_string(), llvm_include_dirs.to_string())
186-
}
187-
188143
/// Build the GenMC model checker library and the Rust-C++ interop library with cxx.rs
189144
fncompile_cpp_dependencies(genmc_path:&Path,always_configure:bool){
190145
// Give each step a separate build directory to prevent interference.
@@ -204,6 +159,7 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
204159
.always_configure(always_configure)// We force running the configure step when the GenMC commit changed.
205160
.out_dir(genmc_build_dir)
206161
.profile(GENMC_CMAKE_PROFILE)
162+
.define("BUILD_LLI","OFF")
207163
.define("GENMC_DEBUG",if enable_genmc_debug {"ON"}else{"OFF"});
208164

209165
// The actual compilation happens here:
@@ -214,19 +170,11 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
214170
println!("cargo::rustc-link-search=native={}", cmake_lib_dir.display());
215171
println!("cargo::rustc-link-lib=static={GENMC_MODEL_CHECKER}");
216172

217-
// FIXME(genmc,llvm): Remove once the LLVM dependency of the GenMC model checker is removed.
218-
let config_file = genmc_install_dir.join("include").join("genmc").join("config.h");
219-
let(llvm_definitions, llvm_include_dirs) = link_to_llvm(&config_file);
220-
221173
// Part 2:
222174
// Compile the cxx_bridge (the link between the Rust and C++ code).
223175

224176
let genmc_include_dir = genmc_install_dir.join("include").join("genmc");
225177

226-
// FIXME(genmc,llvm): remove once LLVM dependency is removed.
227-
// These definitions are parsed into a cmake list and then printed to the config.h file, so they are ';' separated.
228-
let definitions = llvm_definitions.split(";");
229-
230178
// These are all the C++ files we need to compile, which needs to be updated if more C++ files are added to Miri.
231179
// We use absolute paths since relative paths can confuse IDEs when attempting to go-to-source on a path in a compiler error.
232180
let cpp_files_base_path = Path::new("cpp/src/");
@@ -244,16 +192,12 @@ fn compile_cpp_dependencies(genmc_path: &Path, always_configure: bool) {
244192
if enable_genmc_debug {
245193
bridge.define("ENABLE_GENMC_DEBUG",None);
246194
}
247-
for definition in definitions {
248-
bridge.flag(definition);
249-
}
250195
bridge
251196
.opt_level(2)
252197
.debug(true)// Same settings that GenMC uses (default for cmake `RelWithDebInfo`)
253198
.warnings(false)// NOTE: enabling this produces a lot of warnings.
254199
.std("c++23")
255200
.include(genmc_include_dir)
256-
.include(llvm_include_dirs)
257201
.include("./cpp/include")
258202
.files(&cpp_files)
259203
.out_dir(interface_build_dir)

‎src/tools/miri/genmc-sys/cpp/include/MiriInterface.hpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ struct MiriGenmcShim : private GenMCDriver {
220220
autohandle_load_reset_if_none(ThreadId tid, std::optional<SVal> old_val, Ts&&... params)
221221
-> HandleResult<SVal> {
222222
constauto pos = inc_pos(tid);
223-
constauto ret = GenMCDriver::handleLoad<k>(pos, old_val, std::forward<Ts>(params)...);
223+
constauto ret =
224+
GenMCDriver::handleLoad<k>(nullptr, pos, old_val, std::forward<Ts>(params)...);
224225
// If we didn't get a value, we have to reset the index of the current thread.
225226
if (!std::holds_alternative<SVal>(ret)) {
226227
dec_pos(tid);

‎src/tools/miri/genmc-sys/cpp/include/ResultHandling.hpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
// GenMC headers:
88
#include"Verification/VerificationError.hpp"
99

10+
#include<format>
11+
#include<memory>
12+
#include<sstream>
1013
#include<string>
1114

1215
/** Information about an error, formatted as a string to avoid having to share an error enum and
1316
* printing functionality with the Rust side. */
1417
staticautoformat_error(VerificationError err) -> std::unique_ptr<std::string> {
15-
auto buf = std::string();
16-
auto s = llvm::raw_string_ostream(buf);
17-
s << err;
18+
std::stringstream s;
19+
s << std::format("{}", err);
1820
return std::make_unique<std::string>(s.str());
1921
}
2022

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/EventHandling.cpp‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
voidMiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_type) {
3636
BUG_ON(getExec().getGraph().isThreadBlocked(thread_id));
37-
GenMCDriver::handleAssume(inc_pos(thread_id), assume_type);
37+
GenMCDriver::handleAssume(nullptr, inc_pos(thread_id), assume_type);
3838
}
3939

4040
/**** Memory access handling ****/
@@ -76,6 +76,7 @@ void MiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_ty
7676
) -> StoreResult {
7777
constauto pos = inc_pos(thread_id);
7878
constauto ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::Write>(
79+
nullptr,
7980
pos,
8081
GenmcScalarExt::try_to_sval(old_val),
8182
ord,
@@ -100,7 +101,7 @@ void MiriGenmcShim::handle_assume_block(ThreadId thread_id, AssumeType assume_ty
100101

101102
voidMiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
102103
constauto pos = inc_pos(thread_id);
103-
GenMCDriver::handleFence(pos, ord, EventDeps());
104+
GenMCDriver::handleFence(nullptr, pos, ord, EventDeps());
104105
}
105106

106107
[[nodiscard]]autoMiriGenmcShim::handle_read_modify_write(
@@ -143,6 +144,7 @@ void MiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
143144

144145
constauto storePos = inc_pos(thread_id);
145146
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::FaiWrite>(
147+
nullptr,
146148
storePos,
147149
GenmcScalarExt::try_to_sval(old_val),
148150
ordering,
@@ -210,6 +212,7 @@ void MiriGenmcShim::handle_fence(ThreadId thread_id, MemOrdering ord) {
210212

211213
constauto storePos = inc_pos(thread_id);
212214
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::CasWrite>(
215+
nullptr,
213216
storePos,
214217
GenmcScalarExt::try_to_sval(old_val),
215218
success_ordering,
@@ -242,6 +245,7 @@ auto MiriGenmcShim::handle_malloc(ThreadId thread_id, uint64_t size, uint64_t al
242245
constauto address_space = AddressSpace::AS_User;
243246

244247
const SVal ret_val = GenMCDriver::handleMalloc(
248+
nullptr,
245249
pos,
246250
size,
247251
alignment,
@@ -255,7 +259,7 @@ auto MiriGenmcShim::handle_malloc(ThreadId thread_id, uint64_t size, uint64_t al
255259

256260
autoMiriGenmcShim::handle_free(ThreadId thread_id, uint64_t address) -> bool {
257261
constauto pos = inc_pos(thread_id);
258-
GenMCDriver::handleFree(pos, SAddr(address), EventDeps());
262+
GenMCDriver::handleFree(nullptr, pos, SAddr(address), EventDeps());
259263
// FIXME(genmc): use returned error from `handleFree` once implemented in GenMC.
260264
returngetResult().status.has_value();
261265
}

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Exploration.cpp‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,23 @@ auto MiriGenmcShim::schedule_next(
2222
// a scheduling decision.
2323
threads_action_[curr_thread_id].kind = curr_thread_next_instr_kind;
2424

25-
if (constauto result = GenMCDriver::scheduleNext(threads_action_))
26-
return SchedulingResult { ExecutionState::Ok, static_cast<int32_t>(result.value()) };
27-
if (getExec().getGraph().isBlocked())
28-
return SchedulingResult { ExecutionState::Blocked, 0 };
29-
if (getResult().status.has_value()) // the "value" here is a `VerificationError`
30-
return SchedulingResult { ExecutionState::Error, 0 };
31-
return SchedulingResult { ExecutionState::Finished, 0 };
25+
auto result = GenMCDriver::scheduleNext(threads_action_);
26+
returnstd::visit(
27+
[](auto&& arg) {
28+
using T = std::decay_t<decltype(arg)>;
29+
ifconstexpr (std::is_same_v<T, int>)
30+
return SchedulingResult { ExecutionState::Ok, static_cast<int32_t>(arg) };
31+
elseifconstexpr (std::is_same_v<T, Blocked>)
32+
return SchedulingResult { ExecutionState::Blocked, 0 };
33+
elseifconstexpr (std::is_same_v<T, Error>)
34+
return SchedulingResult { ExecutionState::Error, 0 };
35+
elseifconstexpr (std::is_same_v<T, Finished>)
36+
return SchedulingResult { ExecutionState::Finished, 0 };
37+
else
38+
static_assert(false, "non-exhaustive visitor!");
39+
},
40+
result
41+
);
3242
}
3343

3444
/**** Execution start/end handling ****/

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Mutex.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ auto MiriGenmcShim::handle_mutex_lock(ThreadId thread_id, uint64_t address, uint
6060
constbool is_lock_acquired = *ret_val == MUTEX_UNLOCKED;
6161
if (is_lock_acquired) {
6262
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::LockCasWrite>(
63+
nullptr,
6364
inc_pos(thread_id),
6465
old_val,
6566
address,
@@ -93,6 +94,7 @@ auto MiriGenmcShim::handle_mutex_try_lock(ThreadId thread_id, uint64_t address,
9394
// a mutex to be "unlocked".
9495
constauto old_val = MUTEX_UNLOCKED;
9596
constauto load_ret = GenMCDriver::handleLoad<EventLabel::EventLabelKind::TrylockCasRead>(
97+
nullptr,
9698
++currPos,
9799
old_val,
98100
SAddr(address),
@@ -115,6 +117,7 @@ auto MiriGenmcShim::handle_mutex_try_lock(ThreadId thread_id, uint64_t address,
115117
}
116118

117119
constauto store_ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::TrylockCasWrite>(
120+
nullptr,
118121
++currPos,
119122
old_val,
120123
SAddr(address),
@@ -136,6 +139,7 @@ auto MiriGenmcShim::handle_mutex_unlock(ThreadId thread_id, uint64_t address, ui
136139
-> StoreResult {
137140
constauto pos = inc_pos(thread_id);
138141
constauto ret = GenMCDriver::handleStore<EventLabel::EventLabelKind::UnlockWrite>(
142+
nullptr,
139143
pos,
140144
// As usual, we need to tell GenMC which value was stored at this location before this
141145
// atomic access, if there previously was a non-atomic initializing access. We set the

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/Setup.cpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,16 @@ static auto to_genmc_verbosity_level(const LogLevel log_level) -> VerbosityLevel
147147
// that is allowed to leak and memory that is not.
148148
conf->warnUnfreedMemory = false;
149149

150-
// FIXME(genmc,error handling): This function currently exits on error, but will return an
151-
// error value in the future. The return value should be checked once this change is made.
152-
checkConfig(*conf);
150+
// Validate the config and exit if there are any errors
151+
std::vector<std::string> warnings;
152+
auto config_valid = conf->validate(warnings);
153+
for (constauto& w : warnings)
154+
WARN("{}", w);
155+
if (auto* errors = std::get_if<ConfigErrorList>(&config_valid); errors) {
156+
for (constauto& e : *errors)
157+
LOG(VerbosityLevel::Error, "{}", e);
158+
exit(EUSER);
159+
}
153160

154161
// Create the actual driver and Miri-GenMC communication shim.
155162
auto driver = std::make_unique<MiriGenmcShim>(std::move(conf), mode);

‎src/tools/miri/genmc-sys/cpp/src/MiriInterface/ThreadManagement.cpp‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ void MiriGenmcShim::handle_thread_create(ThreadId thread_id, ThreadId parent_id)
1919
// FIXME(genmc): for supporting symmetry reduction, these will need to be properly set:
2020
constunsigned fun_id = 0;
2121
const SVal arg = SVal(0);
22-
const ThreadInfo child_info = ThreadInfo { thread_id, parent_id, fun_id, arg };
22+
const ThreadInfo child_info =
23+
ThreadInfo { thread_id, parent_id, fun_id, arg, "unknown thread" };
2324

2425
// NOTE: Default memory ordering (`Release`) used here.
25-
constauto child_tid = GenMCDriver::handleThreadCreate(pos, child_info, EventDeps());
26+
constauto child_tid = GenMCDriver::handleThreadCreate(nullptr, pos, child_info, EventDeps());
2627
// Sanity check the thread id, which is the index in the `threads_action_` array.
2728
BUG_ON(child_tid != thread_id || child_tid <= 0 || child_tid != threads_action_.size());
2829
threads_action_.push_back(Action(ActionKind::Load, Event(child_tid, 0)));
@@ -33,7 +34,7 @@ void MiriGenmcShim::handle_thread_join(ThreadId thread_id, ThreadId child_id) {
3334
constauto pos = inc_pos(thread_id);
3435

3536
// NOTE: Default memory ordering (`Acquire`) used here.
36-
constauto ret = GenMCDriver::handleThreadJoin(pos, child_id, EventDeps());
37+
constauto ret = GenMCDriver::handleThreadJoin(nullptr, pos, child_id, EventDeps());
3738
// If the join failed, decrease the event index again:
3839
if (!std::holds_alternative<SVal>(ret)) {
3940
dec_pos(thread_id);
@@ -46,10 +47,10 @@ void MiriGenmcShim::handle_thread_join(ThreadId thread_id, ThreadId child_id) {
4647
voidMiriGenmcShim::handle_thread_finish(ThreadId thread_id, uint64_t ret_val) {
4748
constauto pos = inc_pos(thread_id);
4849
// NOTE: Default memory ordering (`Release`) used here.
49-
GenMCDriver::handleThreadFinish(pos, SVal(ret_val));
50+
GenMCDriver::handleThreadFinish(nullptr, pos, SVal(ret_val));
5051
}
5152

5253
voidMiriGenmcShim::handle_thread_kill(ThreadId thread_id) {
5354
constauto pos = inc_pos(thread_id);
54-
GenMCDriver::handleThreadKill(pos);
55+
GenMCDriver::handleThreadKill(nullptr, pos);
5556
}

0 commit comments

Comments
 (0)