diff mbox

api: odp_debug: make ODP_ABORT a weak symbol

Message ID 1420574834-18901-2-git-send-email-mike.holmes@linaro.org
State Rejected
Headers show

Commit Message

Mike Holmes Jan. 6, 2015, 8:07 p.m. UTC
Add a weak definition of ODP_ABORT so that it may be overridden by an
application.

Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
---
 platform/linux-generic/include/api/odp_debug.h      | 14 ++++++++++++++
 platform/linux-generic/include/api/odp_hints.h      |  5 +++++
 platform/linux-generic/include/odp_debug_internal.h |  4 ++--
 platform/linux-generic/odp_weak.c                   |  5 +++++
 4 files changed, 26 insertions(+), 2 deletions(-)

Comments

Bill Fischofer Jan. 7, 2015, 5:17 p.m. UTC | #1
We should typedef these functions to prevent confusion:

typedef int (*odp_log_t)(odp_log_level_e level, const char *fmt, ...);
typedef void (*odp_abort_t)(void);

so that the struct becomes:

typedef struct odp_init_t {
        odp_log_t odp_log;

} odp_init_t;

typedef void (_odp_buf_init_t)(odp_buffer_t buf, void *buf_init_arg);

On Wed, Jan 7, 2015 at 8:18 AM, Savolainen, Petri (NSN - FI/Espoo) <
petri.savolainen@nsn.com> wrote:

