https://sourceware.org/bugzilla/show_bug.cgi?id=32003

            Bug ID: 32003
           Summary: Specifying --package-metadata might not be possible
                    and is too fragile
           Product: binutils
           Version: 2.44 (HEAD)
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: bdrung at posteo dot de
  Target Milestone: ---

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
```

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'
```

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
```

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to