summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 04:57:16 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 04:57:16 +0000
commit82675113ae9f5f1ab73bcbd5fd18754174e4aec9 (patch)
tree047edc3b1bc6ab6f1fb7e8979bc1244343aef390
parentInitial commit. (diff)
downloadpackage-notes-82675113ae9f5f1ab73bcbd5fd18754174e4aec9.tar.xz
package-notes-82675113ae9f5f1ab73bcbd5fd18754174e4aec9.zip
Adding upstream version 0.9.upstream/0.9upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
-rw-r--r--README.md17
-rw-r--r--hello.spec74
-rw-r--r--rpm/macros.package-notes-srpm30
-rw-r--r--rpm/redhat-package-notes.in2
4 files changed, 123 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..6dccd9d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,17 @@
+ELF Package Notes Reference Implementation
+
+## Description
+
+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/ELF_PACKAGE_METADATA/)
+for the overview and details.
+
+The new `--package-metadata` option provided by bfd, gold, mold and lld is used.
+
+## Requirements
+* binutils (>= 2.39)
+* mold (>= 1.3.0)
+* lld (>= 15.0.0)
diff --git a/hello.spec b/hello.spec
new file mode 100644
index 0000000..4cf3ebd
--- /dev/null
+++ b/hello.spec
@@ -0,0 +1,74 @@
+# SPDX-License-Identifier: CC0-1.0
+
+%bcond_without notes
+
+Name: hello
+Version: 0
+Release: 1%{?dist}%{!?with_notes:.nonotes}
+Summary: Aloha!
+
+License: CC0
+
+BuildRequires: binutils >= 2.39
+BuildRequires: gcc
+BuildRequires: rpmdevtools
+
+Source0: rpm/redhat-package-notes.in
+
+%description
+Test with:
+objdump -s -j .note.package %{_bindir}/hello
+objdump -s -j .note.package %{_libdir}/libhello.so
+
+%prep
+%setup -cT
+set -eo pipefail
+
+cat <<EOF >libhello.c
+const char* greeting(void) {
+ return "Hello";
+}
+EOF
+cat <<EOF >hello.c
+#include <stdio.h>
+extern char* greeting(void);
+int main() {
+ puts(greeting());
+ return 0;
+}
+EOF
+
+%build
+set -eo pipefail
+
+%if %{with notes}
+sed "s|@OSCPE@|$(cat /usr/lib/system-release-cpe)|" %{SOURCE0} >redhat-package-notes
+%endif
+
+LDFLAGS="%{build_ldflags} %{?with_notes:-specs=$PWD/redhat-package-notes}"
+CFLAGS="%{build_cflags}"
+
+gcc -Wall -fPIC -o libhello.so -shared libhello.c $CFLAGS $LDFLAGS
+gcc -Wall -o hello hello.c libhello.so $CFLAGS $LDFLAGS
+
+%install
+set -eo pipefail
+
+install -Dt %{buildroot}%{_libdir}/ libhello.so
+install -Dt %{buildroot}%{_bindir}/ hello
+
+%check
+set -eo pipefail
+
+%if %{with notes}
+objdump -s -j .note.package ./hello
+objdump -s -j .note.package ./libhello.so
+%endif
+
+%files
+%{_bindir}/hello
+%{_libdir}/libhello.so
+
+%changelog
+* Wed Feb 3 2021 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0-1
+- Test
diff --git a/rpm/macros.package-notes-srpm b/rpm/macros.package-notes-srpm
new file mode 100644
index 0000000..a15d98c
--- /dev/null
+++ b/rpm/macros.package-notes-srpm
@@ -0,0 +1,30 @@
+# SPDX-License-Identifier: CC0-1.0
+#
+# 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 %[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" : ""]
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@\"}))))