[Xenomai-git] Philippe Gerum : boilerplate/setup: allow DSO bootstrap modules to coexist with main one

2017-04-17 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: d6d8047ecd093bd827026678b3c7619b08dd7dd2
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d6d8047ecd093bd827026678b3c7619b08dd7dd2

Author: Philippe Gerum 
Date:   Tue Mar 21 15:20:29 2017 +0100

boilerplate/setup: allow DSO bootstrap modules to coexist with main one

Gluing a PIC bootstrap module to a DSO is a common way to start the
Xenomai services before constructors of static C++ objects
instantiated by the DSO and which depend on such services, are
invoked.

With such module present in the DSO, a Cobalt-based application
process would attach itself to the Cobalt core via the bootstrapping
sequence, enabling the real-time services for the whole process,
including the static C++ constructors which may be invoked when
attaching the shared object.

e.g. in libfoo.so:

class FOO {
protected:
sem_t sem;
public:
static FOO bar;
};

...

FOO FOO::bar;

FOO::FOO()
{
// Initialize a Cobalt semaphore
sem_init(, 0, 0);
}

However, adding a bootstrap module to a DSO currently prevents from
merging a second bootstrap module aimed at kickstarting the main
program's setup code and early inits, due to conflicting symbols and
the restriction on invoking xenomai_init() only once for any given
process.

The changes introduce a DSO-specific initialization service
(xenomai_init_dso()), which may be called from the context of the
dynamic linker attaching a shared object to the current
executable. The DSO-specific bootstrap module - if present - will call
xenomai_init_dso(), there is no restriction on the number of DSOs
calling this service.

The non-DSO bootstrap module invokes xenomai_init() as previously, for
kickstarting the main program's early inits.

---

 include/boilerplate/setup.h  |1 +
 include/xenomai/init.h   |2 +
 lib/boilerplate/init/Makefile.am |2 +-
 lib/boilerplate/init/bootstrap.c |   28 +++---
 lib/boilerplate/setup.c  |  104 --
 5 files changed, 91 insertions(+), 46 deletions(-)

diff --git a/include/boilerplate/setup.h b/include/boilerplate/setup.h
index 374758b..7df3cfe 100644
--- a/include/boilerplate/setup.h
+++ b/include/boilerplate/setup.h
@@ -46,6 +46,7 @@ struct setup_descriptor {
int opt_start;
int opt_end;
struct pvholder next;
+   int done;
} __reserved;
 };
 
diff --git a/include/xenomai/init.h b/include/xenomai/init.h
index 9adc90d..598bf53 100644
--- a/include/xenomai/init.h
+++ b/include/xenomai/init.h
@@ -27,6 +27,8 @@ extern "C" {
 
 void xenomai_init(int *argcp, char *const **argvp);
 
+void xenomai_init_dso(int *argcp, char *const **argvp);
+
 int xenomai_main(int argc, char *const argv[]);
 
 void xenomai_usage(void);
diff --git a/lib/boilerplate/init/Makefile.am b/lib/boilerplate/init/Makefile.am
index 702c900..b78dd61 100644
--- a/lib/boilerplate/init/Makefile.am
+++ b/lib/boilerplate/init/Makefile.am
@@ -3,7 +3,6 @@ noinst_LIBRARIES = libbootstrap.a
 libbootstrap_a_SOURCES = bootstrap.c
 
 libbootstrap_a_CPPFLAGS =  \
-   -D__INTERCEPT_MAIN__\
@XENO_USER_CFLAGS@  \
-I$(top_srcdir)/include \
-I$(top_srcdir)/lib
@@ -13,6 +12,7 @@ noinst_LTLIBRARIES = libbootstrap-pic.la
 libbootstrap_pic_la_SOURCES = bootstrap.c
 
 libbootstrap_pic_la_CPPFLAGS = \
+   -D__BOOTSTRAP_DSO__ \
@XENO_USER_CFLAGS@  \
-I$(top_srcdir)/include \
-I$(top_srcdir)/lib
diff --git a/lib/boilerplate/init/bootstrap.c b/lib/boilerplate/init/bootstrap.c
index 54d1c46..e72a7b8 100644
--- a/lib/boilerplate/init/bootstrap.c
+++ b/lib/boilerplate/init/bootstrap.c
@@ -26,8 +26,6 @@ static int early_argc;
 
 static char *const *early_argv;
 
-const int xenomai_auto_bootstrap = 1;
-
 /*
  * The bootstrap module object is built in two forms:
  *
@@ -41,11 +39,22 @@ const int xenomai_auto_bootstrap = 1;
  *   any wrapper to a main() routine - which does not exist - but only
  *   a constructor routine performing the inits.
  *
- * The dedicated macro __INTERCEPT_MAIN__ tells us whether the main()
- * interception code should be present in the relocatable object.
+ * The macro __BOOTSTRAP_DSO__ tells us whether we are building the
+ * bootstrap module to be glued into a dynamic shared object. If not,
+ * the main() interception code should be present in the relocatable
+ * object.
  */
 
-#ifdef __INTERCEPT_MAIN__
+#ifdef __BOOTSTRAP_DSO__
+
+static inline void call_init(int *argcp, char *const **argvp)
+{
+   xenomai_init_dso(argcp, argvp);
+}
+
+#else
+
+const int xenomai_auto_bootstrap = 1;
 
 int __real_main(int argc, char *const argv[]);
 
@@ -62,7 +71,12 @@ int xenomai_main(int argc, char *const argv[])
return __real_main(argc, argv);
 }
 
