From dbd04b853b680b0a383e5f58edf3643364f67bdf Mon Sep 17 00:00:00 2001 From: Alex Brachet Date: Mon, 8 Aug 2022 21:31:58 +0000 Subject: [PATCH] [ELF] Support --package-metadata This was recently introduced in GNU linkers and it makes sense for ld.lld to have the same support. This implementation omits checking if the input string is valid json to reduce size bloat. Differential Revision: https://reviews.llvm.org/D131439 --- lld/ELF/Config.h | 1 + lld/ELF/Driver.cpp | 1 + lld/ELF/Options.td | 2 ++ lld/ELF/SyntheticSections.cpp | 14 ++++++++++++++ lld/ELF/SyntheticSections.h | 10 ++++++++++ lld/ELF/Writer.cpp | 5 +++++ lld/docs/ReleaseNotes.rst | 2 ++ lld/test/ELF/package-metadata.s | 19 +++++++++++++++++++ llvm/include/llvm/BinaryFormat/ELF.h | 1 + 9 files changed, 55 insertions(+) create mode 100644 lld/test/ELF/package-metadata.s diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index c29e41d65713..fd9d3b63b2a3 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -291,6 +291,7 @@ struct Configuration { StringRef thinLTOJobs; unsigned timeTraceGranularity; int32_t splitStackAdjustSize; + StringRef packageMetadata; // The following config options do not directly correspond to any // particular command line options. diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 821cf22df35d..2828caa9fdb0 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1146,6 +1146,7 @@ static void readConfigs(opt::InputArgList &args) { config->optimize = args::getInteger(args, OPT_O, 1); config->orphanHandling = getOrphanHandling(args); config->outputFile = args.getLastArgValue(OPT_o); + config->packageMetadata = args.getLastArgValue(OPT_package_metadata); config->pie = args.hasFlag(OPT_pie, OPT_no_pie, false); config->printIcfSections = args.hasFlag(OPT_print_icf_sections, OPT_no_print_icf_sections, false); diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td index 80c0ff9fe1b8..d9266e595887 100644 --- a/lld/ELF/Options.td +++ b/lld/ELF/Options.td @@ -503,6 +503,8 @@ def z: JoinedOrSeparate<["-"], "z">, MetaVarName<"