Remove dependency of check subcmd upon orc
v3 cover Remove dependency of check subcmd upon orc
Hi,
Matt Helsley's change[1] provided a base framework to opt-in/out objtool subcommands at compile time. This makes it easier for architectures to port objtool, one subcommand at a time.
Orc generation relies on the check operation implementation. However, the way this is done causes the check implementation to depend on the implementation of orc generation functions to call if orc generation is requested. This means that in order to implement check subcmd, orc subcmd also need to be implemented.
These patches aim at removing that dependency, having orc subcmd being built on top of the check subcmd.
Changes since v2 [2]:
- Rebased on recent tip/objtool/core
[1] https://www.spinics.net/lists/kernel/msg3510844.html
[2] https://lkml.org/lkml/2020/6/8/59
Cheers,
Julien
-->
Julien Thierry (4):
objtool: Move object file loading out of check
objtool: Move orc outside of check
objtool: orc: Skip setting orc_entry for non-text sections
objtool: orc_gen: Move orc_entry out of instruction structure
tools/objtool/builtin-check.c | 7 ++- tools/objtool/builtin-orc.c | 27 +++++++++++- tools/objtool/check.c | 47 ++++---------------- tools/objtool/check.h | 1 - tools/objtool/objtool.c | 30 +++++++++++++ tools/objtool/objtool.h | 5 ++- tools/objtool/orc_gen.c | 83 ++++++++++++++++++++--------------- tools/objtool/weak.c | 4 +- 8 files changed, 122 insertions(+), 82 deletions(-)
--
2.21.3
PATCH v3 1/4 objtool: Move object file loading out of check
Structure objtool_file can be used by different subcommands. In fact it already is, by check and orc.
Provide a function that allows to initialize objtool_file, that builtin can call, without relying on check to do the correct setup for them and explicitly hand the objtool_file to them.
--- tools/objtool/builtin-check.c | 7 ++++++- tools/objtool/builtin-orc.c | 8 ++++++- tools/objtool/check.c | 39 +++++++++++------------------------ tools/objtool/objtool.c | 29 ++++++++++++++++++++++++++ tools/objtool/objtool.h | 4 +++- tools/objtool/weak.c | 4 +--- 6 files changed, 58 insertions(+), 33 deletions(-)
tools/objtool/builtin-check.c +6 -1
@@ -41,6 +41,7 @@ const struct option check_options[] = {int cmd_check (int argc,const char **argv) {const char *objname, *s; +struct objtool_file *file; argc =parse_options (argc, argv, check_options, check_usage,0 );
@@ -53,5 +54,9 @@ int cmd_check(int argc, const char **argv)if (s && !s[9 ]) vmlinux = true; -return check (objname, false); + file =objtool_setup_file (objname); +if (!file) +return 1 ; + +return check (file, false); }
tools/objtool/builtin-orc.c +7 -1
@@ -31,13 +31,19 @@ int cmd_orc(int argc, const char **argv)usage_with_options (orc_usage, check_options);if (!strncmp (argv[0 ],"gen" ,3 )) { +struct objtool_file *file; + argc =parse_options (argc, argv, check_options, orc_usage,0 );if (argc !=1 )usage_with_options (orc_usage, check_options); objname = argv[0 ]; -return check (objname, true); + file =objtool_setup_file (objname); +if (!file) +return 1 ; + +return check (file, true); }if (!strcmp (argv[0 ],"dump" )) {
tools/objtool/check.c +12 -27
@@ -27,7 +27,6 @@ struct alternative {bool skip_orig; }; -const char *objname;struct cfi_init_state initial_func_cfi; struct instruction *find_insn(struct objtool_file *file,
@@ -2751,36 +2750,22 @@ static int validate_reachable_instructions(struct objtool_file *file)return 0 ; } -static struct objtool_file file; - -int check (const char *_objname,bool orc) +int check (struct objtool_file *file,bool orc) {int ret, warnings =0 ; - objname = _objname; - - file.elf =elf_open_read (objname,O_RDWR ); -if (!file.elf) -return 1 ; - -INIT_LIST_HEAD (&file.insn_list); -hash_init (file.insn_hash); - file.c_file =find_section_by_name (file.elf,".comment" ); - file.ignore_unreachables = no_unreachable; - file.hints = false; -arch_initial_func_cfi_state (&initial_func_cfi); - ret =decode_sections (&file); + ret =decode_sections (file);if (ret <0 ) goto out; warnings += ret; -if (list_empty (&file.insn_list)) +if (list_empty (&file->insn_list)) goto out;if (vmlinux && !validate_dup) { - ret =validate_vmlinux_functions (&file); + ret =validate_vmlinux_functions (file);if (ret <0 ) goto out;
@@ -2789,41 +2774,41 @@ int check(const char *_objname, bool orc) }if (retpoline) { - ret =validate_retpoline (&file); + ret =validate_retpoline (file);if (ret <0 )return ret; warnings += ret; } - ret =validate_functions (&file); + ret =validate_functions (file);if (ret <0 ) goto out; warnings += ret; - ret =validate_unwind_hints (&file,NULL ); + ret =validate_unwind_hints (file,NULL );if (ret <0 ) goto out; warnings += ret;if (!warnings) { - ret =validate_reachable_instructions (&file); + ret =validate_reachable_instructions (file);if (ret <0 ) goto out; warnings += ret; }if (orc) { - ret =create_orc (&file); + ret =create_orc (file);if (ret <0 ) goto out; - ret =create_orc_sections (&file); + ret =create_orc_sections (file);if (ret <0 ) goto out; } -if (file.elf->changed) { - ret =elf_write (file.elf); +if (file->elf->changed) { + ret =elf_write (file->elf);if (ret <0 ) goto out; }
tools/objtool/objtool.c +29 -0
@@ -22,6 +22,8 @@#include <linux/kernel.h> #include "builtin.h" +#include "objtool.h" +#include "warn.h" struct cmd_struct {const char *name;
@@ -39,6 +41,33 @@ static struct cmd_struct objtool_cmds[] = {bool help; +const char *objname; +static struct objtool_file file; + +struct objtool_file *objtool_setup_file (const char *_objname) +{ +if (objname) { +if (strcmp (objname, _objname)) { +WARN ("won't handle more than one file at a time" ); +return NULL ; + } +return &file; + } + objname = _objname; + + file.elf =elf_open_read (objname,O_RDWR ); +if (!file.elf) +return NULL ; + +INIT_LIST_HEAD (&file.insn_list); +hash_init (file.insn_hash); + file.c_file =find_section_by_name (file.elf,".comment" ); + file.ignore_unreachables = no_unreachable; + file.hints = false; + +return &file; +} +static void cmd_usage (void ) {unsigned int i, longest =0 ;
tools/objtool/objtool.h +3 -1
@@ -19,7 +19,9 @@ struct objtool_file {bool ignore_unreachables, c_file, hints, rodata; }; -int check (const char *objname,bool orc); +struct objtool_file *objtool_setup_file (const char *_objname); + +int check (struct objtool_file *file,bool orc);int orc_dump (const char *objname);int create_orc (struct objtool_file *file);int create_orc_sections (struct objtool_file *file);
tools/objtool/weak.c +1 -3
@@ -17,9 +17,7 @@return ENOSYS ; \ }) -const char __weak *objname; - -int __weak check (const char *_objname,bool orc) +int __weak check (struct objtool_file *file,bool orc) {UNSUPPORTED ("check subcommand" ); }
Signature · 1 line
2.21.3
Re: [PATCH v3 1/4] objtool: Move object file loading out of check
Quoted 13 lines · Julien Thierry
tools/objtool/objtool.c +13
-0+struct objtool_file *objtool_setup_file (const char *_objname) +{ +if (objname) { +if (strcmp (objname, _objname)) { +WARN ("won't handle more than one file at a time" ); +return NULL ; + } +return &file; + } + objname = _objname; + + file.elf =elf_open_read (objname,O_RDWR ); +if (!file.elf)
tools/objtool/objtool.c static struct cmd_struct objtool_cmds[] = { · line 69
Quoted 10 lines
tools/objtool/objtool.c +10
-0+return NULL ; + +INIT_LIST_HEAD (&file.insn_list); +hash_init (file.insn_hash); + file.c_file =find_section_by_name (file.elf,".comment" ); + file.ignore_unreachables = no_unreachable; + file.hints = false; + +return &file; +}
How about calling it objtool_open_read()? It's (sort of) a wrapper around elf_open_read().
Signature · 1 line
Josh
Re: [PATCH v3 1/4] objtool: Move object file loading out of check
Quoted 19 lines · Josh Poimboeuf
Quoted 18 lines · Julien Thierry
tools/objtool/objtool.c +18
-0+struct objtool_file *objtool_setup_file (const char *_objname) +{ +if (objname) { +if (strcmp (objname, _objname)) { +WARN ("won't handle more than one file at a time" ); +return NULL ; + } +return &file; + } + objname = _objname; + + file.elf =elf_open_read (objname,O_RDWR ); +if (!file.elf) +return NULL ; + +INIT_LIST_HEAD (&file.insn_list); +hash_init (file.insn_hash); + file.c_file =find_section_by_name (file.elf,".comment" );
Quoted 9 lines
tools/objtool/objtool.c static struct cmd_struct objtool_cmds[] = { · line 69
Quoted 5 lines
tools/objtool/objtool.c +5
-0+ file.ignore_unreachables = no_unreachable; + file.hints = false; + +return &file; +}How about calling it
objtool_open_read()? It's (sort of) a wrapper aroundelf_open_read().
Sure, I'll update that.
Thanks,
Signature · 1 line
Julien Thierry
PATCH v3 2/4 objtool: Move orc outside of check
In reply to Julien ThierryNow that the objtool_file can be obtained outside of the check function, orc generation builtin no longer requires check to explicitly call its orc related functions.
--- tools/objtool/builtin-check.c | 2 +- tools/objtool/builtin-orc.c | 21 ++++++++++++++++++++- tools/objtool/check.c | 18 +----------------- tools/objtool/objtool.h | 2 +- tools/objtool/weak.c | 2 +- 5 files changed, 24 insertions(+), 21 deletions(-)
tools/objtool/builtin-check.c +1 -1
@@ -58,5 +58,5 @@ int cmd_check(int argc, const char **argv)if (!file)return 1 ; -return check (file, false); +return check (file); }
tools/objtool/builtin-orc.c +20 -1
@@ -32,6 +32,7 @@ int cmd_orc(int argc, const char **argv)if (!strncmp (argv[0 ],"gen" ,3 )) {struct objtool_file *file; +int ret; argc =parse_options (argc, argv, check_options, orc_usage,0 );if (argc !=1 )
@@ -43,7 +44,25 @@ int cmd_orc(int argc, const char **argv)if (!file)return 1 ; -return check (file, true); + ret =check (file); +if (ret) +return ret; + +if (list_empty (&file->insn_list)) +return 0 ; + + ret =create_orc (file); +if (ret <0 ) +return ret; + + ret =create_orc_sections (file); +if (ret <0 ) +return ret; + +if (file->elf->changed) +return elf_write (file->elf); +else +return 0 ; }if (!strcmp (argv[0 ],"dump" )) {
tools/objtool/check.c +1 -17
@@ -2750,7 +2750,7 @@ static int validate_reachable_instructions(struct objtool_file *file)return 0 ; } -int check (struct objtool_file *file,bool orc) +int check (struct objtool_file *file) {int ret, warnings =0 ;
@@ -2797,22 +2797,6 @@ int check(struct objtool_file *file, bool orc) warnings += ret; } -if (orc) { - ret =create_orc (file); -if (ret <0 ) - goto out; - - ret =create_orc_sections (file); -if (ret <0 ) - goto out; - } - -if (file->elf->changed) { - ret =elf_write (file->elf); -if (ret <0 ) - goto out; - } - out:if (ret <0 ) {/*
tools/objtool/objtool.h +1 -1
@@ -21,7 +21,7 @@ struct objtool_file {struct objtool_file *objtool_setup_file (const char *_objname); -int check (struct objtool_file *file,bool orc); +int check (struct objtool_file *file);int orc_dump (const char *objname);int create_orc (struct objtool_file *file);int create_orc_sections (struct objtool_file *file);
tools/objtool/weak.c +1 -1
@@ -17,7 +17,7 @@return ENOSYS ; \ }) -int __weak check (struct objtool_file *file,bool orc) +int __weak check (struct objtool_file *file) {UNSUPPORTED ("check subcommand" ); }
Signature · 1 line
2.21.3
[email protected]
maintainerRe: [PATCH v3 2/4] objtool: Move orc outside of check
tools/objtool/builtin-orc.c int cmd_orc(int argc, const char **argv) · line 66
Quoted 5 lines · Julien Thierry
tools/objtool/builtin-orc.c +4
-0+if (file->elf->changed) +return elf_write (file->elf); +else +return 0 ; }
I think we can do without that else :-)
Re: [PATCH v3 2/4] objtool: Move orc outside of check
Quoted 9 lines · On 7/30/20 10:57 AM, [email protected] wrote:
tools/objtool/builtin-orc.c int cmd_orc(int argc, const char **argv) · line 66
Quoted 5 lines · Julien Thierry
tools/objtool/builtin-orc.c +4
-0+if (file->elf->changed) +return elf_write (file->elf); +else +return 0 ; }I think we can do without that else :-)
I did wonder and was not 100% confident about it, but the orc gen will always change the file, correct?
Signature · 1 line
Julien Thierry
[email protected]
maintainerRe: [PATCH v3 2/4] objtool: Move orc outside of check
Quoted 13 lines · Julien Thierry
Quoted 9 lines · On 7/30/20 10:57 AM, [email protected] wrote:
tools/objtool/builtin-orc.c int cmd_orc(int argc, const char **argv) · line 66
Quoted 5 lines · Julien Thierry
tools/objtool/builtin-orc.c +4
-0+if (file->elf->changed) +return elf_write (file->elf); +else +return 0 ; }I think we can do without that else :-)
Quoted 2 lines
I did wonder and was not 100% confident about it, but the orc gen will always change the file, correct?
Not if it already has orc, iirc.
But what I was trying to say is that:
if (file->elf->changed) return elf_write(file->elf) return 0;
is identical code and, IMO, easier to read.
Re: [PATCH v3 2/4] objtool: Move orc outside of check
Quoted 19 lines · On 7/30/20 2:22 PM, [email protected] wrote:
Quoted 13 lines · Julien Thierry
Quoted 9 lines · On 7/30/20 10:57 AM, [email protected] wrote:
tools/objtool/builtin-orc.c int cmd_orc(int argc, const char **argv) · line 66
Quoted 5 lines · Julien Thierry
tools/objtool/builtin-orc.c +4
-0+if (file->elf->changed) +return elf_write (file->elf); +else +return 0 ; }I think we can do without that else :-)
Quoted 2 lines
I did wonder and was not 100% confident about it, but the orc gen will always change the file, correct?
Not if it already has orc, iirc.
Quoted 9 lines
But what I was trying to say is that:
if (file->elf->changed) return elf_write(file->elf) return 0;is identical code and, IMO, easier to read.
Much easier yes, I'll change it.
Thanks,
Signature · 1 line
Julien Thierry
Re: [PATCH v3 2/4] objtool: Move orc outside of check
Quoted 27 lines · Julien Thierry
Quoted 24 lines · On 7/30/20 2:22 PM, [email protected] wrote:
Quoted 13 lines · Julien Thierry
Quoted 9 lines · On 7/30/20 10:57 AM, [email protected] wrote:
tools/objtool/builtin-orc.c int cmd_orc(int argc, const char **argv) · line 66
Quoted 5 lines · Julien Thierry
tools/objtool/builtin-orc.c +4
-0+if (file->elf->changed) +return elf_write (file->elf); +else +return 0 ; }I think we can do without that else :-)
Quoted 2 lines
I did wonder and was not 100% confident about it, but the orc gen will always change the file, correct?
Not if it already has orc, iirc.
But what I was trying to say is that:
if (file->elf->changed) return elf_write(file->elf)
Quoted 6 lines
Quoted 4 lines
return 0;is identical code and, IMO, easier to read.
Much easier yes, I'll change it.
But I think file->elf->changed can be assumed at this point anyway, so it could just be an unconditional
return elf_write(file->elf);
Signature · 1 line
Josh
Re: [PATCH v3 2/4] objtool: Move orc outside of check
Quoted 33 lines · Josh Poimboeuf
Quoted 32 lines · Julien Thierry
Quoted 28 lines · On 7/30/20 2:22 PM, [email protected] wrote:
Quoted 13 lines · Julien Thierry
Quoted 9 lines · On 7/30/20 10:57 AM, [email protected] wrote:
tools/objtool/builtin-orc.c int cmd_orc(int argc, const char **argv) · line 66
Quoted 5 lines · Julien Thierry
tools/objtool/builtin-orc.c +4
-0+if (file->elf->changed) +return elf_write (file->elf); +else +return 0 ; }I think we can do without that else :-)
Quoted 2 lines
I did wonder and was not 100% confident about it, but the orc gen will always change the file, correct?
Not if it already has orc, iirc.
But what I was trying to say is that:
if (file->elf->changed) return elf_write(file->elf) return 0;is identical code and, IMO, easier to read.
Quoted 7 lines
Quoted 1 line
Much easier yes, I'll change it.
But I think
file->elf->changedcan be assumed at this point anyway, so it could just be an unconditionalreturn elf_write(file->elf);
I'll triple check whether that's the case and remove the if if possible.
Signature · 1 line
Julien Thierry
Re: [PATCH v3 2/4] objtool: Move orc outside of check
Quoted 38 lines · Julien Thierry
Quoted 35 lines · Josh Poimboeuf
Quoted 33 lines · Julien Thierry
Quoted 19 lines · On 7/30/20 2:22 PM, [email protected] wrote:
Quoted 13 lines · Julien Thierry
Quoted 9 lines · On 7/30/20 10:57 AM, [email protected] wrote:
Review
Quoted 5 lines · Julien Thierry
(quoted diff) +4
-0+ if (file->elf->changed) + return elf_write(file->elf); + else + return 0; }I think we can do without that else :-)
Quoted 2 lines
I did wonder and was not 100% confident about it, but the orc gen will always change the file, correct?
Not if it already has orc, iirc.
Quoted 9 lines
But what I was trying to say is that:
if (
file->elf->changed)
returnelf_write(file->elf)return 0;
is identical code and, IMO, easier to read.
Much easier yes, I'll change it.
Quoted 7 lines
Quoted 5 lines
But I think
file->elf->changedcan be assumed at this point anyway, so it could just be an unconditionalreturn
elf_write(file->elf);I'll triple check whether that's the case and remove the if if possible.
I think it is the case. And even if not, it would only cause a pointless call to elf_update() in the end and that should not do any harm anyway if I am not mistaken.
However, I think there is a problem with the rebase on top of the current code. The patch moves elf_write() call to orc_gen.c which was ok before Peterz introduced elf_write_insn() et al. We need to keep elf_write() in check.c for this case too.
Miroslav
Re: [PATCH v3 2/4] objtool: Move orc outside of check
Quoted 48 lines · Miroslav Benes
Quoted 38 lines · Julien Thierry
Quoted 35 lines · Josh Poimboeuf
Quoted 33 lines · Julien Thierry
Quoted 19 lines · On 7/30/20 2:22 PM, [email protected] wrote:
Quoted 13 lines · Julien Thierry
Quoted 9 lines · On 7/30/20 10:57 AM, [email protected] wrote:
Review
Quoted 5 lines · Julien Thierry
(quoted diff) +4
-0+ if (file->elf->changed) + return elf_write(file->elf); + else + return 0; }I think we can do without that else :-)
Quoted 2 lines
I did wonder and was not 100% confident about it, but the orc gen will always change the file, correct?
Not if it already has orc, iirc.
Quoted 9 lines
But what I was trying to say is that:
if (
file->elf->changed)
returnelf_write(file->elf)return 0;
is identical code and, IMO, easier to read.
Much easier yes, I'll change it.
Quoted 7 lines
Quoted 5 lines
But I think
file->elf->changedcan be assumed at this point anyway, so it could just be an unconditionalreturn elf_write(file->elf);I'll triple check whether that's the case and remove the if if possible.
Quoted 9 lines
I think it is the case. And even if not, it would only cause a pointless call to
elf_update()in the end and that should not do any harm anyway if I am not mistaken.However, I think there is a problem with the rebase on top of the current code. The patch moves
elf_write()call toorc_gen.cwhich was ok before Peterz introducedelf_write_insn()et al. We need to keepelf_write()incheck.cfor this case too.
Yes, you're right. Looks like I messed things up with the rebase. That means I might have to move the elf_write() to builtin-check.c.
Thanks for pointing it out.
Signature · 1 line
Julien Thierry
PATCH v3 3/4 objtool: orc: Skip setting orc_entry for non-text sections
In reply to Julien ThierryOrc generation is only done for text sections, but some instructions can be found in non-text sections (e.g. .discard.text sections).
Skip setting their orc sections since their whole sections will be skipped for orc generation.
--- tools/objtool/orc_gen.c | 3 +++ 1 file changed, 3 insertions(+)
tools/objtool/orc_gen.c +3 -0
@@ -18,6 +18,9 @@ int create_orc(struct objtool_file *file)struct cfi_reg *cfa = &insn->cfi.cfa;struct cfi_reg *bp = &insn->cfi.regs[CFI_BP ]; +if (!insn->sec->text) +continue ; + orc->end = insn->cfi.end;if (cfa->base ==CFI_UNDEFINED ) {
Signature · 1 line
2.21.3
PATCH v3 4/4 objtool: orc_gen: Move orc_entry out of instruction structure
In reply to Julien ThierryOne orc_entry is associated with each instruction in the object file, but having the orc_entry contained by the instruction structure forces architectures not implementing the orc subcommands to provide a dummy definition of the orc_entry.
Avoid that by having orc_entries in a separate list, part of the objtool_file.
--- tools/objtool/check.h | 1 - tools/objtool/objtool.c | 1 + tools/objtool/objtool.h | 1 + tools/objtool/orc_gen.c | 80 ++++++++++++++++++++++------------------- 4 files changed, 46 insertions(+), 37 deletions(-)
tools/objtool/check.h +0 -1
@@ -42,7 +42,6 @@ struct instruction {struct symbol *func;struct list_head stack_ops;struct cfi_state cfi; -struct orc_entry orc; }; struct instruction *find_insn(struct objtool_file *file,
tools/objtool/objtool.c +1 -0
@@ -61,6 +61,7 @@ struct objtool_file *objtool_setup_file(const char *_objname)INIT_LIST_HEAD (&file.insn_list);hash_init (file.insn_hash); +INIT_LIST_HEAD (&file.orc_data_list); file.c_file =find_section_by_name (file.elf,".comment" ); file.ignore_unreachables = no_unreachable; file.hints = false;
tools/objtool/objtool.h +1 -0
@@ -16,6 +16,7 @@ struct objtool_file {struct elf *elf;struct list_head insn_list;DECLARE_HASHTABLE (insn_hash,20 ); +struct list_head orc_data_list;bool ignore_unreachables, c_file, hints, rodata; };
tools/objtool/orc_gen.c +44 -36
125 lines not on this page · raw message
Signature · 1 line
2.21.3
[email protected]
maintainerRe: [PATCH v3 4/4] objtool: orc_gen: Move orc_entry out of instruction structure
Quoted 38 lines · Julien Thierry
One
orc_entryis associated with each instruction in the object file, but having theorc_entrycontained by the instruction structure forces architectures not implementing the orc subcommands to provide a dummy definition of theorc_entry.Avoid that by having
orc_entriesin a separate list, part of theobjtool_file.tools/objtool/orc_gen.c +9
-1@@ -9,18 +9,33 @@#include "check.h" #include "warn.h" +struct orc_data { +struct list_head list; +struct instruction *insn; +struct orc_entry orc; +}; +int create_orc (struct objtool_file *file) {struct instruction *insn;for_each_insn (file, insn) { -struct orc_entry *orc = &insn->orc;struct cfi_reg *cfa = &insn->cfi.cfa;struct cfi_reg *bp = &insn->cfi.regs[CFI_BP ]; +struct orc_entry *orc; +struct orc_data *od;if (!insn->sec->text)continue ; + od =calloc (1 ,sizeof (*od));
tools/objtool/orc_gen.c line 41
Quoted 10 lines
tools/objtool/orc_gen.c +7
-0+if (!od) +return -1 ; + od->insn = insn; +list_add_tail (&od->list, &file->orc_data_list); + + orc = &od->orc; + orc->end = insn->cfi.end;if (cfa->base ==CFI_UNDEFINED ) {
This will dramatically increase the amount of allocation calls, what, if anything, does this do for the performance of objtool?
Re: [PATCH v3 4/4] objtool: orc_gen: Move orc_entry out of instruction structure
Quoted 48 lines · On 7/30/20 11:03 AM, [email protected] wrote:
Quoted 47 lines · Julien Thierry
One
orc_entryis associated with each instruction in the object file, but having theorc_entrycontained by the instruction structure forces architectures not implementing the orc subcommands to provide a dummy definition of theorc_entry.Avoid that by having
orc_entriesin a separate list, part of theobjtool_file.tools/objtool/orc_gen.c +16
-1@@ -9,18 +9,33 @@#include "check.h" #include "warn.h" +struct orc_data { +struct list_head list; +struct instruction *insn; +struct orc_entry orc; +}; +int create_orc (struct objtool_file *file) {struct instruction *insn;for_each_insn (file, insn) { -struct orc_entry *orc = &insn->orc;struct cfi_reg *cfa = &insn->cfi.cfa;struct cfi_reg *bp = &insn->cfi.regs[CFI_BP ]; +struct orc_entry *orc; +struct orc_data *od;if (!insn->sec->text)continue ; + od =calloc (1 ,sizeof (*od)); +if (!od) +return -1 ; + od->insn = insn; +list_add_tail (&od->list, &file->orc_data_list); + + orc = &od->orc; + orc->end = insn->cfi.end;
Quoted 5 lines
tools/objtool/orc_gen.c line 41
Quoted 1 line
tools/objtool/orc_gen.c +0
-0if (cfa->base ==CFI_UNDEFINED ) {This will dramatically increase the amount of allocation calls, what, if anything, does this do for the performance of objtool?
I guess I forgot about the usecase of running objtool on vmlinux...
On a kernel build for x86_64 defconfig, the difference in time seems to be withing the noise.
But I agree the proposed code is not ideal and on the other we've tried avoiding #ifdef in the code. Ideally I'd have an empty orc_entry definition when SUBCMD_ORC is not implemented.
Would you have a suggested approach to do that?
Thanks,
Signature · 1 line
Julien Thierry
[email protected]
maintainerRe: [PATCH v3 4/4] objtool: orc_gen: Move orc_entry out of instruction structure
Quoted 10 lines · Julien Thierry
Quoted 5 lines · On 7/30/20 11:03 AM, [email protected] wrote:
Quoted 4 lines · Julien Thierry
One
orc_entryis associated with each instruction in the object file, but having theorc_entrycontained by the instruction structure forces architectures not implementing the orc subcommands to provide a dummy definition of theorc_entry.I guess I forgot about the usecase of running objtool on vmlinux...
Right, and LTO builds will even do ORC at that level.
Quoted 2 lines
On a kernel build for
x86_64defconfig, the difference in time seems to be withing the noise.
Good.
Quoted 5 lines
But I agree the proposed code is not ideal and on the other we've tried avoiding #ifdef in the code. Ideally I'd have an empty
orc_entrydefinition whenSUBCMD_ORCis not implemented.Would you have a suggested approach to do that?
How ugly is having that:
struct orc_entry { };
?
Re: [PATCH v3 4/4] objtool: orc_gen: Move orc_entry out of instruction structure
Quoted 23 lines · On 7/30/20 2:33 PM, [email protected] wrote:
Quoted 10 lines · Julien Thierry
Quoted 5 lines · On 7/30/20 11:03 AM, [email protected] wrote:
Quoted 4 lines · Julien Thierry
One
orc_entryis associated with each instruction in the object file, but having theorc_entrycontained by the instruction structure forces architectures not implementing the orc subcommands to provide a dummy definition of theorc_entry.I guess I forgot about the usecase of running objtool on vmlinux...
Right, and LTO builds will even do ORC at that level.
Quoted 2 lines
On a kernel build for
x86_64defconfig, the difference in time seems to be withing the noise.Good.
Quoted 4 lines
But I agree the proposed code is not ideal and on the other we've tried avoiding #ifdef in the code. Ideally I'd have an empty
orc_entrydefinition whenSUBCMD_ORCis not implemented.
Quoted 7 lines
Quoted 1 line
Would you have a suggested approach to do that?
How ugly is having that:
struct
orc_entry{ };?
Not sure I am understanding the suggestion. Without #ifdef this will conflict with the definition in <asm/orc_types.h> for x86. Or every arch needs to provide their own <asm/orc_types.h> and definition of struct orc_entry, even if they don't implement the orc subcommand.
Which would be preferable? #ifdef? or arch provided definition? (or something I have not thought of)
Signature · 1 line
Julien Thierry
Re: [PATCH v3 4/4] objtool: orc_gen: Move orc_entry out of instruction structure
Quoted 12 lines · Julien Thierry
Quoted 11 lines
Quoted 5 lines
But I agree the proposed code is not ideal and on the other we've tried avoiding #ifdef in the code. Ideally I'd have an empty
orc_entrydefinition whenSUBCMD_ORCis not implemented.Would you have a suggested approach to do that?
How ugly is having that:
struct
orc_entry{ };?
Quoted 7 lines
Not sure I am understanding the suggestion. Without #ifdef this will conflict with the definition in <
asm/orc_types.h> for x86. Or every arch needs to provide their own <asm/orc_types.h> and definition of structorc_entry, even if they don't implement the orc subcommand.Which would be preferable? #ifdef? or arch provided definition? (or something I have not thought of)
If we wanted to get fancy we could add a 'struct insn_arch_specific arch' field, and then require every arch to declare it.
But I think just an #ifdef in the 'instruction' struct declaration would be easiest for now.
Signature · 1 line
Josh
Quoted 12 lines · Julien Thierry
Hi,
Matt Helsley's change[1] provided a base framework to opt-in/out objtool subcommands at compile time. This makes it easier for architectures to port objtool, one subcommand at a time.
Orc generation relies on the check operation implementation. However, the way this is done causes the check implementation to depend on the implementation of orc generation functions to call if orc generation is requested. This means that in order to implement check subcmd, orc subcmd also need to be implemented.
Quoted 6 lines
These patches aim at removing that dependency, having orc subcmd being built on top of the check subcmd.
Changes since v2 [2]:
- Rebased on recent tip/objtool/core
tip/objtool/core is slightly outdated, I got a conflict with patch 1.
I guess linus/master would be best.
Signature · 1 line
Josh
Quoted 17 lines · Josh Poimboeuf
Quoted 16 lines · Julien Thierry
Hi,
Matt Helsley's change[1] provided a base framework to opt-in/out objtool subcommands at compile time. This makes it easier for architectures to port objtool, one subcommand at a time.
Orc generation relies on the check operation implementation. However, the way this is done causes the check implementation to depend on the implementation of orc generation functions to call if orc generation is requested. This means that in order to implement check subcmd, orc subcmd also need to be implemented.
These patches aim at removing that dependency, having orc subcmd being built on top of the check subcmd.
Quoted 6 lines
Quoted 2 lines
Changes since v2 [2]:
- Rebased on recent tip/objtool/coretip/objtool/core is slightly outdated, I got a conflict with patch 1.
I guess linus/master would be best.
It looks like linus/master is missing the rela -> reloc rework that is present in tip/objtool/core, which will conflict with other patches from this series.
How shall I proceed?
Signature · 1 line
Julien Thierry
Quoted 25 lines · Julien Thierry
Quoted 22 lines · Josh Poimboeuf
Quoted 12 lines · Julien Thierry
Hi,
Matt Helsley's change[1] provided a base framework to opt-in/out objtool subcommands at compile time. This makes it easier for architectures to port objtool, one subcommand at a time.
Orc generation relies on the check operation implementation. However, the way this is done causes the check implementation to depend on the implementation of orc generation functions to call if orc generation is requested. This means that in order to implement check subcmd, orc subcmd also need to be implemented.
Quoted 6 lines
These patches aim at removing that dependency, having orc subcmd being built on top of the check subcmd.
Changes since v2 [2]:
- Rebased on recent tip/objtool/coretip/objtool/core is slightly outdated, I got a conflict with patch 1.
Quoted 7 lines
Quoted 1 line
I guess linus/master would be best.
It looks like linus/master is missing the rela -> reloc rework that is present in tip/objtool/core, which will conflict with other patches from this series.
How shall I proceed?
Hm. I guess we'll need guidance from Peter, he's the branch wrangler. Maybe tip/objtool/core needs to be rebased onto linus/master.
Signature · 1 line
Josh