https://sourceware.org/bugzilla/show_bug.cgi?id=32003
--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> --- (In reply to Benjamin Drung from comment #0) > In Ubuntu we enabled setting ELF package metadata for the Debian package > that we build starting from Ubuntu 24.10 (oracular) on. Specifying the > linker flag --package-metadata is not possible in a robust way. All tried > approaches are either not working or too fragile: > > 1. The comma in the JSON value is used to split the -Wl parameter specified > for gcc: > > ``` > $ 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 > ``` This is a real issue. > 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. > 3. Add `-specs=<spec-file>` to the gcc linker flags. Then this spec file > could construct the package metadata parameter. Example spec file: > > ``` > $ cat /usr/share/dpkg/elf-package-metadata.specs > *link: > + > --package-metadata={\"type\":\"deb\",\"os\":\"%: > getenv(DEB_BUILD_OS_RELEASE_ID \",\"name\":\"%:getenv(DEB_SOURCE > \",\"version\":\"%:getenv(DEB_VERSION > \",\"architecture\":\"%:getenv(DEB_HOST_ARCH \"})))) > ``` > > Issue with that approach: It requires the spec file to be around and the > environment variables to be set. This will be the case during the package > build, but not at a later stage. See https://launchpad.net/bugs/2071468 for > examples where this breaks. > > ## 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? -- You are receiving this mail because: You are on the CC list for the bug.