From 21773b8dd72b2930f12fa8f7769983d4d581beba Mon Sep 17 00:00:00 2001 From: vutung2311 Date: Thu, 15 Apr 2021 16:26:41 +0530 Subject: [PATCH] Kbuild: fix kallsyms failure when building with GCC LTO for arm64 Fix error "kallsyms failure: relative symbol value 0xffffff8008080000 out of range in relative mode" Change-Id: I5ea6ca54ba0fbf8714b0641e181e1dc99778d88b --- scripts/kallsyms.c | 18 ++++++++++-------- scripts/link-vmlinux.sh | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 6402b0d362914..836341206c7e8 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -115,13 +115,15 @@ static int check_symbol_range(const char *sym, unsigned long long addr, static int read_symbol(FILE *in, struct sym_entry *s) { char str[500]; + char buf[LINE_MAX]; char *sym, stype; int rc; - rc = fscanf(in, "%llx %c %499s\n", &s->addr, &stype, str); - if (rc != 3) { - if (rc != EOF && fgets(str, 500, in) == NULL) - fprintf(stderr, "Read error or end of file.\n"); + if (fgets(buf, sizeof(buf), in) == NULL) { + return -1; + } + rc = sscanf(buf, "%llx %c %499s\n", &s->addr, &stype, str); + if (rc < 3) { return -1; } if (strlen(str) > KSYM_NAME_LEN) { @@ -152,14 +154,13 @@ static int read_symbol(FILE *in, struct sym_entry *s) return -1; } - else if (toupper(stype) == 'U' || - is_arm_mapping_symbol(sym)) + else if (toupper(stype) == 'U') return -1; /* exclude also MIPS ELF local symbols ($L123 instead of .L123) */ else if (str[0] == '$') return -1; /* exclude debugging symbols */ - else if (stype == 'N') + else if (toupper(stype) == 'N') return -1; /* exclude s390 kasan local symbols */ else if (!strncmp(sym, ".LASANPC", 8)) @@ -181,7 +182,8 @@ static int read_symbol(FILE *in, struct sym_entry *s) /* Record if we've found __per_cpu_start/end. */ check_symbol_range(sym, s->addr, &percpu_range, 1); - + if (toupper(stype) == 'W' && strstr(sym, ".c") != NULL) + return -1; return 0; } diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 627af8a176430..ede507baa42e7 100644 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -200,7 +200,7 @@ kallsyms() local afile="`basename ${2} .o`.S" - ${NM} -n ${1} | scripts/kallsyms ${kallsymopt} > ${afile} + ${NM} -n ${1} 2>/dev/null | scripts/kallsyms ${kallsymopt} > ${afile} ${CC} ${aflags} -c -o ${2} ${afile} }