RE: Patch for premain() function
"Ralf Habacker" <[email protected]>
| Newsgroups | gmane.comp.gnu.mingw.patches |
|---|---|
| Message-ID | <006401c26de0$1a23f060$686607d5@BRAMSCHE> |
> > > On Sat, Oct 05, 2002 at 05:14:36PM +0200, Ralf Habacker wrote: > > > >this patches implements a user callable function before main() for > > > >general initialisation purpose without needs for patching the mingw > > > >runtime on user level. > > > > > > Why not just use the __attribute__((constructor)) for your function? > > > > Can you make sure, that a specific constructor is been called first > regardless > > of the position in the list of the used objectfiles ? > > > > As I know one of the possible link lines looks like this : > > > > gcc options ... <objectfiles> ... options ... <libraries> ... options > and so > > one > > > > So if a constructor in <library> must be called at first and there are > ones in > > <objectfiles>, it seems there is no change or are I'm wrong ? > > Normally, you would put global constructors in an object file rather > than a library to force it into the app. Then you could control which > object came last. > > Can you expand on the type of functionality you would call before > invoking global ctors? > I need to hook functions which are imported from other dll's for example fopen/stat/malloc.... and have to be sure, that no unhooked call has been done before. The function, that the hook does is located in a special debug library, which has to be linked to the related application and isn't part of the mingw runtime stuff or the related application. Hooking a function in the executable has the advantage, that there are no needs of source changes or recompile of the whole application, only the exe file must be relinked. This simplifies debug mode switching on to of and vice versa. BTW: I have taken a look into the cygwin source. The cygwin library defines the same functionality with the premain[0-3] hooks. So this patch adds the same functionality to the mingw environment (with some little differences, which could be adapted mostly to the cygwin behavior) Ralf ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf