]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
ld: Support percent-encoded JSON in --package-metadata
authorBenjamin Drung <benjamin.drung@canonical.com>
Mon, 18 Nov 2024 10:38:25 +0000 (11:38 +0100)
committerJan Beulich <jbeulich@suse.com>
Mon, 18 Nov 2024 10:38:25 +0000 (11:38 +0100)
commitb0cc81e87087bb8a6b12dc1e4fd7f2591927977b
treec8d753b1e4c066c636cb50fe43992f84f62a314f
parent20d9fb448c375d5f521eaed8cfc0c49a44803bd1
ld: Support percent-encoded JSON in --package-metadata

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 '-Wl,--package-metadata={"type":"deb","os":"ubuntu"}' test.c
/usr/bin/ld: cannot find "os":"ubuntu"}: No such file or directory
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.

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>
ld/NEWS
ld/emultempl/elf.em
ld/ld.texi
ld/ldmisc.c
ld/ldmisc.h
ld/testsuite/ld-elf/package-note.exp
ld/testsuite/ld-elf/package-note2.rd [new file with mode: 0644]