Skip to content

Commit f404a58

Browse files
aaronp24jpoimboe
authored andcommitted
objtool: Remove max symbol name length limitation
If one of the symbols processed by read_symbols() happens to have a .cold variant with a name longer than objtool's MAX_NAME_LEN limit, the build fails. Avoid this problem by just using strndup() to copy the parent function's name, rather than strncpy()ing it onto the stack. Signed-off-by: Aaron Plattner <[email protected]> Link: https://lore.kernel.org/r/41e94cfea1d9131b758dd637fecdeacd459d4584.1696355111.git.aplattner@nvidia.com Signed-off-by: Josh Poimboeuf <[email protected]>
1 parent e959c27 commit f404a58

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

tools/objtool/elf.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include <objtool/elf.h>
2323
#include <objtool/warn.h>
2424

25-
#define MAX_NAME_LEN 128
26-
2725
static inline u32 str_hash(const char *str)
2826
{
2927
return jhash(str, strlen(str), 0);
@@ -515,7 +513,7 @@ static int read_symbols(struct elf *elf)
515513
/* Create parent/child links for any cold subfunctions */
516514
list_for_each_entry(sec, &elf->sections, list) {
517515
sec_for_each_sym(sec, sym) {
518-
char pname[MAX_NAME_LEN + 1];
516+
char *pname;
519517
size_t pnamelen;
520518
if (sym->type != STT_FUNC)
521519
continue;
@@ -531,15 +529,15 @@ static int read_symbols(struct elf *elf)
531529
continue;
532530

533531
pnamelen = coldstr - sym->name;
534-
if (pnamelen > MAX_NAME_LEN) {
535-
WARN("%s(): parent function name exceeds maximum length of %d characters",
536-
sym->name, MAX_NAME_LEN);
532+
pname = strndup(sym->name, pnamelen);
533+
if (!pname) {
534+
WARN("%s(): failed to allocate memory",
535+
sym->name);
537536
return -1;
538537
}
539538

540-
strncpy(pname, sym->name, pnamelen);
541-
pname[pnamelen] = '\0';
542539
pfunc = find_symbol_by_name(elf, pname);
540+
free(pname);
543541

544542
if (!pfunc) {
545543
WARN("%s(): can't find parent function",

0 commit comments

Comments
 (0)