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

Nick Clifton nickc@redhat.com
Wed Mar 13 12:28:00 GMT 2019


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



More information about the Binutils mailing list