On Thu, 2 Aug 2012 14:50:31 -0300
Bruno Seiva Martins <[email protected]> wrote:
> Hi Mark,
>
> Thanks for your input.
>
> Looking closely, indeed using 'STATIC_BUILD=YES' compiled EPICS code
> statically to my executable, leaving only the shared system libraries out.
Hi Mark & Bruno,
Sorry, I've come to this discussion a little bit late. But I'll
pipe up now anyhow!
I recently set up EPICS to link a static glibc for ARM, as a stop-gap to
deploy to an embedded computer (Embeddedarm TS-7520-BOX) with a very
minimal uclibc[1]/busybox system installed from the vendor (in our
EPICS configuration the computer boots its uclibc system, mounts an NFS
share with the glibc IOC app, and then runs it.)
The static linking is a bit of a dirty hack, but I thought I'd share it anyway. It
works with caveats for ARM, I think it will probably be the same for x86.
The caveats are:
- No name resolution functions (ie DNS lookup, gethostbyname.) Have to
use IP addresses in IOC scripts.[2]
- Minor patch against EPICS base.
- Possibly some other EPICS functions won't work.
With that in mind, these are the arch-specific compile/link flags. For ARM I put them in
base/configure/os/CONFIG_SITE.Common.linux-arm:
# Static linking options:
ARCH_DEP_LDFLAGS += -static -static-libgcc -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -lc
STATIC_BUILD = YES
# this disables the -Wl,-Bdynamic which is -normally- applied when linking "system" libraries for linux
STATIC_LDLIBS_YES =
I also had to add some system search paths to ARCH_DEP_CFLAGS &
ARCH_DEP_LDFLAGS, because my cross-compiler configuration had them
somewhere that EPICS wasn't looking. But that might be toolchain-specific.
The patch against base is to test for a static environment before
calling dlsym(0, xxx), which will otherwise segfault if correct gcc shared
libaries aren't available:
--- base/src/libCom/osi/os/Linux/osdFindSymbol.c (revision 940)
+++ base/src/libCom/osi/os/Linux/osdFindSymbol.c (revision 941)
@@ -23,5 +23,10 @@
epicsShareFunc void * epicsShareAPI epicsFindSymbol(const char *name)
{
- return dlsym(0, name);
+ void *static_test = dlopen(0, RTLD_LAZY);
+ if(!static_test)
+ return 0;
+ dlclose(static_test);
+ return dlsym(0, name);
}
Hope this might be of use. I'm happy to add it to the wiki if folks
feel it is of potential use, and not too hacky.
- Angus
[1] Eventually I want to build EPICS against a shared uclibc (which
I've read on the list is possible.) I've held off because the vendor
supplied version of uclibc is really old. Statically linking glibc
seemed like an easy stop-gap before I try to switch both system & app to a
whole new uclibc.
[2] It might be possible to get name lookups to work by linking
libresolv with -Wl,whole-archive and then copying across libnss_*.so to
the target system and LD_PRELOADing those libaries when running the IOC app.
But as this is a stop-gap and we only need to resolve a small handful of
addresses, I didn't investigate very far.
- References:
- Cross-compilation, static build, etc Bruno Seiva Martins
- RE: Cross-compilation, static build, etc Mark Rivers
- Re: Cross-compilation, static build, etc Bruno Seiva Martins
- Navigate by Date:
- Prev:
Location of caTools sources Shankar, Murali
- Next:
put to disabled records and monitors Dirk Zimoch
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
<2012>
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
Re: Cross-compilation, static build, etc J. Lewis Muir
- Next:
autosave: makeAutosaveFiles() Wesley Moore
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
<2012>
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|