add an flexible bootstrap template header
PATCH 1/3 add an flexible bootstrap template header
this adds a new file 'include/xenomai/bootstrap-template.h', replicating the functionality of the previous bootstrap code, but allowing this functionality to be controlled with macros.
Intended purpose is to allow applications to easily compile their own bootstrap, without depending on precompiled objects or linker wrapping magic.
--- include/xenomai/Makefile.am | 7 +- include/xenomai/bootstrap-template.h | 270 +++++++++++++++++++++++++++ include/xenomai/init.h | 2 + lib/boilerplate/init/Makefile.am | 3 +- lib/boilerplate/init/bootstrap-pic.c | 2 + lib/boilerplate/init/bootstrap.c | 175 +---------------- 6 files changed, 282 insertions(+), 177 deletions(-) create mode 100644 include/xenomai/bootstrap-template.h create mode 100644 lib/boilerplate/init/bootstrap-pic.c
include/xenomai/Makefile.am +4 -3
@@ -1,6 +1,7 @@ includesubdir = $(includedir)/xenomai -includesub_HEADERS = \ - init.h \ - tunables.h \ +includesub_HEADERS = \ + bootstrap-template.h \ + init.h \ + tunables.h \ version.h
include/xenomai/bootstrap-template.h new file +270 -0
270 lines not on this page · raw message
include/xenomai/init.h +2 -0
@@ -29,6 +29,8 @@ void xenomai_init(int *argcp, char *const **argvp);void xenomai_init_dso (int *argcp,char *const **argvp); +int xenomai_bootstrap_getargv (int *argc,char *const ** argv); +int xenomai_main (int argc,char *const argv[]);void xenomai_usage (void );
lib/boilerplate/init/Makefile.am +1 -2
@@ -9,10 +9,9 @@ libbootstrap_a_CPPFLAGS = \ noinst_LTLIBRARIES = libbootstrap-pic.la -libbootstrap_pic_la_SOURCES = bootstrap.c +libbootstrap_pic_la_SOURCES = bootstrap-pic.c libbootstrap_pic_la_CPPFLAGS = \ - -D__BOOTSTRAP_DSO__ \ @XENO_USER_CFLAGS@ \ -I$(top_srcdir)/include \ -I$(top_srcdir)/lib
lib/boilerplate/init/bootstrap-pic.c new file +2 -0
@@ -0,0 +1,2 @@ +#define _XENOMAI_BOOTSTRAP_DSO +#include <xenomai/bootstrap-template.h>
lib/boilerplate/init/bootstrap.c +3 -172
175 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH 2/3 add xenomai_init_fetchargv function to xenomai
this routine was previously linked into every
xenomai-application.
--- include/xenomai/init.h | 3 ++ lib/boilerplate/setup.c | 62 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+)
include/xenomai/init.h +3 -0
@@ -31,6 +31,9 @@ void xenomai_init_dso(int *argcp, char *const **argvp);int xenomai_bootstrap_getargv (int *argc,char *const ** argv); +int xenomai_init_fetchargv (int *argcp,char *const **argvp); +#define _XENOMAI_INIT_HASFETCHARGV +int xenomai_main (int argc,char *const argv[]);void xenomai_usage (void );
lib/boilerplate/setup.c +62 -0
71 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH 3/3 provide an extended xenomai_init function
In reply to Norbert LangeThis function is a single entrypoint for both shared libraries and executables.
Futher it allows passing flags as additional argument.
--- include/xenomai/bootstrap-template.h | 19 +++++++++++++ include/xenomai/init.h | 2 ++ lib/boilerplate/setup.c | 42 +++++++++++++++++++--------- 3 files changed, 50 insertions(+), 13 deletions(-)
include/xenomai/bootstrap-template.h +19 -0
@@ -81,6 +81,8 @@* Set a weak reference to the defined main function * _XENOMAI_BOOTSTRAP_DSO * Should be defined when building shared libraries +* _XENOMAI_BOOTSTRAP_INITFLAGS +* Flags passed to the xenomai_init_ext function */ #define _XENOMAI_BOOTSTRAP_GLIBC_CONSTRUCTORS
@@ -256,11 +258,28 @@ __bootstrap_ctor static void xenomai_bootstrap(void)return ;#endif + +#if !defined(_XENOMAI_BOOTSTRAP_INITFLAGS) +/* prefer previously existing functions for better backwards capability */ #ifdef _XENOMAI_BOOTSTRAP_DSOxenomai_init_dso (&argc, &argv);#else xenomai_init (&argc, &argv);#endif +#else + { +int isDso =0 ; +unsigned long long bflags =0 ; +#ifdef _XENOMAI_BOOTSTRAP_DSO + isDso =1 ; +#endif +#ifdef _XENOMAI_BOOTSTRAP_INITFLAGS + bflags = _XENOMAI_BOOTSTRAP_INITFLAGS; +#endif +xenomai_init_ext (&argc, &argv, isDso, bflags); + } +#endif + early_argc = argc; early_argv = argv; }
include/xenomai/init.h +2 -0
@@ -29,6 +29,8 @@ void xenomai_init(int *argcp, char *const **argvp);void xenomai_init_dso (int *argcp,char *const **argvp); +void xenomai_init_ext (int *argcp,char *const **argvp,int isDso,unsigned long flags); +int xenomai_bootstrap_getargv (int *argc,char *const ** argv);int xenomai_init_fetchargv (int *argcp,char *const **argvp);
lib/boilerplate/setup.c +29 -13
61 lines not on this page · raw message
Signature · 1 line
2.17.0
Re: [Xenomai] [PATCH 3/3] provide an extended xenomai_init function
Short Explanation:
This first patch adds a header for creating bootstrap code, The difference with the auto-init method being that this should be preferable compiled together with the application. Upside is that the compilation units (xenomai libs and applications) now are cleanly separated and arcane linker wrapping is not needed.
This will need some changes, which should be no issue for new Applications, eg. The main routine needs a small adaption:
--------------------------------
int xenomai_init_getargv(int *argc, char *const** argv);
extern "C" int main(int argc, char *const argv[], char * const envp[])
{
xenomai_init_getargv(&argc, &argv);....
}
--------------------------------
And in one file you need to instance the bootstrap code like this:
--------------------------------
#define _XENOMAI_BOOTSTRAP_DEFINE_MAINWRAPPER __real_main #define _XENOMAI_BOOTSTRAP_WEAKREF_MAINWRAPPER __wrap_main #include <xenomai/bootstrap-template.h>
--------------------------------
auto-init is still supported as before.
Second patch would move some code into the xenomai libraries, The last one would allow passing flags to the xenomai_init routine.
I would also like to know if the glibc specific simplification would be acceptable to be enabled by default. (_XENOMAI_BOOTSTRAP_GLIBC_CONSTRUCTORS) I tested it both for executable and shared libraries and it does work, But I am not so certain with the macro guards and how long this extended Functionality has been available.
Kind regards,
Norbert
-----Original Message-----
From: Norbert Lange <[email protected]>
Sent: Montag, 23. April 2018 16:24
To: [email protected]
Cc: Lange Norbert <[email protected]>
Subject: [PATCH 3/3] provide an extended xenomai_init function
E-MAIL FROM A NON-ANDRITZ SOURCE: AS A SECURITY MEASURE, PLEASE EXERCISE CAUTION WITH E-MAIL CONTENT AND ANY LINKS OR ATTACHMENTS.
This function is a single entrypoint for both shared libraries and executables. Futher it allows passing flags as additional argument.
--- include/xenomai/bootstrap-template.h | 19 +++++++++++++ include/xenomai/init.h | 2 ++ lib/boilerplate/setup.c | 42 +++++++++++++++++++--------- 3 files changed, 50 insertions(+), 13 deletions(-)
include/xenomai/bootstrap-template.h +19 -0
@@ -81,6 +81,8 @@* Set a weak reference to the defined main function * _XENOMAI_BOOTSTRAP_DSO * Should be defined when building shared libraries +* _XENOMAI_BOOTSTRAP_INITFLAGS +* Flags passed to the xenomai_init_ext function */ #define _XENOMAI_BOOTSTRAP_GLIBC_CONSTRUCTORS
@@ -256,11 +258,28 @@ __bootstrap_ctor static void xenomai_bootstrap(void)return ;#endif + +#if !defined(_XENOMAI_BOOTSTRAP_INITFLAGS) +/* prefer previously existing functions for better backwards +capability */ #ifdef _XENOMAI_BOOTSTRAP_DSOxenomai_init_dso (&argc, &argv);#else xenomai_init (&argc, &argv);#endif +#else + { +int isDso =0 ; +unsigned long long bflags =0 ;#ifdef +_XENOMAI_BOOTSTRAP_DSO + isDso =1 ; +#endif +#ifdef _XENOMAI_BOOTSTRAP_INITFLAGS + bflags = _XENOMAI_BOOTSTRAP_INITFLAGS;#endif +xenomai_init_ext (&argc, &argv, isDso, bflags); + } +#endif + early_argc = argc; early_argv = argv; }
include/xenomai/init.h +3 -0
@@ -29,6 +29,8 @@ void xenomai_init(int *argcp, char *const **argvp);void xenomai_init_dso (int *argcp,char *const **argvp); +void xenomai_init_ext (int *argcp,char *const **argvp,int isDso, +unsigned long flags); +int xenomai_bootstrap_getargv (int *argc,char *const ** argv);
int xenomai_init_fetchargv(int *argcp, char *const **argvp); diff --git a/lib/boilerplate/setup.c b/lib/boilerplate/setup.c index 6cd035134..60d37e35e 100644
lib/boilerplate/setup.c +2 -1
@@ -486,7 +486,7 @@ __setup_section static int parse_setup_options(int *argcp, char **uargv,return 0 ; } -__setup_section static void __xenomai_init(int *argcp, char *const **argvp, const char *me) +static void __xenomai_init (int *argcp,char *const **argvp,const char +*me,unsigned long flags) {struct setup_descriptor *setup;
int ret, base_opt_start;
@@ -641,25 +641,41 @@ fail:
early_panic("initialization failed, %s", symerror(ret)); }-__setup_section void xenomai_init(int *argcp, char *const **argvp) +static void _xenomai_init_ext(int *argcp, char *const **argvp, int +isDso, unsigned long flags)
{
- const char *me = get_program_name();
+ const char *me = "DSO";
+ if (isDso)
+ {+ __xenomai_init(argcp, argvp, me, flags);
+ } else
+ {
+ me = get_program_name();
- if (main_init_done) {
- early_warning("duplicate call from main program "
- "to %s() ignored", __func__);
- early_warning("(xeno-config --no-auto-init disables implicit call)");
- }
+ if (main_init_done) {
+ early_warning("duplicate call from main program "
+ "to %s() ignored", __func__);
+ early_warning("(xeno-config --no-auto-init disables implicit call)");
+ }
- __xenomai_init(argcp, argvp, me);
- main_init_done = 1;
+ __xenomai_init(argcp, argvp, me, flags);
+ main_init_done = 1;
+ }
trace_me("%s bootstrap done", me); }-__setup_section void xenomai_init_dso(int *argcp, char *const **argvp) +void xenomai_init_ext(int *argcp, char *const **argvp, int isDso, +unsigned long flags) {
+ _xenomai_init_ext(argcp, argvp, isDso, flags); }
+
+void xenomai_init(int *argcp, char *const **argvp) {
+ _xenomai_init_ext(argcp, argvp, 0, 0); }
+
+void xenomai_init_dso(int *argcp, char *const **argvp)
{
- __xenomai_init(argcp, argvp, "DSO");
- trace_me("DSO bootstrap done");
+ _xenomai_init_ext(argcp, argvp, 1, 0);}
void __trace_me(const char *fmt, ...)
--
2.17.0
________________________________
This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system.
ANDRITZ HYDRO GmbH
Rechtsform/ Legal form: Gesellschaft mit beschränkter Haftung / Corporation
Firmensitz/ Registered seat: Wien
Firmenbuchgericht/ Court of registry: Handelsgericht Wien
Firmenbuchnummer/ Company registration: FN 61833 g
DVR: 0605077
UID-Nr.: ATU14756806
Thank You
________________________________