From ab1f721f5dad49eb218b60d5e9bd1b8f8a61685f Mon Sep 17 00:00:00 2001 From: Dimitri John Ledkov Date: Wed, 6 Dec 2023 01:49:12 +0000 Subject: [PATCH] UBUNTU: SAUCE: objtool: Make objtool check actually fatal upon fatal errors BugLink: https://bugs.launchpad.net/bugs/2046440 Currently function calls within check() are sensitive to fatal errors (negative return codes) and abort execution prematurely. However, in all such cases the check() function still returns 0, and thus resulting in a successful kernel build. The only correct code paths were the ones that escpae the control flow with `return ret`. Make the check() function return `ret` status code, and make all negative return codes goto that instruction. This makes fatal errors (not warnings) from various function calls actually fail the build. E.g. if create_retpoline_sites_sections() fails to create elf section pair retpoline_sites the tool now exits with an error code. Signed-off-by: Dimitri John Ledkov Link: https://lore.kernel.org/all/20231213134303.2302285-2-dimitri.ledkov@canonical.com/ Signed-off-by: Andrea Righi --- tools/objtool/check.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 548ec3cd7c00..1fec35cdc206 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4677,8 +4677,10 @@ int check(struct objtool_file *file) init_cfi_state(&force_undefined_cfi); force_undefined_cfi.force_undefined = true; - if (!cfi_hash_alloc(1UL << (file->elf->symbol_bits - 3))) + if (!cfi_hash_alloc(1UL << (file->elf->symbol_bits - 3))) { + ret = -1; goto out; + } cfi_hash_add(&init_cfi); cfi_hash_add(&func_cfi); @@ -4695,7 +4697,7 @@ int check(struct objtool_file *file) if (opts.retpoline) { ret = validate_retpoline(file); if (ret < 0) - return ret; + goto out; warnings += ret; } @@ -4731,7 +4733,7 @@ int check(struct objtool_file *file) */ ret = validate_unrets(file); if (ret < 0) - return ret; + goto out; warnings += ret; } @@ -4794,7 +4796,7 @@ int check(struct objtool_file *file) if (opts.prefix) { ret = add_prefix_symbols(file); if (ret < 0) - return ret; + goto out; warnings += ret; } @@ -4825,10 +4827,5 @@ int check(struct objtool_file *file) } out: - /* - * For now, don't fail the kernel build on fatal warnings. These - * errors are still fairly common due to the growing matrix of - * supported toolchains and their recent pace of change. - */ - return 0; + return ret < 0 ? ret : 0; }