Miscellaneous objtool fixes:

- Fix a build error on ia32-x86_64 cross builds
 
  - Replace locally open coded ALIGN_UP(), ALIGN_UP_POW2()
    and MAX(), which, beyond being duplicates, the
    ALIGN_UP_POW2() is also buggy.
 
  - Fix objtool klp-diff regression caused by a recent
    change to the bug table format.
 
  - Fix klp-build vs CONFIG_MODULE_SRCVERSION_ALL build
    failure.
 
 Signed-off-by: Ingo Molnar <mingo@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iQJFBAABCgAvFiEEBpT5eoXrXCwVQwEKEnMQ0APhK1gFAml/EqgRHG1pbmdvQGtl
 cm5lbC5vcmcACgkQEnMQ0APhK1gkqBAAgna1qjT9fWFQgcEExhEFQ7Qj3CwocVNS
 1t0uiXLApienRho1aBERK4NLyMD9PX3GvGUphYBKL7qtZDUn/Ff1Biuz7EjrszCR
 nOhOL0gofWuaT4hB4UlmRLnmlmWnkXe9G2gYVUnj+7hDP1C3Z+XCxogL+Rr5QBbp
 YhQU8OMsGmA4Jy1P3vikpRXOTsTbdSyhqJxB8OsGdKf+gX8QdnAGgSdNu+d4A67x
 QNx8OH5Qyv4n9GkSNattqtgY75CyppYHUFV46DR/KHlrGHhwibJ01x6TbV0t9Y6p
 ZgOrlLPcwtLM/ZHkO0hR4xSMD4rHiBgVOam6j4Gt+PiyTA5UD3Ypi2hDQfHqi2Dk
 ZQCA6IkqdS/hCxJOj15bO8+kstbnycdBNZp1RLxDlod3AC3ZrotXoRBa4Hdmniw1
 vS5vPEHkTZG8Rz4BpA4NWpFtqDFhqAdOEZJaq0DbihE+WlVz3faXTQaDlBtYgYnE
 RCTUfwsgzgCdSElX4qXI5Hls0FdDJdfVgkVhlH0kvmMS8Jdjb/z197zK0787fiRD
 anIUj9R/2B1QMV5fdwcRDAhVmxpL4a2d96xCSRM/9eWYhm/zlZlo8Y9oSsjtTAQ4
 5p35CFA7Y8WgVJI+tEraw0AXErcpnyDk4+BktVl2liWYUsxV6jODayQnxqltu/UA
 +Anv57mVzRE=
 =ySDm
 -----END PGP SIGNATURE-----

Merge tag 'objtool-urgent-2026-02-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull objtool fixes from Ingo Molnar:

 - Fix a build error on ia32-x86_64 cross builds

 - Replace locally open coded ALIGN_UP(), ALIGN_UP_POW2()
   and MAX(), which, beyond being duplicates, the
   ALIGN_UP_POW2() is also buggy

 - Fix objtool klp-diff regression caused by a recent
   change to the bug table format

 - Fix klp-build vs CONFIG_MODULE_SRCVERSION_ALL build
   failure

* tag 'objtool-urgent-2026-02-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  livepatch/klp-build: Fix klp-build vs CONFIG_MODULE_SRCVERSION_ALL
  objtool/klp: Fix bug table handling for __WARN_printf()
  objtool: Replace custom macros in elf.c with shared ones
  objtool: Print bfd_vma as unsigned long long on ia32-x86_64 cross build
This commit is contained in:
Linus Torvalds 2026-02-01 10:27:43 -08:00
commit 969b5726ac
4 changed files with 29 additions and 20 deletions

View file

