2020-05-11 17:38:09

by Matt Helsley

[permalink] [raw]
Subject: [RFC][PATCH 2/5] objtool: Move struct objtool_file into arch-independent header

The objtool_file structure describing the files objtool works on is
not architecture dependent -- it's not x86 only -- and it will be useful
for any future commands that might not be part of the check / orc
tooling. So we move it from the check.h header into the objtool.h header.

Signed-off-by: Matt Helsley <[email protected]>
---
tools/objtool/check.h | 10 +---------
tools/objtool/objtool.h | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+), 9 deletions(-)
create mode 100644 tools/objtool/objtool.h

diff --git a/tools/objtool/check.h b/tools/objtool/check.h
index f0ce8ffe7135..ec6ff7f0970c 100644
--- a/tools/objtool/check.h
+++ b/tools/objtool/check.h
@@ -7,11 +7,10 @@
#define _CHECK_H

#include <stdbool.h>
-#include "elf.h"
+#include "objtool.h"
#include "cfi.h"
#include "arch.h"
#include "orc.h"
-#include <linux/hashtable.h>

struct insn_state {
struct cfi_reg cfa;
@@ -47,13 +46,6 @@ struct instruction {
struct orc_entry orc;
};

-struct objtool_file {
- struct elf *elf;
- struct list_head insn_list;
- DECLARE_HASHTABLE(insn_hash, 20);
- bool ignore_unreachables, c_file, hints, rodata;
-};
-
int check(const char *objname, bool orc);

struct instruction *find_insn(struct objtool_file *file,
diff --git a/tools/objtool/objtool.h b/tools/objtool/objtool.h
new file mode 100644
index 000000000000..afa52fe6f644
--- /dev/null
+++ b/tools/objtool/objtool.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2020 Matt Helsley <[email protected]>
+ */
+
+#ifndef _OBJTOOL_H
+#define _OBJTOOL_H
+#include <stdbool.h>
+#include <linux/list.h>
+#include <linux/hashtable.h>
+
+#include "elf.h"
+
+struct objtool_file {
+ struct elf *elf;
+ struct list_head insn_list;
+ DECLARE_HASHTABLE(insn_hash, 20);
+ bool ignore_unreachables, c_file, hints, rodata;
+};
+#endif
--
2.20.1


2020-05-12 17:07:59

by Julien Thierry

[permalink] [raw]
Subject: Re: [RFC][PATCH 2/5] objtool: Move struct objtool_file into arch-independent header

Hi Matt,

On 5/11/20 6:35 PM, Matt Helsley wrote:
> The objtool_file structure describing the files objtool works on is
> not architecture dependent -- it's not x86 only -- and it will be useful
> for any future commands that might not be part of the check / orc
> tooling. So we move it from the check.h header into the objtool.h header.
>

The change itself looks alright to me, however I'd say the justification
is more about the fact the more subcommands dealing with object files
are going to be added to objtool, and all those subcommand will likely
use the objtool_file representation.

I think it doesn't have much to do with arch specificity. (But this is
really about the commit message, otherwise the changes make sense)

> Signed-off-by: Matt Helsley <[email protected]>
> ---
> tools/objtool/check.h | 10 +---------
> tools/objtool/objtool.h | 20 ++++++++++++++++++++
> 2 files changed, 21 insertions(+), 9 deletions(-)
> create mode 100644 tools/objtool/objtool.h
>
> diff --git a/tools/objtool/check.h b/tools/objtool/check.h
> index f0ce8ffe7135..ec6ff7f0970c 100644
> --- a/tools/objtool/check.h
> +++ b/tools/objtool/check.h
> @@ -7,11 +7,10 @@
> #define _CHECK_H
>
> #include <stdbool.h>
> -#include "elf.h"
> +#include "objtool.h"
> #include "cfi.h"
> #include "arch.h"
> #include "orc.h"
> -#include <linux/hashtable.h>
>
> struct insn_state {
> struct cfi_reg cfa;
> @@ -47,13 +46,6 @@ struct instruction {
> struct orc_entry orc;
> };
>
> -struct objtool_file {
> - struct elf *elf;
> - struct list_head insn_list;
> - DECLARE_HASHTABLE(insn_hash, 20);
> - bool ignore_unreachables, c_file, hints, rodata;
> -};
> -
> int check(const char *objname, bool orc);
>
> struct instruction *find_insn(struct objtool_file *file,
> diff --git a/tools/objtool/objtool.h b/tools/objtool/objtool.h
> new file mode 100644
> index 000000000000..afa52fe6f644
> --- /dev/null
> +++ b/tools/objtool/objtool.h
> @@ -0,0 +1,20 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (C) 2020 Matt Helsley <[email protected]>
> + */
> +
> +#ifndef _OBJTOOL_H
> +#define _OBJTOOL_H
> +#include <stdbool.h>
> +#include <linux/list.h>
> +#include <linux/hashtable.h>
> +
> +#include "elf.h"
> +
> +struct objtool_file {
> + struct elf *elf;
> + struct list_head insn_list;
> + DECLARE_HASHTABLE(insn_hash, 20);
> + bool ignore_unreachables, c_file, hints, rodata;
> +};
> +#endif
>

--
Julien Thierry

2020-05-12 18:10:24

by Matt Helsley

[permalink] [raw]
Subject: Re: [RFC][PATCH 2/5] objtool: Move struct objtool_file into arch-independent header

On Tue, May 12, 2020 at 06:04:43PM +0100, Julien Thierry wrote:
> Hi Matt,
>
> On 5/11/20 6:35 PM, Matt Helsley wrote:
> > The objtool_file structure describing the files objtool works on is
> > not architecture dependent -- it's not x86 only -- and it will be useful
> > for any future commands that might not be part of the check / orc
> > tooling. So we move it from the check.h header into the objtool.h header.
> >
>
> The change itself looks alright to me, however I'd say the justification is
> more about the fact the more subcommands dealing with object files are going
> to be added to objtool, and all those subcommand will likely use the
> objtool_file representation.
>
> I think it doesn't have much to do with arch specificity. (But this is
> really about the commit message, otherwise the changes make sense)

Good point. Here's a rewrite of the commit message:

The objtool_file structure describes the files objtool works on,
is used by the check subcommand, and the check.h header is included
by the orc subcommands so it's presently used by all subcommands.

Since the structure will be useful in all subcommands besides check,
and some subcommands may not want to include check.h to get the
definition, split the structure out into a new header meant for use
by all objtool subcommands.

Thanks!

Cheers,
-Matt Helsley

>
> > Signed-off-by: Matt Helsley <[email protected]>
> > ---
> > tools/objtool/check.h | 10 +---------
> > tools/objtool/objtool.h | 20 ++++++++++++++++++++
> > 2 files changed, 21 insertions(+), 9 deletions(-)
> > create mode 100644 tools/objtool/objtool.h
> >
> > diff --git a/tools/objtool/check.h b/tools/objtool/check.h
> > index f0ce8ffe7135..ec6ff7f0970c 100644
> > --- a/tools/objtool/check.h
> > +++ b/tools/objtool/check.h
> > @@ -7,11 +7,10 @@
> > #define _CHECK_H
> > #include <stdbool.h>
> > -#include "elf.h"
> > +#include "objtool.h"
> > #include "cfi.h"
> > #include "arch.h"
> > #include "orc.h"
> > -#include <linux/hashtable.h>
> > struct insn_state {
> > struct cfi_reg cfa;
> > @@ -47,13 +46,6 @@ struct instruction {
> > struct orc_entry orc;
> > };
> > -struct objtool_file {
> > - struct elf *elf;
> > - struct list_head insn_list;
> > - DECLARE_HASHTABLE(insn_hash, 20);
> > - bool ignore_unreachables, c_file, hints, rodata;
> > -};
> > -
> > int check(const char *objname, bool orc);
> > struct instruction *find_insn(struct objtool_file *file,
> > diff --git a/tools/objtool/objtool.h b/tools/objtool/objtool.h
> > new file mode 100644
> > index 000000000000..afa52fe6f644
> > --- /dev/null
> > +++ b/tools/objtool/objtool.h
> > @@ -0,0 +1,20 @@
> > +/* SPDX-License-Identifier: GPL-2.0-or-later */
> > +/*
> > + * Copyright (C) 2020 Matt Helsley <[email protected]>
> > + */
> > +
> > +#ifndef _OBJTOOL_H
> > +#define _OBJTOOL_H
> > +#include <stdbool.h>
> > +#include <linux/list.h>
> > +#include <linux/hashtable.h>
> > +
> > +#include "elf.h"
> > +
> > +struct objtool_file {
> > + struct elf *elf;
> > + struct list_head insn_list;
> > + DECLARE_HASHTABLE(insn_hash, 20);
> > + bool ignore_unreachables, c_file, hints, rodata;
> > +};
> > +#endif
> >
>
> --
> Julien Thierry
>