[haiku-development] main() in shared libraries?

  • From: François Revol <revol@xxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Thu, 23 Apr 2015 15:00:25 +0200

It is a rarely known fact but at least on Linux some shared libraries
have a main() function and can be called as executables, including the
dynamic loader, usually it just prints the library name and version.

$ /lib64/ld-linux-x86-64.so.2
Usage: ld.so [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]
You have invoked `ld.so', the helper program for shared library executables.
...

$ /lib/x86_64-linux-gnu/libc.so.6
GNU C Library (Debian GLIBC 2.19-17) stable release version 2.19, by
Roland McGrath et al.
Copyright (C) 2014 Free Software Foundation, Inc.
...


Although it doesn't seem to be the case for all of them:

http://unix.stackexchange.com/questions/40587/why-are-shared-libraries-executable


I've looked into porting Gambas3 <http://gambas.sourceforge.net/> and I
noticed this in the configure tests:

AC_CHECK_LIB(gcc_s, main, CXX_LIB="$CXX_LIB -lgcc_s")
AC_CHECK_LIB(stdc++, main, CXX_LIB="$CXX_LIB -lstdc++")

Obviously it fails on Haiku because they don't have a main() call.

Do we want to mimic the linux behaviour or fix those checks (but then
I'm not sure which symbol to test for on those)?

François.

Other related posts: