https://sourceware.org/bugzilla/show_bug.cgi?id=32003
--- Comment #6 from Benjamin Drung <bdrung at posteo dot de> --- (In reply to H.J. Lu from comment #2) > > 2. The quotation marks in the JSON value are eaten by configure scripts and > > Makefiles. Example: > > > > ``` > > $ echo "void main() { }" > test.c > > $ printf 'test:\n\tgcc $(CFLAGS) test.c\n' > Makefile > > $ env CFLAGS='-Wl,--package-metadata={"type":"deb"}' make > > gcc -Wl,--package-metadata={"type":"deb"} test.c > > /usr/bin/ld: warning: --package-metadata={type:deb} does not contain valid > > JSON, ignoring: string or '}' expected near 'type' > > ``` > > The linker testcase has > > "--package-metadata='{\"foo\":\"bar\"}'" > > which is how this option should be used. That linker testcase snippet is evaluated to: --package-metadata='{"foo":"bar"}' Passing that to a shell or makefile works, because the singe quotes protect the JSON content inside. But this escaping protects this snippet from evaluating only once. The problem is that the linker flag can be passed around and evaluated multiple times. This will happen easily during Debian package build, where debian/rules is a Makefile that calls the project build system (that can use makefiles as well). Simple example that shows the problem: ``` $ cat example.c #include <stdio.h> void main() { printf("Hello world!"); } $ cat Makefile2 all: example %: %.c gcc $(LDFLAGS) -o $@ $< .PHONY: all $ cat Makefile all: make -f Makefile2 all LDFLAGS=$(LDFLAGS) .PHONY: all $ LANG=C make LDFLAGS="-Wl,--package-metadata='{\"foo\":\"bar\"}'" make -f Makefile2 all LDFLAGS=-Wl,--package-metadata='{"foo":"bar"}' make[1]: Entering directory 'makefile2' gcc -Wl,--package-metadata={"foo":"bar"} -o example example.c /usr/bin/ld: warning: --package-metadata={foo:bar} does not contain valid JSON, ignoring: string or '}' expected near 'foo' make[1]: Leaving directory 'makefile2' ``` I am very confident to find a real world Debian package that will resemble this example. There is no way to programmatically determine how many times the linker flag needs to be escaped for each individual Debian package build. Fixing those cases by quoting will be a lot of work and might not cover all cases (i.e. it will be a fragile approach). > > ## Proposed solution > > > > Add support for an `--escaped-package-metadata` parameter to the linkers > > that takes a percent encoded (RFC 3986) parameter. Example: > > ``` > > -Wl,--encoded-package-metadata,%7B%22type%22:%22deb%22%2C%22os%22: > > %22ubuntu%22%2C%22name%22:%22dpkg%22%2C%22version%22:%221.22. > > 6ubuntu15%22%2C%22architecture%22:%22amd64%22%7D > > ``` > > It is very much unreadable. The main issue is that compiler drivers eat > comma. Can we update linker to support an escape for comma which won't be > eaten by compiler drivers? The encoding is flexible and you could just encode the characters that are problematic in your case: -Wl,--encoded-package-metadata,{"type":"deb"%2C"os":"ubuntu"%2C"name":"dpkg"%2C"version":"1.22.6ubuntu15"%2C"architecture":"amd64"} -- You are receiving this mail because: You are on the CC list for the bug.