Skip to content

Commit

Permalink
Kbuild: fix kallsyms failure when building with GCC LTO for arm64
Browse files Browse the repository at this point in the history
Fix error "kallsyms failure: relative symbol value 0xffffff8008080000 out of range in relative mode"

Change-Id: I5ea6ca54ba0fbf8714b0641e181e1dc99778d88b
  • Loading branch information
vutung2311 authored and Abhinavgupta371 committed Sep 29, 2023
1 parent 7954dbb commit 21773b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions scripts/kallsyms.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/link-vmlinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

Expand Down

0 comments on commit 21773b8

Please sign in to comment.