|
|
672c60 |
From 68d383c39cef8d58b80940b13dd132d3f41a03f0 Mon Sep 17 00:00:00 2001
|
|
|
672c60 |
Message-Id: <68d383c39cef8d58b80940b13dd132d3f41a03f0.1571917458.git.pmatilai@redhat.com>
|
|
|
672c60 |
From: Panu Matilainen <pmatilai@redhat.com>
|
|
|
672c60 |
Date: Tue, 2 Apr 2019 15:22:07 +0300
|
|
|
672c60 |
Subject: [PATCH 1/2] Detect kernel modules by .modinfo section presence for
|
|
|
672c60 |
build-id generation
|
|
|
672c60 |
|
|
|
672c60 |
File extension based heuristics only work so far at best, and break
|
|
|
672c60 |
completely on compressed files with arbitrary .gz/.xz etc extension.
|
|
|
672c60 |
This isn't supposed to change any behavior as such, only provide more
|
|
|
672c60 |
reliable detection of kernel modules.
|
|
|
672c60 |
---
|
|
|
672c60 |
build/files.c | 27 ++++++++++++++++++++++++---
|
|
|
672c60 |
1 file changed, 24 insertions(+), 3 deletions(-)
|
|
|
672c60 |
|
|
|
672c60 |
diff --git a/build/files.c b/build/files.c
|
|
|
672c60 |
index dbad9a7f3..3822be3d3 100644
|
|
|
672c60 |
--- a/build/files.c
|
|
|
672c60 |
+++ b/build/files.c
|
|
|
672c60 |
@@ -1739,6 +1739,28 @@ static int addNewIDSymlink(ARGV_t *files,
|
|
|
672c60 |
return rc;
|
|
|
672c60 |
}
|
|
|
672c60 |
|
|
|
672c60 |
+static int haveModinfo(Elf *elf)
|
|
|
672c60 |
+{
|
|
|
672c60 |
+ Elf_Scn * scn = NULL;
|
|
|
672c60 |
+ size_t shstrndx;
|
|
|
672c60 |
+ int have_modinfo = 0;
|
|
|
672c60 |
+ const char *sname;
|
|
|
672c60 |
+
|
|
|
672c60 |
+ if (elf_getshdrstrndx(elf, &shstrndx) == 0) {
|
|
|
672c60 |
+ while ((scn = elf_nextscn(elf, scn)) != NULL) {
|
|
|
672c60 |
+ GElf_Shdr shdr_mem, *shdr = gelf_getshdr(scn, &shdr_mem);
|
|
|
672c60 |
+ if (shdr == NULL)
|
|
|
672c60 |
+ continue;
|
|
|
672c60 |
+ sname = elf_strptr(elf, shstrndx, shdr->sh_name);
|
|
|
672c60 |
+ if (sname && rstreq(sname, ".modinfo")) {
|
|
|
672c60 |
+ have_modinfo = 1;
|
|
|
672c60 |
+ break;
|
|
|
672c60 |
+ }
|
|
|
672c60 |
+ }
|
|
|
672c60 |
+ }
|
|
|
672c60 |
+ return have_modinfo;
|
|
|
672c60 |
+}
|
|
|
672c60 |
+
|
|
|
672c60 |
static int generateBuildIDs(FileList fl, ARGV_t *files)
|
|
|
672c60 |
{
|
|
|
672c60 |
int rc = 0;
|
|
|
672c60 |
@@ -1803,15 +1825,14 @@ static int generateBuildIDs(FileList fl, ARGV_t *files)
|
|
|
672c60 |
int fd = open (flp->diskPath, O_RDONLY);
|
|
|
672c60 |
if (fd >= 0) {
|
|
|
672c60 |
/* Only real ELF files, that are ET_EXEC, ET_DYN or
|
|
|
672c60 |
- kernel modules (ET_REL files with names ending in .ko)
|
|
|
672c60 |
+ kernel modules (ET_REL files with .modinfo section)
|
|
|
672c60 |
should have build-ids. */
|
|
|
672c60 |
GElf_Ehdr ehdr;
|
|
|
672c60 |
Elf *elf = elf_begin (fd, ELF_C_READ, NULL);
|
|
|
672c60 |
if (elf != NULL && elf_kind(elf) == ELF_K_ELF
|
|
|
672c60 |
&& gelf_getehdr(elf, &ehdr) != NULL
|
|
|
672c60 |
&& (ehdr.e_type == ET_EXEC || ehdr.e_type == ET_DYN
|
|
|
672c60 |
- || (ehdr.e_type == ET_REL
|
|
|
672c60 |
- && rpmFileHasSuffix (flp->diskPath, ".ko")))) {
|
|
|
672c60 |
+ || (ehdr.e_type == ET_REL && haveModinfo(elf)))) {
|
|
|
672c60 |
const void *build_id;
|
|
|
672c60 |
ssize_t len = dwelf_elf_gnu_build_id (elf, &build_id);
|
|
|
672c60 |
/* len == -1 means error. Zero means no
|
|
|
672c60 |
--
|
|
|
672c60 |
2.21.0
|
|
|
672c60 |
|