[v2] sim/igen: Fix linker error with -fno-common

Message ID 20200703051732.32622-1-sebastian.huber@embedded-brains.de
State New
Headers show
Series
  • [v2] sim/igen: Fix linker error with -fno-common
Related show

Commit Message

Sebastian Huber July 3, 2020, 5:17 a.m.
GCC 10 enables -fno-common by default.  This resulted in multiple
definition linker errors since a global variable was declared and
defined in a header file:

  ld: libsim.a(idecode.o):sim/v850/idecode.h:71: multiple definition of
  `idecode_issue'; libsim.a(irun.o):sim/v850/idecode.h:71: first defined
  here

  ld: libsim.a(engine.o):sim/v850/idecode.h:71: multiple definition of
  `idecode_issue'; libsim.a(irun.o):sim/v850/idecode.h:71: first defined
  here

  ld: libsim.a(support.o):sim/v850/idecode.h:71: multiple definition of
  `idecode_issue'; libsim.a(irun.o):sim/v850/idecode.h:71: first defined
  here

  ld: libsim.a(semantics.o):sim/v850/idecode.h:71: multiple definition
  of `idecode_issue'; libsim.a(irun.o):sim/v850/idecode.h:71: first
  defined here

sim/igen

	PR sim/26194

	* lf.h (lf_get_file_type): Declare.
	* lf.c (lf_get_file_type): Define.
	* gen-idecode.c (print_idecode_issue_function_header): Use
	lf_get_file_type() to issue an extern variable declaration in
	case of header files.
---

v2: Improve commit message.

 sim/igen/gen-idecode.c | 2 ++
 sim/igen/lf.c          | 7 +++++++
 sim/igen/lf.h          | 2 ++
 3 files changed, 11 insertions(+)

-- 
2.26.2

Comments

Andrew Burgess July 3, 2020, 5:03 p.m. | #1
* Sebastian Huber <sebastian.huber@embedded-brains.de> [2020-07-03 07:17:32 +0200]:

> GCC 10 enables -fno-common by default.  This resulted in multiple

> definition linker errors since a global variable was declared and

> defined in a header file:

> 

>   ld: libsim.a(idecode.o):sim/v850/idecode.h:71: multiple definition of

>   `idecode_issue'; libsim.a(irun.o):sim/v850/idecode.h:71: first defined

>   here

> 

>   ld: libsim.a(engine.o):sim/v850/idecode.h:71: multiple definition of

>   `idecode_issue'; libsim.a(irun.o):sim/v850/idecode.h:71: first defined

>   here

> 

>   ld: libsim.a(support.o):sim/v850/idecode.h:71: multiple definition of

>   `idecode_issue'; libsim.a(irun.o):sim/v850/idecode.h:71: first defined

>   here

> 

>   ld: libsim.a(semantics.o):sim/v850/idecode.h:71: multiple definition

>   of `idecode_issue'; libsim.a(irun.o):sim/v850/idecode.h:71: first

>   defined here

> 

> sim/igen

> 

> 	PR sim/26194

> 

> 	* lf.h (lf_get_file_type): Declare.

> 	* lf.c (lf_get_file_type): Define.

> 	* gen-idecode.c (print_idecode_issue_function_header): Use

> 	lf_get_file_type() to issue an extern variable declaration in

> 	case of header files.


Approved, please go ahead and push.

Thank you for addressing both of these sim issues.

Thanks,
Andrew

> ---

> 

> v2: Improve commit message.

> 

>  sim/igen/gen-idecode.c | 2 ++

>  sim/igen/lf.c          | 7 +++++++

>  sim/igen/lf.h          | 2 ++

>  3 files changed, 11 insertions(+)

> 

> diff --git a/sim/igen/gen-idecode.c b/sim/igen/gen-idecode.c

> index b8f8ca15061..741498a1be9 100644

> --- a/sim/igen/gen-idecode.c

> +++ b/sim/igen/gen-idecode.c

> @@ -930,6 +930,8 @@ print_idecode_issue_function_header (lf *file,

>  					"INLINE_IDECODE", "\n");

>        break;

>      case is_function_variable:

> +      if (lf_get_file_type (file) == lf_is_h)

> +	lf_printf (file, "extern ");

>        print_semantic_function_type (file);

>        lf_printf (file, " (*");

>        break;

> diff --git a/sim/igen/lf.c b/sim/igen/lf.c

> index 0f377d48d88..937e3d939ff 100644

> --- a/sim/igen/lf.c

> +++ b/sim/igen/lf.c

> @@ -86,6 +86,13 @@ lf_open (char *name,

>  }

>  

>  

> +lf_file_type

> +lf_get_file_type (const lf *file)

> +{

> +  return file->type;

> +}

> +

> +

>  void

>  lf_close (lf *file)

>  {

> diff --git a/sim/igen/lf.h b/sim/igen/lf.h

> index 54b4dcd0de1..6d86fac8d3f 100644

> --- a/sim/igen/lf.h

> +++ b/sim/igen/lf.h

> @@ -54,6 +54,8 @@ extern lf *lf_open

>     lf_file_references file_references,

>     lf_file_type type, const char *program);

>  

> +extern lf_file_type lf_get_file_type (const lf *file);

> +

>  extern void lf_close (lf *file);

>  

>  

> -- 

> 2.26.2

>
Sebastian Huber July 3, 2020, 7:07 p.m. | #2
On 03/07/2020 19:03, Andrew Burgess wrote:

> Approved, please go ahead and push.

>

> Thank you for addressing both of these sim issues.

Thanks for the quick review.

Patch

diff --git a/sim/igen/gen-idecode.c b/sim/igen/gen-idecode.c
index b8f8ca15061..741498a1be9 100644
--- a/sim/igen/gen-idecode.c
+++ b/sim/igen/gen-idecode.c
@@ -930,6 +930,8 @@  print_idecode_issue_function_header (lf *file,
 					"INLINE_IDECODE", "\n");
       break;
     case is_function_variable:
+      if (lf_get_file_type (file) == lf_is_h)
+	lf_printf (file, "extern ");
       print_semantic_function_type (file);
       lf_printf (file, " (*");
       break;
diff --git a/sim/igen/lf.c b/sim/igen/lf.c
index 0f377d48d88..937e3d939ff 100644
--- a/sim/igen/lf.c
+++ b/sim/igen/lf.c
@@ -86,6 +86,13 @@  lf_open (char *name,
 }
 
 
+lf_file_type
+lf_get_file_type (const lf *file)
+{
+  return file->type;
+}
+
+
 void
 lf_close (lf *file)
 {
diff --git a/sim/igen/lf.h b/sim/igen/lf.h
index 54b4dcd0de1..6d86fac8d3f 100644
--- a/sim/igen/lf.h
+++ b/sim/igen/lf.h
@@ -54,6 +54,8 @@  extern lf *lf_open
    lf_file_references file_references,
    lf_file_type type, const char *program);
 
+extern lf_file_type lf_get_file_type (const lf *file);
+
 extern void lf_close (lf *file);