-#endif /* !__INTERCEPT_MAIN__ */
+static inline void call_init(int *argcp, char *const **argvp)

[Xenomai-git] Philippe Gerum : boilerplate/setup: allow DSO bootstrap modules to coexist with main one

2017-04-15 Thread git repository hosting
Module: xenomai-3
Branch: master
Commit: d6d8047ecd093bd827026678b3c7619b08dd7dd2
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d6d8047ecd093bd827026678b3c7619b08dd7dd2

Author: Philippe Gerum 
Date:   Tue Mar 21 15:20:29 2017 +0100

boilerplate/setup: allow DSO bootstrap modules to coexist with main one

Gluing a PIC bootstrap module to a DSO is a common way to start the
Xenomai services before constructors of static C++ objects
instantiated by the DSO and which depend on such services, are
invoked.

With such module present in the DSO, a Cobalt-based application
process would attach itself to the Cobalt core via the bootstrapping
sequence, enabling the real-time services for the whole process,
including the static C++ constructors which may be invoked when
attaching the shared object.

e.g. in libfoo.so:

class FOO {
protected:
sem_t sem;
public:
static FOO bar;
};

...

FOO FOO::bar;

FOO::FOO()
{
// Initialize a Cobalt semaphore
sem_init(, 0, 0);
}

However, adding a bootstrap module to a DSO currently prevents from
merging a second bootstrap module aimed at kickstarting the main
program's setup code and early inits, due to conflicting symbols and
the restriction on invoking xenomai_init() only once for any given
process.

The changes introduce a DSO-specific initialization service
(xenomai_init_dso()), which may be called from the context of the
dynamic linker attaching a shared object to the current
executable. The DSO-specific bootstrap module - if present - will call
xenomai_init_dso(), there is no restriction on the number of DSOs
calling this service.

The non-DSO bootstrap module invokes xenomai_init() as previously, for
kickstarting the main program's early inits.

---

 include/boilerplate/setup.h  |1 +
 include/xenomai/init.h   |2 +
 lib/boilerplate/init/Makefile.am |2 +-
 lib/boilerplate/init/bootstrap.c |   28 +++---
 lib/boilerplate/setup.c  |  104 --
 5 files changed, 91 insertions(+), 46 deletions(-)

diff --git a/include/boilerplate/setup.h b/include/boilerplate/setup.h
index 374758b..7df3cfe 100644
--- a/include/boilerplate/setup.h
+++ b/include/boilerplate/setup.h
@@ -46,6 +46,7 @@ struct setup_descriptor {
int opt_start;
int opt_end;
struct pvholder next;
+   int done;
} __reserved;
 };
 
