Skip to content

Commit a99713a

Browse files
OSS-Fuzz Teamcopybara-github
authored andcommitted
clang_wrapper: More fixes to get V8 working.
- Automatically select indexer threads and merge queues for the indexer binary. Indexing V8 seems to be very slow. - Ignore simdutf.cpp: This file seems seems to break the indexer with ``` Failed to run action on /src/v8/third_party/simdutf/simdutf.cpp F0901 05:21:50.920894 6185 queue_state.cc:90] Check failed: (current & from) != 0 (0 vs. 0) Found kTaken while advancing kFinished -> kTaken *** Check failure stack trace: *** @ 0xe3bbc4 absl::lts_20250127::log_internal::LogMessage::SendToLog() @ 0xe3b5f2 absl::lts_20250127::log_internal::LogMessage::Flush() @ 0xe3c079 absl::lts_20250127::log_internal::LogMessageFatal::~LogMessageFatal() @ 0xe2821a oss_fuzz::indexer::QueueState::Advance() @ 0xe263e5 oss_fuzz::indexer::SingleThreadMergeQueue::TakeIndex() @ 0xe26b26 oss_fuzz::indexer::ParallelMergeQueue::TakeIndex() @ 0xe26acf oss_fuzz::indexer::ParallelMergeQueue::Cancel() @ 0xc92211 main @ 0x31e33a0 __libc_start_main ``` PiperOrigin-RevId: 801669979
1 parent 6158cd5 commit a99713a

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

infra/base-images/base-builder/indexer/clang_wrapper.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,32 @@
5757
"-ffile-compilation-dir=",
5858
)
5959

60+
_IGNORED_FILES = (
61+
# This file seems to cause a crash in the indexer, as well as performance
62+
# issues.
63+
"simdutf.cpp",
64+
)
65+
66+
_INDEXER_THREADS_PER_MERGE_QUEUE = 16
67+
_INDEXER_PER_THREAD_MEMORY = 2 * 1024**3 # 2 GiB
68+
6069
SRC = Path(os.getenv("SRC", "/src"))
6170
# On OSS-Fuzz build infra, $OUT is not /out.
6271
OUT = Path(os.getenv("OUT", "/out"))
6372
INDEXES_PATH = Path(os.getenv("INDEXES_PATH", "/indexes"))
6473
FUZZER_ENGINE = os.getenv("LIB_FUZZING_ENGINE", "/usr/lib/libFuzzingEngine.a")
6574

6675

76+
def _get_available_memory() -> int:
77+
"""Returns the available memory in bytes."""
78+
with open("/proc/meminfo", "r") as f:
79+
for line in f:
80+
if line.startswith("MemAvailable:"):
81+
return int(line.split()[1]) * 1024
82+
83+
raise RuntimeError("Failed to get available memory")
84+
85+
6786
def rewrite_argv0(argv: Sequence[str], clang_toolchain: str) -> list[str]:
6887
"""Rewrite argv[0] to point to the real clang location."""
6988
# We do this because we've set PATH to our wrapper.
@@ -318,6 +337,16 @@ def run_indexer(build_id: str, linker_commands: dict[str, Any]):
318337
with (compile_commands_dir / "full_compile_commands.json").open("wt") as f:
319338
json.dump(linker_commands["full_compile_commands"], f, indent=2)
320339

340+
# Auto-tune the number of threads and merge queues according to the number
341+
# of cores and available memory.
342+
# Note: this might require further tuning -- this might not work well if there
343+
# are multiple binaries being linked/indexed at the same time.
344+
num_cores = len(os.sched_getaffinity(0))
345+
num_threads = max(
346+
1, min(_get_available_memory() // _INDEXER_PER_THREAD_MEMORY, num_cores)
347+
)
348+
merge_queues = max(1, num_threads // _INDEXER_THREADS_PER_MERGE_QUEUE)
349+
321350
cmd = [
322351
_INDEXER_PATH,
323352
"--build_dir",
@@ -326,6 +355,10 @@ def run_indexer(build_id: str, linker_commands: dict[str, Any]):
326355
index_dir.as_posix(),
327356
"--source_dir",
328357
SRC.as_posix(),
358+
"--index_threads",
359+
str(num_threads),
360+
"--merge_queues",
361+
str(merge_queues),
329362
]
330363
result = subprocess.run(cmd, check=False, capture_output=True)
331364
if result.returncode != 0:
@@ -425,7 +458,7 @@ def _filter_compile_commands(
425458
directory = Path(compile_command["directory"])
426459

427460
cc_path = Path(directory / compile_command["file"])
428-
if cc_path in cu_paths:
461+
if cc_path in cu_paths and cc_path.name not in _IGNORED_FILES:
429462
filtered_compile_commands.append(compile_command)
430463
used_cu_paths.add(cc_path)
431464
else:

0 commit comments

Comments
 (0)