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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-01-22 11:20:25 +01:00
parent b7381d643d
commit 87708e909b
2 changed files with 11 additions and 2 deletions

View File

@ -1,5 +1,7 @@
#!/bin/bash
readonly=1
pad_string() {
for _ in $(seq "$1"); do
printf ' BYTE(0x00)'
@ -28,9 +30,10 @@ write_string() {
write_script() {
value_len=$(( (${#1} + 3) / 4 * 4 ))
[ -n "$readonly" ] && readonly_attr='(READONLY) '
printf 'SECTIONS\n{\n'
printf ' .note.package (READONLY) : ALIGN(4) {\n'
printf ' .note.package %s: ALIGN(4) {\n' "$readonly_attr"
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))
@ -44,6 +47,11 @@ write_script() {
printf 'INSERT AFTER .note.gnu.build-id;\n'
}
if [ "$1" == "--readonly=no" ]; then
shift
readonly=
fi
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

@ -2,7 +2,8 @@
# See https://fedoraproject.org/wiki/Changes/Package_information_on_ELF_objects
# for details.
%_package_note_file %{_builddir}%{?buildsubdir:/%{buildsubdir}}/.package_note-%{name}-%{version}-%{release}.%{_arch}.ld
%_package_note_readonly 1
%_package_note_flags %{?_package_note_file:%{?name:%["%_target_cpu" == "noarch"?"":"-Wl,-dT,%{_package_note_file}"]}}
%_generate_package_note_file %{?_package_note_file:%{?name:%["%_target_cpu" == "noarch"?"":"if [ -f %{_rpmconfigdir}/generate-rpm-note.sh ]; then %{_rpmconfigdir}/generate-rpm-note.sh ${RPM_PACKAGE_NAME:?} ${RPM_PACKAGE_VERSION:?}-${RPM_PACKAGE_RELEASE:?} ${RPM_ARCH:?} >%{_package_note_file}; fi"]}}
%_generate_package_note_file %{?_package_note_file:%{?name:%["%_target_cpu" == "noarch"?"":"if [ -f %{_rpmconfigdir}/generate-rpm-note.sh ]; then %{_rpmconfigdir}/generate-rpm-note.sh %{!?_package_note_readonly:--readonly=no} ${RPM_PACKAGE_NAME:?} ${RPM_PACKAGE_VERSION:?}-${RPM_PACKAGE_RELEASE:?} ${RPM_ARCH:?} >%{_package_note_file}; fi"]}}