[Libwebsockets] Static link on newer Ubuntu version

Andy Green andy at warmcat.com
Fri Jul 8 00:17:49 CEST 2016



On July 7, 2016 11:53:25 PM GMT+08:00, Michael Behrns-Miller <moodboom at gmail.com> wrote:
>Hello lws, Andy, et al.
>
>I am having issues static linking lws after an upgrade to Ubuntu Xenial
>(16.04 and I also tried 16.10).  gcc version 5.4.0 20160609 (Ubuntu
>5.4.0-6ubuntu1)
>
>My C app compiles and runs fine on earlier versions, and on Raspian and
>other places as well.
>It is likely not lws specific but I thought I would ask in case anyone
>had
>solved this issue.

Personally I use Fedora, so I haven't met it.

>My lws cmake call:
>
>cmake -static \
>
>    -DLWS_WITH_SHARED=OFF           \
>
>    -DLWS_WITHOUT_TESTAPPS=1        \
>
>    -DLWS_WITH_SSL=1                \
>
>    -DLWS_WITH_ZLIB=1               \
>
>    -DLWS_WITHOUT_EXTENSIONS=0      \
>
>    -DLWS_HAVE_SSL_CTX_set1_param=1 \
>
>    -DLWS_WITHOUT_DAEMONIZE=0       \
>
>    -DLWS_WITHOUT_SERVER=1          \
>
>    ..
>
>
>Relevant bits from my application CMakeLists.txt:
>
>
>SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
>
>SET(BUILD_SHARED_LIBRARIES OFF)
>
>SET(CMAKE_EXE_LINKER_FLAGS "-static")
>
>include_directories(/usr/local/include /usr/include)
>
>link_directories(/usr/local/lib /usr/lib)
>
>TARGET_LINK_LIBRARIES(${PROJECT_NAME} websockets ssl crypto pthread dl
>c z)
>
>Works fine on many architectures, but on Ubuntu 16.04/16.10, I get an
>instant segfault, related to all those nasty tricky issues with static
>link
>of pthreads and dlopen, it seems:

In itself, lws doesn't need pthreads if LWS_MAX_SMP is the default of 1.  But other libs may need it regardless.

>(gdb) run
>Starting program: /.../my-lws-client
>
>Program received signal SIGSEGV, Segmentation fault.
>0x0000000000000000 in ?? ()
>(gdb) bt
>#0  0x0000000000000000 in ?? ()
>#1  0x00007ffff76f1a33 in __GI__dl_addr
>(address=address at entry=0x7ffff7633de0
><ptmalloc_init>, info=info at entry=0x7fffffffc2b0,
>mapp=mapp at entry=0x7fffffffc2a8,
>symbolp=symbolp at entry=0x0) at dl-addr.c:131
>#2  0x00007ffff7633b96 in ptmalloc_init () at arena.c:397
>#3  0x00007ffff7633f7d in ptmalloc_init () at malloc.c:2924
>#4  malloc_hook_ini (sz=1168, caller=<optimized out>) at hooks.c:31

Above here is from glibc

https://github.com/lattera/glibc/blob/master/malloc/arena.c#L367

static void
ptmalloc_init (void)
{
  if(__malloc_initialized >= 0) return;
  __malloc_initialized = 0;

#ifdef SHARED
  /* In case this libc copy is in a non-default namespace, never use brk.
     Likewise if dlopened from statically linked program.  */
  Dl_info di;
  struct link_map *l;

  if (_dl_open_hook != NULL
      || (_dl_addr (ptmalloc_init, &di, &l, NULL) != 0. <<==== dies in here
	  && l->l_ns != LM_ID_BASE))
    __morecore = __failing_morecore;
#endif

I dunno if the fact we're running stuff from #ifdef SHARED means anything.

Sorry no real idea, but maybe ask on launchpad if it's ubunrtu-specific.

-Andy

>#5  0x00007ffff7be2078 in CRYPTO_malloc () from
>/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
>#6  0x00007ffff7d136df in ?? () from
>/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
>#7  0x00007ffff7d14eb9 in ?? () from
>/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
>#8  0x00007ffff7d135f0 in ?? () from
>/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
>#9  0x00007ffff7c9d8f3 in RAND_init_fips () from
>/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
>#10 0x00007ffff7be0f7a in OPENSSL_init_library () from
>/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
>#11 0x000000000061c1ca in call_init.part ()
>#12 0x000000000061c2db in _dl_init ()
>#13 0x00000000005e4955 in dl_open_worker ()
>#14 0x00000000005e2ac4 in _dl_catch_error ()
>#15 0x00000000005e42b9 in _dl_open ()
>#16 0x000000000057f7c7 in dlopen_doit ()
>#17 0x00000000005e2ac4 in _dl_catch_error ()
>#18 0x000000000057fbf2 in _dlerror_run ()
>#19 0x000000000057f81e in __dlopen ()
>#20 0x00000000004be10a in verify_checksums ()
>#21 0x00000000004be4ff in FIPS_module_mode_set ()
>#22 0x000000000044ba9b in FIPS_mode_set ()
>#23 0x00000000004007e8 in OPENSSL_init_library ()
>#24 0x0000000000565ea7 in __libc_csu_init ()
>#25 0x00000000005654ae in generic_start_main ()
>#26 0x00000000005656fa in __libc_start_main ()
>#27 0x0000000000400b29 in _start ()
>
>Any advice?
>
>Thanks,
>Michael
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>http://libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list