Skip to content

Truly independent web browser

Meta: Lay out the Linux debug symbols by build ID

Jelle Raaijmakers02c04ec23399
diff --git a/Meta/CMake/write_symbol_file.cmake b/Meta/CMake/write_symbol_file.cmake
new file mode 100644
index 00000000000..c02d9eb848b
--- /dev/null
+++ b/Meta/CMake/write_symbol_file.cmake
@@ -0,0 +1,20 @@
+# Writes the debug info of the ELF binary BINARY to SYMBOL_FILES_DIR/.build-id/xx/yyyy.debug, where debuggers and
+# debuginfod look for it by build ID. The STAMP file remembers that path, so a relinked binary replaces its old file.
+
+execute_process(COMMAND "${READELF}" --notes "${BINARY}" OUTPUT_VARIABLE notes COMMAND_ERROR_IS_FATAL ANY)
+if (NOT notes MATCHES "Build ID: ([0-9a-f][0-9a-f])([0-9a-f]+)")
+ message(FATAL_ERROR "${BINARY} has no build ID")
+endif()
+set(symbol_file "${SYMBOL_FILES_DIR}/.build-id/${CMAKE_MATCH_1}/${CMAKE_MATCH_2}.debug")
+
+if (EXISTS "${STAMP}")
+ file(READ "${STAMP}" previous_symbol_file)
+ if (NOT previous_symbol_file STREQUAL symbol_file)
+ file(REMOVE "${previous_symbol_file}")
+ endif()
+endif()
+
+get_filename_component(symbol_file_dir "${symbol_file}" DIRECTORY)
+file(MAKE_DIRECTORY "${symbol_file_dir}")
+execute_process(COMMAND "${OBJCOPY}" --only-keep-debug "${BINARY}" "${symbol_file}" COMMAND_ERROR_IS_FATAL ANY)
+file(WRITE "${STAMP}" "${symbol_file}")
diff --git a/UI/cmake/InstallRules.cmake b/UI/cmake/InstallRules.cmake
index 200fba6f264..2580f97d104 100644
--- a/UI/cmake/InstallRules.cmake
+++ b/UI/cmake/InstallRules.cmake
@@ -121,9 +121,10 @@ if (LADYBIRD_GENERATE_SYMBOL_FILES)
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}")
+ set(output "${CMAKE_BINARY_DIR}/symbol_file_stamps/${name}")
+ set(command "${CMAKE_COMMAND}" "-DREADELF=${CMAKE_READELF}" "-DOBJCOPY=${CMAKE_OBJCOPY}"
+ "-DBINARY=$<TARGET_FILE:${target}>" "-DSYMBOL_FILES_DIR=${symbol_files_dir}" "-DSTAMP=${output}"
+ -P "${LADYBIRD_SOURCE_DIR}/Meta/CMake/write_symbol_file.cmake")
endif()
add_custom_command(OUTPUT "${output}" COMMAND ${command} DEPENDS ${target}
COMMENT "Writing the symbols of ${name}" VERBATIM)