This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Provide string description of definition, visibility and resolution in LTO plug-in.


Hi Martin,
 
  Sorry for the delay in reviewing.

> I would like to enhance get_symbols function to report string
> representation of definition, visibility and resolution.
> It's easier for users to read it.

Agreed, but ...

@@ -777,9 +808,11 @@ get_symbols (const void *handle, int nsyms, struct ld_plugin_symbol *syms,
       syms[n].resolution = res;
       if (report_plugin_symbols)
 	einfo (_("%P: %pB: symbol `%s' "
-		 "definition: %d, visibility: %d, resolution: %d\n"),
+		 "definition: %s, visibility: %s, resolution: %s\n"),
 	       abfd, syms[n].name,
-	       syms[n].def, syms[n].visibility, res);
+	       lto_kind_str[syms[n].def],
+	       lto_visibility_str[syms[n].visibility],
+	       lto_resolution_str[res]);

You need to be more paranoid.  If one of the values is not in the
expected range, then you will have an illegal or unexpected memory
dereference via the array accesses.

My suggestion - create a set of small new functions which return
the name of a particular value, and which handle unknown values.
eg:

  const char *
  get_lto_kind (unsigned int index)
  {
     const char *lto_kind_str[5] =
     {
      "DEF",
      "WEAKDEF",
      "UNDEF",
      "WEAKUNDEF",
      "COMMON"
     };

    if (index < ARRAY_SIZE (lto_kind_str))
      return lto_kind_str [index];

    const char buf [1024];
    sprintf (buf, _("unknown definition value %x"), index);
    return buf;
  }

Then use these new functions in the einfo() statement.

Cheers
  Nick


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]