@ -555,13 +555,11 @@ copy_orig_objects() {
local file_dir="$(dirname "$file")"
local orig_file="$ORIG_DIR/$rel_file"
local orig_dir="$(dirname "$orig_file")"
local cmd_file="$file_dir/.$(basename "$file").cmd"
[[ ! -f "$file" ]] && die "missing $(basename "$file") for $_file"
mkdir -p "$orig_dir"
cp -f "$file" "$orig_dir"
[[ -e "$cmd_file" ]] && cp -f "$cmd_file" "$orig_dir"
done
xtrace_restore
@ -740,15 +738,17 @@ build_patch_module() {
local orig_dir="$(dirname "$orig_file")"
local kmod_file="$KMOD_DIR/$rel_file"
local kmod_dir="$(dirname "$kmod_file")"
local cmd_file="$orig_dir/.$(basename "$file").cmd"
local cmd_file="$kmod_dir/.$(basename "$file").cmd"
mkdir -p "$kmod_dir"
cp -f "$file" "$kmod_dir"
[[ -e "$cmd_file" ]] && cp -f "$cmd_file" "$kmod_dir"
# Tell kbuild this is a prebuilt object
cp -f "$file" "${kmod_file}_shipped"
# Make modpost happy
touch "$cmd_file"
echo -n " $rel_file" >> "$makefile"
done

View file

@ -108,6 +108,8 @@ static int sprint_name(char *str, const char *name, unsigned long offset)
#define DINFO_FPRINTF(dinfo, ...) \
((*(dinfo)->fprintf_func)((dinfo)->stream, __VA_ARGS__))
#define bfd_vma_fmt \
__builtin_choose_expr(sizeof(bfd_vma) == sizeof(unsigned long), "%#lx <%s>", "%#llx <%s>")
static int disas_result_fprintf(struct disas_context *dctx,
const char *fmt, va_list ap)
@ -170,10 +172,10 @@ static void disas_print_addr_sym(struct section *sec, struct symbol *sym,
if (sym) {
sprint_name(symstr, sym->name, addr - sym->offset);
DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr);
DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, symstr);
} else {
str = offstr(sec, addr);
DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, str);
DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, str);
free(str);
}
}
@ -252,7 +254,7 @@ static void disas_print_addr_reloc(bfd_vma addr, struct disassemble_info *dinfo)
* example: "lea 0x0(%rip),%rdi". The kernel can reference
* the next IP with _THIS_IP_ macro.
*/
DINFO_FPRINTF(dinfo, "0x%lx <_THIS_IP_>", addr);
DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, "_THIS_IP_");
return;
}
@ -264,11 +266,11 @@ static void disas_print_addr_reloc(bfd_vma addr, struct disassemble_info *dinfo)
*/
if (reloc->sym->type == STT_SECTION) {
str = offstr(reloc->sym->sec, reloc->sym->offset + offset);
DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, str);
DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, str);
free(str);
} else {
sprint_name(symstr, reloc->sym->name, offset);
DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr);
DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, symstr);
}
}
@ -311,7 +313,7 @@ static void disas_print_address(bfd_vma addr, struct disassemble_info *dinfo)
*/
sym = insn_call_dest(insn);
if (sym && (sym->offset == addr || (sym->offset == 0 && is_reloc))) {
DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, sym->name);
DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, sym->name);
return;
}

View file

@ -18,15 +18,14 @@
#include <errno.h>
#include <libgen.h>
#include <ctype.h>
#include <linux/align.h>
#include <linux/kernel.h>
#include <linux/interval_tree_generic.h>
#include <linux/log2.h>
#include <objtool/builtin.h>
#include <objtool/elf.h>
#include <objtool/warn.h>
#define ALIGN_UP(x, align_to) (((x) + ((align_to)-1)) & ~((align_to)-1))
#define ALIGN_UP_POW2(x) (1U << ((8 * sizeof(x)) - __builtin_clz((x) - 1U)))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
static inline u32 str_hash(const char *str)
{
return jhash(str, strlen(str), 0);
@ -1336,7 +1335,7 @@ unsigned int elf_add_string(struct elf *elf, struct section *strtab, const char
return -1;
}
offset = ALIGN_UP(strtab->sh.sh_size, strtab->sh.sh_addralign);
offset = ALIGN(strtab->sh.sh_size, strtab->sh.sh_addralign);
if (!elf_add_data(elf, strtab, str, strlen(str) + 1))
return -1;
@ -1378,7 +1377,7 @@ void *elf_add_data(struct elf *elf, struct section *sec, const void *data, size_
sec->data->d_size = size;
sec->data->d_align = 1;
offset = ALIGN_UP(sec->sh.sh_size, sec->sh.sh_addralign);
offset = ALIGN(sec->sh.sh_size, sec->sh.sh_addralign);
sec->sh.sh_size = offset + size;
mark_sec_changed(elf, sec, true);
@ -1502,7 +1501,7 @@ static int elf_alloc_reloc(struct elf *elf, struct section *rsec)
rsec->data->d_size = nr_relocs_new * elf_rela_size(elf);
rsec->sh.sh_size = rsec->data->d_size;
nr_alloc = MAX(64, ALIGN_UP_POW2(nr_relocs_new));
nr_alloc = max(64UL, roundup_pow_of_two(nr_relocs_new));
if (nr_alloc <= rsec->nr_alloc_relocs)
return 0;

View file

@ -1425,9 +1425,6 @@ static int clone_special_sections(struct elfs *e)
{
struct section *patched_sec;
if (create_fake_symbols(e->patched))
return -1;
for_each_sec(e->patched, patched_sec) {
if (is_special_section(patched_sec)) {
if (clone_special_section(e, patched_sec))
@ -1704,6 +1701,17 @@ int cmd_klp_diff(int argc, const char **argv)
if (!e.out)
return -1;
/*
* Special section fake symbols are needed so that individual special
* section entries can be extracted by clone_special_sections().
*
* Note the fake symbols are also needed by clone_included_functions()
* because __WARN_printf() call sites add references to bug table
* entries in the calling functions.
*/
if (create_fake_symbols(e.patched))
return -1;
if (clone_included_functions(&e))
return -1;