From 701821154b110230f52a0367e120ecc51f490e56 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Thu, 4 Aug 2022 17:19:52 -0700 Subject: Add gold support for --package-metadata option. Following the same format as the implementation in ld: 9e2bb0cb5e74aed4158f08495534922d7108f928 Generate a .note.package FDO package metadata ELF note, following the spec: https://systemd.io/ELF_PACKAGE_METADATA/ If the jansson library is available at build time (and it is explicitly enabled), link ld to it, and use it to validate that the input is correct JSON, to avoid writing garbage to the file. The configure option --enable-jansson has to be used to explicitly enable it (error out when not found). This allows bootstrappers (or others who are not interested) to seamlessly skip it without issues. elfcpp/ * elfcpp.h: Add FDO_PACKAGING_METADATA note type. gold/ * Makefile.am: Add jansson flags and libraries. * configure.ac: Check for jansson library. * layout.cc (Layout::create_notes): Call create_package_metadata(). (Layout::create_package_metadata): New function. * layout.h (Layout::create_package_metadata): New function. (Layout::package_metadata_note_): New data member. * options.h (class General_options): Add --package-metadata option. * testsuite/Makefile.am (object_unittest): Add jansson libraries. (binary_unittest): Likewise. (leb128_unittest): Likewise. (overflow_unittest): Likewise. (package_metadata_test): New test. * testsuite/package_metadata_main.c: New test source. --- gold/layout.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gold/layout.h') diff --git a/gold/layout.h b/gold/layout.h index 98c03b93f5f..ee4f78c3c78 100644 --- a/gold/layout.h +++ b/gold/layout.h @@ -1107,6 +1107,10 @@ class Layout void create_build_id(); + // Create a package metadata note if needed. + void + create_package_metadata(); + // Link .stab and .stabstr sections. void link_stabs_sections(); @@ -1453,6 +1457,8 @@ class Layout Gdb_index* gdb_index_data_; // The space for the build ID checksum if there is one. Output_section_data* build_id_note_; + // The space for the package metadata JSON if there is one. + Output_section_data* package_metadata_note_; // The output section containing dwarf abbreviations Output_reduced_debug_abbrev_section* debug_abbrev_; // The output section containing the dwarf debug info tree -- cgit v1.2.1