Date: Thu, 28 Jan 1999 10:09:07 -0800 (PST) From: John Polstra <jdp@polstra.com> To: wilson@ensim.com Cc: hackers@FreeBSD.ORG Subject: Re: need help with linker_set Message-ID: <199901281809.KAA11835@vashon.polstra.com> In-Reply-To: <36AC3072.E5EEF339@ensim.com>
next in thread | previous in thread | raw e-mail | index | archive | help
In article <36AC3072.E5EEF339@ensim.com>,
Xun Wilson Huang <wilson@ensim.com> wrote:
> Hi,
>
> I have been reading codes from the FreeBSD kernel and discover this
> neat thing "linker_set". As I understand, linker_set allows different
> modules/subsystems/files to put data into a "set" by inserting an
> assembly directive .stabs in the c code. At the linking stage, the
> linker puts all these set elements into an array, and one can write code
> to enumerate this array of set elements. ( Am I getting this right?)
Yes, exactly right. You end up with a NULL-terminated vector of
addresses, immediately preceded by an int that gives the number of
elements in the set.
We also support this for ELF, using a somewhat different technique.
> I have been digging for something similar to this on other platform and
> sadly, I can't find anything. I am wondering if any BSD guru here can
> point me to something that leads to a more system independent version of
> this trick? thanks a million.
The most portable way to do it would be to use C++ and include global
constructors which at start-up time would register each module into a
data structure representing the set. You wouldn't need to write all
the code in C++, just the tiny portion that contains the constructor.
The rest of the code could still be in C. We used something similar
to this in "src/lib/libc_r/uthread/uthread_autoinit.cc".
If you wanted to use only C code, you could use GCC's "constructor"
extension. See the section "Declaring Attributes of Functions"
section of the gcc info pages.
I don't know of a portable way to get what you want using strictly
ANSI/ISO C only.
John
--
John Polstra jdp@polstra.com
John D. Polstra & Co., Inc. Seattle, Washington USA
"Nobody ever went broke underestimating the taste of the American public."
-- H. L. Mencken
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199901281809.KAA11835>
