Opened 9 years ago

Closed 9 years ago

#321 closed defect (invalid)

__attribute__((constructor/destructor)) and _DLL_InitTerm()

Reported by: KO Myung-Hun Owned by:
Priority: normal Milestone: libc-0.7
Component: libc Version: 0.6.6
Severity: normal Keywords:
Cc:

Description

Hi/2.

__attribute__((consturctor)) and __attribute__((destructor)) can be used as a startup code and an exit code, respectively.

But when using custom _DLL_InitTerm(), if it does not call __ctordtorInit(), those startup and exit codes are not called.

This is very annoying because a static library is using those features and it is linked into a DLL which does not call __ctordtorInit(), those startup/exit codes are not executed.

Attachments (1)

ctordtor.zip (1.3 KB) - added by KO Myung-Hun 9 years ago.
testcase

Download all attachments as: .zip

Change History (8)

Changed 9 years ago by KO Myung-Hun

Attachment: ctordtor.zip added

testcase

comment:1 Changed 9 years ago by KO Myung-Hun

Call ctordtor-mk.cmd to build and execute ctordtor.exe. You cannot see 'Hello' and 'Bye' before and after a message of f(), respectively.

If you change CALL_CTORDTOR_INITTERM of ctordtor-dll.c to 1, then you can see them.

comment:2 Changed 9 years ago by bird

Resolution: invalid
Status: newclosed

This is done so for hysterical raisins (IBM/MS compatibility or smth), not going to be changed. Fix your custom _DLL_InitTerm.

comment:3 Changed 9 years ago by KO Myung-Hun

Resolution: invalid
Status: closedreopened

But I don't think attribute((constructor/destructor)) is related to IBM/MS compatibility. And an application seeming to call _CRT_init() only, has no problem with attribute((constructor/destructor)) even if it is a plain C program. Due to this, I opened a ticket.

comment:4 Changed 9 years ago by bird

Resolution: invalid
Status: reopenedclosed

If you replace the default _DLL_InitTerm you have no right to complain that your replacement doesn't do what it needs to do! (Just like if you replaced the open() call with say remove(), it's entirely your choice, even if it's a bad idea in general.)

comment:5 Changed 9 years ago by KO Myung-Hun

None of those who create DLLs in C expect attribute((consturctor/destructor)) functions in third-party C library not to be called because they did not call C++ constructor initializer!

If replacing _DLL_InitTerm() is problem, then it would be better to introduce another level init/term functions like LibMain?() of Open Watcom, called by default _DLL_InitTerm(). By this, we can avoid this annoying problem. Nevertheless if an user uses custom _DLL_InitTerm(), then the user has no right to complain as you said.

comment:6 Changed 9 years ago by KO Myung-Hun

Resolution: invalid
Status: closedreopened

comment:7 Changed 9 years ago by bird

Resolution: invalid
Status: reopenedclosed
Note: See TracTickets for help on using tickets.