[PATCH RESEND] gold: Support percent-encoded JSON in --package-metadata
authorBenjamin Drung <benjamin.drung@canonical.com>
Tue, 17 Dec 2024 15:27:46 +0000 (15:27 +0000)
committerMatthias Klose <doko@debian.org>
Mon, 27 Jan 2025 10:12:03 +0000 (11:12 +0100)
commitc257628f0d0df344933a90c1ada2f63ddf7291ad
tree0178c3ecd741093b80f29088e6dc981ed174f98d
parent925adb7fff6467a6d73b005486006238a0339fa5
[PATCH RESEND] gold: Support percent-encoded JSON in --package-metadata

From benjamin.drung@canonical.com  Tue Dec 17 15:27:46 2024
Message-ID: <20241217152746.98360-1-benjamin.drung@canonical.com>

Specifying the compiler flag `-Wl,--package-metadata=<JSON>` will not
work in case the JSON contains a comma, because compiler drivers eat
commas. Example:

```
$ echo "void main() { }" > test.c
$ gcc -fuse-ld=gold '-Wl,--package-metadata={"type":"deb","os":"ubuntu"}' test.c
/usr/bin/ld.gold: error: cannot open "os":"ubuntu"}: No such file or directory
/usr/bin/ld.gold: fatal error: error: --package-metadata={"type":"deb" does not contain valid JSON: '}' expected near end of file

collect2: error: ld returned 1 exit status
```

The quotation marks in the JSON value do not work well with shell nor
make. Specifying the `--package-metadata` linker flag in a `LDFLAGS`
environment variable might loose its quotation marks when it hits the
final compiler call.

Following the same format as the implementation in ld:
b0cc81e87087bb8a6b12dc1e4fd7f2591927977b

So support percent-encoded and %[string] encoded JSON data in the
`--package-metadata` linker flag. Percent-encoding is used because it is
a standard, simple to implement, and does take too many additional
characters. %[string] encoding is supported for having a more readable
encoding.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32003
Bug-Ubutru: https://bugs.launchpad.net/bugs/2071468
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
Gbp-Pq: Name gold-package-metadata.diff
gold/options.cc
gold/options.h
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in