RFC [PATCH 1/2] Update include/plugin-api.h

Message ID 20200318120638.178388-2-hjl.tools@gmail.com
State New
Headers show
Series
  • RFC [PATCH 1/2] Update include/plugin-api.h
Related show

Commit Message

Jose E. Marchesi via Binutils March 18, 2020, 12:06 p.m.
From: Martin Liska <mliska@suse.cz>


2020-03-12  Martin Liska  <mliska@suse.cz>

	PR binutils/25640
	* plugin-api.h (struct ld_plugin_symbol): Split
	int def into 4 char fields.
	(enum ld_plugin_symbol_type): New.
	(enum ld_plugin_symbol_section_flags): New.
	(enum ld_plugin_tag): Add LDPT_ADD_SYMBOLS_V2 and
	LDPT_GET_SYMBOLS_V4.
---
 include/plugin-api.h | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

-- 
2.25.1

Comments

Jose E. Marchesi via Binutils March 19, 2020, 4:09 p.m. | #1
On Wed, Mar 18, 2020 at 5:06 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>

> From: Martin Liska <mliska@suse.cz>

>

> 2020-03-12  Martin Liska  <mliska@suse.cz>

>

>         PR binutils/25640

>         * plugin-api.h (struct ld_plugin_symbol): Split

>         int def into 4 char fields.

>         (enum ld_plugin_symbol_type): New.

>         (enum ld_plugin_symbol_section_flags): New.

>         (enum ld_plugin_tag): Add LDPT_ADD_SYMBOLS_V2 and

>         LDPT_GET_SYMBOLS_V4.


I am checking in this patch to sync with GCC.

-- 
H.J.
Jose E. Marchesi via Binutils March 20, 2020, 2:33 a.m. | #2
On Thu, Mar 19, 2020 at 09:09:00AM -0700, H.J. Lu via Binutils wrote:
> On Wed, Mar 18, 2020 at 5:06 AM H.J. Lu <hjl.tools@gmail.com> wrote:

> >

> > From: Martin Liska <mliska@suse.cz>

> >

> > 2020-03-12  Martin Liska  <mliska@suse.cz>

> >

> >         PR binutils/25640

> >         * plugin-api.h (struct ld_plugin_symbol): Split

> >         int def into 4 char fields.

> >         (enum ld_plugin_symbol_type): New.

> >         (enum ld_plugin_symbol_section_flags): New.

> >         (enum ld_plugin_tag): Add LDPT_ADD_SYMBOLS_V2 and

> >         LDPT_GET_SYMBOLS_V4.

> 

> I am checking in this patch to sync with GCC.


Silence warnings due to plugin API change.

	* testplug.c (parse_symdefstr): Use %hhi to read sym->def, and
	clear new fields.
	* testplug2.c (parse_symdefstr): Likewise.
	* testplug3.c (parse_symdefstr): Likewise.
	* testplug4.c (parse_symdefstr): Likewise.

diff --git a/ld/testplug.c b/ld/testplug.c
index 9dd0b91e45..c126f03607 100644
--- a/ld/testplug.c
+++ b/ld/testplug.c
@@ -239,12 +239,15 @@ parse_symdefstr (const char *str, struct ld_plugin_symbol *sym)
   /* Finally we'll use sscanf to parse the numeric fields, then
      we'll split out the strings which we need to allocate separate
      storage for anyway so that we can add nul termination.  */
-  n = sscanf (colon2 + 1, "%i:%i:%lli", &sym->def, &sym->visibility, &size);
+  n = sscanf (colon2 + 1, "%hhi:%i:%lli", &sym->def, &sym->visibility, &size);
   if (n != 3)
     return LDPS_ERR;
 
   /* Parsed successfully, so allocate strings and fill out fields.  */
   sym->size = size;
+  sym->unused = 0;
+  sym->section_kind = 0;
+  sym->symbol_type = 0;
   sym->resolution = LDPR_UNKNOWN;
   sym->name = malloc (colon1 - str + 1);
   if (!sym->name)
diff --git a/ld/testplug2.c b/ld/testplug2.c
index ecd9a44d73..27553d0781 100644
--- a/ld/testplug2.c
+++ b/ld/testplug2.c
@@ -218,12 +218,15 @@ parse_symdefstr (const char *str, struct ld_plugin_symbol *sym)
   /* Finally we'll use sscanf to parse the numeric fields, then
      we'll split out the strings which we need to allocate separate
      storage for anyway so that we can add nul termination.  */
