Compare commits

...
Sign in to create a new pull request.

29 commits

Author SHA1 Message Date
Fedora Release Engineering
9fc5054e7b Rebuilt for https://fedoraproject.org/wiki/Fedora_43_Mass_Rebuild 2025-07-24 23:51:09 +00:00
Fedora Release Engineering
46cd4aa72b Rebuilt for https://fedoraproject.org/wiki/Fedora_42_Mass_Rebuild 2025-01-17 22:09:44 +00:00
Fedora Release Engineering
799dca8e72 Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild 2024-07-18 21:17:17 +00:00
Fedora Release Engineering
6b27ac2112 Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild 2024-01-25 11:45:53 +00:00
Fedora Release Engineering
fada8d387c Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild 2024-01-21 11:40:19 +00:00
Fedora Release Engineering
8819e2bc7f Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2023-07-20 18:28:14 +00:00
Zbigniew Jędrzejewski-Szmek
f329e5dd44 Make sure redhat-package-notes spec is skipped if _package_note_flags is undefined
... (rbhz#2184553)

The proposed fix was provided by Adam Williamson.
2023-05-20 20:49:07 +02:00
Fedora Release Engineering
a57c7ae4f3 Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2023-01-19 23:13:02 +00:00
Luca Boccassi
9f2673bf3a test: run clang build too 2022-09-03 15:26:26 +01:00
Luca Boccassi
42dfa0c11b Disable by default with lld
lld does not support -spec files, so it cannot be used. Disable it again.

- Fixes RHBZ#2119266
2022-08-29 13:44:29 +01:00
Benjamin A. Beasley
791dc804c3 Fix regression due to typo in _package_note_status
- Fixes RHBZ#2118722
2022-08-16 10:31:14 -04:00
Zbigniew Jędrzejewski-Szmek
9f2cdc9ab4 Switch to --package-metadata also with lld 2022-08-16 15:32:17 +02:00
Zbigniew Jędrzejewski-Szmek
5c54ab3586 Adjust whitespace and tweak comments
Also drop the now-unused script.

The URL is restored because we have documentation there.

[skip changelog]

drop
2022-08-16 15:32:17 +02:00
Luca Boccassi
9da9df8af2 Switch to --package-metadata
Use a compiler specs file to avoid issues with escaping and quoting
when a package is built using autotools.
Generate the osCpe string at build time for now, as it's not set
as an env var by rpm yet.
2022-08-09 10:59:13 +01:00
Tom Stellard
145f26fa48 Add CI test 2022-08-06 19:24:00 +02:00
Fedora Release Engineering
5615a58334 Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2022-07-22 02:31:01 +00:00
Luca Boccassi
58ec8a67f5 Fix wrong binary fields on big endian
Sync with https://github.com/systemd/package-notes/pull/31

On big endian machines we need to swap the first three fields, which
are binary and thus need to match endianess.
Just use LONG() instead of BYTE sequences.
2022-03-26 18:22:42 +00:00
Zbigniew Jędrzejewski-Szmek
d26d18e6f4 Disable notes when clang toolchain is used on arm
Per https://bugzilla.redhat.com/show_bug.cgi?id=2043178#c27.
2022-01-25 18:19:07 +01:00
Zbigniew Jędrzejewski-Szmek
2ee6aa07f8 Disable notes with linkers other than bfd
%_package_note_linker != "bfd" disables note insertion, so that it also works
as another opt-out mechanism. Maybe we can improve support in the future.

From https://bugzilla.redhat.com/show_bug.cgi?id=2043178#c26:

  It turns out that gold does something wrong with sections.
  When we add the new section, it shifts existing sections (and even gets one section less than before):
  │ -  Entry point address:               0x500
  │ +  Entry point address:               0x50
  │    Start of program headers:          64 (bytes into file)
  │ -  Start of section headers:          6328 (bytes into file)
  │ +  Start of section headers:          8344 (bytes into file)
  │    Flags:                             0x0
  │    Size of this header:               64 (bytes)
  │    Size of program headers:           56 (bytes)
  │ -  Number of program headers:         9
  │ +  Number of program headers:         8
  │    Size of section headers:           64 (bytes)
  │ -  Number of section headers:         36
  │ -  Section header string table index: 35
  │ +  Number of section headers:         38
  │ +  Section header string table index: 37

  There's a bug open to add INSERT AFTER [https://sourceware.org/bugzilla/show_bug.cgi?id=15373],
  but it's 8 years old.

  Opting out seems to be the best we can do for now.

I also noticed that gold support -dT, only lld doesn't, so the conditional is
adjusted accordingly.
2022-01-24 13:10:04 +01:00
Zbigniew Jędrzejewski-Szmek
41c9a3140e Add --insert-after param to the note generation script
I thought this would allow insertion with ld.gold, but it turns out
that the resulting binary has something wrong with sections. So only the
change to the script is committed, because it makes it much easier to
experiment with various linkers.
2022-01-24 13:09:53 +01:00
Zbigniew Jędrzejewski-Szmek
e9d5c37bb3 Add %_package_note_linker and document everything (rhbz#2043178, rhbz#2043368) 2022-01-22 12:02:34 +01:00
Zbigniew Jędrzejewski-Szmek
87708e909b Allow unsetting %_package_note_readonly to drop the READONLY attribute
READONLY is supported in ld.bfd from binutils >= 2.38, though the
patch was backported in rawhide. It is also unsupported by ld.gold,
so let's make it easy to skip it, since things will also work without
it, just a tiny bit worse.
2022-01-22 11:20:25 +01:00
Zbigniew Jędrzejewski-Szmek
b7381d643d Use %{buildsubdir} in %_package_note_file if defined
Thanks to this the file is (in the common case) created in the unpacked
build directory, and not one level up. I.e.
/builddir/build/BUILD/lirc-0.10.0/.package_note-lirc-0.10.0-34.fc36.x86_64
instead of /builddir/build/BUILD/.package_note-lirc-0.10.0-34.fc36.x86_64.ld.
This is nicer esp. for 'fedpkg local' builds, where the dist-git directory is
used as the build dir.

When there are multiple %setup calls, the *last* extracted directory
becomes %{buildsubdir}. This might be confusing, but it shouldn't cause
problems for this use.

Suggested in https://bugzilla.redhat.com/show_bug.cgi?id=2043092#c21.
2022-01-21 17:01:16 +01:00
Zbigniew Jędrzejewski-Szmek
d32fe6caa2 Also voidify the macros if we're on a noarch build
IIUC, the normal %ifarch syntax cannot be used, because the definition
needs to be inline. The best I could find is %_target_cpu, which seems to be
set to "noarch" for noarch builds.
2022-01-21 17:01:16 +01:00
Zbigniew Jędrzejewski-Szmek
04c3c7d716 Use $RPM_PACKAGE_VERSION variable to refer to the package version
When subpackages are used, and have different Version fields, we end up with
the version of the last subpackage in %version. But RPM_PACKAGE_VERSION is
set early, and seems to have the right version.

Fixes rhbz#2043143.
2022-01-21 17:01:16 +01:00
Zbigniew Jędrzejewski-Szmek
1acac701a6 Make _generate_package_note_file always recreate the file
The idea was that we can avoid unnecessary work if the macro is called more than
once. But in hindsight this might be risky: let's instead minimize the number of
places where the macros is called, but always overwrite the file so that we
don't end up with a stale version from a previous build.
2022-01-21 17:01:16 +01:00
Zbigniew Jędrzejewski-Szmek
fb5900700e Conditionalize all macros on %_package_note_file being defined
This way %undefine _package_note_file is a good way to opt-out of the
feature. The other macros wouldn't work without %_package_note_file anyway.
2022-01-21 17:01:16 +01:00
Fedora Release Engineering
52ae83790c - Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2022-01-20 22:44:01 +00:00
Zbigniew Jędrzejewski-Szmek
070ec6f27f Rename srpm macros file 2022-01-14 19:17:33 +01:00
14 changed files with 185 additions and 88 deletions

1
.fmf/version Normal file
View file

@ -0,0 +1 @@
1

1
.gitignore vendored
View file

@ -1 +1,2 @@
/package-notes-0.4.tar.gz
/redhat-package-notes

57
changelog Normal file
View file

@ -0,0 +1,57 @@
* Tue Aug 16 2022 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.5-3
- Switch to --package-metadata also with lld (#2051597)
* Tue Aug 09 2022 Luca Boccassi <bluca@debian.org> - 0.5-1
- Switch to --package-metadata (#2055863, #2083878, #2099999, #2059858, #2055458)
* Sat Aug 06 2022 Tom Stellard <tstellar@redhat.com> - 0.4-17
- Add CI test
* Fri Jul 22 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.4-16
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild
* Sat Mar 26 2022 Luca Boccassi <bluca@debian.org> - 0.4-15
- Fix wrong binary fields on big endian
* Tue Jan 25 2022 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.4-14
- Disable notes when clang toolchain is used on arm
* Mon Jan 24 2022 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.4-13
- Disable notes with linkers other than bfd
* Mon Jan 24 2022 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.4-12
- Add --insert-after param to the note generation script
* Sat Jan 22 2022 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.4-11
- Add %%_package_note_linker and document everything (rhbz#2043178,
rhbz#2043368)
* Sat Jan 22 2022 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.4-10
- Allow unsetting %%_package_note_readonly to drop the READONLY attribute
* Fri Jan 21 2022 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.4-9
- Use %%{buildsubdir} in %%_package_note_file if defined
* Fri Jan 21 2022 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.4-8
- Also voidify the macros if we're on a noarch build
* Fri Jan 21 2022 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.4-7
- Use $RPM_PACKAGE_VERSION variable to refer to the package version
* Fri Jan 21 2022 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.4-6
- Make _generate_package_note_file always recreate the file
* Fri Jan 21 2022 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.4-5
- Conditionalize all macros on %%_package_note_file being defined
* Thu Jan 20 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.4-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild
* Fri Jan 14 2022 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.4-3
- Rename srpm macros file
* Fri Jan 14 2022 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.4-2
- Add package-notes-srpm-macros subpackage to configure rpm builds
* Tue Nov 16 2021 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.4-1
- Version 0.4

View file

@ -1,49 +0,0 @@
#!/bin/bash
pad_string() {
for _ in $(seq "$1"); do
printf ' BYTE(0x00)'
done
}
write_string() {
text="$1"
prefix="$2"
label="$3"
total="$4"
printf "%s/* %s: '%s' */" "$prefix" "$label" "$text"
for i in $(seq ${#text}); do
if (( i % 4 == 1 )); then
printf '\n%s' "$prefix"
else
printf ' '
fi
printf 'BYTE(0x%02x)' "'${text:i-1:1}"
done
pad_string $(( total - ${#text} ))
printf '\n'
}
write_script() {
value_len=$(( (${#1} + 3) / 4 * 4 ))
printf 'SECTIONS\n{\n'
printf ' .note.package (READONLY) : ALIGN(4) {\n'
printf ' BYTE(0x04) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Owner including NUL */\n'
printf ' BYTE(0x%02x) BYTE(0x%02x) BYTE(0x00) BYTE(0x00) /* Length of Value including NUL */\n' \
$((value_len % 256)) $((value_len / 256))
printf ' BYTE(0x7e) BYTE(0x1a) BYTE(0xfe) BYTE(0xca) /* Note ID */\n'
printf " BYTE(0x46) BYTE(0x44) BYTE(0x4f) BYTE(0x00) /* Owner: 'FDO' */\n"
write_string "$1" ' ' 'Value' "$value_len"
printf ' }\n}\n'
printf 'INSERT AFTER .note.gnu.build-id;\n'
}
cpe="$(cat /usr/lib/system-release-cpe)"
json="$(printf '{"type":"rpm","name":"%s","version":"%s","architecture":"%s","osCpe":"%s"}' "$1" "$2" "$3" "$cpe")"
write_script "$json"

View file

@ -1,8 +0,0 @@
# Add an ELF note with information about the package the code was compiled for.
# See https://fedoraproject.org/wiki/Changes/Package_information_on_ELF_objects
# for details.
%_package_note_file %{_builddir}/.package_note-%{name}-%{version}-%{release}.%{_arch}.ld
%_package_note_flags %{?name:-Wl,-dT,%{_package_note_file}}
%_generate_package_note_file %{?name: if ! [ -f %{_package_note_file} ] && [ -f %{_rpmconfigdir}/generate-rpm-note.sh ]; then %{_rpmconfigdir}/generate-rpm-note.sh %{name} %{version}-%{release} %{_arch} >%{_package_note_file}; fi}

29
macros.package-notes-srpm Normal file
View file

@ -0,0 +1,29 @@
# This file is part of the package-notes package.
#
# Add an ELF note with information about the package the code was compiled for.
# 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:
#
# %undefine _package_note_flags
#
# 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"]
# 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
# Unfortunately "clang" does not support specs files so the note insertion is disabled when using it.
%_package_note_status %{!?_package_note_flags:0}%{?_package_note_flags:%[0%{?_package_note_file:1} && 0%{?name:1} && "%_target_cpu" != "noarch" && "%{toolchain}" != "clang" ? 1 : 0]}
# 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" : ""]

View file

@ -1,21 +1,14 @@
Name: package-notes
Version: 0.4
Version: 0.5
Release: %autorelease
Summary: Generate a linker script to insert .note.package section
Summary: Generate LDFLAGS to insert .note.package section
License: 0BSD
URL: https://github.com/systemd/package-notes
%global forgeurl https://github.com/systemd/package-notes
%forgemeta
License: CC0
URL: %{forgeurl}
Source0: %{forgesource}
Source1: generate-rpm-note.sh
Source2: macros.package-notes-srpm
Source0: redhat-package-notes.in
Source1: macros.package-notes-srpm
BuildArch: noarch
BuildRequires: python3-devel
Requires: python3dist(simplejson)
%description
This package provides a generator of linker scripts that insert a section with
@ -24,32 +17,29 @@ for.
%package srpm-macros
Summary: %{summary}
Obsoletes: package-notes < 0.5
# Those are minimum versions that implement --package-metadata
Conflicts: binutils < 2.37-34
Conflicts: binutils-gold < 2.37-34
Conflicts: mold < 1.3.0
Conflicts: lld < 14.0.5-4
%description srpm-macros
RPM macros to inject a linker script into link flags and a helper to generate
a script that inserts a section with an ELF note with a JSON payload that
describes the package the binary was built for.
RPM macros to insert a section with an ELF note with a JSON payload that
describes the package the binary was built for via a compiler spec file.
%prep
%autosetup
%build
# nothing to do
%build
sed "s|@OSCPE@|$(cat /usr/lib/system-release-cpe)|" %{SOURCE0} >redhat-package-notes
%install
install -Dt %{buildroot}%{_bindir}/ generate-package-notes
install -m0644 -Dt %{buildroot}%{_mandir}/man1/ debian/generate-package-notes.1
# A partial reimplementation without Python
install -Dt %{buildroot}%{_rpmconfigdir}/ %{SOURCE1}
install -m0644 -Dt %{buildroot}%{_rpmmacrodir}/ %{SOURCE2}
%files
%{_bindir}/generate-package-notes
%{_mandir}/man1/generate-package-notes.1*
install -Dt %{buildroot}%{_rpmconfigdir}/redhat/ redhat-package-notes
install -m0644 -Dt %{buildroot}%{_rpmmacrodir}/ %{SOURCE1}
%files srpm-macros
%{_rpmconfigdir}/generate-rpm-note.sh
%{_rpmconfigdir}/redhat/redhat-package-notes
%{_rpmmacrodir}/macros.package-notes-srpm
%changelog

5
plans/basic.fmf Normal file
View file

@ -0,0 +1,5 @@
summary: Basic smoke test
discover:
how: fmf
execute:
how: tmt

2
redhat-package-notes.in Normal file
View file

@ -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@\"}))))

View file

@ -1 +0,0 @@
SHA512 (package-notes-0.4.tar.gz) = 97a36e4125db99bca02e02eac5d2f823ae38e4c8a083a624f5f72f8d4a4c80fcfb24c8d15bbb922e0f28f5d6da97a87789a881a26aa02e2c1034c485a8866735

4
tests/build-gating.fmf Normal file
View file

@ -0,0 +1,4 @@
discover:
how: fmf
exexute:
how: tmt

View file

@ -0,0 +1,6 @@
summary: Test build a simple RPM package to ensure package notes are working
require:
- dnf
- dnf-plugins-core
- rpm-build
test: ./runtest.sh

10
tests/simple-rpm/runtest.sh Executable file
View file

@ -0,0 +1,10 @@
#!/bin/bash
set -ex
dnf -y build-dep test.spec
rpmbuild --define '_sourcedir .' --define '_builddir .' -bb test.spec
dnf -y build-dep test.spec -D "_with_ld_lld 1"
rpmbuild --with ld_lld --define '_sourcedir .' --define '_builddir .' -bb test.spec
dnf -y build-dep test.spec -D "_with_clang 1"
rpmbuild --with clang --define '_sourcedir .' --define '_builddir .' -bb test.spec

View file

@ -0,0 +1,50 @@
%bcond_with ld_lld
%bcond_with clang
%if %{with ld_lld}
%global extra_ldflags -fuse-ld=lld
%global _package_note_linker lld
%endif
%if %{with clang}
%global toolchain clang
%endif
Name: test
Version: 1
Release: 1
Summary: Test package for checking package notes
License: MIT
%if %{with clang}
BuildRequires: clang
%else
BuildRequires: gcc
%endif
# For %check
BuildRequires: binutils
BuildRequires: jq
%if %{with ld_lld}
BuildRequires: lld
%endif
%description
Test package for checking package notes
%build
echo 'int main(int argc, char **argv) { return 0; }' | %{build_cc} ${CFLAGS} -x c -c - -o main.o
%{build_cc} -Werror ${LDFLAGS} %{?extra_ldflags} main.o -o main
# Package notes not supported with clang, so the the build succeeding is enough.
%if %{without clang}
%check
# avoid any attempt to access the network by readelf
export DEBUGINFOD_URLS=
readelf --notes ./main | sed -r -n 's/.*Packaging Metadata: (.*)/\1/p' | tee package-note.text
test "`cat package-note.text | jq -r '[.type,.name,.version,.architecture]|join(" ")'`" == "rpm %{name} %{version}-%{release} %{_arch}"
%endif
%changelog
* Sat Aug 6 2022 Jane Doe <jane@example.org> - 1-1
- Dummy