diff options
Diffstat (limited to 'gold/layout.cc')
-rw-r--r-- | gold/layout.cc | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/gold/layout.cc b/gold/layout.cc index 3efe8d9..184caa2 100644 --- a/gold/layout.cc +++ b/gold/layout.cc @@ -38,6 +38,9 @@ #include <windows.h> #include <rpcdce.h> #endif +#ifdef HAVE_JANSSON +#include <jansson.h> +#endif #include "parameters.h" #include "options.h" @@ -2437,6 +2440,7 @@ Layout::create_notes() this->create_gold_note(); this->create_stack_segment(); this->create_build_id(); + this->create_package_metadata(); } // Create the dynamic sections which are needed before we read the @@ -3534,6 +3538,52 @@ Layout::create_build_id() } } +// If --package-metadata was used, set up the package metadata note. +// https://systemd.io/ELF_PACKAGE_METADATA/ + +void +Layout::create_package_metadata() +{ + if (!parameters->options().user_set_package_metadata()) + return; + + const char* desc = parameters->options().package_metadata(); + if (strcmp(desc, "") == 0) + return; + +#ifdef HAVE_JANSSON + json_error_t json_error; + json_t *json = json_loads(desc, 0, &json_error); + if (json) + json_decref(json); + else + { + gold_fatal(_("error: --package-metadata=%s does not contain valid " + "JSON: %s\n"), + desc, json_error.text); + } +#endif + + // Create the note. + size_t trailing_padding; + // Ensure the trailing NULL byte is always included, as per specification. + size_t descsz = strlen(desc) + 1; + Output_section* os = this->create_note("FDO", elfcpp::FDO_PACKAGING_METADATA, + ".note.package", descsz, true, + &trailing_padding); + if (os == NULL) + return; + + Output_section_data* posd = new Output_data_const(desc, descsz, 4); + os->add_output_section_data(posd); + + if (trailing_padding != 0) + { + posd = new Output_data_zero_fill(trailing_padding, 0); + os->add_output_section_data(posd); + } +} + // If we have both .stabXX and .stabXXstr sections, then the sh_link // field of the former should point to the latter. I'm not sure who // started this, but the GNU linker does it, and some tools depend |