diff --git a/.github/super-linter-links/dh/dh_package_notes.pl b/.github/super-linter-links/dh/dh_package_notes.pl deleted file mode 120000 index 1db1a04..0000000 --- a/.github/super-linter-links/dh/dh_package_notes.pl +++ /dev/null @@ -1 +0,0 @@ -../../../dh/dh_package_notes \ No newline at end of file diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml deleted file mode 100644 index 133ee57..0000000 --- a/.github/workflows/linter.yml +++ /dev/null @@ -1,44 +0,0 @@ ---- -# SPDX-License-Identifier: CC0-1.0 -# vi: ts=2 sw=2 et: - -name: Lint Code Base -on: [pull_request] - -jobs: - build: - runs-on: ubuntu-latest - concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - strategy: - fail-fast: false - steps: - - name: Repository checkout - uses: actions/checkout@v2 - with: - # We need a full repo clone to get a correct list of changed files - fetch-depth: 0 - # FIXME: super-linter doesn't recognize perl/python scripts without - # an extension; let's workaround it by creating a dummy symlink - # directory with necessary extensions until it's resolved. - # The `find` below just checks if all symlinks in the dummy - # directory are valid. - - name: Check test-related symlinks - run: find .github/super-linter-links/ -type l -exec ls -L {} + - - name: Lint Code Base - uses: github/super-linter/slim@latest - env: - DEFAULT_BRANCH: main - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MULTI_STATUS: true - # FIXME: until the above FIXME is resolved, we need to always check - # the whole codebase, otherwise only changed files would be - # considered, which would ignore the symlinked files. Since - # we have only couple of files to check, it's not an issue - # (yet). - VALIDATE_ALL_CODEBASE: true - VALIDATE_BASH: true - VALIDATE_PERL: true - VALIDATE_PYTHON_ISORT: true - VALIDATE_PYTHON_PYLINT: true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 7551a39..0000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,29 +0,0 @@ ---- -# SPDX-License-Identifier: CC0-1.0 -# vi: ts=2 sw=2 et: - -name: Run tests -on: [pull_request] - -permissions: - contents: read - -jobs: - build: - runs-on: ubuntu-20.04 - concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - strategy: - fail-fast: false - steps: - - name: Repository checkout - uses: actions/checkout@v2 - - name: Install dependencies - run: sudo apt -y update && sudo apt -y install binutils python3-pytest python3-simplejson devscripts - - name: Run python tests - run: python3 -m pytest -v - - name: Run shell tests - run: ./tests/test_basics.sh - - name: Check shell script for bashism - run: checkbashisms ./tests/test_basics.sh diff --git a/README.md b/README.md index de53094..6dccd9d 100644 --- a/README.md +++ b/README.md @@ -2,25 +2,16 @@ ELF Package Notes Reference Implementation ## Description -This repository provides a script to generate an ELF note that can be -linked into compiled binaries (programs and shared libraries) to provide -metadata about the package for which the binary was compiled. +This repository provides RPM and DEB packaging tools to generate an ELF note +that will be linked into compiled binaries (programs and shared libraries) to +provide metadata about the package for which the binary was compiled. -See [Package Metadata for Core Files](https://systemd.io/COREDUMP_PACKAGE_METADATA/) +See [Package Metadata for Core Files](https://systemd.io/ELF_PACKAGE_METADATA/) for the overview and details. -We provide implementations in Python and POSIX shell, with compatible CLI -interfaces. +The new `--package-metadata` option provided by bfd, gold, mold and lld is used. ## Requirements - -### generate-package-notes.py - -* python3 (>= 3.5) -* python3-simplejson -* binutils (>= 2.38) [--readonly true] - -### generate-package-notes.sh - -* POSIX shell -* binutils (>= 2.38) [--readonly true] +* binutils (>= 2.39) +* mold (>= 1.3.0) +* lld (>= 15.0.0) diff --git a/debian/changelog b/debian/changelog index ec710ce..bcf0c61 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +package-notes (0.9) unstable; urgency=medium + + * Switch to --package-metadata linker flag via specs file + + -- Luca Boccassi Sun, 27 Nov 2022 16:43:58 +0000 + package-notes (0.8) unstable; urgency=medium * use LONG instead of BYTEs for binary fields diff --git a/debian/control b/debian/control index 17c6019..1ca23da 100644 --- a/debian/control +++ b/debian/control @@ -3,9 +3,9 @@ Section: admin Priority: optional Rules-Requires-Root: no Maintainer: Luca Boccassi -Build-Depends: debhelper-compat (= 13), dh-exec, -Standards-Version: 4.6.0 -Homepage: https://systemd.io/COREDUMP_PACKAGE_METADATA/ +Build-Depends: debhelper-compat (= 13), +Standards-Version: 4.6.1 +Homepage: https://systemd.io/ELF_PACKAGE_METADATA/ Vcs-Git: https://github.com/systemd/package-notes.git Vcs-Browser: https://github.com/systemd/package-notes @@ -13,8 +13,7 @@ Package: dh-package-notes Architecture: all Multi-Arch: foreign Enhances: debhelper -Depends: ${misc:Depends}, ${perl:Depends}, debhelper, -Provides: dh-sequence-package-notes +Depends: ${misc:Depends}, debhelper, Description: Debian Helper for adding package metadata to ELF binaries - Generate a linker script to add package metadata to the ELF binaries being - built. See: https://systemd.io/COREDUMP_PACKAGE_METADATA/ + Provides a linker specs file to add package metadata to the ELF binaries being + built. See: https://systemd.io/ELF_PACKAGE_METADATA/ diff --git a/debian/debian-package-notes.specs b/debian/debian-package-notes.specs new file mode 100644 index 0000000..9045a9a --- /dev/null +++ b/debian/debian-package-notes.specs @@ -0,0 +1,2 @@ +*link: ++ --package-metadata={\"type\":\"deb\",\"os\":\"%:getenv(DEB_VENDOR \",\"name\":\"%:getenv(DEB_SOURCE_PACKAGE_NAME \",\"version\":\"%:getenv(DEB_SOURCE_PACKAGE_VERSION \",\"architecture\":\"%:getenv(DEB_HOST_ARCH \",\"debugInfoUrl\":\"%:getenv(DEBUGINFOD_URLS \"}))))) diff --git a/debian/dh-package-notes.install b/debian/dh-package-notes.install old mode 100755 new mode 100644 index 9265a15..215cc86 --- a/debian/dh-package-notes.install +++ b/debian/dh-package-notes.install @@ -1,5 +1,2 @@ -#!/usr/bin/dh-exec -dh/dh_package_notes usr/bin -generate-package-notes.sh => usr/bin/generate-package-notes -dh/package_notes.pm usr/share/perl5/Debian/Debhelper/Sequence -dh/package-notes.mk usr/share/debhelper/dh_package_notes +debian/package-notes.mk usr/share/debhelper/dh_package_notes/ +debian/debian-package-notes.specs usr/share/debhelper/dh_package_notes/ diff --git a/debian/dh-package-notes.manpages b/debian/dh-package-notes.manpages index 799a2af..6c26efd 100644 --- a/debian/dh-package-notes.manpages +++ b/debian/dh-package-notes.manpages @@ -1,2 +1 @@ debian/dh_package_notes.1 -man/generate-package-notes.1 diff --git a/debian/dh_package_notes.1 b/debian/dh_package_notes.1 new file mode 100644 index 0000000..8942874 --- /dev/null +++ b/debian/dh_package_notes.1 @@ -0,0 +1,172 @@ +.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) +.\" +.\" Standard preamble: +.\" ======================================================================== +.de Sp \" Vertical space (when we can't use .PP) +.if t .sp .5v +.if n .sp +.. +.de Vb \" Begin verbatim text +.ft CW +.nf +.ne \\$1 +.. +.de Ve \" End verbatim text +.ft R +.fi +.. +.\" Set up some character translations and predefined strings. \*(-- will +.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left +.\" double quote, and \*(R" will give a right double quote. \*(C+ will +.\" give a nicer C++. Capital omega is used to do unbreakable dashes and +.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, +.\" nothing in troff, for use with C<>. +.tr \(*W- +.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' +.ie n \{\ +. ds -- \(*W- +. ds PI pi +. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch +. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch +. ds L" "" +. ds R" "" +. ds C` "" +. ds C' "" +'br\} +.el\{\ +. ds -- \|\(em\| +. ds PI \(*p +. ds L" `` +. ds R" '' +. ds C` +. ds C' +'br\} +.\" +.\" Escape single quotes in literal strings from groff's Unicode transform. +.ie \n(.g .ds Aq \(aq +.el .ds Aq ' +.\" +.\" If the F register is >0, we'll generate index entries on stderr for +.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index +.\" entries marked with X<> in POD. Of course, you'll have to process the +.\" output yourself in some meaningful fashion. +.\" +.\" Avoid warning from groff about undefined register 'F'. +.de IX +.. +.nr rF 0 +.if \n(.g .if rF .nr rF 1 +.if (\n(rF:(\n(.g==0)) \{\ +. if \nF \{\ +. de IX +. tm Index:\\$1\t\\n%\t"\\$2" +.. +. if !\nF==2 \{\ +. nr % 0 +. nr F 2 +. \} +. \} +.\} +.rr rF +.\" +.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). +.\" Fear. Run. Save yourself. No user-serviceable parts. +. \" fudge factors for nroff and troff +.if n \{\ +. ds #H 0 +. ds #V .8m +. ds #F .3m +. ds #[ \f1 +. ds #] \fP +.\} +.if t \{\ +. ds #H ((1u-(\\\\n(.fu%2u))*.13m) +. ds #V .6m +. ds #F 0 +. ds #[ \& +. ds #] \& +.\} +. \" simple accents for nroff and troff +.if n \{\ +. ds ' \& +. ds ` \& +. ds ^ \& +. ds , \& +. ds ~ ~ +. ds / +.\} +.if t \{\ +. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" +. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' +. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' +. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' +. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' +. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' +.\} +. \" troff and (daisy-wheel) nroff accents +.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' +.ds 8 \h'\*(#H'\(*b\h'-\*(#H' +.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] +.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' +.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' +.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] +.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] +.ds ae a\h'-(\w'a'u*4/10)'e +.ds Ae A\h'-(\w'A'u*4/10)'E +. \" corrections for vroff +.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' +.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' +. \" for low resolution devices (crt and lpr) +.if \n(.H>23 .if \n(.V>19 \ +\{\ +. ds : e +. ds 8 ss +. ds o a +. ds d- d\h'-1'\(ga +. ds D- D\h'-1'\(hy +. ds th \o'bp' +. ds Th \o'LP' +. ds ae ae +. ds Ae AE +.\} +.rm #[ #] #H #V #F C +.\" ======================================================================== +.\" +.IX Title "DH_PACKAGE_NOTES 1" +.TH DH_PACKAGE_NOTES 1 "2022-11-27" +.\" For nroff, turn off justification. Always turn off hyphenation; it makes +.\" way too many mistakes in technical documents. +.if n .ad l +.nh +.SH "NAME" +dh_package_notes \- Add package metadata to ELF header +.SH "SYNOPSIS" +.IX Header "SYNOPSIS" +\&\fBdh_package_notes\fR +.SH "DESCRIPTION" +.IX Header "DESCRIPTION" +\&\fBdh_package_notes\fR provides a linker specs file to include package metadata in +\&\s-1ELF\s0 binaries built by packages. +.PP +The package metadata specification for \s-1ELF\s0 binaries can be found at +. +.PP +\&\fBdh_package_notes\fR provides a linker specs file at +\&\fB/usr/share/debhelper/dh_package_notes/debian\-package\-notes.specs\fR which can be +used by including \fB/usr/share/debhelper/dh_package_notes/debian\-package\-notes.mk\fR +at the dop of \fBdebian/rules\fR. This will export the right environment variables +that will result in a package note \s-1ELF\s0 section being added to all packaged \s-1ELF\s0 +files, with the package type set to \fBdeb\fR, the package name and version set to +the source package name and version respectively, the \s-1OS\s0 set to \fBDebian\fR and +debuginfod \s-1URL\s0 set to \fBhttps://debuginfod.debian.net\fR. On Ubuntu, the \s-1OS\s0 +will be set to \fBUbuntu\fR and debuginfod \s-1URL\s0 will be set to +\&\fBhttps://debuginfod.ubuntu.com\fR. +.PP +Note that it is not sufficient to build-depend on this package, the \fBinclude\fR +must be used at the top of \fBdebian/rules\fR for this to be enabled. +.SH "SEE ALSO" +.IX Header "SEE ALSO" +\&\fBdebhelper\fR\|(7) +.SH "AUTHOR" +.IX Header "AUTHOR" +Luca Boccassi diff --git a/debian/package-notes.mk b/debian/package-notes.mk new file mode 100644 index 0000000..feaf1bc --- /dev/null +++ b/debian/package-notes.mk @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: CC0-1.0 +# Include from debian/rules to use with dh_package_notes. +# See dh_package_notes(1) for details +include /usr/share/dpkg/vendor.mk +ifeq (, $(filter nocheck, $(DEBUGINFOD_URLS))) +ifeq ($(DEB_VENDOR),Ubuntu) +export DEBUGINFOD_URLS=https://debuginfod.ubuntu.com +else +export DEBUGINFOD_URLS=https://debuginfod.debian.net +endif +endif +export DEB_SOURCE_PACKAGE_VERSION=$(shell dpkg-parsechangelog -S Version) +export DEB_SOURCE_PACKAGE_NAME=$(shell dpkg-parsechangelog -S Source) +export DEB_LDFLAGS_MAINT_APPEND+= -specs=/usr/share/debhelper/dh_package_notes/debian-package-notes.specs +export DEB_VENDOR + diff --git a/debian/rules b/debian/rules index b1d1286..2d33f6a 100755 --- a/debian/rules +++ b/debian/rules @@ -2,9 +2,3 @@ %: dh $@ - -execute_after_dh_auto_build: - pod2man $(CURDIR)/dh/dh_package_notes $(CURDIR)/debian/dh_package_notes.1 - -execute_after_dh_auto_clean: - rm -f $(CURDIR)/debian/dh_package_notes.1 diff --git a/dh/dh_package_notes b/dh/dh_package_notes deleted file mode 100755 index e0323a7..0000000 --- a/dh/dh_package_notes +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/perl -w -# SPDX-License-Identifier: CC0-1.0 - -=head1 NAME - -dh_package_notes - Add package metadata to ELF header - -=cut - -use strict; -use warnings; -use Debian::Debhelper::Dh_Lib - qw(%dh doit hostarch init isnative sourcepackage); -use Dpkg::Vendor qw(get_current_vendor); -our $VERSION = '0.8'; - -=head1 SYNOPSIS - -B - -=cut - -=head1 DESCRIPTION - -B is a debhelper program that creates a linker script to -include package metadata in ELF binaries built by packages. - -The package metadata specification for ELF binaries can be found at -L. - -B creates a linker script in a fixed location at -B with the package type set to B, the package -name and version set to the source package name and version respectively, and -the B and B fields set to the values of the B and -B fields found in B. Simply add -B to the Build-Depends or add -B<--with package_notes> to the B call to make this happen. - -The package using B also needs to manually set in debian/rules -B as it is -not possible to do so from a debhelper addon. - -=cut - -init(); - -isnative( $dh{MAINPACKAGE} ); # Necessary to have $dh{VERSION} -my $source_package = sourcepackage(); -my $package_arch = hostarch(); -my $vendor = get_current_vendor(); -my $url = $ENV{'DEBUGINFOD_URLS'}; -if (!defined $url) { - $url = "https://debuginfod.debian.net"; -} -my %options = ( 'stdout' => "debian/.debhelper/notes.ld" ); -my @cmd = ( - "/usr/bin/generate-package-notes", - "--type", "deb", - "--os", lc ${vendor}, - "--name", ${source_package}, - "--architecture", ${package_arch}, - "--version", $dh{VERSION}, - "--debugInfoUrl", ${url} -); - -if ( not mkdir("debian/.debhelper") ) { - error("mkdir debian/.debhelper failed: $!"); -} - -doit( \%options, @cmd ); - -# FIXME: neither of these work, so appending from each debian/rules file is -# currently the only way to make this work, which is less than ideal -#$ENV{'DEB_LDFLAGS_MAINT_APPEND'} .= ' -Wl,-dT,debian/.debhelper/notes.ld'; -#$ENV{'LDFLAGS'} .= ' -Wl,-dT,debian/.debhelper/notes.ld'; - -=head1 SEE ALSO - -L - -=head1 AUTHOR - -Luca Boccassi - -=cut diff --git a/dh/package-notes.mk b/dh/package-notes.mk deleted file mode 100644 index 1dfa595..0000000 --- a/dh/package-notes.mk +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: CC0-1.0 -# Include from debian/rules to use with dh_package_notes. -# See dh_package_notes(1) for details -export DEB_LDFLAGS_MAINT_APPEND+= -Wl,-dT,$(CURDIR)/debian/.debhelper/notes.ld diff --git a/dh/package_notes.pm b/dh/package_notes.pm deleted file mode 100755 index 7a963aa..0000000 --- a/dh/package_notes.pm +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/perl -# SPDX-License-Identifier: CC0-1.0 - -use warnings; -use strict; -use Debian::Debhelper::Dh_Lib; - -insert_before('dh_auto_configure', 'dh_package_notes'); - -1 diff --git a/generate-package-notes.py b/generate-package-notes.py deleted file mode 100755 index 1f70b3e..0000000 --- a/generate-package-notes.py +++ /dev/null @@ -1,222 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: CC0-1.0 - -""" -Generates a linker script to insert a .note.package section with a -JSON payload. The contents are derived from the specified options and the -os-release file. Use the output with -Wl,-dT,/path/to/output in $LDFLAGS. - -$ ./generate-package-notes.py --package-type rpm --package-name systemd --package-version 248~rc2-1.fc34 --package-architecture x86_64 --cpe 'cpe:/o:fedoraproject:fedora:33' -SECTIONS -{ - .note.package (READONLY) : ALIGN(4) { - BYTE(0x04) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Owner including NUL */ - BYTE(0x7c) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Value including NUL */ - BYTE(0x7e) BYTE(0x1a) BYTE(0xfe) BYTE(0xca) /* Note ID */ - BYTE(0x46) BYTE(0x44) BYTE(0x4f) BYTE(0x00) /* Owner: 'FDO\x00' */ - BYTE(0x7b) BYTE(0x22) BYTE(0x74) BYTE(0x79) /* Value: '{"type":"rpm","name":"systemd","version":"248~rc2-1.fc34","architecture":"x86_64","osCpe":"cpe:/o:fedoraproject:fedora:33"}\x00' */ - BYTE(0x70) BYTE(0x65) BYTE(0x22) BYTE(0x3a) - BYTE(0x22) BYTE(0x72) BYTE(0x70) BYTE(0x6d) - BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x6e) - BYTE(0x61) BYTE(0x6d) BYTE(0x65) BYTE(0x22) - BYTE(0x3a) BYTE(0x22) BYTE(0x73) BYTE(0x79) - BYTE(0x73) BYTE(0x74) BYTE(0x65) BYTE(0x6d) - BYTE(0x64) BYTE(0x22) BYTE(0x2c) BYTE(0x22) - BYTE(0x76) BYTE(0x65) BYTE(0x72) BYTE(0x73) - BYTE(0x69) BYTE(0x6f) BYTE(0x6e) BYTE(0x22) - BYTE(0x3a) BYTE(0x22) BYTE(0x32) BYTE(0x34) - BYTE(0x38) BYTE(0x7e) BYTE(0x72) BYTE(0x63) - BYTE(0x32) BYTE(0x2d) BYTE(0x31) BYTE(0x2e) - BYTE(0x66) BYTE(0x63) BYTE(0x33) BYTE(0x34) - BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x61) - BYTE(0x72) BYTE(0x63) BYTE(0x68) BYTE(0x69) - BYTE(0x74) BYTE(0x65) BYTE(0x63) BYTE(0x74) - BYTE(0x75) BYTE(0x72) BYTE(0x65) BYTE(0x22) - BYTE(0x3a) BYTE(0x22) BYTE(0x78) BYTE(0x38) - BYTE(0x36) BYTE(0x5f) BYTE(0x36) BYTE(0x34) - BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x6f) - BYTE(0x73) BYTE(0x43) BYTE(0x70) BYTE(0x65) - BYTE(0x22) BYTE(0x3a) BYTE(0x22) BYTE(0x63) - BYTE(0x70) BYTE(0x65) BYTE(0x3a) BYTE(0x2f) - BYTE(0x6f) BYTE(0x3a) BYTE(0x66) BYTE(0x65) - BYTE(0x64) BYTE(0x6f) BYTE(0x72) BYTE(0x61) - BYTE(0x70) BYTE(0x72) BYTE(0x6f) BYTE(0x6a) - BYTE(0x65) BYTE(0x63) BYTE(0x74) BYTE(0x3a) - BYTE(0x66) BYTE(0x65) BYTE(0x64) BYTE(0x6f) - BYTE(0x72) BYTE(0x61) BYTE(0x3a) BYTE(0x33) - BYTE(0x33) BYTE(0x22) BYTE(0x7d) BYTE(0x00) - } -} -INSERT AFTER .note.gnu.build-id; -/* HINT: add -Wl,-dT,/path/to/this/file to $LDFLAGS */ - -See https://systemd.io/COREDUMP_PACKAGE_METADATA/ for details. -""" - -__version__ = '0.8' - -import argparse -import itertools -import os -import re -from pathlib import Path - -import simplejson as json - -DOC_PARAGRAPHS = ['\n'.join(group) - for (key, group) in itertools.groupby(__doc__.splitlines(), bool) - if key] - -def read_os_release(field, root=Path('/')): - try: - f = open(root / 'etc/os-release') - except FileNotFoundError: - f = open(root / 'usr/lib/os-release') - - prefix = '{}='.format(field) - for line in f: - if line.startswith(prefix): - break - else: - return None - - value = line.rstrip() - value = value[value.startswith(prefix) and len(prefix):] - if value[0] in '"\'' and value[0] == value[-1]: - value = value[1:-1] - - return value - -def str_to_bool(v): - if isinstance(v, bool): - return v - if v.lower() in {'yes', 'true', '1'}: - return True - if v.lower() in {'no', 'false', '0'}: - return False - raise argparse.ArgumentTypeError('"yes"/"true"/"1"/"no"/"false"/"0" expected') - -def parse_args(): - p = argparse.ArgumentParser(description=DOC_PARAGRAPHS[0], - epilog=DOC_PARAGRAPHS[-1], - allow_abbrev=False) - p.add_argument('--package-type', metavar='TYPE', - default='package', - help='Specify the package type, e.g. "rpm" or "deb"') - p.add_argument('--package-name', metavar='NAME', - help='The name of the package (e.g. "foo" or "libbar")') - p.add_argument('--package-version', metavar='VERSION', - help='The full version of the package (e.g. 1.5-1.fc35.s390x)') - p.add_argument('--package-architecture', metavar='ARCH', - help='The code architecture of the binaries (e.g. arm64 or s390x)') - p.add_argument('--cpe', - help='NIST CPE identifier of the vendor operating system, or \'auto\' to parse from system-release-cpe or os-release') - p.add_argument('--rpm', metavar='NEVRA', - help='Extract type,name,version,architecture from a full rpm name') - p.add_argument('--debug-info-url', metavar='URL', - help='URL of the debuginfod server where sources can be queried') - p.add_argument('--readonly', metavar='BOOL', - type=str_to_bool, default=True, - help='Make the notes section read-only (requires binutils 2.38)') - p.add_argument('--root', metavar='PATH', type=Path, default="/", - help='When a file (eg: /usr/lib/os-release) is parsed, open it relatively from this hierarchy') - p.add_argument('--version', action='version', version=f'%(prog)s {__version__}') - - opts = p.parse_args() - - return opts - -def encode_bytes(arr): - return ' '.join('BYTE(0x{:02x})'.format(n) for n in arr) - -def encode_bytes_lines(arr, prefix='', label='string'): - assert len(arr) % 4 == 0 - s = bytes(arr).decode() - yield prefix + encode_bytes(arr[:4]) + ' /* {}: {!r} */'.format(label, s) - for offset in range(4, len(arr), 4): - yield prefix + encode_bytes(arr[offset:offset+4]) - -def encode_length(s, prefix='', label='string'): - n = (len(s) + 1) * 4 // 4 - return f'{prefix}LONG(0x{n:04x}) /* Length of {label} including NUL */' - -def encode_note_id(id, prefix=''): - return f'{prefix}LONG(0x{id:04x}) /* Note ID */' - -def pad_string(s): - return [0] * ((len(s) + 4) // 4 * 4 - len(s)) - -def encode_string(s, prefix='', label='string'): - arr = list(s.encode()) + pad_string(s) - yield from encode_bytes_lines(arr, prefix=prefix, label=label) - -def encode_note(note_name, note_id, owner, value, readonly=True, prefix=''): - l1 = encode_length(owner, prefix=prefix + ' ', label='Owner') - l2 = encode_length(value, prefix=prefix + ' ', label='Value') - l3 = encode_note_id(note_id, prefix=prefix + ' ') - l4 = encode_string(owner, prefix=prefix + ' ', label='Owner') - l5 = encode_string(value, prefix=prefix + ' ', label='Value') - readonly = '(READONLY) ' if readonly else '' - - return [prefix + '.note.{} {}: ALIGN(4) {{'.format(note_name, readonly), - l1, l2, l3, *l4, *l5, - prefix + '}'] - -NOTE_ID= 0xcafe1a7e - -def json_serialize(s): - # Avoid taking space in the ELF header if there's no value to store - return json.dumps({k: v for k, v in s.items() if v is not None}, - ensure_ascii=False, - separators=(',', ':')) - -def gather_data(opts): - if opts.cpe == 'auto': - try: - with open(Path(opts.root, 'usr/lib/system-release-cpe'), 'r') as f: - opts.cpe = f.read() - except FileNotFoundError: - opts.cpe = read_os_release('CPE_NAME', root=opts.root) - if opts.cpe is None or opts.cpe == "": - raise ValueError(f"Could not read {opts.root}usr/lib/system-release-cpe or CPE_NAME from {opts.root}usr/lib/os-release") - - if opts.rpm: - split = re.match(r'(.*?)-([0-9].*)\.(.*)', opts.rpm) - if not split: - raise ValueError('{!r} does not seem to be a valid package name'.format(opts.rpm)) - opts.package_type = 'rpm' - opts.package_name = split.group(1) - opts.package_version = split.group(2) - opts.package_architecture = split.group(3) - - data = { - 'type': opts.package_type, - 'name': opts.package_name, - 'version': opts.package_version, - 'architecture': opts.package_architecture, - } - if opts.cpe: - data['osCpe'] = opts.cpe - else: - data['os'] = read_os_release('ID', root=opts.root) - data['osVersion'] = read_os_release('VERSION_ID', root=opts.root) - if opts.debug_info_url: - data['debugInfoUrl'] = opts.debug_info_url - return data - -def generate_section(data, readonly=True): - json = json_serialize(data) - - section = encode_note('package', NOTE_ID, 'FDO', json, readonly=readonly, prefix=' ') - return ['SECTIONS', '{', - *section, - '}', - 'INSERT AFTER .note.gnu.build-id;', - '/* HINT: add -Wl,-dT,/path/to/this/file to $LDFLAGS */'] - -if __name__ == '__main__': - opts = parse_args() - data = gather_data(opts) - lines = generate_section(data, readonly=opts.readonly) - - print('\n'.join(lines)) diff --git a/generate-package-notes.sh b/generate-package-notes.sh deleted file mode 100755 index 7581091..0000000 --- a/generate-package-notes.sh +++ /dev/null @@ -1,287 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: CC0-1.0 -# -# Generates a linker script to insert a .note.package section with a -# JSON payload. The contents are derived from the specified options and the -# os-release file. Use the output with -Wl,-dT,/path/to/output in $LDFLAGS. -# -# $ ./generate-package-notes.sh --type rpm --name systemd --version 248~rc2-1.fc34 --architecture x86_64 --osCpe 'cpe:/o:fedoraproject:fedora:33' -# SECTIONS -# { -# .note.package (READONLY) : ALIGN(4) { -# BYTE(0x04) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Owner including NUL */ -# BYTE(0x7c) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Value including NUL */ -# BYTE(0x7e) BYTE(0x1a) BYTE(0xfe) BYTE(0xca) /* Note ID */ -# BYTE(0x46) BYTE(0x44) BYTE(0x4f) BYTE(0x00) /* Owner: 'FDO\x00' */ -# BYTE(0x7b) BYTE(0x22) BYTE(0x74) BYTE(0x79) /* Value: '{"type":"rpm","name":"systemd","version":"248~rc2-1.fc34","architecture":"x86_64","osCpe":"cpe:/o:fedoraproject:fedora:33"}\x00' */ -# BYTE(0x70) BYTE(0x65) BYTE(0x22) BYTE(0x3a) -# BYTE(0x22) BYTE(0x72) BYTE(0x70) BYTE(0x6d) -# BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x6e) -# BYTE(0x61) BYTE(0x6d) BYTE(0x65) BYTE(0x22) -# BYTE(0x3a) BYTE(0x22) BYTE(0x73) BYTE(0x79) -# BYTE(0x73) BYTE(0x74) BYTE(0x65) BYTE(0x6d) -# BYTE(0x64) BYTE(0x22) BYTE(0x2c) BYTE(0x22) -# BYTE(0x76) BYTE(0x65) BYTE(0x72) BYTE(0x73) -# BYTE(0x69) BYTE(0x6f) BYTE(0x6e) BYTE(0x22) -# BYTE(0x3a) BYTE(0x22) BYTE(0x32) BYTE(0x34) -# BYTE(0x38) BYTE(0x7e) BYTE(0x72) BYTE(0x63) -# BYTE(0x32) BYTE(0x2d) BYTE(0x31) BYTE(0x2e) -# BYTE(0x66) BYTE(0x63) BYTE(0x33) BYTE(0x34) -# BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x61) -# BYTE(0x72) BYTE(0x63) BYTE(0x68) BYTE(0x69) -# BYTE(0x74) BYTE(0x65) BYTE(0x63) BYTE(0x74) -# BYTE(0x75) BYTE(0x72) BYTE(0x65) BYTE(0x22) -# BYTE(0x3a) BYTE(0x22) BYTE(0x78) BYTE(0x38) -# BYTE(0x36) BYTE(0x5f) BYTE(0x36) BYTE(0x34) -# BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x6f) -# BYTE(0x73) BYTE(0x43) BYTE(0x70) BYTE(0x65) -# BYTE(0x22) BYTE(0x3a) BYTE(0x22) BYTE(0x63) -# BYTE(0x70) BYTE(0x65) BYTE(0x3a) BYTE(0x2f) -# BYTE(0x6f) BYTE(0x3a) BYTE(0x66) BYTE(0x65) -# BYTE(0x64) BYTE(0x6f) BYTE(0x72) BYTE(0x61) -# BYTE(0x70) BYTE(0x72) BYTE(0x6f) BYTE(0x6a) -# BYTE(0x65) BYTE(0x63) BYTE(0x74) BYTE(0x3a) -# BYTE(0x66) BYTE(0x65) BYTE(0x64) BYTE(0x6f) -# BYTE(0x72) BYTE(0x61) BYTE(0x3a) BYTE(0x33) -# BYTE(0x33) BYTE(0x22) BYTE(0x7d) BYTE(0x00) -# } -# } -# INSERT AFTER .note.gnu.build-id; -# /* HINT: add -Wl,-dT,/path/to/this/file to $LDFLAGS */ -# -# See https://systemd.io/COREDUMP_PACKAGE_METADATA/ for details. - - -json= -readonly="(READONLY) " -root= - -help() { - echo "Usage: $0 [OPTION]..." - echo "Generate a package notes linker script from specified metadata." - echo - echo " -h, --help display this help and exit" - echo " --readonly BOOL whether to add the READONLY attribute to script (default: true)" - echo " --root PATH when a file (eg: os-release) is parsed, open it relatively to this hierarchy (default: not set)" - echo " --cpe VALUE NIST CPE identifier of the vendor operating system, or 'auto' to parse from system-release-cpe or os-release" - echo " --package-type TYPE set the package type (e.g. 'rpm' or 'deb')" - echo " --package-name NAME set the package name" - echo " --package-version VERSION set the package version" - echo " --package-architecture ARCH set the package architecture" - echo " --NAME VALUE set an arbitrary name/value pair" -} - -invalid_argument() { - printf 'ERROR: "%s" requires a non-empty option argument.\n' "${1}" >&2 - exit 1 -} - -append_parameter() { - if [ -z "${2}" ]; then - invalid_argument "${1}" - fi - - # Posix-compatible substring check - case "$json" in - *"\"${1}\":"*) echo "Duplicated argument: --${1}"; exit 1 ;; - esac - - if [ -z "${json}" ]; then - json="{\"${1}\":\"${2}\"" - else - json="${json},\"${1}\":\"${2}\"" - fi -} - -# Support the same fixed parameters as the python script -parse_options() { - cpe= - - while :; do - case $1 in - -h|-\?|--help) - help - exit - ;; - --readonly) - if [ -z "${2}" ]; then - invalid_argument "${1}" - fi - case $2 in - no|NO|No|false|FALSE|False|0) - readonly="" - ;; - esac - shift - ;; - --root) - if [ -z "${2}" ] || [ ! -d "${2}" ]; then - invalid_argument "${1}" - fi - root="${2}" - shift - ;; - --package-type) - append_parameter "type" "${2}" - shift - ;; - --package-name) - append_parameter "name" "${2}" - shift - ;; - --package-version) - append_parameter "version" "${2}" - shift - ;; - --package-architecture) - append_parameter "architecture" "${2}" - shift - ;; - --cpe) - if [ -z "${2}" ]; then - invalid_argument "${1}" - fi - cpe="${2}" - shift - ;; - --debug-info-url) - append_parameter "debugInfoUrl" "${2}" - shift - ;; - --*) - # Allow passing arbitrary name/value pairs - append_parameter "$(echo "${1}" | cut -c 3-)" "${2}" - shift - ;; - -*) - printf 'WARNING: Unknown option (ignored): %s\n' "${1}" >&2 - ;; - *) - break - esac - - shift - done - - # Parse at the end, so that --root can be used in any position - if [ "${cpe}" = "auto" ]; then - if [ -r "${root}/usr/lib/system-release-cpe" ]; then - cpe="$(cat "${root}/usr/lib/system-release-cpe")" - elif [ -r "${root}/etc/os-release" ]; then - # shellcheck disable=SC1090 disable=SC1091 - cpe="$(. "${root}/etc/os-release" && echo "${CPE_NAME}")" - elif [ -r "${root}/usr/lib/os-release" ]; then - # shellcheck disable=SC1090 disable=SC1091 - cpe="$(. "${root}/usr/lib/os-release" && echo "${CPE_NAME}")" - fi - if [ -z "${cpe}" ]; then - printf 'ERROR: --cpe auto but cannot read %s/usr/lib/system-release-cpe or parse CPE_NAME from %s/etc/os-release or %s/usr/lib/os-release.\n' "${root}" "${root}" "${root}" >&2 - exit 1 - fi - fi - if [ -n "${cpe}" ]; then - append_parameter "osCpe" "${cpe}" - fi - - # Terminate the JSON object - if [ -n "${json}" ]; then - json="${json}}" - fi - - return "$#" -} - -pad_comment() { - for _ in $(seq "$1"); do - printf '\\x00' - done -} - -pad_string() { - for i in $(seq "$1"); do - if [ $(( ( $2 + i - 1) % 4 )) -eq 0 ]; then - printf '\n%sBYTE(0x00)' "${3}" - else - printf ' BYTE(0x00)' - fi - done -} - -write_string() { - text="$1" - prefix="$2" - label="$3" - total="$4" - - # We always have at least the terminating NULL - if [ $(( total % 4)) -eq 0 ]; then - padding_nulls=1 - else - padding_nulls="$(( 1 + 4 - (total % 4) ))" - fi - - for i in $(seq ${#text}); do - if [ $(( i % 4)) -eq 1 ]; then - printf '\n%s' "$prefix" - else - printf ' ' - fi - byte=$(echo "${text}" | cut -c "${i}") - printf 'BYTE(0x%02x)' "'${byte}" - - # Print the json object as a comment after the first 4 bytes - # to match the output of the older script, including padding NUL. - if [ "${i}" -eq 4 ]; then - printf " /* %s: '%s" "$label" "$text" - pad_comment "${padding_nulls}" - printf "' */" - fi - done - - pad_string "${padding_nulls}" "${#text}" "$prefix" - printf '\n' -} - -write_script() { - # NULL terminator is included in the size, but not padding - value_len=$(( ${#1} + 1 )) - - if [ "${value_len}" -gt 65536 ]; then - printf 'ERROR: "%s" is too long.\n' "${1}" >&2 - exit 1 - fi - - printf 'SECTIONS\n{\n' - printf ' .note.package %s: ALIGN(4) {\n' "${readonly}" - # Note that for the binary fields we use the native 4 bytes type, to avoid - # endianness issues. - printf ' LONG(0x0004) /* Length of Owner including NUL */\n' - printf ' LONG(0x%04x) /* Length of Value including NUL */\n' \ - ${value_len} - printf ' LONG(0xcafe1a7e) /* Note ID */\n' - - printf " BYTE(0x46) BYTE(0x44) BYTE(0x4f) BYTE(0x00) /* Owner: 'FDO\\\\x00' */" # newline will be added by write_string - - write_string "$1" ' ' 'Value' "$value_len" - - printf ' }\n}\n' - printf 'INSERT AFTER .note.gnu.build-id;\n' - # shellcheck disable=SC2016 - printf '/* HINT: add -Wl,-dT,/path/to/this/file to $LDFLAGS */\n' -} - -if ! parse_options "$@" && [ "$#" -gt 0 ]; then - # Not supported on every distro - if [ -r "${root}/usr/lib/system-release-cpe" ]; then - cpe="$(cat "${root}/usr/lib/system-release-cpe")" - json_cpe=",\"osCpe\":\"${cpe}\"" - fi - - # old-style invocation with positional parameters for backward compatibility - json="$(printf '{"type":"rpm","name":"%s","version":"%s","architecture":"%s"%s}' "$1" "$2" "$3" "$json_cpe")" -elif [ -z "${json}" ]; then - help - exit 1 -fi - -write_script "$json" diff --git a/hello.spec b/hello.spec index eb0025d..4cf3ebd 100644 --- a/hello.spec +++ b/hello.spec @@ -9,13 +9,11 @@ Summary: Aloha! License: CC0 -BuildRequires: binutils +BuildRequires: binutils >= 2.39 BuildRequires: gcc BuildRequires: rpmdevtools -BuildRequires: python3 -BuildRequires: python3-simplejson -Source0: generate-package-notes.py +Source0: rpm/redhat-package-notes.in %description Test with: @@ -43,20 +41,11 @@ EOF %build set -eo pipefail -ld_version="$(ld --version | sed -r -n '1 {s/.*version (.*)/\1/p}')" -set +e -rpmdev-vercmp "$ld_version" "2.38" >/dev/null -if [ $? == 12 ]; then - readonly="--readonly=no" -fi -set -e - %if %{with notes} -python3 %{SOURCE0} $readonly --rpm '%{name}-%{VERSION}-%{RELEASE}.%{_arch}' | \ - tee notes.ld +sed "s|@OSCPE@|$(cat /usr/lib/system-release-cpe)|" %{SOURCE0} >redhat-package-notes %endif -LDFLAGS="%{build_ldflags} %{?with_notes:-Wl,-dT,$PWD/notes.ld}" +LDFLAGS="%{build_ldflags} %{?with_notes:-specs=$PWD/redhat-package-notes}" CFLAGS="%{build_cflags}" gcc -Wall -fPIC -o libhello.so -shared libhello.c $CFLAGS $LDFLAGS diff --git a/man/generate-package-notes.1 b/man/generate-package-notes.1 deleted file mode 100644 index ebdc55a..0000000 --- a/man/generate-package-notes.1 +++ /dev/null @@ -1,136 +0,0 @@ -.TH GENERATE\-PACKAGE\-NOTES 1 "May 2021" -.SH NAME -generate\-package\-notes \- generate a linker script for package metadata -.SH SYNOPSIS -.B generate\-package\-notes -.RI [ OPTION ...] -.SH DESCRIPTION -ELF binaries get stamped with a unique, build-time generated hex string -identifier called build-id, which gets embedded as an ELF note called -.IR \%.note.gnu.build\-id . -In most cases, this allows to associate a stripped binary with -its debugging information. -It is used, for example, to dynamically fetch DWARF symbols from -a debuginfo server, or to query the local package manager and find out -the package metadata or, again, the DWARF symbols or program sources. -.PP -However, this usage of the build-id requires either local metadata, -usually set up by the package manager, -or access to a remote server over the network. -Both of those might be unavailable or forbidden. -.PP -Thus it becomes desirable to add additional metadata to a binary -at build time, so that -.BR \%systemd\-coredump (8) -and other services analyzing -core files are able to extract said metadata simply from the core file -itself, without external dependencies. -The metadata is embedded in a single ELF header section, -in a key-value JSON format. -.PP -The metadata format is intentionally left open, -so that vendors can add their own information. -A set of well-known keys is defined in the document -.UR https://systemd.io/COREDUMP_PACKAGE_METADATA/ -.B Package Metadata for Core Files -.UE , -and hopefully shared among all vendors. -.PP -.B generate\-package\-notes -generates a linker script on standard output, -which can then be used at build time via -.I \%LDFLAGS="\-Wl,\-dT,/path/to/generated/script" -to include the note in the binary. -If a Debian package is built using the -.BR dh (1) -sequencer, the generation can be partly automated using -.BR \%dh_package_notes (1). -.SH OPTIONS -.TP -.BI \-\-package\-type= TYPE -Set the key -.I type -to -.IR TYPE . -This defaults to -.IR package , -but for Debian packages it should be set to -.IR deb . -.TP -.BI \-\-package\-name= NAME -Set the key -.I name -to -.IR NAME . -This defaults to the empty string, but for Debian packages it should -be set to the name of the binary package containing the binary. -.TP -.BI \-\-package\-version= VERSION -Set the key -.I version -to -.IR VERSION . -This defaults to the empty string, but for Debian packages it should -be set to the Debian version of the binary package containing the binary. -.TP -.BI \-\-package\-architecture= ARCHITECTURE -Set the key -.I architecture -to -.IR ARCHITECTURE . -This defaults to the empty string, but for Debian packages it should -be set to the Debian architecture identifier of the binary. -.TP -.TP -.BI \-\-root= PATH -When reading files, for example /usr/lib/system-release-cpe and /usr/lib/os-release, -open them relatively to the specified directory. -.TP -.BI \-\-cpe= CPE -Set the key -.I osCpe -to -.IR CPE . -If the special value -.I auto -is passed, then the content of the /usr/lib/system-release-cpe file, or the value of CPE_NAME -from os-release if the former was not found, will be used. -.TP -.BI \-\-rpm= PACKAGE \- VERSION -Set the keys -.I type -to -.BR rpm , -.I name -to -.IR PACKAGE , -and -.I version -to -.IR VERSION . -Overrides -.BR \-\-package\-type , -.BR \-\-package\-name , -.BR \-\-package\-architecture , -and -.BR \-\-package\-version . -.TP -.BI \-\-debug\-info\-url= URL -Set the key -.I debugInfoUrl -to -.IR URL . -By default this key is omitted, but for Debian packages it should -be set to the official Debian debuginfod server address -.IR https://debuginfod.debian.org/ . -.TP -.BR \-h ", " \-\-help -Show a short help message and exit. -.SH SEE ALSO -.ad l -.nh -.BR dh_package_notes (1), -.BR systemd\-coredump (8), -.UR https://systemd.io/COREDUMP_PACKAGE_METADATA/ -.B Package Metadata for Core Files -.UE diff --git a/rpm/macros.package-notes-srpm b/rpm/macros.package-notes-srpm index 7899ba6..a15d98c 100644 --- a/rpm/macros.package-notes-srpm +++ b/rpm/macros.package-notes-srpm @@ -6,52 +6,25 @@ # See https://fedoraproject.org/wiki/Changes/Package_information_on_ELF_objects # for details. # -# To opt out of the use of this feature completely, include this in -# the spec file: +# To opt out of the use of this feature completely, include this in the spec +# file: # -# %undefine _package_note_file +# %undefine _package_note_flags # -# The other macros can be undefined too to replace parts of the -# functionality. If %_generate_package_note_file is undefined, the -# linker script will not be generated, but the link flags may still -# refer to it. This may be useful if the default generation method is -# insufficient and a different mechanism will be used to generate -# %_package_note_file. If %_package_note_flags is undefined, the -# linker argument that injects the script will not be added to -# %build_ldfags, but the linker script would still be generated. - -# The name of the file with the linker script. If %{buildsubdir} is -# defined, the file will be placed therein. Otherwise, one level up, -# directly in %{_builddir}. -# -# Note that %{version}-%{release} used here might be redefined from -# the "primary" values when subpackages with different version-release -# are specified. The contents of the script use the shell variable -# $RPM_PACKAGE_NAME, $RPM_PACKAGE_VERSION, $RPM_PACKAGE_RELEASE, -# and $RPM_ARCH that are set early and seem to always contain the "primary" -# values for the main package. -%_package_note_file %{_builddir}%{?buildsubdir:/%{buildsubdir}}/.package_note-%{name}-%{version}-%{release}.%{_arch}.ld - -# Which linker will be used? This should be either "bfd", "gold", or -# "lld". Unfortunately linkers other than bfd do not support some of -# the options that we'd like to use, so if this is set to anything -# other than "bfd", note insertion is disabled. +# Which linker will be used? This should be either "bfd", "gold", "mold", or "lld". # # (The default linker for clang on armv7hl is lld.) %_package_note_linker %["%_target_cpu" == "armv7hl" && "%{toolchain}" == "clang" ? "lld" : "bfd"] -# Whether to specify the READONLY attribute for the inserted -# section. We generally want this, but binutils <= 2.37 and other -# linkers do not support it. -%_package_note_readonly %["%_package_note_linker" == "bfd"?"1":"0"] +# These are defined for backwards compatibility. Do not use. +%_package_note_file 1 +%_generate_package_note_file %{nil} # Overall status: 1 if looks like we can insert the note, 0 otherwise -%_package_note_status %[0%{?_package_note_file:1} && 0%{?name:1} && "%_target_cpu" != "noarch" && "%_package_note_linker" == "bfd" ? 1 : 0] - -# The linker flags to be passed to the compiler to insert the notes section. -%_package_note_flags %[%_package_note_status?"-Wl,%["%_package_note_linker" != "lld"?"-dT":"-T"],%{_package_note_file}":""] +# Unfortunately "clang" does not support specs files so the note insertion is disabled when using it. +%_package_note_status %[0%{?_package_note_file:1} && 0%{?name:1} && "%_target_cpu" != "noarch" && "%{toolchain}" != "clang" ? 1 : 0] -# The command to actually generate the linker script that inserts the -# notes file. This command is automatically used as part of the build -# preamble. -%_generate_package_note_file %[%_package_note_status?"if [ -f %{_rpmconfigdir}/generate-package-notes.sh ]; then %{_rpmconfigdir}/generate-package-notes.sh %[0%{?_package_note_readonly}?"":"--readonly no "]--package-name ${RPM_PACKAGE_NAME:?} --package-version ${RPM_PACKAGE_VERSION:?}-${RPM_PACKAGE_RELEASE:?} --package-architecture ${RPM_ARCH:?} --cpe auto >%{_package_note_file}; fi":""] +# The linker flags to be passed to the compiler to insert the notes section will +# be created by the spec file, to avoid issues with quoting and escaping across +# different build systems and shells. +%_package_note_flags %[%_package_note_status ? "-specs=/usr/lib/rpm/redhat/redhat-package-notes" : ""] diff --git a/rpm/redhat-package-notes.in b/rpm/redhat-package-notes.in new file mode 100644 index 0000000..3a19b1b --- /dev/null +++ b/rpm/redhat-package-notes.in @@ -0,0 +1,2 @@ +*link: ++ --package-metadata={\"type\":\"rpm\",\"name\":\"%:getenv(RPM_PACKAGE_NAME \",\"version\":\"%:getenv(RPM_PACKAGE_VERSION -%:getenv(RPM_PACKAGE_RELEASE \",\"architecture\":\"%:getenv(RPM_ARCH \",\"osCpe\":\"@OSCPE@\"})))) diff --git a/tests/.gitattributes b/tests/.gitattributes deleted file mode 100644 index 51d713a..0000000 --- a/tests/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -resources/* generated diff --git a/tests/_generate_package_notes.py b/tests/_generate_package_notes.py deleted file mode 120000 index e37242a..0000000 --- a/tests/_generate_package_notes.py +++ /dev/null @@ -1 +0,0 @@ -../generate-package-notes.py \ No newline at end of file diff --git a/tests/resources/__init__.py b/tests/resources/__init__.py deleted file mode 100644 index 19b869e..0000000 --- a/tests/resources/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# SPDX-License-Identifier: CC0-1.0 diff --git a/tests/resources/fedora-cpe-os-release.ld b/tests/resources/fedora-cpe-os-release.ld deleted file mode 100644 index 37e67b2..0000000 --- a/tests/resources/fedora-cpe-os-release.ld +++ /dev/null @@ -1,25 +0,0 @@ -SECTIONS -{ - .note.package (READONLY) : ALIGN(4) { - LONG(0x0004) /* Length of Owner including NUL */ - LONG(0x0038) /* Length of Value including NUL */ - LONG(0xcafe1a7e) /* Note ID */ - BYTE(0x46) BYTE(0x44) BYTE(0x4f) BYTE(0x00) /* Owner: 'FDO\x00' */ - BYTE(0x7b) BYTE(0x22) BYTE(0x74) BYTE(0x79) /* Value: '{"type":"rpm","osCpe":"cpe:/o:fedoraproject:fedora:34"}\x00' */ - BYTE(0x70) BYTE(0x65) BYTE(0x22) BYTE(0x3a) - BYTE(0x22) BYTE(0x72) BYTE(0x70) BYTE(0x6d) - BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x6f) - BYTE(0x73) BYTE(0x43) BYTE(0x70) BYTE(0x65) - BYTE(0x22) BYTE(0x3a) BYTE(0x22) BYTE(0x63) - BYTE(0x70) BYTE(0x65) BYTE(0x3a) BYTE(0x2f) - BYTE(0x6f) BYTE(0x3a) BYTE(0x66) BYTE(0x65) - BYTE(0x64) BYTE(0x6f) BYTE(0x72) BYTE(0x61) - BYTE(0x70) BYTE(0x72) BYTE(0x6f) BYTE(0x6a) - BYTE(0x65) BYTE(0x63) BYTE(0x74) BYTE(0x3a) - BYTE(0x66) BYTE(0x65) BYTE(0x64) BYTE(0x6f) - BYTE(0x72) BYTE(0x61) BYTE(0x3a) BYTE(0x33) - BYTE(0x34) BYTE(0x22) BYTE(0x7d) BYTE(0x00) - } -} -INSERT AFTER .note.gnu.build-id; -/* HINT: add -Wl,-dT,/path/to/this/file to $LDFLAGS */ diff --git a/tests/resources/fedora-cpe-system-release.ld b/tests/resources/fedora-cpe-system-release.ld deleted file mode 100644 index c11f5fa..0000000 --- a/tests/resources/fedora-cpe-system-release.ld +++ /dev/null @@ -1,25 +0,0 @@ -SECTIONS -{ - .note.package (READONLY) : ALIGN(4) { - LONG(0x0004) /* Length of Owner including NUL */ - LONG(0x0038) /* Length of Value including NUL */ - LONG(0xcafe1a7e) /* Note ID */ - BYTE(0x46) BYTE(0x44) BYTE(0x4f) BYTE(0x00) /* Owner: 'FDO\x00' */ - BYTE(0x7b) BYTE(0x22) BYTE(0x74) BYTE(0x79) /* Value: '{"type":"rpm","osCpe":"cpe:/o:fedoraproject:fedora:33"}\x00' */ - BYTE(0x70) BYTE(0x65) BYTE(0x22) BYTE(0x3a) - BYTE(0x22) BYTE(0x72) BYTE(0x70) BYTE(0x6d) - BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x6f) - BYTE(0x73) BYTE(0x43) BYTE(0x70) BYTE(0x65) - BYTE(0x22) BYTE(0x3a) BYTE(0x22) BYTE(0x63) - BYTE(0x70) BYTE(0x65) BYTE(0x3a) BYTE(0x2f) - BYTE(0x6f) BYTE(0x3a) BYTE(0x66) BYTE(0x65) - BYTE(0x64) BYTE(0x6f) BYTE(0x72) BYTE(0x61) - BYTE(0x70) BYTE(0x72) BYTE(0x6f) BYTE(0x6a) - BYTE(0x65) BYTE(0x63) BYTE(0x74) BYTE(0x3a) - BYTE(0x66) BYTE(0x65) BYTE(0x64) BYTE(0x6f) - BYTE(0x72) BYTE(0x61) BYTE(0x3a) BYTE(0x33) - BYTE(0x33) BYTE(0x22) BYTE(0x7d) BYTE(0x00) - } -} -INSERT AFTER .note.gnu.build-id; -/* HINT: add -Wl,-dT,/path/to/this/file to $LDFLAGS */ diff --git a/tests/resources/fedora-long-name.ld b/tests/resources/fedora-long-name.ld deleted file mode 100644 index 122eefa..0000000 --- a/tests/resources/fedora-long-name.ld +++ /dev/null @@ -1,88 +0,0 @@ -SECTIONS -{ - .note.package (READONLY) : ALIGN(4) { - LONG(0x0004) /* Length of Owner including NUL */ - LONG(0x0133) /* Length of Value including NUL */ - LONG(0xcafe1a7e) /* Note ID */ - BYTE(0x46) BYTE(0x44) BYTE(0x4f) BYTE(0x00) /* Owner: 'FDO\x00' */ - BYTE(0x7b) BYTE(0x22) BYTE(0x74) BYTE(0x79) /* Value: '{"type":"rpm","name":"rust-plist+enable_unstable_features_that_may_break_with_minor_version_bumps-devel","version":"200:1.3.1~rc1.post2^final3","architecture":"ppc64le","osCpe":"cpe:/o:fedoraproject:fedora:35","debugInfoUrl":"https://somewhere.on.the.internet.there.is.a.server.which.is.never.wrong/query"}\x00\x00' */ - BYTE(0x70) BYTE(0x65) BYTE(0x22) BYTE(0x3a) - BYTE(0x22) BYTE(0x72) BYTE(0x70) BYTE(0x6d) - BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x6e) - BYTE(0x61) BYTE(0x6d) BYTE(0x65) BYTE(0x22) - BYTE(0x3a) BYTE(0x22) BYTE(0x72) BYTE(0x75) - BYTE(0x73) BYTE(0x74) BYTE(0x2d) BYTE(0x70) - BYTE(0x6c) BYTE(0x69) BYTE(0x73) BYTE(0x74) - BYTE(0x2b) BYTE(0x65) BYTE(0x6e) BYTE(0x61) - BYTE(0x62) BYTE(0x6c) BYTE(0x65) BYTE(0x5f) - BYTE(0x75) BYTE(0x6e) BYTE(0x73) BYTE(0x74) - BYTE(0x61) BYTE(0x62) BYTE(0x6c) BYTE(0x65) - BYTE(0x5f) BYTE(0x66) BYTE(0x65) BYTE(0x61) - BYTE(0x74) BYTE(0x75) BYTE(0x72) BYTE(0x65) - BYTE(0x73) BYTE(0x5f) BYTE(0x74) BYTE(0x68) - BYTE(0x61) BYTE(0x74) BYTE(0x5f) BYTE(0x6d) - BYTE(0x61) BYTE(0x79) BYTE(0x5f) BYTE(0x62) - BYTE(0x72) BYTE(0x65) BYTE(0x61) BYTE(0x6b) - BYTE(0x5f) BYTE(0x77) BYTE(0x69) BYTE(0x74) - BYTE(0x68) BYTE(0x5f) BYTE(0x6d) BYTE(0x69) - BYTE(0x6e) BYTE(0x6f) BYTE(0x72) BYTE(0x5f) - BYTE(0x76) BYTE(0x65) BYTE(0x72) BYTE(0x73) - BYTE(0x69) BYTE(0x6f) BYTE(0x6e) BYTE(0x5f) - BYTE(0x62) BYTE(0x75) BYTE(0x6d) BYTE(0x70) - BYTE(0x73) BYTE(0x2d) BYTE(0x64) BYTE(0x65) - BYTE(0x76) BYTE(0x65) BYTE(0x6c) BYTE(0x22) - BYTE(0x2c) BYTE(0x22) BYTE(0x76) BYTE(0x65) - BYTE(0x72) BYTE(0x73) BYTE(0x69) BYTE(0x6f) - BYTE(0x6e) BYTE(0x22) BYTE(0x3a) BYTE(0x22) - BYTE(0x32) BYTE(0x30) BYTE(0x30) BYTE(0x3a) - BYTE(0x31) BYTE(0x2e) BYTE(0x33) BYTE(0x2e) - BYTE(0x31) BYTE(0x7e) BYTE(0x72) BYTE(0x63) - BYTE(0x31) BYTE(0x2e) BYTE(0x70) BYTE(0x6f) - BYTE(0x73) BYTE(0x74) BYTE(0x32) BYTE(0x5e) - BYTE(0x66) BYTE(0x69) BYTE(0x6e) BYTE(0x61) - BYTE(0x6c) BYTE(0x33) BYTE(0x22) BYTE(0x2c) - BYTE(0x22) BYTE(0x61) BYTE(0x72) BYTE(0x63) - BYTE(0x68) BYTE(0x69) BYTE(0x74) BYTE(0x65) - BYTE(0x63) BYTE(0x74) BYTE(0x75) BYTE(0x72) - BYTE(0x65) BYTE(0x22) BYTE(0x3a) BYTE(0x22) - BYTE(0x70) BYTE(0x70) BYTE(0x63) BYTE(0x36) - BYTE(0x34) BYTE(0x6c) BYTE(0x65) BYTE(0x22) - BYTE(0x2c) BYTE(0x22) BYTE(0x6f) BYTE(0x73) - BYTE(0x43) BYTE(0x70) BYTE(0x65) BYTE(0x22) - BYTE(0x3a) BYTE(0x22) BYTE(0x63) BYTE(0x70) - BYTE(0x65) BYTE(0x3a) BYTE(0x2f) BYTE(0x6f) - BYTE(0x3a) BYTE(0x66) BYTE(0x65) BYTE(0x64) - BYTE(0x6f) BYTE(0x72) BYTE(0x61) BYTE(0x70) - BYTE(0x72) BYTE(0x6f) BYTE(0x6a) BYTE(0x65) - BYTE(0x63) BYTE(0x74) BYTE(0x3a) BYTE(0x66) - BYTE(0x65) BYTE(0x64) BYTE(0x6f) BYTE(0x72) - BYTE(0x61) BYTE(0x3a) BYTE(0x33) BYTE(0x35) - BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x64) - BYTE(0x65) BYTE(0x62) BYTE(0x75) BYTE(0x67) - BYTE(0x49) BYTE(0x6e) BYTE(0x66) BYTE(0x6f) - BYTE(0x55) BYTE(0x72) BYTE(0x6c) BYTE(0x22) - BYTE(0x3a) BYTE(0x22) BYTE(0x68) BYTE(0x74) - BYTE(0x74) BYTE(0x70) BYTE(0x73) BYTE(0x3a) - BYTE(0x2f) BYTE(0x2f) BYTE(0x73) BYTE(0x6f) - BYTE(0x6d) BYTE(0x65) BYTE(0x77) BYTE(0x68) - BYTE(0x65) BYTE(0x72) BYTE(0x65) BYTE(0x2e) - BYTE(0x6f) BYTE(0x6e) BYTE(0x2e) BYTE(0x74) - BYTE(0x68) BYTE(0x65) BYTE(0x2e) BYTE(0x69) - BYTE(0x6e) BYTE(0x74) BYTE(0x65) BYTE(0x72) - BYTE(0x6e) BYTE(0x65) BYTE(0x74) BYTE(0x2e) - BYTE(0x74) BYTE(0x68) BYTE(0x65) BYTE(0x72) - BYTE(0x65) BYTE(0x2e) BYTE(0x69) BYTE(0x73) - BYTE(0x2e) BYTE(0x61) BYTE(0x2e) BYTE(0x73) - BYTE(0x65) BYTE(0x72) BYTE(0x76) BYTE(0x65) - BYTE(0x72) BYTE(0x2e) BYTE(0x77) BYTE(0x68) - BYTE(0x69) BYTE(0x63) BYTE(0x68) BYTE(0x2e) - BYTE(0x69) BYTE(0x73) BYTE(0x2e) BYTE(0x6e) - BYTE(0x65) BYTE(0x76) BYTE(0x65) BYTE(0x72) - BYTE(0x2e) BYTE(0x77) BYTE(0x72) BYTE(0x6f) - BYTE(0x6e) BYTE(0x67) BYTE(0x2f) BYTE(0x71) - BYTE(0x75) BYTE(0x65) BYTE(0x72) BYTE(0x79) - BYTE(0x22) BYTE(0x7d) BYTE(0x00) BYTE(0x00) - } -} -INSERT AFTER .note.gnu.build-id; -/* HINT: add -Wl,-dT,/path/to/this/file to $LDFLAGS */ diff --git a/tests/resources/fedora-package.ld b/tests/resources/fedora-package.ld deleted file mode 100644 index c90ab05..0000000 --- a/tests/resources/fedora-package.ld +++ /dev/null @@ -1,33 +0,0 @@ -SECTIONS -{ - .note.package (READONLY) : ALIGN(4) { - LONG(0x0004) /* Length of Owner including NUL */ - LONG(0x0058) /* Length of Value including NUL */ - LONG(0xcafe1a7e) /* Note ID */ - BYTE(0x46) BYTE(0x44) BYTE(0x4f) BYTE(0x00) /* Owner: 'FDO\x00' */ - BYTE(0x7b) BYTE(0x22) BYTE(0x74) BYTE(0x79) /* Value: '{"type":"rpm","name":"package","version":"1.2.3","architecture":"noarch","osCpe":"CPE"}\x00' */ - BYTE(0x70) BYTE(0x65) BYTE(0x22) BYTE(0x3a) - BYTE(0x22) BYTE(0x72) BYTE(0x70) BYTE(0x6d) - BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x6e) - BYTE(0x61) BYTE(0x6d) BYTE(0x65) BYTE(0x22) - BYTE(0x3a) BYTE(0x22) BYTE(0x70) BYTE(0x61) - BYTE(0x63) BYTE(0x6b) BYTE(0x61) BYTE(0x67) - BYTE(0x65) BYTE(0x22) BYTE(0x2c) BYTE(0x22) - BYTE(0x76) BYTE(0x65) BYTE(0x72) BYTE(0x73) - BYTE(0x69) BYTE(0x6f) BYTE(0x6e) BYTE(0x22) - BYTE(0x3a) BYTE(0x22) BYTE(0x31) BYTE(0x2e) - BYTE(0x32) BYTE(0x2e) BYTE(0x33) BYTE(0x22) - BYTE(0x2c) BYTE(0x22) BYTE(0x61) BYTE(0x72) - BYTE(0x63) BYTE(0x68) BYTE(0x69) BYTE(0x74) - BYTE(0x65) BYTE(0x63) BYTE(0x74) BYTE(0x75) - BYTE(0x72) BYTE(0x65) BYTE(0x22) BYTE(0x3a) - BYTE(0x22) BYTE(0x6e) BYTE(0x6f) BYTE(0x61) - BYTE(0x72) BYTE(0x63) BYTE(0x68) BYTE(0x22) - BYTE(0x2c) BYTE(0x22) BYTE(0x6f) BYTE(0x73) - BYTE(0x43) BYTE(0x70) BYTE(0x65) BYTE(0x22) - BYTE(0x3a) BYTE(0x22) BYTE(0x43) BYTE(0x50) - BYTE(0x45) BYTE(0x22) BYTE(0x7d) BYTE(0x00) - } -} -INSERT AFTER .note.gnu.build-id; -/* HINT: add -Wl,-dT,/path/to/this/file to $LDFLAGS */ diff --git a/tests/resources/root-no-cpe/usr/lib/os-release b/tests/resources/root-no-cpe/usr/lib/os-release deleted file mode 100644 index 86268aa..0000000 --- a/tests/resources/root-no-cpe/usr/lib/os-release +++ /dev/null @@ -1 +0,0 @@ -CPE_NAME="cpe:/o:fedoraproject:fedora:34" diff --git a/tests/resources/root/usr/lib/os-release b/tests/resources/root/usr/lib/os-release deleted file mode 100644 index 560da14..0000000 --- a/tests/resources/root/usr/lib/os-release +++ /dev/null @@ -1 +0,0 @@ -ID=fedora diff --git a/tests/resources/root/usr/lib/system-release-cpe b/tests/resources/root/usr/lib/system-release-cpe deleted file mode 100644 index 769fe43..0000000 --- a/tests/resources/root/usr/lib/system-release-cpe +++ /dev/null @@ -1 +0,0 @@ -cpe:/o:fedoraproject:fedora:33 \ No newline at end of file diff --git a/tests/resources/very-short-rw.ld b/tests/resources/very-short-rw.ld deleted file mode 100644 index 01a1f0f..0000000 --- a/tests/resources/very-short-rw.ld +++ /dev/null @@ -1,29 +0,0 @@ -SECTIONS -{ - .note.package : ALIGN(4) { - LONG(0x0004) /* Length of Owner including NUL */ - LONG(0x0047) /* Length of Value including NUL */ - LONG(0xcafe1a7e) /* Note ID */ - BYTE(0x46) BYTE(0x44) BYTE(0x4f) BYTE(0x00) /* Owner: 'FDO\x00' */ - BYTE(0x7b) BYTE(0x22) BYTE(0x74) BYTE(0x79) /* Value: '{"type":"deb","name":"A","version":"0","architecture":"x","osCpe":"o"}\x00\x00' */ - BYTE(0x70) BYTE(0x65) BYTE(0x22) BYTE(0x3a) - BYTE(0x22) BYTE(0x64) BYTE(0x65) BYTE(0x62) - BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x6e) - BYTE(0x61) BYTE(0x6d) BYTE(0x65) BYTE(0x22) - BYTE(0x3a) BYTE(0x22) BYTE(0x41) BYTE(0x22) - BYTE(0x2c) BYTE(0x22) BYTE(0x76) BYTE(0x65) - BYTE(0x72) BYTE(0x73) BYTE(0x69) BYTE(0x6f) - BYTE(0x6e) BYTE(0x22) BYTE(0x3a) BYTE(0x22) - BYTE(0x30) BYTE(0x22) BYTE(0x2c) BYTE(0x22) - BYTE(0x61) BYTE(0x72) BYTE(0x63) BYTE(0x68) - BYTE(0x69) BYTE(0x74) BYTE(0x65) BYTE(0x63) - BYTE(0x74) BYTE(0x75) BYTE(0x72) BYTE(0x65) - BYTE(0x22) BYTE(0x3a) BYTE(0x22) BYTE(0x78) - BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x6f) - BYTE(0x73) BYTE(0x43) BYTE(0x70) BYTE(0x65) - BYTE(0x22) BYTE(0x3a) BYTE(0x22) BYTE(0x6f) - BYTE(0x22) BYTE(0x7d) BYTE(0x00) BYTE(0x00) - } -} -INSERT AFTER .note.gnu.build-id; -/* HINT: add -Wl,-dT,/path/to/this/file to $LDFLAGS */ diff --git a/tests/resources/very-short.ld b/tests/resources/very-short.ld deleted file mode 100644 index 5a3b9eb..0000000 --- a/tests/resources/very-short.ld +++ /dev/null @@ -1,29 +0,0 @@ -SECTIONS -{ - .note.package (READONLY) : ALIGN(4) { - LONG(0x0004) /* Length of Owner including NUL */ - LONG(0x0047) /* Length of Value including NUL */ - LONG(0xcafe1a7e) /* Note ID */ - BYTE(0x46) BYTE(0x44) BYTE(0x4f) BYTE(0x00) /* Owner: 'FDO\x00' */ - BYTE(0x7b) BYTE(0x22) BYTE(0x74) BYTE(0x79) /* Value: '{"type":"deb","name":"A","version":"0","architecture":"x","osCpe":"o"}\x00\x00' */ - BYTE(0x70) BYTE(0x65) BYTE(0x22) BYTE(0x3a) - BYTE(0x22) BYTE(0x64) BYTE(0x65) BYTE(0x62) - BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x6e) - BYTE(0x61) BYTE(0x6d) BYTE(0x65) BYTE(0x22) - BYTE(0x3a) BYTE(0x22) BYTE(0x41) BYTE(0x22) - BYTE(0x2c) BYTE(0x22) BYTE(0x76) BYTE(0x65) - BYTE(0x72) BYTE(0x73) BYTE(0x69) BYTE(0x6f) - BYTE(0x6e) BYTE(0x22) BYTE(0x3a) BYTE(0x22) - BYTE(0x30) BYTE(0x22) BYTE(0x2c) BYTE(0x22) - BYTE(0x61) BYTE(0x72) BYTE(0x63) BYTE(0x68) - BYTE(0x69) BYTE(0x74) BYTE(0x65) BYTE(0x63) - BYTE(0x74) BYTE(0x75) BYTE(0x72) BYTE(0x65) - BYTE(0x22) BYTE(0x3a) BYTE(0x22) BYTE(0x78) - BYTE(0x22) BYTE(0x2c) BYTE(0x22) BYTE(0x6f) - BYTE(0x73) BYTE(0x43) BYTE(0x70) BYTE(0x65) - BYTE(0x22) BYTE(0x3a) BYTE(0x22) BYTE(0x6f) - BYTE(0x22) BYTE(0x7d) BYTE(0x00) BYTE(0x00) - } -} -INSERT AFTER .note.gnu.build-id; -/* HINT: add -Wl,-dT,/path/to/this/file to $LDFLAGS */ diff --git a/tests/test_basics.py b/tests/test_basics.py deleted file mode 100644 index 550e7ec..0000000 --- a/tests/test_basics.py +++ /dev/null @@ -1,54 +0,0 @@ -# SPDX-License-Identifier: CC0-1.0 - -import sys -from importlib import resources -from pathlib import Path - -from _generate_package_notes import gather_data, generate_section - - -class dict_dot(dict): - __getattr__ = dict.get - -def test_fedora_package(): - input = dict(type='rpm', name='package', version='1.2.3', architecture='noarch', osCpe='CPE') - text = '\n'.join(generate_section(input)) - expected = resources.read_text('resources', 'fedora-package.ld') - assert text == expected[:-1] - -def test_very_short(): - input = dict(type='deb', name='A', version='0', architecture='x', osCpe='o') - text = '\n'.join(generate_section(input)) - expected = resources.read_text('resources', 'very-short.ld') - assert text == expected[:-1] - -def test_very_short_rw(): - input = dict(type='deb', name='A', version='0', architecture='x', osCpe='o') - text = '\n'.join(generate_section(input, readonly=False)) - expected = resources.read_text('resources', 'very-short-rw.ld') - assert text == expected[:-1] - -def test_fedora_long_name(): - input = dict(type='rpm', - name='rust-plist+enable_unstable_features_that_may_break_with_minor_version_bumps-devel', - version='200:1.3.1~rc1.post2^final3', - architecture='ppc64le', - osCpe='cpe:/o:fedoraproject:fedora:35', - debugInfoUrl='https://somewhere.on.the.internet.there.is.a.server.which.is.never.wrong/query') - text = '\n'.join(generate_section(input)) - expected = resources.read_text('resources', 'fedora-long-name.ld') - assert text == expected[:-1] - -def test_auto_cpe_system_release(): - opts = dict_dot(package_type='rpm', cpe='auto', root=Path(__file__).absolute().parent / 'resources/root/') - input = gather_data(opts) - text = '\n'.join(generate_section(input)) - expected = resources.read_text('resources', 'fedora-cpe-system-release.ld') - assert text == expected[:-1] - -def test_auto_cpe_os_release(): - opts = dict_dot(package_type='rpm', cpe='auto', root=Path(__file__).absolute().parent / 'resources/root-no-cpe/') - input = gather_data(opts) - text = '\n'.join(generate_section(input)) - expected = resources.read_text('resources', 'fedora-cpe-os-release.ld') - assert text == expected[:-1] diff --git a/tests/test_basics.sh b/tests/test_basics.sh deleted file mode 100755 index 8262cca..0000000 --- a/tests/test_basics.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: CC0-1.0 - -set -e - -testdir="$(dirname "$(realpath "${0}")")" - -diff <("${testdir}/../generate-package-notes.sh" --type rpm --name package --version 1.2.3 --architecture noarch --osCpe CPE) "${testdir}/resources/fedora-package.ld" -diff <("${testdir}/../generate-package-notes.sh" --type deb --name A --package-version 0 --architecture x --cpe o) "${testdir}/resources/very-short.ld" -diff <("${testdir}/../generate-package-notes.sh" --type deb --name A --version 0 --architecture x --osCpe o --readonly false) "${testdir}/resources/very-short-rw.ld" -diff <("${testdir}/../generate-package-notes.sh" --type rpm --name rust-plist+enable_unstable_features_that_may_break_with_minor_version_bumps-devel --version 200:1.3.1~rc1.post2^final3 --architecture ppc64le --osCpe cpe:/o:fedoraproject:fedora:35 --debugInfoUrl https://somewhere.on.the.internet.there.is.a.server.which.is.never.wrong/query) "${testdir}/resources/fedora-long-name.ld" -diff <("${testdir}/../generate-package-notes.sh" --type rpm --cpe auto --root "${testdir}/resources/root-no-cpe/") "${testdir}/resources/fedora-cpe-os-release.ld" -diff <("${testdir}/../generate-package-notes.sh" --type rpm --cpe auto --root "${testdir}/resources/root/") "${testdir}/resources/fedora-cpe-system-release.ld"