4141OUT = Path (os .getenv ('OUT' , '/out' ))
4242INDEXES_PATH = Path (os .getenv ('INDEXES_PATH' , '/indexes' ))
4343INCREMENTAL_CDB_PATH = Path ('/incremental_cdb' )
44+ _GCC_BASE_PATH = Path ('/usr/lib/gcc/x86_64-linux-gnu' )
4445
4546_LD_BINARY = 'ld-linux-x86-64.so.2'
4647_LD_PATH = Path ('/lib64' ) / _LD_BINARY
48+ _DEFAULT_GCC_VERSION = '9'
4749_LLVM_READELF_PATH = '/usr/local/bin/llvm-readelf'
4850
4951DEFAULT_COVERAGE_FLAGS = '-fsanitize-coverage=bb,no-prune,trace-pc-guard'
@@ -391,6 +393,26 @@ def copy_fuzzing_engine(fuzzing_engine: str) -> Path:
391393 return fuzzing_engine_dir
392394
393395
396+ def _get_latest_gcc_version () -> str :
397+ """Finds the latest GCC version installed.
398+
399+ Defaults to '9' for backward compatibility if detection fails.
400+
401+ Returns:
402+ The latest GCC version found, or the default.
403+ """
404+ if _GCC_BASE_PATH .exists ():
405+ versions = []
406+ for d in _GCC_BASE_PATH .iterdir ():
407+ if d .is_dir () and d .name .isdigit ():
408+ versions .append (int (d .name ))
409+
410+ if versions :
411+ return str (max (versions ))
412+
413+ return _DEFAULT_GCC_VERSION
414+
415+
394416def build_project (
395417 targets_to_index : Sequence [str ] | None = None ,
396418 compile_args : Sequence [str ] | None = None ,
@@ -415,6 +437,7 @@ def build_project(
415437 )
416438
417439 fuzzing_engine_dir = copy_fuzzing_engine (DEFAULT_FUZZING_ENGINE )
440+ gcc_version = _get_latest_gcc_version ()
418441 build_fuzzing_engine_command = [
419442 f'{ _CLANG_TOOLCHAIN } /bin/clang++' ,
420443 '-c' ,
@@ -433,11 +456,11 @@ def build_project(
433456 f'{ OUT } /cdb' ,
434457 '-Qunused-arguments' ,
435458 f'-isystem { _CLANG_TOOLCHAIN } /lib/clang/{ clang_version } ' ,
436- '/usr/lib/gcc/x86_64-linux-gnu/9 /../../../../include/c++/9 ' ,
459+ f '/usr/lib/gcc/x86_64-linux-gnu/{ gcc_version } /../../../../include/c++/{ gcc_version } ' ,
437460 '-I' ,
438- '/usr/lib/gcc/x86_64-linux-gnu/9 /../../../../include/x86_64-linux-gnu/c++/9 ' ,
461+ f '/usr/lib/gcc/x86_64-linux-gnu/{ gcc_version } /../../../../include/x86_64-linux-gnu/c++/{ gcc_version } ' ,
439462 '-I' ,
440- '/usr/lib/gcc/x86_64-linux-gnu/9 /../../../../include/c++/9 /backward' ,
463+ f '/usr/lib/gcc/x86_64-linux-gnu/{ gcc_version } /../../../../include/c++/{ gcc_version } /backward' ,
441464 '-I' ,
442465 f'{ _CLANG_TOOLCHAIN } /lib/clang/{ clang_version } /include' ,
443466 '-I' ,
0 commit comments