public inbox for annobin@sourceware.org
 help / color / mirror / Atom feed
From: Nick Clifton <nickc@redhat.com>
To: annobin@sourceware.org,
	Tulio Magno Quites Machado Filho <tuliom@redhat.com>
Cc: grant@hcubed.com
Subject: Re: [PATCH] Add support for global-file-syms to the clang and llvm plugins
Date: Mon, 25 Mar 2024 16:00:28 +0000	[thread overview]
Message-ID: <c51f1323-12cd-4852-aa7d-34eb9557e75c@redhat.com> (raw)
In-Reply-To: <20240322201736.421134-1-tuliom@ascii.art.br>

Hi Tulio,

> This part starts by moving the implementation of parse_env() to
> annobin-common.cc in order to be shared between the gcc and the llvm
> plugins.
> 
> This was required because the llvm plugin didn't have a mechanism to
> receive arguments from the user. This commit adds support for using the
> environment variable ANNOBIN for the LLVM plugin, although it's still
> missing many of the basic features available in the other plugins.
> 
> Both clang and llvm plugins are now able to generate the same output as
> the GCC plugin, e.g. _annobin_hello_c_1711138217_00204218_start.

Thanks very much for writing this patch.

I do have a few comments on the code, but overall I thought that it was
excellent.

> diff --git a/annobin-common.cc b/annobin-common.cc

> +extern bool parse_argument (const char *, const char *);

There is no external function called parse_argument() so you do not
have to provide a prototype for it...

> +void
> +parse_env (bool (* parse_argument)(const char *, const char *))

I think that the function should be called 'annobin_parse_env' rather
than 'parse_env'.  There are two reasons: 1) there is a distinct
possibility that it might clash with a same-named function in the
sources of Clang, LLVM or GCC one day.  2) when running the compiler
inside a debugger it is helpful to have function names that indicate
to which part of the program they belong.  Thus a user using gdb to
debug a clang crash for example might run across "parse_env" and have
no idea where to look for it in the sources.  But if they see
"annobin_parse_env" they immediately have a big clue for where to look.

Also - the function should return a BOOL based upon the results
of calling parse_argument().  Ie if any invocation of parse_argument()
fails, then parse_env() should also fail.

Also - the parse_argument function should take a third argument, a void *
pointer provided to parse_env() by the caller.  The reason for this is
that the caller may wish to pass extra information to the parse_argument
function.


> +{
> +  char arg[2048];

Large buffers on the stack are a security hazzard.  Better to make
the buffer static - or better yet, dynamic.

> +      comma = strchr (env, ',');
> +      if (comma)
> +	{
> +	  strncpy (arg, env, comma - env);

Potential buffer overflow if (common - env >= sizeof arg)


> diff --git a/annobin-common.h b/annobin-common.h

> +void parse_env (bool (* parse_argument)(const char *, const char *));
> +#endif // ANNOBIN-COMMON_H_

I am a firm believer in header files providing descriptions of the functions
that they prototype.  This makes it easier for users unfamiliar with the source
code to use the header without having to delve into the sources themselves.
So in the version of your patch that I have checked in I added:

/* Checks for an ANNOBIN environment variable.
    If it exists, parses it for comma separated command line options,
     passing each in turn to PARSE_ARGUMENT.  Arguments are copied
     into a buffer before processing and can be manipulated by
     PARSE_ARGUMENT.  If an argument contains a '=' character then
     it is split into two pieces and passed to PARSE_ARGUMENT as
     (NAME, VALUE).  Otherwise it is just passed as (NAME, "").
     The return value from PARSE_ARGUMENT is recorded, but
     parsing will continue even if PARSE_ARGUMENT returns FALSE.
    Returns TRUE if the ANNOBIN environment variable does not exist.
    Returns TRUE if the ANNOBIN environment exists and PARSE_ARGUMENT
     returns TRUE for all of the arguments.
    Return FALSE otherwise.  */


I also thought that we should be consistent and allow the clang plugin to also
parse the ANNOBIN environment variable.  So I added that.  But basically I
was very happy with your patch and I have now checked it in to the annobin
repository.

Cheers
   Nick

PS. I have not built the rawhide version yet as I have run into some problems with the testsuites...


  reply	other threads:[~2024-03-25 16:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-20 17:28 global-file-syms for clang grant
2024-03-21  8:35 ` Nick Clifton
2024-03-21 15:32   ` grant
2024-03-21 20:47     ` Tulio Magno Quites Machado Filho
2024-03-22 20:17     ` [PATCH] Add support for global-file-syms to the clang and llvm plugins Tulio Magno Quites Machado Filho
2024-03-25 16:00       ` Nick Clifton [this message]
2024-03-25 17:19     ` global-file-syms for clang Nick Clifton
2024-03-25 17:38       ` grant
2024-03-26 11:31         ` Nick Clifton

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=c51f1323-12cd-4852-aa7d-34eb9557e75c@redhat.com \
    --to=nickc@redhat.com \
    --cc=annobin@sourceware.org \
    --cc=grant@hcubed.com \
    --cc=tuliom@redhat.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).