diff --git a/include/xenomai/init.h b/include/xenomai/init.h
index 9adc90d..598bf53 100644
--- a/include/xenomai/init.h
+++ b/include/xenomai/init.h
@@ -27,6 +27,8 @@ extern "C" {
 
 void xenomai_init(int *argcp, char *const **argvp);
 
+void xenomai_init_dso(int *argcp, char *const **argvp);
+
 int xenomai_main(int argc, char *const argv[]);
 
 void xenomai_usage(void);
diff --git a/lib/boilerplate/init/Makefile.am b/lib/boilerplate/init/Makefile.am
index 702c900..b78dd61 100644
--- a/lib/boilerplate/init/Makefile.am
+++ b/lib/boilerplate/init/Makefile.am
@@ -3,7 +3,6 @@ noinst_LIBRARIES = libbootstrap.a
 libbootstrap_a_SOURCES = bootstrap.c
 
 libbootstrap_a_CPPFLAGS =  \
-   -D__INTERCEPT_MAIN__\
@XENO_USER_CFLAGS@  \
-I$(top_srcdir)/include \
-I$(top_srcdir)/lib
@@ -13,6 +12,7 @@ noinst_LTLIBRARIES = libbootstrap-pic.la
 libbootstrap_pic_la_SOURCES = bootstrap.c
 
 libbootstrap_pic_la_CPPFLAGS = \
+   -D__BOOTSTRAP_DSO__ \
@XENO_USER_CFLAGS@  \
-I$(top_srcdir)/include \
-I$(top_srcdir)/lib
diff --git a/lib/boilerplate/init/bootstrap.c b/lib/boilerplate/init/bootstrap.c
index 54d1c46..e72a7b8 100644
--- a/lib/boilerplate/init/bootstrap.c
+++ b/lib/boilerplate/init/bootstrap.c
@@ -26,8 +26,6 @@ static int early_argc;
 
 static char *const *early_argv;
 
-const int xenomai_auto_bootstrap = 1;
-
 /*
  * The bootstrap module object is built in two forms:
  *
@@ -41,11 +39,22 @@ const int xenomai_auto_bootstrap = 1;
  *   any wrapper to a main() routine - which does not exist - but only
  *   a constructor routine performing the inits.
  *
- * The dedicated macro __INTERCEPT_MAIN__ tells us whether the main()
- * interception code should be present in the relocatable object.
+ * The macro __BOOTSTRAP_DSO__ tells us whether we are building the
+ * bootstrap module to be glued into a dynamic shared object. If not,
+ * the main() interception code should be present in the relocatable
+ * object.
  */
 
-#ifdef __INTERCEPT_MAIN__
+#ifdef __BOOTSTRAP_DSO__
+
+static inline void call_init(int *argcp, char *const **argvp)
+{
+   xenomai_init_dso(argcp, argvp);
+}
+
+#else
+
+const int xenomai_auto_bootstrap = 1;
 
 int __real_main(int argc, char *const argv[]);
 
@@ -62,7 +71,12 @@ int xenomai_main(int argc, char *const argv[])
return __real_main(argc, argv);
 }
 
-#endif /* !__INTERCEPT_MAIN__ */
+static inline void call_init(int *argcp, char *const 

[Xenomai-git] Philippe Gerum : boilerplate/setup: allow DSO bootstrap modules to coexist with main one

2017-03-21 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: d6d8047ecd093bd827026678b3c7619b08dd7dd2
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d6d8047ecd093bd827026678b3c7619b08dd7dd2

Author: Philippe Gerum 
Date:   Tue Mar 21 15:20:29 2017 +0100

boilerplate/setup: allow DSO bootstrap modules to coexist with main one

Gluing a PIC bootstrap module to a DSO is a common way to start the
Xenomai services before constructors of static C++ objects
instantiated by the DSO and which depend on such services, are
invoked.

With such module present in the DSO, a Cobalt-based application
process would attach itself to the Cobalt core via the bootstrapping
sequence, enabling the real-time services for the whole process,
including the static C++ constructors which may be invoked when
attaching the shared object.

e.g. in libfoo.so:

class FOO {
protected:
sem_t sem;
public:
static FOO bar;
};

...

FOO FOO::bar;

FOO::FOO()
{
// Initialize a Cobalt semaphore
sem_init(, 0, 0);
}

However, adding a bootstrap module to a DSO currently prevents from
merging a second bootstrap module aimed at kickstarting the main
program's setup code and early inits, due to conflicting symbols and
the restriction on invoking xenomai_init() only once for any given
process.

The changes introduce a DSO-specific initialization service
(xenomai_init_dso()), which may be called from the context of the
dynamic linker attaching a shared object to the current
executable. The DSO-specific bootstrap module - if present - will call
xenomai_init_dso(), there is no restriction on the number of DSOs
calling this service.

The non-DSO bootstrap module invokes xenomai_init() as previously, for
kickstarting the main program's early inits.

---

 include/boilerplate/setup.h  |1 +
 include/xenomai/init.h   |2 +
 lib/boilerplate/init/Makefile.am |2 +-
 lib/boilerplate/init/bootstrap.c |   28 +++---
 lib/boilerplate/setup.c  |  104 --
 5 files changed, 91 insertions(+), 46 deletions(-)

diff --git a/include/boilerplate/setup.h b/include/boilerplate/setup.h
index 374758b..7df3cfe 100644
--- a/include/boilerplate/setup.h
+++ b/include/boilerplate/setup.h
@@ -46,6 +46,7 @@ struct setup_descriptor {
int opt_start;
int opt_end;
struct pvholder next;
+   int done;
} __reserved;
 };
 
