From f7cfe25e8a4ccda7785328b3e20ddc501d9feb8a Mon Sep 17 00:00:00 2001 From: Artem Savkov Date: Wed, 12 Sep 2018 15:57:26 +0200 Subject: [PATCH 1/2] symtab_read(): fix SECTION detection in symtab_read symtab_read has been checking a wrong field for "SECTION". Switch the field from "bind" to "type". Signed-off-by: Artem Savkov --- kpatch-build/lookup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kpatch-build/lookup.c b/kpatch-build/lookup.c index d08c10b..9fa6c47 100644 --- a/kpatch-build/lookup.c +++ b/kpatch-build/lookup.c @@ -206,7 +206,7 @@ static void symtab_read(struct lookup_table *table, char *path) if (sscanf(line, "%*s %lx %lu %s %s %*s %s %s\n", &value, &size, type, bind, ndx, name) != 6 || !strcmp(ndx, "UNDEF") || - !strcmp(bind, "SECTION")) + !strcmp(type, "SECTION")) continue; table->obj_nr++; @@ -223,7 +223,7 @@ static void symtab_read(struct lookup_table *table, char *path) if (sscanf(line, "%*s %lx %lu %s %s %*s %s %s\n", &value, &size, type, bind, ndx, name) != 6 || !strcmp(ndx, "UNDEF") || - !strcmp(bind, "SECTION")) + !strcmp(type, "SECTION")) continue; table->obj_syms[i].value = value; From f5679c97809ba2e0a2eff0908d20c5e30ff577c0 Mon Sep 17 00:00:00 2001 From: Artem Savkov Date: Wed, 12 Sep 2018 16:23:17 +0200 Subject: [PATCH 2/2] symtab_read: support entries with blank names symtab_read() would previously skip entries with blank names resulting in some of important entries being skipped. For instance vmlinux file has an STT_FILE entry at the end with a blank name that contains global offset table. Because it was skipped all of the global entries from this table were considered a part of previous processed file resulting in create-diff-object failing in find_local_syms(). Signed-off-by: Artem Savkov --- kpatch-build/lookup.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/kpatch-build/lookup.c b/kpatch-build/lookup.c index 9fa6c47..b88dc59 100644 --- a/kpatch-build/lookup.c +++ b/kpatch-build/lookup.c @@ -197,14 +197,22 @@ static void symtab_read(struct lookup_table *table, char *path) FILE *file; long unsigned int value, size; unsigned int i = 0; + int matched; char line[256], name[256], type[16], bind[16], ndx[16]; if ((file = fopen(path, "r")) == NULL) ERROR("fopen"); while (fgets(line, 256, file)) { - if (sscanf(line, "%*s %lx %lu %s %s %*s %s %s\n", - &value, &size, type, bind, ndx, name) != 6 || + matched = sscanf(line, "%*s %lx %lu %s %s %*s %s %s\n", + &value, &size, type, bind, ndx, name); + + if (matched == 5) { + name[0] = '\0'; + matched++; + } + + if (matched != 6 || !strcmp(ndx, "UNDEF") || !strcmp(type, "SECTION")) continue; @@ -220,8 +228,15 @@ static void symtab_read(struct lookup_table *table, char *path) rewind(file); while (fgets(line, 256, file)) { - if (sscanf(line, "%*s %lx %lu %s %s %*s %s %s\n", - &value, &size, type, bind, ndx, name) != 6 || + matched = sscanf(line, "%*s %lx %lu %s %s %*s %s %s\n", + &value, &size, type, bind, ndx, name); + + if (matched == 5) { + name[0] = '\0'; + matched++; + } + + if (matched != 6 || !strcmp(ndx, "UNDEF") || !strcmp(type, "SECTION")) continue;