mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Matt Helsley <mhelsley@vmware.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH v3 04/13] recordmcount: Rewrite error/success handling
Date: Fri, 26 Jul 2019 13:45:23 -0400	[thread overview]
Message-ID: <20190726134523.4e7afd55@gandalf.local.home> (raw)
In-Reply-To: <316706a0e2727af0a2639b8e90366746d7a3a84a.1563992889.git.mhelsley@vmware.com>

On Wed, 24 Jul 2019 14:04:58 -0700
Matt Helsley <mhelsley@vmware.com> wrote:


Hi Matt,

As I'm applying these for real, I'm taking a deeper look at the
patches. This one I have some questions about.

> Recordmcount uses setjmp/longjmp to manage control flow as
> it reads and then writes the ELF file. This unusual control
> flow is hard to follow and check in addition to being unlike
> kernel coding style.
> 
> So we rewrite these paths to use regular return values to
> indicate error/success. When an error or previously-completed object
> file is found we return an error code following kernel
> coding conventions -- negative error values and 0 for success when
> we're not returning a pointer. We return NULL for those that fail
> and return non-NULL pointers otherwise.
> 
> One oddity is already_has_rel_mcount -- there we use pointer comparison
> rather than string comparison to differentiate between
> previously-processed object files and returning the name of a text
> section.

This is fine, but it's got a strange implementation.



> diff --git a/scripts/recordmcount.h b/scripts/recordmcount.h
> index c1e1b04b4871..909a3e4775c2 100644
> --- a/scripts/recordmcount.h
> +++ b/scripts/recordmcount.h
> @@ -24,7 +24,9 @@
>  #undef mcount_adjust
>  #undef sift_rel_mcount
>  #undef nop_mcount
> +#undef missing_sym
>  #undef find_secsym_ndx
> +#undef already_has_rel_mcount

Why do we need these as defines? Can't you just have a single:

const char *already_has_mcount = "success";

in recordmcount.c before recordmcount.h is included?

And same for missing_sym.

Another, probably more robust way of doing this, is change
find_secsym_ndx() to return 0 on success and -1 on missing symbol, and
just pass a pointer by reference to fill the recsym (which doesn't have
to be a constant).

I've applied the first 3 patches of this series, but stopped here. I'll
continue to take a deeper look at your other patches.

Thanks!

-- Steve



>  #undef __has_rel_mcount
>  #undef has_rel_mcount
>  #undef tot_relsize
> @@ -54,7 +56,9 @@
>  # define append_func		append64
>  # define sift_rel_mcount	sift64_rel_mcount
>  # define nop_mcount		nop_mcount_64
> +# define missing_sym		missing_sym_64
>  # define find_secsym_ndx	find64_secsym_ndx
> +# define already_has_rel_mcount	already_has_rel_mcount_64
>  # define __has_rel_mcount	__has64_rel_mcount
>  # define has_rel_mcount		has64_rel_mcount
>  # define tot_relsize		tot64_relsize
> @@ -87,7 +91,9 @@
>  # define append_func		append32
>  # define sift_rel_mcount	sift32_rel_mcount
>  # define nop_mcount		nop_mcount_32
> +# define missing_sym		missing_sym_32
>  # define find_secsym_ndx	find32_secsym_ndx
> +# define already_has_rel_mcount	already_has_rel_mcount_32
>  # define __has_rel_mcount	__has32_rel_mcount
>  # define has_rel_mcount		has32_rel_mcount
>  # define tot_relsize		tot32_relsize

> +static const unsigned int missing_sym = (unsigned int)-1;
>  
>  /*
>   * Find a symbol in the given section, to be used as the base for relocating
> @@ -443,9 +469,11 @@ static unsigned find_secsym_ndx(unsigned const txtndx,
>  	}
>  	fprintf(stderr, "Cannot find symbol for section %u: %s.\n",
>  		txtndx, txtname);
> -	fail_file();
> +	cleanup();
> +	return missing_sym;
>  }
>  
> +char const *already_has_rel_mcount = "success"; /* our work here is done! */
>  
>  /* Evade ISO C restriction: no declaration after statement in has_rel_mcount. */
>  static char const *
> @@ -461,7 +489,8 @@ __has_rel_mcount(Elf_Shdr const *const relhdr,  /* is SHT_REL or SHT_RELA */
>  	if (strcmp("__mcount_loc", txtname) == 0) {
>  		fprintf(stderr, "warning: __mcount_loc already exists: %s\n",
>  			fname);
> -		succeed_file();
> +		cleanup();
> +		return already_has_rel_mcount;
>  	}
>  	if (w(txthdr->sh_type) != SHT_PROGBITS ||
>  	    !(_w(txthdr->sh_flags) & SHF_EXECINSTR))

  reply	other threads:[~2019-07-26 17:45 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-24 21:04 [PATCH v3 00/13] Cleanup recordmcount and begin objtool conversion Matt Helsley
2019-07-24 21:04 ` [PATCH v3 01/13] recordmcount: Remove redundant strcmp Matt Helsley
2019-07-24 21:04 ` [PATCH v3 02/13] recordmcount: Remove uread() Matt Helsley
2019-07-24 21:04 ` [PATCH v3 03/13] recordmcount: Remove unused fd from uwrite() and ulseek() Matt Helsley
2019-07-24 21:04 ` [PATCH v3 04/13] recordmcount: Rewrite error/success handling Matt Helsley
2019-07-26 17:45   ` Steven Rostedt [this message]
2019-07-26 18:37     ` Matt Helsley
2019-07-26 18:43       ` Steven Rostedt
2019-07-26 19:23         ` Matt Helsley
2019-07-24 21:04 ` [PATCH v3 05/13] recordmcount: Kernel style function signature formatting Matt Helsley
2019-07-24 21:05 ` [PATCH v3 06/13] recordmcount: Kernel style formatting Matt Helsley
2019-07-24 21:05 ` [PATCH v3 07/13] recordmcount: Remove redundant cleanup() calls Matt Helsley
2019-07-24 21:05 ` [PATCH v3 08/13] recordmcount: Clarify what cleanup() does Matt Helsley
2019-07-26 16:10   ` Steven Rostedt
2019-07-26 16:13   ` Steven Rostedt
2019-07-24 21:05 ` [PATCH v3 09/13] objtool: Prepare to merge recordmcount Matt Helsley
2019-07-28 17:48   ` Josh Poimboeuf
2019-07-29 20:10     ` Matt Helsley
2019-07-24 21:05 ` [PATCH v3 10/13] objtool: Make recordmcount into an objtool subcmd Matt Helsley
2019-07-28 17:48   ` Josh Poimboeuf
2019-07-29 20:19     ` Matt Helsley
2019-07-24 21:05 ` [PATCH v3 11/13] objtool: recordmcount: Start using objtool's elf wrapper Matt Helsley
2019-07-24 21:05 ` [PATCH v3 12/13] objtool: recordmcount: Search for __mcount_loc before walking the sections Matt Helsley
2019-07-24 21:05 ` [PATCH v3 13/13] objtool: recordmcount: Convert do_func() relhdrs Matt Helsley
2019-07-28 17:52 ` [PATCH v3 00/13] Cleanup recordmcount and begin objtool conversion Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190726134523.4e7afd55@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhelsley@vmware.com \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®