-  n = sscanf (colon2 + 1, "%i:%i:%lli", &sym->def, &sym->visibility, &size);
+  n = sscanf (colon2 + 1, "%hhi:%i:%lli", &sym->def, &sym->visibility, &size);
   if (n != 3)
     return LDPS_ERR;
 
   /* Parsed successfully, so allocate strings and fill out fields.  */
   sym->size = size;
+  sym->unused = 0;
+  sym->section_kind = 0;
+  sym->symbol_type = 0;
   sym->resolution = LDPR_UNKNOWN;
   sym->name = malloc (colon1 - str + 1);
   if (!sym->name)
diff --git a/ld/testplug3.c b/ld/testplug3.c
index 05fdca02e2..928f4d6842 100644
--- a/ld/testplug3.c
+++ b/ld/testplug3.c
@@ -217,12 +217,15 @@ parse_symdefstr (const char *str, struct ld_plugin_symbol *sym)
   /* Finally we'll use sscanf to parse the numeric fields, then
      we'll split out the strings which we need to allocate separate
      storage for anyway so that we can add nul termination.  */
-  n = sscanf (colon2 + 1, "%i:%i:%lli", &sym->def, &sym->visibility, &size);
+  n = sscanf (colon2 + 1, "%hhi:%i:%lli", &sym->def, &sym->visibility, &size);
   if (n != 3)
     return LDPS_ERR;
 
   /* Parsed successfully, so allocate strings and fill out fields.  */
   sym->size = size;
+  sym->unused = 0;
+  sym->section_kind = 0;
+  sym->symbol_type = 0;
   sym->resolution = LDPR_UNKNOWN;
   sym->name = malloc (colon1 - str + 1);
   if (!sym->name)
diff --git a/ld/testplug4.c b/ld/testplug4.c
index adaedf47c3..ca899b11da 100644
--- a/ld/testplug4.c
+++ b/ld/testplug4.c
@@ -218,12 +218,15 @@ parse_symdefstr (const char *str, struct ld_plugin_symbol *sym)
   /* Finally we'll use sscanf to parse the numeric fields, then
      we'll split out the strings which we need to allocate separate
      storage for anyway so that we can add nul termination.  */
-  n = sscanf (colon2 + 1, "%i:%i:%lli", &sym->def, &sym->visibility, &size);
+  n = sscanf (colon2 + 1, "%hhi:%i:%lli", &sym->def, &sym->visibility, &size);
   if (n != 3)
     return LDPS_ERR;
 
   /* Parsed successfully, so allocate strings and fill out fields.  */
   sym->size = size;
+  sym->unused = 0;
+  sym->section_kind = 0;
+  sym->symbol_type = 0;
   sym->resolution = LDPR_UNKNOWN;
   sym->name = malloc (colon1 - str + 1);
   if (!sym->name)



-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/include/plugin-api.h b/include/plugin-api.h
index 09e1202df0..88676a63e5 100644
--- a/include/plugin-api.h
+++ b/include/plugin-api.h
@@ -87,7 +87,19 @@  struct ld_plugin_symbol
 {
   char *name;
   char *version;
-  int def;
+  /* This is for compatibility with older ABIs.  The older ABI defined
+     only 'def' field.  */
+#ifdef __BIG_ENDIAN__
+  char unused;
+  char section_flags;
+  char symbol_type;
+  char def;
+#else
+  char def;
+  char symbol_type;
+  char section_flags;
+  char unused;
+#endif
   int visibility;
   uint64_t size;
   char *comdat_key;
@@ -123,6 +135,20 @@  enum ld_plugin_symbol_visibility
   LDPV_HIDDEN
 };
 
+/* The type of the symbol.  */
+
+enum ld_plugin_symbol_type
+{
+  LDST_UNKNOWN,
+  LDST_FUNCTION,
+  LDST_VARIABLE,
+};
+
+enum ld_plugin_symbol_section_flags
+{
+  LDSSS_BSS = 1
+};
+
 /* How a symbol is resolved.  */
 
 enum ld_plugin_symbol_resolution
@@ -431,7 +457,9 @@  enum ld_plugin_tag
   LDPT_GET_INPUT_SECTION_ALIGNMENT = 29,
   LDPT_GET_INPUT_SECTION_SIZE = 30,
   LDPT_REGISTER_NEW_INPUT_HOOK = 31,
-  LDPT_GET_WRAP_SYMBOLS = 32
+  LDPT_GET_WRAP_SYMBOLS = 32,
+  LDPT_ADD_SYMBOLS_V2 = 33,
+  LDPT_GET_SYMBOLS_V4 = 34,
 };
 
 /* The plugin transfer vector.  */