0.186-3 - Add support for FDO packaging metadata

Also add s390x big endian workaround for broken FDO ELF note.
And a workaround for ppc64le -Werror=null-dereference
This commit is contained in:
Mark Wielaard 2022-03-25 12:21:37 +01:00
parent ebdf87f265
commit 4a3ca6544c
6 changed files with 430 additions and 1 deletions

View File

@ -0,0 +1,208 @@
commit 31d551ae4dd8cf307c68f86b6c1ecac2f92b522a
Author: Mark Wielaard <mark@klomp.org>
Date: Thu Mar 24 23:06:09 2022 +0100
libelf: Sync elf.h from glibc.
Adds EM_INTELGT, NT_ARM_TAGGED_ADDR_CTRL, NT_ARM_PAC_ENABLED_KEYS,
ELF_NOTE_FDO, NT_FDO_PACKAGING_METADATA and OpenRISC 1000 specific
relocs.
It also adds and renames some GNU_PROPERTY constants. But none of the
constants the elfutils code uses was renamed or given a different
constant value.
dwelf_elf_e_machine_string was updated to handle EM_INTELGT.
Signed-off-by: Mark Wielaard <mark@klomp.org>
diff --git a/libdwelf/dwelf_elf_e_machine_string.c b/libdwelf/dwelf_elf_e_machine_string.c
index 387648e2..051c70b5 100644
--- a/libdwelf/dwelf_elf_e_machine_string.c
+++ b/libdwelf/dwelf_elf_e_machine_string.c
@@ -360,6 +360,8 @@ dwelf_elf_e_machine_string (int machine)
return "XMOS xCORE";
case EM_MCHP_PIC:
return "Microchip 8-bit PIC";
+ case EM_INTELGT:
+ return "Intel Graphics Technology";
case EM_KM32:
return "KM211 KM32";
case EM_KMX32:
* elf_getdata.c (__libelf_type_aligns): ELF_T_GNUHASH has different
diff --git a/libelf/elf.h b/libelf/elf.h
index 8e3e618f..0735f6b5 100644
--- a/libelf/elf.h
+++ b/libelf/elf.h
@@ -1,5 +1,5 @@
/* This file defines standard ELF types, structures, and macros.
- Copyright (C) 1995-2020 Free Software Foundation, Inc.
+ Copyright (C) 1995-2022 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -336,7 +336,8 @@ typedef struct
#define EM_BA2 202 /* Beyond BA2 */
#define EM_XCORE 203 /* XMOS xCORE */
#define EM_MCHP_PIC 204 /* Microchip 8-bit PIC(r) */
- /* reserved 205-209 */
+#define EM_INTELGT 205 /* Intel Graphics Technology */
+ /* reserved 206-209 */
#define EM_KM32 210 /* KM211 KM32 */
#define EM_KMX32 211 /* KM211 KMX32 */
#define EM_EMX16 212 /* KM211 KMX16 */
@@ -813,6 +814,10 @@ typedef struct
address keys. */
#define NT_ARM_PACG_KEYS 0x408 /* ARM pointer authentication
generic key. */
+#define NT_ARM_TAGGED_ADDR_CTRL 0x409 /* AArch64 tagged address
+ control. */
+#define NT_ARM_PAC_ENABLED_KEYS 0x40a /* AArch64 pointer authentication
+ enabled keys. */
#define NT_VMCOREDD 0x700 /* Vmcore Device Dump Note. */
#define NT_MIPS_DSP 0x800 /* MIPS DSP ASE registers. */
#define NT_MIPS_FP_MODE 0x801 /* MIPS floating-point mode. */
@@ -1226,8 +1231,7 @@ typedef struct
#define AT_L3_CACHESIZE 46
#define AT_L3_CACHEGEOMETRY 47
-#define AT_MINSIGSTKSZ 51 /* Stack needed for signal delivery
- (AArch64). */
+#define AT_MINSIGSTKSZ 51 /* Stack needed for signal delivery */
/* Note section contents. Each entry in the note section begins with
a header of a fixed form. */
@@ -1254,6 +1258,8 @@ typedef struct
/* Note entries for GNU systems have this name. */
#define ELF_NOTE_GNU "GNU"
+/* Note entries for freedesktop.org have this name. */
+#define ELF_NOTE_FDO "FDO"
/* Defined types of notes for Solaris. */
@@ -1297,6 +1303,10 @@ typedef struct
/* Program property. */
#define NT_GNU_PROPERTY_TYPE_0 5
+/* Packaging metadata as defined on
+ https://systemd.io/COREDUMP_PACKAGE_METADATA/ */
+#define NT_FDO_PACKAGING_METADATA 0xcafe1a7e
+
/* Note section name of program property. */
#define NOTE_GNU_PROPERTY_SECTION_NAME ".note.gnu.property"
@@ -1307,6 +1317,23 @@ typedef struct
/* No copy relocation on protected data symbol. */
#define GNU_PROPERTY_NO_COPY_ON_PROTECTED 2
+/* A 4-byte unsigned integer property: A bit is set if it is set in all
+ relocatable inputs. */
+#define GNU_PROPERTY_UINT32_AND_LO 0xb0000000
+#define GNU_PROPERTY_UINT32_AND_HI 0xb0007fff
+
+/* A 4-byte unsigned integer property: A bit is set if it is set in any
+ relocatable inputs. */
+#define GNU_PROPERTY_UINT32_OR_LO 0xb0008000
+#define GNU_PROPERTY_UINT32_OR_HI 0xb000ffff
+
+/* The needed properties by the object file. */
+#define GNU_PROPERTY_1_NEEDED GNU_PROPERTY_UINT32_OR_LO
+
+/* Set if the object file requires canonical function pointers and
+ cannot be used with copy relocation. */
+#define GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS (1U << 0)
+
/* Processor-specific semantics, lo */
#define GNU_PROPERTY_LOPROC 0xc0000000
/* Processor-specific semantics, hi */
@@ -1324,31 +1351,26 @@ typedef struct
/* The x86 instruction sets indicated by the corresponding bits are
used in program. Their support in the hardware is optional. */
-#define GNU_PROPERTY_X86_ISA_1_USED 0xc0000000
+#define GNU_PROPERTY_X86_ISA_1_USED 0xc0010002
/* The x86 instruction sets indicated by the corresponding bits are
used in program and they must be supported by the hardware. */
-#define GNU_PROPERTY_X86_ISA_1_NEEDED 0xc0000001
+#define GNU_PROPERTY_X86_ISA_1_NEEDED 0xc0008002
/* X86 processor-specific features used in program. */
#define GNU_PROPERTY_X86_FEATURE_1_AND 0xc0000002
-#define GNU_PROPERTY_X86_ISA_1_486 (1U << 0)
-#define GNU_PROPERTY_X86_ISA_1_586 (1U << 1)
-#define GNU_PROPERTY_X86_ISA_1_686 (1U << 2)
-#define GNU_PROPERTY_X86_ISA_1_SSE (1U << 3)
-#define GNU_PROPERTY_X86_ISA_1_SSE2 (1U << 4)
-#define GNU_PROPERTY_X86_ISA_1_SSE3 (1U << 5)
-#define GNU_PROPERTY_X86_ISA_1_SSSE3 (1U << 6)
-#define GNU_PROPERTY_X86_ISA_1_SSE4_1 (1U << 7)
-#define GNU_PROPERTY_X86_ISA_1_SSE4_2 (1U << 8)
-#define GNU_PROPERTY_X86_ISA_1_AVX (1U << 9)
-#define GNU_PROPERTY_X86_ISA_1_AVX2 (1U << 10)
-#define GNU_PROPERTY_X86_ISA_1_AVX512F (1U << 11)
-#define GNU_PROPERTY_X86_ISA_1_AVX512CD (1U << 12)
-#define GNU_PROPERTY_X86_ISA_1_AVX512ER (1U << 13)
-#define GNU_PROPERTY_X86_ISA_1_AVX512PF (1U << 14)
-#define GNU_PROPERTY_X86_ISA_1_AVX512VL (1U << 15)
-#define GNU_PROPERTY_X86_ISA_1_AVX512DQ (1U << 16)
-#define GNU_PROPERTY_X86_ISA_1_AVX512BW (1U << 17)
+/* GNU_PROPERTY_X86_ISA_1_BASELINE: CMOV, CX8 (cmpxchg8b), FPU (fld),
+ MMX, OSFXSR (fxsave), SCE (syscall), SSE and SSE2. */
+#define GNU_PROPERTY_X86_ISA_1_BASELINE (1U << 0)
+/* GNU_PROPERTY_X86_ISA_1_V2: GNU_PROPERTY_X86_ISA_1_BASELINE,
+ CMPXCHG16B (cmpxchg16b), LAHF-SAHF (lahf), POPCNT (popcnt), SSE3,
+ SSSE3, SSE4.1 and SSE4.2. */
+#define GNU_PROPERTY_X86_ISA_1_V2 (1U << 1)
+/* GNU_PROPERTY_X86_ISA_1_V3: GNU_PROPERTY_X86_ISA_1_V2, AVX, AVX2, BMI1,
+ BMI2, F16C, FMA, LZCNT, MOVBE, XSAVE. */
+#define GNU_PROPERTY_X86_ISA_1_V3 (1U << 2)
+/* GNU_PROPERTY_X86_ISA_1_V4: GNU_PROPERTY_X86_ISA_1_V3, AVX512F,
+ AVX512BW, AVX512CD, AVX512DQ and AVX512VL. */
+#define GNU_PROPERTY_X86_ISA_1_V4 (1U << 3)
/* This indicates that all executable sections are compatible with
IBT. */
@@ -4102,4 +4124,41 @@ enum
#define R_ARC_TLS_LE_S9 0x4a
#define R_ARC_TLS_LE_32 0x4b
+/* OpenRISC 1000 specific relocs. */
+#define R_OR1K_NONE 0
+#define R_OR1K_32 1
+#define R_OR1K_16 2
+#define R_OR1K_8 3
+#define R_OR1K_LO_16_IN_INSN 4
+#define R_OR1K_HI_16_IN_INSN 5
+#define R_OR1K_INSN_REL_26 6
+#define R_OR1K_GNU_VTENTRY 7
+#define R_OR1K_GNU_VTINHERIT 8
+#define R_OR1K_32_PCREL 9
+#define R_OR1K_16_PCREL 10
+#define R_OR1K_8_PCREL 11
+#define R_OR1K_GOTPC_HI16 12
+#define R_OR1K_GOTPC_LO16 13
+#define R_OR1K_GOT16 14
+#define R_OR1K_PLT26 15
+#define R_OR1K_GOTOFF_HI16 16
+#define R_OR1K_GOTOFF_LO16 17
+#define R_OR1K_COPY 18
+#define R_OR1K_GLOB_DAT 19
+#define R_OR1K_JMP_SLOT 20
+#define R_OR1K_RELATIVE 21
+#define R_OR1K_TLS_GD_HI16 22
+#define R_OR1K_TLS_GD_LO16 23
+#define R_OR1K_TLS_LDM_HI16 24
+#define R_OR1K_TLS_LDM_LO16 25
+#define R_OR1K_TLS_LDO_HI16 26
+#define R_OR1K_TLS_LDO_LO16 27
+#define R_OR1K_TLS_IE_HI16 28
+#define R_OR1K_TLS_IE_LO16 29
+#define R_OR1K_TLS_LE_HI16 30
+#define R_OR1K_TLS_LE_LO16 31
+#define R_OR1K_TLS_TPOFF 32
+#define R_OR1K_TLS_DTPOFF 33
+#define R_OR1K_TLS_DTPMOD 34
+
#endif /* elf.h */

