Opened 10 years ago

Closed 10 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 10 years ago.
testcase

Download all attachments as: .zip

Change History (8)

by KO Myung-Hun, 10 years ago

Attachment: ctordtor.zip added

testcase

comment:1 by KO Myung-Hun, 10 years ago

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 by bird, 10 years ago

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 by KO Myung-Hun, 10 years ago

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 by bird, 10 years ago

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 by KO Myung-Hun, 10 years ago

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 by KO Myung-Hun, 10 years ago

Resolution: invalid
Status: closedreopened

comment:7 by bird, 10 years ago

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