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/testsuite/Makefile.am | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'gold/testsuite/Makefile.am') diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 38e5481..b15000e 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -149,25 +149,25 @@ check_PROGRAMS += object_unittest object_unittest_SOURCES = object_unittest.cc object_unittest_LDFLAGS = $(THREADFLAGS) object_unittest_LDADD = libgoldtest.a ../libgold.a ../../libiberty/libiberty.a $(LIBINTL) \ - $(THREADLIBS) $(LIBDL) $(ZLIB) + $(THREADLIBS) $(LIBDL) $(ZLIB) $(JANSSON_LIBS) check_PROGRAMS += binary_unittest binary_unittest_SOURCES = binary_unittest.cc binary_unittest_LDFLAGS = $(THREADFLAGS) binary_unittest_LDADD = libgoldtest.a ../libgold.a ../../libiberty/libiberty.a $(LIBINTL) \ - $(THREADLIBS) $(LIBDL) $(ZLIB) + $(THREADLIBS) $(LIBDL) $(ZLIB) $(JANSSON_LIBS) check_PROGRAMS += leb128_unittest leb128_unittest_SOURCES = leb128_unittest.cc leb128_unittest_LDFLAGS = $(THREADFLAGS) leb128_unittest_LDADD = libgoldtest.a ../libgold.a ../../libiberty/libiberty.a $(LIBINTL) \ - $(THREADLIBS) $(LIBDL) $(ZLIB) + $(THREADLIBS) $(LIBDL) $(ZLIB) $(JANSSON_LIBS) check_PROGRAMS += overflow_unittest overflow_unittest_SOURCES = overflow_unittest.cc overflow_unittest_LDFLAGS = $(THREADFLAGS) overflow_unittest_LDADD = libgoldtest.a ../libgold.a ../../libiberty/libiberty.a $(LIBINTL) \ - $(THREADLIBS) $(LIBDL) $(ZLIB) + $(THREADLIBS) $(LIBDL) $(ZLIB) $(JANSSON_LIBS) overflow_unittest.o: overflow_unittest.cc $(CXXCOMPILE) -O3 -c -o $@ $< @@ -4435,3 +4435,10 @@ retain_2.o: retain_2.s $(TEST_AS) -o $@ $< endif DEFAULT_TARGET_X86_64 + +check_PROGRAMS += package_metadata_test +package_metadata_test.o: package_metadata_main.c + $(COMPILE) -c -o $@ $< +package_metadata_test$(EXEEXT): package_metadata_test.o gcctestdir/ld + $(CXXLINK) package_metadata_test.o -Wl,--package-metadata='{"foo":"bar"}' + $(TEST_READELF) --notes $@ | grep -q '{"foo":"bar"}' -- cgit v1.1