> Hi,
>
> As agreed in the call today, it's better to remove API dependency to
> non-standard weak symbol feature of GCC. Instead we'll define these two as
> callback functions for odp_init_global()...
>
> typedef struct odp_init_t {
>
>  int (*odp_log)(odp_log_level_e level, const char *fmt, ...);
>  void (*odp_abort)(void);
>
> } odp_init_t;
>
>
> NULL would mean default log/abort implementation (with those user could
> still override default implementation at his own risk of non-portability).
>
>
> -Petri
>
>
>
>
> > -----Original Message-----
> > From: lng-odp-bounces@lists.linaro.org [mailto:lng-odp-
> > bounces@lists.linaro.org] On Behalf Of ext Mike Holmes
> > Sent: Tuesday, January 06, 2015 10:07 PM
> > To: lng-odp@lists.linaro.org
> > Subject: [lng-odp] [PATCH] api: odp_debug: make ODP_ABORT a weak symbol
> >
> > Add a weak definition of ODP_ABORT so that it may be overridden by an
> > application.
> >
> > Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
> > ---
> >  platform/linux-generic/include/api/odp_debug.h      | 14 ++++++++++++++
> >  platform/linux-generic/include/api/odp_hints.h      |  5 +++++
> >  platform/linux-generic/include/odp_debug_internal.h |  4 ++--
> >  platform/linux-generic/odp_weak.c                   |  5 +++++
> >  4 files changed, 26 insertions(+), 2 deletions(-)
> >
> > diff --git a/platform/linux-generic/include/api/odp_debug.h
> > b/platform/linux-generic/include/api/odp_debug.h
> > index a4ce1d9..dd4eb89 100644
> > --- a/platform/linux-generic/include/api/odp_debug.h
> > +++ b/platform/linux-generic/include/api/odp_debug.h
> > @@ -12,6 +12,7 @@
> >  #ifndef ODP_DEBUG_H_
> >  #define ODP_DEBUG_H_
> >
> > +#include <odp_hints.h>
> >
> >  #ifdef __cplusplus
> >  extern "C" {
> > @@ -75,6 +76,19 @@ typedef enum odp_log_level {
> >   */
> >  extern int odp_override_log(odp_log_level_e level, const char *fmt,
> ...);
> >
> > +/**
> > + * ODP abort function
> > + *
> > + * Where a fatal event can be identified within the ODP implementation
> an
> > + * ODP_ASSERT may used which can be controlled via ODP_DEBUG. In cases
> > where
> > + * an abort must always be called ODP_ABORT may be called directly. In
> > + * both cases these macros will call odp_override_abort
> > + * ODP platform MUST provide a default *weak* implementation of this
> > function.
> > + * Application MAY override the function if needed by providing a strong
> > + * function.
> > + * @note This function must never return.
> > + */
> > +extern void odp_override_abort(void) ODP_NORETURN;
> >
> >
> >  /**
> > diff --git a/platform/linux-generic/include/api/odp_hints.h
> > b/platform/linux-generic/include/api/odp_hints.h
> > index 7f04886..7eb9e36 100644
> > --- a/platform/linux-generic/include/api/odp_hints.h
> > +++ b/platform/linux-generic/include/api/odp_hints.h
> > @@ -32,6 +32,11 @@ extern "C" {
> >  #define ODP_WEAK_SYMBOL __attribute__((__weak__))
> >
> >  /**
> > + * Function never returns
> > + */
> > +#define ODP_NORETURN    __attribute__((__noreturn__))
> > +
> > +/**
> >   * Hot code section
> >   */
> >  #define ODP_HOT_CODE    __attribute__((__hot__))
> > diff --git a/platform/linux-generic/include/odp_debug_internal.h
> > b/platform/linux-generic/include/odp_debug_internal.h
> > index f6180d1..bbbe591 100644
> > --- a/platform/linux-generic/include/odp_debug_internal.h
> > +++ b/platform/linux-generic/include/odp_debug_internal.h
> > @@ -53,7 +53,7 @@ extern "C" {
> >  #define ODP_ASSERT(cond, msg) \
> >       do { if ((ODP_DEBUG == 1) && (!(cond))) { \
> >               ODP_ERR("%s\n", msg); \
> > -             abort(); } \
> > +             odp_override_abort(); } \
> >       } while (0)
> >
> >  /**
> > @@ -85,7 +85,7 @@ extern "C" {
> >  #define ODP_ABORT(fmt, ...) \
> >       do { \
> >               ODP_LOG(ODP_LOG_ABORT, fmt, ##__VA_ARGS__); \
> > -             abort(); \
> > +             odp_override_abort(); \
> >       } while (0)
> >
> >  /**
> > diff --git a/platform/linux-generic/odp_weak.c b/platform/linux-
> > generic/odp_weak.c
> > index fccbc3f..ce87119 100644
> > --- a/platform/linux-generic/odp_weak.c
> > +++ b/platform/linux-generic/odp_weak.c
> > @@ -21,3 +21,8 @@ ODP_WEAK_SYMBOL int odp_override_log(odp_log_level_e
> > level ODP_UNUSED,
> >
> >       return r;
> >  }
> > +
> > +ODP_WEAK_SYMBOL void odp_override_abort(void)
> > +{
> > +     abort();
> > +}
> > --
> > 2.1.0
> >
> >
> > _______________________________________________
> > lng-odp mailing list
> > lng-odp@lists.linaro.org
> > http://lists.linaro.org/mailman/listinfo/lng-odp
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
>
Bill Fischofer Jan. 7, 2015, 5:20 p.m. UTC | #2
Hit reply too soon.

We should typedef these functions to prevent confusion:

typedef int (*odp_log_t)(odp_log_level_e level, const char *fmt, ...);
typedef void (odp_abort_t)(void);

so that the struct becomes:

typedef struct odp_init_t {
        odp_log_t *odp_log;
        odp_abort_t *odp_abort;
} odp_init_t;


Callers then define their functions as:

int *my_log_func(odp_log_level_e level, const char *fmt, ...)
{
}

and

void my_abort_func(void)
{
}




On Wed, Jan 7, 2015 at 11:17 AM, Bill Fischofer <bill.fischofer@linaro.org>
wrote:

> We should typedef these functions to prevent confusion:
>
> typedef int (*odp_log_t)(odp_log_level_e level, const char *fmt, ...);
> typedef void (*odp_abort_t)(void);
>
> so that the struct becomes:
>
> typedef struct odp_init_t {
>         odp_log_t odp_log;
>
> } odp_init_t;
>
> typedef void (_odp_buf_init_t)(odp_buffer_t buf, void *buf_init_arg);
>
> On Wed, Jan 7, 2015 at 8:18 AM, Savolainen, Petri (NSN - FI/Espoo) <
> petri.savolainen@nsn.com> wrote:
>
>> Hi,
>>
>> As agreed in the call today, it's better to remove API dependency to
>> non-standard weak symbol feature of GCC. Instead we'll define these two as
>> callback functions for odp_init_global()...
>>
>> typedef struct odp_init_t {
>>
>>  int (*odp_log)(odp_log_level_e level, const char *fmt, ...);
>>  void (*odp_abort)(void);
>>
>> } odp_init_t;
>>
>>
>> NULL would mean default log/abort implementation (with those user could
>> still override default implementation at his own risk of non-portability).
>>
>>
>> -Petri
>>
>>
>>
>>
>> > -----Original Message-----
>> > From: lng-odp-bounces@lists.linaro.org [mailto:lng-odp-
>> > bounces@lists.linaro.org] On Behalf Of ext Mike Holmes
>> > Sent: Tuesday, January 06, 2015 10:07 PM
>> > To: lng-odp@lists.linaro.org
>> > Subject: [lng-odp] [PATCH] api: odp_debug: make ODP_ABORT a weak symbol
>> >
>> > Add a weak definition of ODP_ABORT so that it may be overridden by an
>> > application.
>> >
>> > Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
>> > ---
>> >  platform/linux-generic/include/api/odp_debug.h      | 14 ++++++++++++++
>> >  platform/linux-generic/include/api/odp_hints.h      |  5 +++++
>> >  platform/linux-generic/include/odp_debug_internal.h |  4 ++--
>> >  platform/linux-generic/odp_weak.c                   |  5 +++++
>> >  4 files changed, 26 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/platform/linux-generic/include/api/odp_debug.h
>> > b/platform/linux-generic/include/api/odp_debug.h
>> > index a4ce1d9..dd4eb89 100644
>> > --- a/platform/linux-generic/include/api/odp_debug.h
>> > +++ b/platform/linux-generic/include/api/odp_debug.h
>> > @@ -12,6 +12,7 @@
>> >  #ifndef ODP_DEBUG_H_
>> >  #define ODP_DEBUG_H_
>> >
>> > +#include <odp_hints.h>
>> >
>> >  #ifdef __cplusplus
>> >  extern "C" {
>> > @@ -75,6 +76,19 @@ typedef enum odp_log_level {
>> >   */
>> >  extern int odp_override_log(odp_log_level_e level, const char *fmt,
>> ...);
>> >
>> > +/**
>> > + * ODP abort function
>> > + *
>> > + * Where a fatal event can be identified within the ODP implementation
>> an
>> > + * ODP_ASSERT may used which can be controlled via ODP_DEBUG. In cases
>> > where
>> > + * an abort must always be called ODP_ABORT may be called directly. In
>> > + * both cases these macros will call odp_override_abort
>> > + * ODP platform MUST provide a default *weak* implementation of this
>> > function.
>> > + * Application MAY override the function if needed by providing a
>> strong
>> > + * function.
>> > + * @note This function must never return.
>> > + */
>> > +extern void odp_override_abort(void) ODP_NORETURN;
>> >
>> >
>> >  /**
>> > diff --git a/platform/linux-generic/include/api/odp_hints.h
>> > b/platform/linux-generic/include/api/odp_hints.h
>> > index 7f04886..7eb9e36 100644
>> > --- a/platform/linux-generic/include/api/odp_hints.h
>> > +++ b/platform/linux-generic/include/api/odp_hints.h
>> > @@ -32,6 +32,11 @@ extern "C" {
>> >  #define ODP_WEAK_SYMBOL __attribute__((__weak__))
>> >
>> >  /**
>> > + * Function never returns
>> > + */
>> > +#define ODP_NORETURN    __attribute__((__noreturn__))
>> > +
>> > +/**
>> >   * Hot code section
>> >   */
>> >  #define ODP_HOT_CODE    __attribute__((__hot__))
>> > diff --git a/platform/linux-generic/include/odp_debug_internal.h
>> > b/platform/linux-generic/include/odp_debug_internal.h
>> > index f6180d1..bbbe591 100644
>> > --- a/platform/linux-generic/include/odp_debug_internal.h
>> > +++ b/platform/linux-generic/include/odp_debug_internal.h
>> > @@ -53,7 +53,7 @@ extern "C" {
>> >  #define ODP_ASSERT(cond, msg) \
>> >       do { if ((ODP_DEBUG == 1) && (!(cond))) { \
>> >               ODP_ERR("%s\n", msg); \
>> > -             abort(); } \
>> > +             odp_override_abort(); } \
>> >       } while (0)
>> >
>> >  /**
>> > @@ -85,7 +85,7 @@ extern "C" {
>> >  #define ODP_ABORT(fmt, ...) \
>> >       do { \
>> >               ODP_LOG(ODP_LOG_ABORT, fmt, ##__VA_ARGS__); \
>> > -             abort(); \
>> > +             odp_override_abort(); \
>> >       } while (0)
>> >
>> >  /**
>> > diff --git a/platform/linux-generic/odp_weak.c b/platform/linux-
>> > generic/odp_weak.c
>> > index fccbc3f..ce87119 100644
>> > --- a/platform/linux-generic/odp_weak.c
>> > +++ b/platform/linux-generic/odp_weak.c
>> > @@ -21,3 +21,8 @@ ODP_WEAK_SYMBOL int odp_override_log(odp_log_level_e
>> > level ODP_UNUSED,
>> >
>> >       return r;
>> >  }
>> > +
>> > +ODP_WEAK_SYMBOL void odp_override_abort(void)
>> > +{
>> > +     abort();
>> > +}
>> > --
>> > 2.1.0
>> >
>> >
>> > _______________________________________________
>> > lng-odp mailing list
>> > lng-odp@lists.linaro.org
>> > http://lists.linaro.org/mailman/listinfo/lng-odp
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> http://lists.linaro.org/mailman/listinfo/lng-odp
>>
>
>
diff mbox

Patch

diff --git a/platform/linux-generic/include/api/odp_debug.h b/platform/linux-generic/include/api/odp_debug.h
index a4ce1d9..dd4eb89 100644
--- a/platform/linux-generic/include/api/odp_debug.h
+++ b/platform/linux-generic/include/api/odp_debug.h
@@ -12,6 +12,7 @@ 
 #ifndef ODP_DEBUG_H_
 #define ODP_DEBUG_H_
 
+#include <odp_hints.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -75,6 +76,19 @@  typedef enum odp_log_level {
  */
 extern int odp_override_log(odp_log_level_e level, const char *fmt, ...);
 
+/**
+ * ODP abort function
+ *
+ * Where a fatal event can be identified within the ODP implementation an
+ * ODP_ASSERT may used which can be controlled via ODP_DEBUG. In cases where
+ * an abort must always be called ODP_ABORT may be called directly. In
+ * both cases these macros will call odp_override_abort
+ * ODP platform MUST provide a default *weak* implementation of this function.
+ * Application MAY override the function if needed by providing a strong
+ * function.
+ * @note This function must never return.
+ */
+extern void odp_override_abort(void) ODP_NORETURN;
 
 
 /**
diff --git a/platform/linux-generic/include/api/odp_hints.h b/platform/linux-generic/include/api/odp_hints.h
index 7f04886..7eb9e36 100644
--- a/platform/linux-generic/include/api/odp_hints.h
+++ b/platform/linux-generic/include/api/odp_hints.h
@@ -32,6 +32,11 @@  extern "C" {
 #define ODP_WEAK_SYMBOL __attribute__((__weak__))
 
 /**
+ * Function never returns
+ */
+#define ODP_NORETURN    __attribute__((__noreturn__))
+
+/**
  * Hot code section
  */
 #define ODP_HOT_CODE    __attribute__((__hot__))
diff --git a/platform/linux-generic/include/odp_debug_internal.h b/platform/linux-generic/include/odp_debug_internal.h
index f6180d1..bbbe591 100644
--- a/platform/linux-generic/include/odp_debug_internal.h
+++ b/platform/linux-generic/include/odp_debug_internal.h
@@ -53,7 +53,7 @@  extern "C" {
 #define ODP_ASSERT(cond, msg) \
 	do { if ((ODP_DEBUG == 1) && (!(cond))) { \
 		ODP_ERR("%s\n", msg); \
-		abort(); } \
+		odp_override_abort(); } \
 	} while (0)
 
 /**
@@ -85,7 +85,7 @@  extern "C" {
 #define ODP_ABORT(fmt, ...) \
 	do { \
 		ODP_LOG(ODP_LOG_ABORT, fmt, ##__VA_ARGS__); \
-		abort(); \
+		odp_override_abort(); \
 	} while (0)
 
 /**
diff --git a/platform/linux-generic/odp_weak.c b/platform/linux-generic/odp_weak.c
index fccbc3f..ce87119 100644
--- a/platform/linux-generic/odp_weak.c
+++ b/platform/linux-generic/odp_weak.c
@@ -21,3 +21,8 @@  ODP_WEAK_SYMBOL int odp_override_log(odp_log_level_e level ODP_UNUSED,
 
 	return r;
 }
+
+ODP_WEAK_SYMBOL void odp_override_abort(void)
+{
+	abort();
+}