[sim] Fix linkage errors in Clang.

Message ID CAJBvFxNwjU62PuQv=BSL_VTJWVV=8e+behmW0YFxa2YimZBUaQ@mail.gmail.com
State Superseded
Delegated to: Mike Frysinger
Headers

Commit Message

Masaki Muranaka May 14, 2014, 2:31 a.m. UTC
  Hello.

By differences about inline function, we can't build simulators on Clang.

I have write after approval permission. Ok to apply this?


>From 4c2093a1765fdf626335d3f3479bd076627bdb3b Mon Sep 17 00:00:00 2001
From: Masaki Muranaka <monaka@monami-software.com>
Date: Wed, 14 May 2014 11:17:12 +0900
Subject: [PATCH] Fix linkage errors in Clang

* common/cgen-mem.h: Fix linkage errors in Clang
* common/cgen-ops.h: Ditto.
* common/sim-arange.h: Ditto.
---
 sim/ChangeLog           | 6 ++++++
 sim/common/cgen-mem.h   | 4 +++-
 sim/common/cgen-ops.h   | 7 ++++++-
 sim/common/sim-arange.h | 7 ++++++-
 4 files changed, 21 insertions(+), 3 deletions(-)
  

Comments

Pedro Alves May 30, 2014, 11:09 a.m. UTC | #1
On 05/14/2014 03:31 AM, Masaki Muranaka wrote:
> Hello.
> 
> By differences about inline function, we can't build simulators on Clang.

The difference is probably that Clang defaults to C99.
You should probably be using CC="clang -std=gnu89".

Patchwise, please try using __attribute__ ((gnu_inline)).
  
Mike Frysinger Aug. 2, 2014, 5:32 p.m. UTC | #2
On Fri 30 May 2014 12:09:49 Pedro Alves wrote:
> On 05/14/2014 03:31 AM, Masaki Muranaka wrote:
> > By differences about inline function, we can't build simulators on Clang.
> 
> The difference is probably that Clang defaults to C99.
> You should probably be using CC="clang -std=gnu89".
> 
> Patchwise, please try using __attribute__ ((gnu_inline)).

yeah i'm not a fan of sprinkling __clang__ everywhere.  i'm aware that there's 
a bunch of __GNUC__ in there, but those should get cleaned up/centralized 
rather than expanded.  a quick glance shows that there's already cases where 
that can happen (like moving to ATTRIBUTE_NORETURN).
-mike
  

Patch

diff --git a/sim/ChangeLog b/sim/ChangeLog
index 35d0920..94445fa 100644
--- a/sim/ChangeLog
+++ b/sim/ChangeLog
@@ -1,3 +1,9 @@ 
+2014-05-14  Muranaka Masaki  <monaka@monami-software.com>
+
+ * common/cgen-mem.h: Fix linkage errors in Clang
+ * common/cgen-ops.h: Ditto.
+ * common/sim-arange.h: Ditto.
+
 2014-03-12  Nick Clifton  <nickc@redhat.com>

  * MAINTAINERS: Add myself as the maintainer for the MSP430.
diff --git a/sim/common/cgen-mem.h b/sim/common/cgen-mem.h
index 1999b29..f2d93a1 100644
--- a/sim/common/cgen-mem.h
+++ b/sim/common/cgen-mem.h
@@ -20,7 +20,9 @@  along with this program.  If not, see
<http://www.gnu.org/licenses/>.  */
 #ifndef CGEN_MEM_H
 #define CGEN_MEM_H

-#ifdef MEMOPS_DEFINE_INLINE
+#if defined (__clang__)
+#define MEMOPS_INLINE static inline
+#elif defined (MEMOPS_DEFINE_INLINE)
 #define MEMOPS_INLINE
 #else
 #define MEMOPS_INLINE extern inline
diff --git a/sim/common/cgen-ops.h b/sim/common/cgen-ops.h
index e1a827a..96372b3 100644
--- a/sim/common/cgen-ops.h
+++ b/sim/common/cgen-ops.h
@@ -24,7 +24,12 @@  along with this program.  If not, see
<http://www.gnu.org/licenses/>.

 #include <assert.h>

-#if defined (__GNUC__) && ! defined (SEMOPS_DEFINE_INLINE)
+#if defined (__clang__)
+#ifndef SEMOPS_DEFINE_INLINE
+#define SEMOPS_DEFINE_INLINE
+#endif
+#define SEMOPS_INLINE static inline
+#elif defined (__GNUC__) && ! defined (SEMOPS_DEFINE_INLINE)
 #define SEMOPS_DEFINE_INLINE
 #define SEMOPS_INLINE extern inline
 #else
diff --git a/sim/common/sim-arange.h b/sim/common/sim-arange.h
index 61cd4d4..b001105 100644
--- a/sim/common/sim-arange.h
+++ b/sim/common/sim-arange.h
@@ -62,7 +62,12 @@  extern void sim_addr_range_delete (ADDR_RANGE * /*ar*/,

 /* Return non-zero if ADDR is in range AR, traversing the entire tree.
    If no range is specified, that is defined to mean "everything".  */
-extern INLINE int
+#if defined (__clang__)
+static
+#else
+extern
+#endif
+INLINE int
 sim_addr_range_hit_p (ADDR_RANGE * /*ar*/, address_word /*addr*/);
 #define ADDR_RANGE_HIT_P(ar, addr) \
   ((ar)->range_tree == NULL || sim_addr_range_hit_p ((ar), (addr)))