2019-05-19 21:51:43 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2017-06-28 23:11:07 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015-2017 Josh Poimboeuf <jpoimboe@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _OBJTOOL_CFI_H
|
|
|
|
#define _OBJTOOL_CFI_H
|
|
|
|
|
2020-03-27 23:28:46 +08:00
|
|
|
#include "cfi_regs.h"
|
objtool: Introduce CFI hash
commit 8b946cc38e063f0f7bb67789478c38f6d7d457c9 upstream.
Andi reported that objtool on vmlinux.o consumes more memory than his
system has, leading to horrific performance.
This is in part because we keep a struct instruction for every
instruction in the file in-memory. Shrink struct instruction by
removing the CFI state (which includes full register state) from it
and demand allocating it.
Given most instructions don't actually change CFI state, there's lots
of repetition there, so add a hash table to find previous CFI
instances.
Reduces memory consumption (and runtime) for processing an
x86_64-allyesconfig:
pre: 4:40.84 real, 143.99 user, 44.18 sys, 30624988 mem
post: 2:14.61 real, 108.58 user, 25.04 sys, 16396184 mem
Suggested-by: Andi Kleen <andi@firstfloor.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20210624095147.756759107@infradead.org
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
[bwh: Backported to 5.10:
- Don't use bswap_if_needed() since we don't have any of the other fixes
for mixed-endian cross-compilation
- Since we don't have "objtool: Rewrite hashtable sizing", make
cfi_hash_alloc() set the number of bits similarly to elf_hash_bits()
- objtool doesn't have any mcount handling
- Adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-24 17:41:01 +08:00
|
|
|
#include <linux/list.h>
|
2020-03-27 23:28:46 +08:00
|
|
|
|
2017-06-28 23:11:07 +08:00
|
|
|
#define CFI_UNDEFINED -1
|
|
|
|
#define CFI_CFA -2
|
|
|
|
#define CFI_SP_INDIRECT -3
|
|
|
|
#define CFI_BP_INDIRECT -4
|
|
|
|
|
|
|
|
struct cfi_reg {
|
|
|
|
int base;
|
|
|
|
int offset;
|
|
|
|
};
|
|
|
|
|
2020-03-25 22:34:50 +08:00
|
|
|
struct cfi_init_state {
|
2020-03-25 21:04:45 +08:00
|
|
|
struct cfi_reg regs[CFI_NUM_REGS];
|
2017-06-28 23:11:07 +08:00
|
|
|
struct cfi_reg cfa;
|
2020-03-25 21:04:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cfi_state {
|
objtool: Introduce CFI hash
commit 8b946cc38e063f0f7bb67789478c38f6d7d457c9 upstream.
Andi reported that objtool on vmlinux.o consumes more memory than his
system has, leading to horrific performance.
This is in part because we keep a struct instruction for every
instruction in the file in-memory. Shrink struct instruction by
removing the CFI state (which includes full register state) from it
and demand allocating it.
Given most instructions don't actually change CFI state, there's lots
of repetition there, so add a hash table to find previous CFI
instances.
Reduces memory consumption (and runtime) for processing an
x86_64-allyesconfig:
pre: 4:40.84 real, 143.99 user, 44.18 sys, 30624988 mem
post: 2:14.61 real, 108.58 user, 25.04 sys, 16396184 mem
Suggested-by: Andi Kleen <andi@firstfloor.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20210624095147.756759107@infradead.org
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
[bwh: Backported to 5.10:
- Don't use bswap_if_needed() since we don't have any of the other fixes
for mixed-endian cross-compilation
- Since we don't have "objtool: Rewrite hashtable sizing", make
cfi_hash_alloc() set the number of bits similarly to elf_hash_bits()
- objtool doesn't have any mcount handling
- Adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-24 17:41:01 +08:00
|
|
|
struct hlist_node hash; /* must be first, cficmp() */
|
2017-06-28 23:11:07 +08:00
|
|
|
struct cfi_reg regs[CFI_NUM_REGS];
|
2020-03-25 21:04:45 +08:00
|
|
|
struct cfi_reg vals[CFI_NUM_REGS];
|
|
|
|
struct cfi_reg cfa;
|
|
|
|
int stack_size;
|
|
|
|
int drap_reg, drap_offset;
|
|
|
|
unsigned char type;
|
|
|
|
bool bp_scratch;
|
|
|
|
bool drap;
|
|
|
|
bool end;
|
2017-06-28 23:11:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _OBJTOOL_CFI_H */
|