Igor Gnatenko 082d5d
From fa61c840ba6be18c6579b247605634c1e2a320f8 Mon Sep 17 00:00:00 2001
Mark Wielaard 1a7230
From: Mark Wielaard <mark@klomp.org>
Mark Wielaard 1a7230
Date: Thu, 9 Mar 2017 22:13:01 +0100
Igor Gnatenko 082d5d
Subject: [PATCH 17/49] generateBuildIDs: Fix error handling.
Mark Wielaard 1a7230
Mark Wielaard 1a7230
commit e6bdf7 made it so that we don't give a warning or error message
Mark Wielaard 1a7230
for non-kernel ET_REL object files with missing or bad build-ids. But
Mark Wielaard 1a7230
we still (unintentionally) failed generateBuildIDs which made us skip
Mark Wielaard 1a7230
generating the cpioList causing an obscure failure message.
Mark Wielaard 1a7230
Mark Wielaard 1a7230
Move the sanity check earlier so we don't process such object files at
Mark Wielaard 1a7230
all. And if there is any real error from generateBuildIDs give a clear
Mark Wielaard 1a7230
error message and explicitly set processingFailed.
Mark Wielaard 1a7230
Mark Wielaard 1a7230
Signed-off-by: Mark Wielaard <mark@klomp.org>
Igor Gnatenko 082d5d
(cherry picked from commit 5bd77379eee167fbdb8d139dc9ab2da74f2a544f)
Mark Wielaard 1a7230
---
Mark Wielaard 1a7230
 build/files.c | 18 +++++++++++-------
Mark Wielaard 1a7230
 1 file changed, 11 insertions(+), 7 deletions(-)
Mark Wielaard 1a7230
Mark Wielaard 1a7230
diff --git a/build/files.c b/build/files.c
Igor Gnatenko 082d5d
index b19abf299..fef0c6960 100644
Mark Wielaard 1a7230
--- a/build/files.c
Mark Wielaard 1a7230
+++ b/build/files.c
Mark Wielaard 1a7230
@@ -1686,10 +1686,16 @@ static int generateBuildIDs(FileList fl)
Mark Wielaard 1a7230
 	if (lstat(flp->diskPath, &sbuf) == 0 && S_ISREG (sbuf.st_mode)) {
Mark Wielaard 1a7230
 	    int fd = open (flp->diskPath, O_RDONLY);
Mark Wielaard 1a7230
 	    if (fd >= 0) {
Mark Wielaard 1a7230
+		/* Only real ELF files, that are ET_EXEC, ET_DYN or
Mark Wielaard 1a7230
+		   kernel modules (ET_REL files with names ending in .ko)
Mark Wielaard 1a7230
+		   should have build-ids. */
Mark Wielaard 1a7230
 		GElf_Ehdr ehdr;
Mark Wielaard 1a7230
 		Elf *elf = elf_begin (fd, ELF_C_READ, NULL);
Mark Wielaard 1a7230
 		if (elf != NULL && elf_kind(elf) == ELF_K_ELF
Mark Wielaard 1a7230
-		    && gelf_getehdr(elf, &ehdr) != NULL) {
Mark Wielaard 1a7230
+		    && gelf_getehdr(elf, &ehdr) != NULL
Mark Wielaard 1a7230
+		    && (ehdr.e_type == ET_EXEC || ehdr.e_type == ET_DYN
Mark Wielaard 1a7230
+			|| (ehdr.e_type == ET_REL
Mark Wielaard 1a7230
+			    && rpmFileHasSuffix (flp->diskPath, ".ko")))) {
Mark Wielaard 1a7230
 		    const void *build_id;
Mark Wielaard 1a7230
 		    ssize_t len = dwelf_elf_gnu_build_id (elf, &build_id);
Mark Wielaard 1a7230
 		    /* len == -1 means error. Zero means no
Mark Wielaard 1a7230
@@ -1738,11 +1744,6 @@ static int generateBuildIDs(FileList fl)
Mark Wielaard 1a7230
 				   _("error reading build-id in %s: %s\n"),
Mark Wielaard 1a7230
 				   flp->diskPath, elf_errmsg (-1));
Mark Wielaard 1a7230
 			} else if (len == 0) {
Mark Wielaard 1a7230
-			    /* Only ET_EXEC, ET_DYN or kernel modules
Mark Wielaard 1a7230
-			       have build-ids. */
Mark Wielaard 1a7230
-			    if (ehdr.e_type == ET_EXEC || ehdr.e_type == ET_DYN
Mark Wielaard 1a7230
-				|| (ehdr.e_type == ET_REL
Mark Wielaard 1a7230
-				    && rpmFileHasSuffix (flp->diskPath, ".ko")))
Mark Wielaard 1a7230
 			      rpmlog(terminate ? RPMLOG_ERR : RPMLOG_WARNING,
Mark Wielaard 1a7230
 				     _("Missing build-id in %s\n"),
Mark Wielaard 1a7230
 				     flp->diskPath);
Mark Wielaard 1a7230
@@ -2354,8 +2355,11 @@ static rpmRC processPackageFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags,
Mark Wielaard 1a7230
 	goto exit;
Mark Wielaard 1a7230
 
Mark Wielaard 1a7230
 #if HAVE_LIBDW
Mark Wielaard 1a7230
-    if (generateBuildIDs (&fl) != 0)
Mark Wielaard 1a7230
+    if (generateBuildIDs (&fl) != 0) {
Mark Wielaard 1a7230
+	rpmlog(RPMLOG_ERR, _("Generating build-id links failed\n"));
Mark Wielaard 1a7230
+	fl.processingFailed = 1;
Mark Wielaard 1a7230
 	goto exit;
Mark Wielaard 1a7230
+    }
Mark Wielaard 1a7230
 #endif
Mark Wielaard 1a7230
 
Mark Wielaard 1a7230
     /* Verify that file attributes scope over hardlinks correctly. */
Mark Wielaard 1a7230
-- 
Igor Gnatenko 082d5d
2.13.2
Mark Wielaard 1a7230