diff --git a/include/xenomai/init.h b/include/xenomai/init.h
index 9adc90d..598bf53 100644
--- a/include/xenomai/init.h
+++ b/include/xenomai/init.h
@@ -27,6 +27,8 @@ extern "C" {
 
 void xenomai_init(int *argcp, char *const **argvp);
 
+void xenomai_init_dso(int *argcp, char *const **argvp);
+
 int xenomai_main(int argc, char *const argv[]);
 
 void xenomai_usage(void);
diff --git a/lib/boilerplate/init/Makefile.am b/lib/boilerplate/init/Makefile.am
index 702c900..b78dd61 100644
--- a/lib/boilerplate/init/Makefile.am
+++ b/lib/boilerplate/init/Makefile.am
@@ -3,7 +3,6 @@ noinst_LIBRARIES = libbootstrap.a
 libbootstrap_a_SOURCES = bootstrap.c
 
 libbootstrap_a_CPPFLAGS =  \
-   -D__INTERCEPT_MAIN__\
@XENO_USER_CFLAGS@  \
-I$(top_srcdir)/include \
-I$(top_srcdir)/lib
@@ -13,6 +12,7 @@ noinst_LTLIBRARIES = libbootstrap-pic.la
 libbootstrap_pic_la_SOURCES = bootstrap.c
 
 libbootstrap_pic_la_CPPFLAGS = \
+   -D__BOOTSTRAP_DSO__ \
@XENO_USER_CFLAGS@  \
-I$(top_srcdir)/include \
-I$(top_srcdir)/lib
diff --git a/lib/boilerplate/init/bootstrap.c b/lib/boilerplate/init/bootstrap.c
index 54d1c46..e72a7b8 100644
--- a/lib/boilerplate/init/bootstrap.c
+++ b/lib/boilerplate/init/bootstrap.c
@@ -26,8 +26,6 @@ static int early_argc;
 
 static char *const *early_argv;
 
-const int xenomai_auto_bootstrap = 1;
-
 /*
  * The bootstrap module object is built in two forms:
  *
@@ -41,11 +39,22 @@ const int xenomai_auto_bootstrap = 1;
  *   any wrapper to a main() routine - which does not exist - but only
  *   a constructor routine performing the inits.
  *
- * The dedicated macro __INTERCEPT_MAIN__ tells us whether the main()
- * interception code should be present in the relocatable object.
+ * The macro __BOOTSTRAP_DSO__ tells us whether we are building the
+ * bootstrap module to be glued into a dynamic shared object. If not,
+ * the main() interception code should be present in the relocatable
+ * object.
  */
 
-#ifdef __INTERCEPT_MAIN__
+#ifdef __BOOTSTRAP_DSO__
+
+static inline void call_init(int *argcp, char *const **argvp)
+{
+   xenomai_init_dso(argcp, argvp);
+}
+
+#else
+
+const int xenomai_auto_bootstrap = 1;
 
 int __real_main(int argc, char *const argv[]);
 
@@ -62,7 +71,12 @@ int xenomai_main(int argc, char *const argv[])
return __real_main(argc, argv);
 }
 
-#endif /* !__INTERCEPT_MAIN__ */
+static inline void call_init(int *argcp, char *const