@@ -816,6 +816,26 @@ static ICFLevel getICF(opt::InputArgList &args) {
816816 return ICFLevel::All;
817817}
818818
819+ static void parsePackageMetadata (Ctx &ctx, const opt::Arg &arg) {
820+ unsigned c0, c1;
821+ SmallVector<uint8_t , 0 > decoded;
822+ StringRef s = arg.getValue ();
823+ for (size_t i = 0 , e = s.size (); i != e; ++i) {
824+ if (s[i] != ' %' ) {
825+ decoded.push_back (s[i]);
826+ } else if (i + 2 < e && (c1 = hexDigitValue (s[i + 1 ])) != -1u &&
827+ (c0 = hexDigitValue (s[i + 2 ])) != -1u ) {
828+ decoded.push_back (uint8_t (c1 * 16 + c0));
829+ i += 2 ;
830+ } else {
831+ ErrAlways (ctx) << arg.getSpelling () << " : invalid % escape at byte " << i
832+ << " ; supports only %[0-9a-fA-F][0-9a-fA-F]" ;
833+ return ;
834+ }
835+ }
836+ ctx.arg .packageMetadata = std::move (decoded);
837+ }
838+
819839static StripPolicy getStrip (Ctx &ctx, opt::InputArgList &args) {
820840 if (args.hasArg (OPT_relocatable))
821841 return StripPolicy::None;
@@ -1425,7 +1445,8 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
14251445 ctx.arg .optimize = args::getInteger (args, OPT_O, 1 );
14261446 ctx.arg .orphanHandling = getOrphanHandling (ctx, args);
14271447 ctx.arg .outputFile = args.getLastArgValue (OPT_o);
1428- ctx.arg .packageMetadata = args.getLastArgValue (OPT_package_metadata);
1448+ if (auto *arg = args.getLastArg (OPT_package_metadata))
1449+ parsePackageMetadata (ctx, *arg);
14291450 ctx.arg .pie = args.hasFlag (OPT_pie, OPT_no_pie, false );
14301451 ctx.arg .printIcfSections =
14311452 args.hasFlag (OPT_print_icf_sections, OPT_no_print_icf_sections, false );
0 commit comments