Add gold support for --package-metadata option.
authorLuca Boccassi <bluca@debian.org>
Fri, 5 Aug 2022 00:19:52 +0000 (17:19 -0700)
committerCary Coutant <ccoutant@gmail.com>
Fri, 5 Aug 2022 00:37:32 +0000 (17:37 -0700)
commit701821154b110230f52a0367e120ecc51f490e56
treeffbb47ef447a2cbddafa2b2bd0bc5c220771b924
parent1369522f36eece1b37139a81f7f2139ba3915172
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.
13 files changed:
elfcpp/elfcpp.h
gold/Makefile.am
gold/Makefile.in
gold/aclocal.m4
gold/config.in
gold/configure
gold/configure.ac
gold/layout.cc
gold/layout.h
gold/options.h
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/testsuite/package_metadata_main.c [new file with mode: 0644]