Skip to content

Truly independent web browser

Meta+UI: Write separate symbol files for Distribution builds

Jelle Raaijmakers08d807403b7c
diff --git a/Meta/CMake/cmake_options.cmake b/Meta/CMake/cmake_options.cmake
index 16584e6e42d..7a1e9a41281 100644
--- a/Meta/CMake/cmake_options.cmake
+++ b/Meta/CMake/cmake_options.cmake
@@ -34,6 +34,10 @@ option(ENABLE_INSTALL_HEADERS "Enable installing headers" ON)
option(ENABLE_INSTALL_FREEDESKTOP_FILES "Enable installing .desktop and .service files" ${freedesktop_files_default})
option(LADYBIRD_ENABLE_CPPTRACE "Enable use of cpptrace as the default library for stacktraces. If not available falls back to backtrace.h" ON)
option(LADYBIRD_GENERATE_DSYM "Generate dSYM bundles for binaries and libraries (macOS only)" OFF)
+option(LADYBIRD_GENERATE_SYMBOL_FILES "Build with debug info and write the symbols of the installed executables to separate files" OFF)
+if (LADYBIRD_GENERATE_SYMBOL_FILES AND MSVC)
+ message(FATAL_ERROR "LADYBIRD_GENERATE_SYMBOL_FILES is not supported with MSVC-style toolchains")
+endif()
option(ENABLE_CI_BASELINE_CPU "Use a baseline CPU target for improved ccache sharing" OFF)
# lto1 uses a crazy amount of RAM in static builds.
diff --git a/Meta/CMake/compile_options.cmake b/Meta/CMake/compile_options.cmake
index b0f56cf4bab..8e723048718 100644
--- a/Meta/CMake/compile_options.cmake
+++ b/Meta/CMake/compile_options.cmake
@@ -233,6 +233,13 @@ endif()
if (APPLE)
list(APPEND CMAKE_PREFIX_PATH /opt/homebrew)
add_cxx_link_options(LINKER:-dead_strip)
+
+ # The debug info of LTO code lives in the objects the linker generates, which it deletes after linking unless told
+ # where to keep them; dsymutil reads it from there.
+ if (LADYBIRD_GENERATE_SYMBOL_FILES)
+ file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/lto")
+ add_cxx_link_options("LINKER:-object_path_lto,${CMAKE_BINARY_DIR}/lto/$<TARGET_PROPERTY:NAME>")
+ endif()
endif()
if (HAIKU)
@@ -244,6 +251,7 @@ endif()
if (NOT WIN32)
add_cxx_link_option_if_supported(LINKER:--gdb-index)
+ add_cxx_link_option_if_supported(LINKER:--build-id)
if (NOT ENABLE_FUZZERS)
add_cxx_link_option_if_supported(LINKER:-Bsymbolic-non-weak-functions)
@@ -287,6 +295,11 @@ elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
if (NOT MSVC)
add_cxx_compile_options(-O3)
+
+ # Line tables, inlined frames included, are what symbolicating a crash report needs.
+ if (LADYBIRD_GENERATE_SYMBOL_FILES)
+ add_cxx_compile_options(-g1)
+ endif()
else()
add_cxx_compile_options(/O2)
endif()
diff --git a/Meta/CMake/presets/CMakeBasePresets.json b/Meta/CMake/presets/CMakeBasePresets.json
index 4fdc34ec566..3820d439e21 100644
--- a/Meta/CMake/presets/CMakeBasePresets.json
+++ b/Meta/CMake/presets/CMakeBasePresets.json
@@ -84,6 +84,7 @@
"cacheVariables": {
"BUILD_SHARED_LIBS": "OFF",
"CMAKE_BUILD_TYPE": "Release",
+ "LADYBIRD_GENERATE_SYMBOL_FILES": "ON",
"LADYBIRD_VCPKG_TYPE": "distribution"
}
},
diff --git a/Meta/CMake/rust_crate.cmake b/Meta/CMake/rust_crate.cmake
index ecf66156dc7..83b8866814c 100644
--- a/Meta/CMake/rust_crate.cmake
+++ b/Meta/CMake/rust_crate.cmake
@@ -395,6 +395,10 @@ function(_rust_crate_common_setup)
list(APPEND cargo_env "CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS=true")
endif()
+ if (LADYBIRD_GENERATE_SYMBOL_FILES)
+ list(APPEND cargo_env "CARGO_PROFILE_RELEASE_DEBUG=line-tables-only")
+ endif()
+
if (RUSTC_WRAPPER)
list(APPEND cargo_env
"RUSTC_WRAPPER=${RUSTC_WRAPPER}"
diff --git a/UI/cmake/InstallRules.cmake b/UI/cmake/InstallRules.cmake
index 39962f19738..2c634c5186b 100644
--- a/UI/cmake/InstallRules.cmake
+++ b/UI/cmake/InstallRules.cmake
@@ -89,6 +89,40 @@ install(TARGETS ${all_required_lagom_libraries}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
+if (LADYBIRD_GENERATE_SYMBOL_FILES)
+ set(symbol_files_dir "${CMAKE_BINARY_DIR}/symbols")
+ set(symbol_files)
+ foreach (target IN LISTS ladybird_applications)
+ get_target_property(name ${target} OUTPUT_NAME)
+ if (NOT name)
+ set(name ${target})
+ endif()
+ if (APPLE)
+ get_target_property(is_bundle ${target} MACOSX_BUNDLE)
+ if (is_bundle)
+ string(APPEND name ".app")
+ endif()
+ set(symbol_file "${symbol_files_dir}/${name}.dSYM")
+ set(output "${symbol_file}/Contents/Info.plist")
+ set(command dsymutil "$<TARGET_FILE:${target}>" -o "${symbol_file}")
+ else()
+ set(symbol_file "${symbol_files_dir}/${name}.debug")
+ set(output "${symbol_file}")
+ set(command "${CMAKE_OBJCOPY}" --only-keep-debug "$<TARGET_FILE:${target}>" "${symbol_file}")
+ endif()
+ add_custom_command(OUTPUT "${output}" COMMAND ${command} DEPENDS ${target}
+ COMMENT "Writing the symbols of ${name}" VERBATIM)
+ list(APPEND symbol_files "${output}")
+ endforeach()
+ add_custom_target(ladybird_symbol_files ALL DEPENDS ${symbol_files})
+
+ install(DIRECTORY "${symbol_files_dir}/"
+ DESTINATION .
+ COMPONENT ladybird_Symbols
+ EXCLUDE_FROM_ALL
+ )
+endif()
+
write_basic_package_version_file(
"${package}ConfigVersion.cmake"
COMPATIBILITY SameMajorVersion