Commit cd063c8b authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'objtool-core-2023-10-28' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull objtool updates from Ingo Molnar:
 "Misc fixes and cleanups:

   - Fix potential MAX_NAME_LEN limit related build failures

   - Fix scripts/faddr2line symbol filtering bug

   - Fix scripts/faddr2line on LLVM=1

   - Fix scripts/faddr2line to accept readelf output with mapping
     symbols

   - Minor cleanups"

* tag 'objtool-core-2023-10-28' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  scripts/faddr2line: Skip over mapping symbols in output from readelf
  scripts/faddr2line: Use LLVM addr2line and readelf if LLVM=1
  scripts/faddr2line: Don't filter out non-function symbols from readelf
  objtool: Remove max symbol name length limitation
  objtool: Propagate early errors
  objtool: Use 'the fallthrough' pseudo-keyword
  x86/speculation, objtool: Use absolute relocations for annotations
  x86/unwind/orc: Remove redundant initialization of 'mid' pointer in __orc_find()
parents 63ce50ff 60fd39af
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
#define ANNOTATE_IGNORE_ALTERNATIVE \ #define ANNOTATE_IGNORE_ALTERNATIVE \
"999:\n\t" \ "999:\n\t" \
".pushsection .discard.ignore_alts\n\t" \ ".pushsection .discard.ignore_alts\n\t" \
".long 999b - .\n\t" \ ".long 999b\n\t" \
".popsection\n\t" ".popsection\n\t"
/* /*
...@@ -352,7 +352,7 @@ static inline int alternatives_text_reserved(void *start, void *end) ...@@ -352,7 +352,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
.macro ANNOTATE_IGNORE_ALTERNATIVE .macro ANNOTATE_IGNORE_ALTERNATIVE
.Lannotate_\@: .Lannotate_\@:
.pushsection .discard.ignore_alts .pushsection .discard.ignore_alts
.long .Lannotate_\@ - . .long .Lannotate_\@
.popsection .popsection
.endm .endm
......
...@@ -196,7 +196,7 @@ ...@@ -196,7 +196,7 @@
.macro ANNOTATE_RETPOLINE_SAFE .macro ANNOTATE_RETPOLINE_SAFE
.Lhere_\@: .Lhere_\@:
.pushsection .discard.retpoline_safe .pushsection .discard.retpoline_safe
.long .Lhere_\@ - . .long .Lhere_\@
.popsection .popsection
.endm .endm
...@@ -320,7 +320,7 @@ ...@@ -320,7 +320,7 @@
#define ANNOTATE_RETPOLINE_SAFE \ #define ANNOTATE_RETPOLINE_SAFE \
"999:\n\t" \ "999:\n\t" \
".pushsection .discard.retpoline_safe\n\t" \ ".pushsection .discard.retpoline_safe\n\t" \
".long 999b - .\n\t" \ ".long 999b\n\t" \
".popsection\n\t" ".popsection\n\t"
typedef u8 retpoline_thunk_t[RETPOLINE_THUNK_SIZE]; typedef u8 retpoline_thunk_t[RETPOLINE_THUNK_SIZE];
......
...@@ -85,7 +85,7 @@ static struct orc_entry *__orc_find(int *ip_table, struct orc_entry *u_table, ...@@ -85,7 +85,7 @@ static struct orc_entry *__orc_find(int *ip_table, struct orc_entry *u_table,
{ {
int *first = ip_table; int *first = ip_table;
int *last = ip_table + num_entries - 1; int *last = ip_table + num_entries - 1;
int *mid = first, *found = first; int *mid, *found = first;
if (!num_entries) if (!num_entries)
return NULL; return NULL;
......
...@@ -48,13 +48,13 @@ ...@@ -48,13 +48,13 @@
#define ANNOTATE_NOENDBR \ #define ANNOTATE_NOENDBR \
"986: \n\t" \ "986: \n\t" \
".pushsection .discard.noendbr\n\t" \ ".pushsection .discard.noendbr\n\t" \
".long 986b - .\n\t" \ ".long 986b\n\t" \
".popsection\n\t" ".popsection\n\t"
#define ASM_REACHABLE \ #define ASM_REACHABLE \
"998:\n\t" \ "998:\n\t" \
".pushsection .discard.reachable\n\t" \ ".pushsection .discard.reachable\n\t" \
".long 998b - .\n\t" \ ".long 998b\n\t" \
".popsection\n\t" ".popsection\n\t"
#else /* __ASSEMBLY__ */ #else /* __ASSEMBLY__ */
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
#define ANNOTATE_INTRA_FUNCTION_CALL \ #define ANNOTATE_INTRA_FUNCTION_CALL \
999: \ 999: \
.pushsection .discard.intra_function_calls; \ .pushsection .discard.intra_function_calls; \
.long 999b - .; \ .long 999b; \
.popsection; .popsection;
/* /*
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
.macro ANNOTATE_NOENDBR .macro ANNOTATE_NOENDBR
.Lhere_\@: .Lhere_\@:
.pushsection .discard.noendbr .pushsection .discard.noendbr
.long .Lhere_\@ - . .long .Lhere_\@
.popsection .popsection
.endm .endm
...@@ -142,7 +142,7 @@ ...@@ -142,7 +142,7 @@
.macro REACHABLE .macro REACHABLE
.Lhere_\@: .Lhere_\@:
.pushsection .discard.reachable .pushsection .discard.reachable
.long .Lhere_\@ - . .long .Lhere_\@
.popsection .popsection
.endm .endm
......
...@@ -58,8 +58,21 @@ die() { ...@@ -58,8 +58,21 @@ die() {
exit 1 exit 1
} }
READELF="${CROSS_COMPILE:-}readelf" UTIL_SUFFIX=""
ADDR2LINE="${CROSS_COMPILE:-}addr2line" if [[ "${LLVM:-}" == "" ]]; then
UTIL_PREFIX=${CROSS_COMPILE:-}
else
UTIL_PREFIX=llvm-
if [[ "${LLVM}" == *"/" ]]; then
UTIL_PREFIX=${LLVM}${UTIL_PREFIX}
elif [[ "${LLVM}" == "-"* ]]; then
UTIL_SUFFIX=${LLVM}
fi
fi
READELF="${UTIL_PREFIX}readelf${UTIL_SUFFIX}"
ADDR2LINE="${UTIL_PREFIX}addr2line${UTIL_SUFFIX}"
AWK="awk" AWK="awk"
GREP="grep" GREP="grep"
...@@ -166,6 +179,11 @@ __faddr2line() { ...@@ -166,6 +179,11 @@ __faddr2line() {
local cur_sym_elf_size=${fields[2]} local cur_sym_elf_size=${fields[2]}
local cur_sym_name=${fields[7]:-} local cur_sym_name=${fields[7]:-}
# is_mapping_symbol(cur_sym_name)
if [[ ${cur_sym_name} =~ ^(\.L|L0|\$) ]]; then
continue
fi
if [[ $cur_sym_addr = $sym_addr ]] && if [[ $cur_sym_addr = $sym_addr ]] &&
[[ $cur_sym_elf_size = $sym_elf_size ]] && [[ $cur_sym_elf_size = $sym_elf_size ]] &&
[[ $cur_sym_name = $sym_name ]]; then [[ $cur_sym_name = $sym_name ]]; then
...@@ -260,7 +278,7 @@ __faddr2line() { ...@@ -260,7 +278,7 @@ __faddr2line() {
DONE=1 DONE=1
done < <(${READELF} --symbols --wide $objfile | sed 's/\[.*\]//' | ${AWK} -v fn=$sym_name '$4 == "FUNC" && $8 == fn') done < <(${READELF} --symbols --wide $objfile | sed 's/\[.*\]//' | ${AWK} -v fn=$sym_name '$8 == fn')
} }
[[ $# -lt 2 ]] && usage [[ $# -lt 2 ]] && usage
......
...@@ -291,7 +291,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec ...@@ -291,7 +291,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
switch (modrm_reg & 7) { switch (modrm_reg & 7) {
case 5: case 5:
imm = -imm; imm = -imm;
/* fallthrough */ fallthrough;
case 0: case 0:
/* add/sub imm, %rsp */ /* add/sub imm, %rsp */
ADD_OP(op) { ADD_OP(op) {
...@@ -375,7 +375,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec ...@@ -375,7 +375,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
break; break;
} }
/* fallthrough */ fallthrough;
case 0x88: case 0x88:
if (!rex_w) if (!rex_w)
break; break;
...@@ -656,7 +656,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec ...@@ -656,7 +656,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
break; break;
} }
/* fallthrough */ fallthrough;
case 0xca: /* retf */ case 0xca: /* retf */
case 0xcb: /* retf */ case 0xcb: /* retf */
......
...@@ -22,8 +22,6 @@ ...@@ -22,8 +22,6 @@
#include <objtool/elf.h> #include <objtool/elf.h>
#include <objtool/warn.h> #include <objtool/warn.h>
#define MAX_NAME_LEN 128
static inline u32 str_hash(const char *str) static inline u32 str_hash(const char *str)
{ {
return jhash(str, strlen(str), 0); return jhash(str, strlen(str), 0);
...@@ -515,7 +513,7 @@ static int read_symbols(struct elf *elf) ...@@ -515,7 +513,7 @@ static int read_symbols(struct elf *elf)
/* Create parent/child links for any cold subfunctions */ /* Create parent/child links for any cold subfunctions */
list_for_each_entry(sec, &elf->sections, list) { list_for_each_entry(sec, &elf->sections, list) {
sec_for_each_sym(sec, sym) { sec_for_each_sym(sec, sym) {
char pname[MAX_NAME_LEN + 1]; char *pname;
size_t pnamelen; size_t pnamelen;
if (sym->type != STT_FUNC) if (sym->type != STT_FUNC)
continue; continue;
...@@ -531,15 +529,15 @@ static int read_symbols(struct elf *elf) ...@@ -531,15 +529,15 @@ static int read_symbols(struct elf *elf)
continue; continue;
pnamelen = coldstr - sym->name; pnamelen = coldstr - sym->name;
if (pnamelen > MAX_NAME_LEN) { pname = strndup(sym->name, pnamelen);
WARN("%s(): parent function name exceeds maximum length of %d characters", if (!pname) {
sym->name, MAX_NAME_LEN); WARN("%s(): failed to allocate memory",
sym->name);
return -1; return -1;
} }
strncpy(pname, sym->name, pnamelen);
pname[pnamelen] = '\0';
pfunc = find_symbol_by_name(elf, pname); pfunc = find_symbol_by_name(elf, pname);
free(pname);
if (!pfunc) { if (!pfunc) {
WARN("%s(): can't find parent function", WARN("%s(): can't find parent function",
......
...@@ -146,7 +146,5 @@ int main(int argc, const char **argv) ...@@ -146,7 +146,5 @@ int main(int argc, const char **argv)
exec_cmd_init("objtool", UNUSED, UNUSED, UNUSED); exec_cmd_init("objtool", UNUSED, UNUSED, UNUSED);
pager_init(UNUSED); pager_init(UNUSED);
objtool_run(argc, argv); return objtool_run(argc, argv);
return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment