diff --git a/src/chromium.ts b/src/chromium.ts new file mode 100644 index 0000000..fcb8f0b --- /dev/null +++ b/src/chromium.ts @@ -0,0 +1,75 @@ +/** + * @file Declares chromium debugging functions and constants + */ + +import { spawn } from 'child_process'; +import * as gn from './commands/gn.js'; +import path from 'path'; +import { local } from './environment/index.js'; + + +/** + * Arguments to GN build, copied from README. + * + */ +export const gnArgs = (llvmInstall: string) => [ + 'is_clang=true', + 'clang_use_chrome_plugins=false', + 'is_debug=false', + 'use_goma=false', + 'use_sysroot=false', + 'use_openh264=false', + 'use_allocator="none"', + 'use_libjpeg_turbo=true', + 'use_gnome_keyring=false', + 'use_unofficial_version_number=false', + 'enable_nacl=false', + 'enable_nacl_nonsfi=false', + 'enable_swiftshader=false', + 'enable_reading_list=false', + 'enable_iterator_debugging=false', + 'enable_hangout_services_extension=false', + 'optimize_webui=false', + 'treat_warnings_as_errors=false', + 'linux_use_bundled_binutils=false', + 'remove_webcore_debug_symbols=true', + 'use_gio=true', + 'use_vaapi=false', + 'use_pulseaudio=true', + 'link_pulseaudio=true', + 'enable_widevine=true', + 'v8_enable_backtrace=true', + 'use_system_zlib=true', + 'use_system_lcms2=true', + 'use_system_libjpeg=true', + 'use_system_harfbuzz=false', + 'use_jumbo_build=true', + 'jumbo_file_merge_limit=8', + 'concurrent_links=1', + 'proprietary_codecs=true', + 'ffmpeg_branding="Chrome"', + 'fieldtrial_testing_like_official_build=true', + 'host_cpu="sw_64"', + 'use_lld=false', + 'enable_dav1d_decoder=false', + 'rtc_include_dav1d_in_internal_decoder_factory=false', + 'dcheck_always_on=false', + 'enable_libaom=false', + `clang_base_path="${llvmInstall}"` +]; + +/** + * Invoke meta-build system "gn", returns the process. + */ +export function configure(source: string, gnExe: string, outDir: string, gnArgs: string[]) { + return spawn(gnExe, [ + 'gen', + outDir, + ...gn.generalOptions({ args: gnArgs }), + ], { cwd: source }); +} + +/** + * Local directory for chromium - related debugging. + */ +export const dir = path.resolve(local, 'chromium') \ No newline at end of file diff --git a/src/chromium/mksnapshot.ts b/src/chromium/mksnapshot.ts new file mode 100644 index 0000000..650ea3b --- /dev/null +++ b/src/chromium/mksnapshot.ts @@ -0,0 +1,10 @@ +/** + * Wuxi reported "mksnapshot" is errorneous (RE, segmantation fault). + * This file addresses this issue. + */ + + +import path from 'path'; +import * as chromium from '../chromium.js' + +export const dir = path.resolve(chromium.dir, 'mksnapshot') \ No newline at end of file diff --git a/src/chromium/mksnapshot/compile-schedule.ts b/src/chromium/mksnapshot/compile-schedule.ts new file mode 100644 index 0000000..deee366 --- /dev/null +++ b/src/chromium/mksnapshot/compile-schedule.ts @@ -0,0 +1,148 @@ +import path from 'path'; +import { lycEnv } from '../../environment/index.js'; +import { llvmToolchain } from '../../toolchain/index.js'; +import { promisifySpawn } from '../../cli.js'; +import { spawn } from 'child_process'; +import { dir } from '../mksnapshot.js'; +import * as compiler from '../../commands/compiler.js'; + + +const hash = '7081b8371ae6460baabc370de4570ebd7e67f923'; + +const envToolchain = (hash: string) => llvmToolchain(path.resolve(lycEnv.sharedLLVMInstall, hash)); +const toolchain = envToolchain(hash); + +const args = [ + "-DUSE_UDEV", + "-DUSE_AURA=1", + "-DUSE_GLIB=1", + "-DUSE_OZONE=1", + "-D__STDC_CONSTANT_MACROS", + "-D__STDC_FORMAT_MACROS", + "-D_FORTIFY_SOURCE=2", + "-D_FILE_OFFSET_BITS=64", + "-D_LARGEFILE_SOURCE", + "-D_LARGEFILE64_SOURCE", + "-D_GNU_SOURCE", + "-D_LIBCPP_ABI_UNSTABLE", + "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS", + "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS", + "-D_LIBCPP_ENABLE_NODISCARD", + "-DCR_LIBCXX_REVISION=79a2e924d96e2fc1e4b937c42efd08898fa472d7", + "-DNDEBUG", + "-DNVALGRIND", + "-DDYNAMIC_ANNOTATIONS_ENABLED=0", + "-DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64", + "-DV8_INTL_SUPPORT", + "-DV8_USE_EXTERNAL_STARTUP_DATA", + "-DV8_ATOMIC_OBJECT_FIELD_WRITES", + "-DV8_ENABLE_LAZY_SOURCE_POSITIONS", + "-DV8_SHARED_RO_HEAP", + "-DV8_WIN64_UNWINDING_INFO", + "-DV8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH", + "-DV8_ENABLE_WEBASSEMBLY", + "-DV8_ALLOCATION_FOLDING", + "-DV8_ALLOCATION_SITE_TRACKING", + "-DV8_ADVANCED_BIGINT_ALGORITHMS", + "-DV8_DEPRECATION_WARNINGS", + "-DV8_TARGET_ARCH_SW64", + "-DSW64", + "-DV8_HAVE_TARGET_OS", + "-DV8_TARGET_OS_LINUX", + "-DU_USING_ICU_NAMESPACE=0", + "-DU_ENABLE_DYLOAD=0", + "-DUSE_CHROMIUM_ICU=1", + "-DU_ENABLE_TRACING=1", + "-DU_ENABLE_RESOURCE_TRACING=0", + "-DU_STATIC_IMPLEMENTATION", + "-DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE", + "-Wall", + "-Wextra", + "-Wimplicit-fallthrough", + "-Wunreachable-code-aggressive", + "-Wthread-safety", + "-Wno-missing-field-initializers", + "-Wno-unused-parameter", + "-Wloop-analysis", + "-Wno-unneeded-internal-declaration", + "-Wenum-compare-conditional", + "-Wno-psabi", + "-Wno-ignored-pragma-optimize", + "-Wno-unqualified-std-cast-call", + "-Wno-deprecated-non-prototype", + "-Wshadow", + "-fno-delete-null-pointer-checks", + "-fno-ident", + "-fno-strict-aliasing", + "--param=ssp-buffer-size=4", + "-fstack-protector", + "-funwind-tables", + "-fPIC", + "-pthread", + "-fcolor-diagnostics", + "-fmerge-all-constants", + "-mllvm", + "-instcombine-lower-dbg-declare=0", + "-ffp-contract=off", + "-fcomplete-member-pointers", + "-Wno-builtin-macro-redefined", + "-D__DATE__=", + "-D__TIME__=", + "-D__TIMESTAMP__=", + "-ffile-compilation-dir=.", + "-no-canonical-prefixes", + "-fno-omit-frame-pointer", + "-g0", + "-Wheader-hygiene", + "-Wstring-conversion", + "-Wtautological-overlap-compare", + "-Wmissing-field-initializers", + "-Wno-shadow", + "-Wunreachable-code", + "-O3", + "-fdata-sections", + "-ffunction-sections", + "-fvisibility=default", + "-Wexit-time-destructors", + "-std=c++17", + "-Wno-trigraphs", + "-fno-aligned-new", + "-fno-exceptions", + "-fno-rtti", +]; + +// Two processes, true/false simd settings. +const simdCompareProcesses = [true, false].map(simd => spawn( + toolchain.CXX, + [ + // Input file + path.resolve(dir, 'mksnapshot-schedule', 'error', 'schedule.i'), + // Fixed arguments. + ...args, + '-emit-llvm', + '-fno-discard-value-names', + ...compiler.generalCommand({ + output: '-', + outputKind: 'object', + }), + ...compiler.sw64TargetOptions({ simd }), + ] +)); + +// For each LLVM bitfile output, create a process to extract "_ZN2v88internal8compiler10BasicBlock18GetCommonDominatorEPS2_S3_" +const extractProcesses = simdCompareProcesses.map((x, index) => { + const functionName = "_ZN2v88internal8compiler10BasicBlock18GetCommonDominatorEPS2_S3_"; + const extract = spawn(toolchain.LLVM_EXTRACT, [ + ...compiler.extractCommand({ + func: [functionName], + input: "-", + output: path.resolve(dir, `${index}.ll`), + asm: true, + }) + ]); + x.stdout.pipe(extract.stdin); + return extract; +}); + + +await Promise.all([...extractProcesses, ...simdCompareProcesses].map(promisifySpawn)); \ No newline at end of file diff --git a/src/chromium/mksnapshot/decompress.ts b/src/chromium/mksnapshot/decompress.ts new file mode 100644 index 0000000..65288b6 --- /dev/null +++ b/src/chromium/mksnapshot/decompress.ts @@ -0,0 +1,21 @@ +/** + * Decompress the tarball for mksnapshot. + */ + +import { spawn } from 'child_process'; +import path from 'path'; +import { dir } from '../mksnapshot.js'; +import { promisifySpawn } from '../../cli.js'; +import { mkdir } from 'fs/promises'; + +const { HOME } = process.env; + + +await mkdir(dir, { recursive: true }); + +await promisifySpawn(spawn('tar', [ + '-xvzf', + path.resolve(HOME!, 'resources', 'mksnapshot_schedule.tar.gz'), + '-C', + dir +])); \ No newline at end of file