View File

@ -0,0 +1,46 @@
commit 1e5302ad3cf02788339a340f6322d1af1f05d9f9
Author: Luca Boccassi <bluca@debian.org>
Date: Sun Nov 21 19:43:18 2021 +0000
libebl: recognize FDO Packaging Metadata ELF note
As defined on: https://systemd.io/COREDUMP_PACKAGE_METADATA/
this note will be used starting from Fedora 36. Allow
readelf --notes to pretty print it:
Note section [ 3] '.note.package' of 76 bytes at offset 0x2e8:
Owner Data size Type
FDO 57 FDO_PACKAGING_METADATA
Packaging Metadata: {"type":"deb","name":"fsverity-utils","version":"1.3-1"}
Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
diff --git a/libebl/eblobjnote.c b/libebl/eblobjnote.c
index 36efe275..5a7c5c62 100644
--- a/libebl/eblobjnote.c
+++ b/libebl/eblobjnote.c
@@ -288,6 +288,10 @@ ebl_object_note (Ebl *ebl, uint32_t namesz, const char *name, uint32_t type,
if (descsz == 0 && type == NT_VERSION)
return;
+ if (strcmp ("FDO", name) == 0 && type == NT_FDO_PACKAGING_METADATA
+ && descsz > 0 && desc[descsz - 1] == '\0')
+ printf(" Packaging Metadata: %.*s\n", (int) descsz, desc);
+
/* Everything else should have the "GNU" owner name. */
if (strcmp ("GNU", name) != 0)
return;
diff --git a/libebl/eblobjnotetypename.c b/libebl/eblobjnotetypename.c
index 4662906d..473a1f2f 100644
--- a/libebl/eblobjnotetypename.c
+++ b/libebl/eblobjnotetypename.c
@@ -101,6 +101,9 @@ ebl_object_note_type_name (Ebl *ebl, const char *name, uint32_t type,
return buf;
}
+ if (strcmp (name, "FDO") == 0 && type == NT_FDO_PACKAGING_METADATA)
+ return "FDO_PACKAGING_METADATA";
+
if (strcmp (name, "GNU") != 0)
{
/* NT_VERSION is special, all data is in the name. */

View File

@ -0,0 +1,26 @@
commit 4a22e01277e37540d753e3513c4df3bd2b6e1246
Author: Mark Wielaard <mark@klomp.org>
Date: Fri Mar 25 00:00:47 2022 +0100
elflint: Recognize NT_FDO_PACKAGING_METADATA
Signed-off-by: Mark Wielaard <mark@klomp.org>
diff --git a/src/elflint.c b/src/elflint.c
index ef7725ce..d919936f 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -4384,6 +4384,13 @@ section [%2d] '%s': unknown core file note type %" PRIu32
else
goto unknown_note;
+ case NT_FDO_PACKAGING_METADATA:
+ if (nhdr.n_namesz == sizeof ELF_NOTE_FDO
+ && strcmp (data->d_buf + name_offset, ELF_NOTE_FDO) == 0)
+ break;
+ else
+ goto unknown_note;
+
case 0:
/* Linux vDSOs use a type 0 note for the kernel version word. */
if (nhdr.n_namesz == sizeof "Linux"

View File

@ -0,0 +1,35 @@
diff --git a/libelf/gelf_getnote.c b/libelf/gelf_getnote.c
index 0f7b9d68..6ef970c5 100644
--- a/libelf/gelf_getnote.c
+++ b/libelf/gelf_getnote.c
@@ -31,6 +31,7 @@
#endif
#include <assert.h>
+#include <byteswap.h>
#include <gelf.h>
#include <string.h>
@@ -73,6 +74,22 @@ gelf_getnote (Elf_Data *data, size_t offset, GElf_Nhdr *result,
offset = 0;
else
{
+ /* Workaround FDO package notes on big-endian systems,
+ getting namesz and descsz wrong. Detect it by getting
+ a bad namesz, descsz and byte swapped n_type for
+ NT_FDO_PACKAGING_METADATA. */
+ if (unlikely (n->n_type == bswap_32 (NT_FDO_PACKAGING_METADATA)
+ && n->n_namesz > data->d_size
+ && n->n_descsz > data->d_size))
+ {
+ /* n might not be writable, use result and redirect n. */
+ *result = *n;
+ result->n_type = bswap_32 (n->n_type);
+ result->n_namesz = bswap_32 (n->n_namesz);
+ result->n_descsz = bswap_32 (n->n_descsz);
+ n = result;
+ }
+
/* This is slightly tricky, offset is guaranteed to be 4
byte aligned, which is what we need for the name_offset.
And normally desc_offset is also 4 byte aligned, but not

View File

@ -0,0 +1,97 @@
diff --git a/src/readelf.c b/src/readelf.c
index 93fb5989..43ae00b6 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -1661,10 +1661,13 @@ print_scngrp (Ebl *ebl)
elf_ndxscn (scn));
shdr = gelf_getshdr (scn, &shdr_mem);
if (unlikely (shdr == NULL))
+ {
error (EXIT_FAILURE, 0,
_("cannot get section [%zd] header: %s"),
elf_ndxscn (scn),
elf_errmsg (-1));
+ return;
+ }
}
handle_scngrp (ebl, scn, shdr);
}
@@ -2388,9 +2391,12 @@ print_symtab (Ebl *ebl, int type)
elf_ndxscn (scn));
shdr = gelf_getshdr (scn, &shdr_mem);
if (unlikely (shdr == NULL))
+ {
error (EXIT_FAILURE, 0,
_("cannot get section [%zd] header: %s"),
elf_ndxscn (scn), elf_errmsg (-1));
+ return;
+ }
}
handle_symtab (ebl, scn, shdr);
}
@@ -2722,8 +2728,11 @@ handle_verneed (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
&glink_mem);
if (glink == NULL)
+ {
error (EXIT_FAILURE, 0, _("invalid sh_link value in section %zu"),
elf_ndxscn (scn));
+ return;
+ }
printf (ngettext ("\
\nVersion needs section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n",
@@ -2798,8 +2807,11 @@ handle_verdef (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
&glink_mem);
if (glink == NULL)
+ {
error (EXIT_FAILURE, 0, _("invalid sh_link value in section %zu"),
elf_ndxscn (scn));
+ return;
+ }
int class = gelf_getclass (ebl->elf);
printf (ngettext ("\
@@ -3102,8 +3114,11 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
&glink_mem);
size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_HALF, 1, EV_CURRENT);
if (glink == NULL)
+ {
error (EXIT_FAILURE, 0, _("invalid sh_link value in section %zu"),
elf_ndxscn (scn));
+ return;
+ }
/* Print the header. */
printf (ngettext ("\
@@ -3495,9 +3510,12 @@ handle_hash (Ebl *ebl)
elf_ndxscn (scn));
shdr = gelf_getshdr (scn, &shdr_mem);
if (unlikely (shdr == NULL))
+ {
error (EXIT_FAILURE, 0,
_("cannot get section [%zd] header: %s"),
elf_ndxscn (scn), elf_errmsg (-1));
+ return;
+ }
}
if (shdr->sh_type == SHT_HASH)
diff --git a/src/unstrip.c b/src/unstrip.c
index aacc9aad..0dc713aa 100644
--- a/src/unstrip.c
+++ b/src/unstrip.c
@@ -1552,9 +1552,12 @@ more sections in stripped file than debug file -- arguments reversed?"));
}
if (sec == NULL)
+ {
error (EXIT_FAILURE, 0,
_("cannot find matching section for [%zu] '%s'"),
elf_ndxscn (scn), name);
+ return;
+ }
sec->outscn = scn;
}

View File

@ -1,6 +1,6 @@
Name: elfutils Name: elfutils
Version: 0.186 Version: 0.186
%global baserelease 2 %global baserelease 3
Release: %{baserelease}%{?dist} Release: %{baserelease}%{?dist}
URL: http://elfutils.org/ URL: http://elfutils.org/
%global source_url ftp://sourceware.org/pub/elfutils/%{version}/ %global source_url ftp://sourceware.org/pub/elfutils/%{version}/
@ -63,6 +63,16 @@ BuildRequires: gettext-devel
# Patches # Patches
# Support for FDO packaging metadata
Patch1: elfutils-0.186-elf-glibc.patch
Patch2: elfutils-0.186-fdo-ebl.patch
Patch3: elfutils-0.186-fdo-efllint.patch
# For s390x...
Patch4: elfutils-0.186-fdo-swap.patch
# Workaround for gcc on ppc64le
# error: potential null pointer dereference [-Werror=null-dereference]
Patch5: elfutils-0.186-ppc64le-error-return-workaround.patch
%description %description
Elfutils is a collection of utilities, including stack (to show Elfutils is a collection of utilities, including stack (to show
backtraces), nm (for listing symbols from object files), size backtraces), nm (for listing symbols from object files), size
@ -399,6 +409,13 @@ exit 0
%systemd_postun_with_restart debuginfod.service %systemd_postun_with_restart debuginfod.service
%changelog %changelog
* Fri Mar 25 2022 Mark Wielaard <mjw@fedoraproject.org> - 0.186-3
- Add elfutils-0.186-elf-glibc.patch
- Add elfutils-0.186-fdo-ebl.patch
- Add elfutils-0.186-fdo-efllint.patch
- Add elfutils-0.186-fdo-swap.patch
- Add elfutils-0.186-ppc64le-error-return-workaround.patch
* Thu Jan 20 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.186-2 * Thu Jan 20 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.186-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild - Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild