Can a dylib have an entry point?

164 views
Skip to first unread message

ariel....@roguewave.com

unread,
Feb 18, 2014, 10:40:10 AM2/18/14
to darwi...@lists.apple.com
Hi,

ELF-like systems, particularly linux, allow a shared library
to have an entry point. This allows a library to be constructed
so that it emits, say, version information if it's executed.

This is an example from linux:

% /lib/libc.so.6
GNU C Library development release version 2.4 (20060428), by Roland McGrath et al.
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Configured for i686-suse-linux.
Compiled by GNU CC version 4.1.0 (SUSE Linux).
Compiled on a Linux 2.6.16 system on 2006-04-28.
Available extensions:
crypt add-on version 2.1 by Michael Glad and others
GNU Libidn by Simon Josefsson
GNU libio by Per Bothner
NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
NoVersion patch for broken glibc 2.0 binaries
Native POSIX Threads Library by Ulrich Drepper et al
BIND-8.2.3-T5B
Thread-local storage support included.
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.

Is there a way to do something similar with a .dylib
on darwin/macos?

Thanks,

Ariel Burton


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (Darwi...@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/darwin-dev/darwin-dev-garchive-73044%40googlegroups.com

This email sent to darwin-dev-g...@googlegroups.com

Jens Alfke

unread,
Feb 18, 2014, 12:00:44 PM2/18/14
to ariel....@roguewave.com, darwi...@lists.apple.com
I'm pretty sure it can, since there are language facilities for making functions run when the code is loaded — Clang and GCC's C compilers have __attribute((constructor)), and C++ of course has static initializers.

—Jens

Shantonu Sen

unread,
Feb 18, 2014, 12:14:58 PM2/18/14
to Jens Alfke, darwi...@lists.apple.com
that’s an initializer function(s), which are run when dyld loads the library.

However the kernel will never execve(2) a Mach-O file of dylib type, so the usage describe is not possible.

Shantonu

On Feb 18, 2014, at 9:00 AM, Jens Alfke <je...@mooseyard.com> wrote:

> I'm pretty sure it can, since there are language facilities for making functions run when the code is loaded — Clang and GCC's C compilers have __attribute((constructor)), and C++ of course has static initializers.
>
> —Jens
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Darwin-dev mailing list (Darwi...@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:

> https://lists.apple.com/mailman/options/darwin-dev/ssen%40apple.com
>
> This email sent to ss...@apple.com

Ariel Burton

unread,
Feb 18, 2014, 12:16:53 PM2/18/14
to Jens Alfke, darwi...@lists.apple.com
Hi Jens,

That assumes the loader will the load process to progress that far.

Ariel
==

Reply all
Reply to author
Forward
0 new messages