Date: Sun, 27 Jan 2002 17:37:13 -0800 From: Peter Wemm <peter@wemm.org> To: Terry Lambert <tlambert2@mindspring.com> Cc: Alexey Zelkin <phantom@FreeBSD.ORG>, Chad David <davidc@acns.ab.ca>, "Andrey A. Chernov" <ache@nagual.pp.ru>, "Brian F. Feldman" <green@FreeBSD.ORG>, Bruce Evans <bde@zeta.org.au>, arch@FreeBSD.ORG Subject: Re: strtod() Message-ID: <20020128013713.9915D3A9A@overcee.wemm.org> In-Reply-To: <3C549659.13EEA86C@mindspring.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Terry Lambert wrote: > Alexey Zelkin wrote: > > Heh! I'm not a linker guru, so could you please explain problem more > > deeply ? And in case if it's actually problem -- it will be fixed. > > > > It's important now since I am going to merge many locale specific changes > > to STABLE soon. And would like to have it as more clean as possible. > > /usr/src/lib/csu/i386-elf/ > > Look at how _init: is defined in crti.S, and look for > the definition of "monstartup()", and its use in crt1.c. > > Basically, this is code that gets called before any > user code. > > In Windows terms, this is where you would put "process > attach" functions for starting things like apartment > model threading for a COM/OLE component in a DLL. The > "process detach" is basically the "atexit". > > FreeBSD and Linux still don't have a "thread attach/detach", > so don't get your hopes up, if you're a Windows programmer: > there's still cool things you simply can't do. 8-). > > The G++ abuse is for the constructors. There's a linker > set called "ctor_list"; this is executed by dereferencing > the function pointer from the list (not in a particular > order... bad for C++, actually) from the function "do_ctors" > in the file /usr/src/lib/csu/common/crtbegin.c . To "abuse" > this, all you have to do is add a function to the linker > set, using an asm directive, and the function will get > called around the time the constructors are called. If you > think it's important to call your function earlier than any > constructors, this might not be the way to go. First of all, dont look at /usr/src/lib/csu/common/crtbegin.c - it is not used on FreeBSD. We use the crtstuff.c file from gcc instead when gcc is being used. On Alpha we use an alpha assembler crtstuff.asm file and the same on many of the other cpu platforms. This file is only here as a placeholder while bootstrapping new platforms. The files used instead of /usr/src/lib/csu/common/crtbegin.c are: src/contrib/gcc.295/crtstuff.c src/contrib/gcc.295/config/alpha/crtbegin.asm src/contrib/gcc.295/config/alpha/crtend.asm src/contrib/gcc/config/ia64/crtbegin.asm (gcc 3 and later) src/contrib/gcc/config/ia64/crtend.asm (gcc 3 and later) and so on. If you want to do this in a ``portable'' way (I say portable because it uses gcc extensions rather than inline asm for each platform), try this: peter@overcee[5:31pm]/tmp-122> cat cons.c void begin (void) __attribute__((__constructor__)); void end (void) __attribute__((__destructor__)); void begin(void) { write(1, "BEGIN\n", 6); } void end(void) { write(1, "END\n", 4); } int main(int ac, char **av) { printf("hello world\n"); exit(0); } peter@overcee[5:32pm]/tmp-123> cc -static -o cons cons.c peter@overcee[5:33pm]/tmp-124> ./cons BEGIN hello world END (I used -static because the destructor call happens after libc.so has become unavailable.. ie: less than useful). This works for shared objects too. If this solves the problem at hand, I'd far rather that we used this gcc extension than yet more magic inline asm (a different gcc extension). Cheers, -Peter -- Peter Wemm - peter@FreeBSD.org; peter@yahoo-inc.com; peter@netplex.com.au "All of this is for nothing if we don't go to the stars" - JMS/B5 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020128013713.9915D3A9A>