* program exit code, "at exit" handler and explicit close of shared objects
@ 2019-10-26 15:07 Roumen Petrov
2019-10-29 14:53 ` Ken Brown
0 siblings, 1 reply; 4+ messages in thread
From: Roumen Petrov @ 2019-10-26 15:07 UTC (permalink / raw)
To: cygwin
[-- Attachment #1: Type: text/plain, Size: 1372 bytes --]
Hello Cygwin developers,
This email is mainly for issue with exist code for a program.
It is inspired from openssl issue #10107 - "test_ssl_old freezes on
cygwin". Actually after one or another work-around "unfreeze" test and
this shows that one of subtests fail. This failure is main topic of this
email.
More about failed test "testing connection with weak DH, expecting
failure". So failure is expected and program code try to exit with 1.
Unfortunately OS returns zero exit code.
Since version 1.1 OpenSSL uses "at exit handler" to clean-up allocated
resources. Removing registered handler restores program exit code. So
something in handler triggers issue.
After additional tests (research) I was able to isolate issues to simple
test case. Please find attached "test-dlclose.c" and "Makefile".
First test is as is:
$ make
cc -g -Wall -Wextra test-dlclose.c -o test-dlclose
./test-dlclose
exit with code 33
make: [Makefile:4: all] Error 33 (ignored)
For next test change test-dlclose.c to define DLCLOSE_ATEXIT ( s/#if 0/#if 1/ ):
$ make
cc -g -Wall -Wextra test-dlclose.c -o test-dlclose
./test-dlclose
exit with code 33
As is visible make does not report error, i.e. program exit code is zero.
Is there a way to bypass issue?
For protocol:
$ uname -srvm -> CYGWIN_NT-10.0 3.0.7(0.338/5/3) 2019-04-30 18:08 x86_64
Regards,
Roumen Petrov
[-- Attachment #2: test-dlclose.c --]
[-- Type: text/x-csrc, Size: 701 bytes --]
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
void *handle = NULL;
#if 0
# define DLCLOSE_ATEXIT 1
#endif
#ifdef DLCLOSE_ATEXIT
static void
dlclose_atexit(void) {
if (dlclose(handle) != 0) {
fprintf(stderr, "dlclose fail : %s\n", dlerror());
}
}
#endif
int
main() {
handle = dlopen("libz.so", RTLD_LAZY | RTLD_NOW);
if (handle == NULL) {
fprintf(stderr, "dlopen fail : %s\n", dlerror());
return 1;
}
#ifndef DLCLOSE_ATEXIT
if (dlclose(handle) != 0) {
fprintf(stderr, "dlclose fail : %s\n", dlerror());
return 2;
}
#else
if (atexit(dlclose_atexit) != 0) {
fprintf(stderr, "atexit fail\n");
return 3;
}
#endif
printf("exit with code 33\n");
return 33;
}
[-- Attachment #3: Makefile --]
[-- Type: text/plain, Size: 62 bytes --]
CFLAGS = -g -Wall -Wextra
all: test-dlclose
-./test-dlclose
[-- Attachment #4: Type: text/plain, Size: 219 bytes --]
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: program exit code, "at exit" handler and explicit close of shared objects
2019-10-26 15:07 program exit code, "at exit" handler and explicit close of shared objects Roumen Petrov
@ 2019-10-29 14:53 ` Ken Brown
2019-10-29 15:31 ` Ken Brown
0 siblings, 1 reply; 4+ messages in thread
From: Ken Brown @ 2019-10-29 14:53 UTC (permalink / raw)
To: cygwin
On 10/26/2019 11:07 AM, Roumen Petrov wrote:
>
> After additional tests (research) I was able to isolate issues to simple test
> case. Please find attached "test-dlclose.c" and "Makefile".
> First test is as is:
>
> $ make
> cc -g -Wall -Wextra test-dlclose.c -o test-dlclose
> ./test-dlclose
> exit with code 33
> make: [Makefile:4: all] Error 33 (ignored)
>
> For next test change test-dlclose.c to define DLCLOSE_ATEXIT ( s/#if 0/#if 1/ ):
> $ make
> cc -g -Wall -Wextra test-dlclose.c -o test-dlclose
> ./test-dlclose
> exit with code 33
I ran this second version of test-dlclose (with DLCLOSE_ATEXIT defined) under
strace and got the following:
$ strace -o trace.out ./test-dlclose.exe
exit with code 33
Segmentation fault
The strace output ends with
30 30143 [main] test-dlclose 847 write: 18 = write(1, 0x600061E20, 18)
--- Process 33456 (pid: 847) unloaded DLL at 00000003e7930000
--- Process 33456 (pid: 847), exception c0000005 at 00000003e7931080
--- Process 33456 (pid: 847) thread 26088 exited with status 0xc0000005
--- Process 33456 (pid: 847) thread 33544 exited with status 0xc0000005
--- Process 33456 (pid: 847) thread 36020 exited with status 0xc0000005
--- Process 33456 exited with status 0xc0000005
The address 00000003e7930000 seems to be in /usr/bin/cygz.dll, which is the DLL
that got unloaded. After installing zlib-debuginfo, I ran addr2line to see
where the crash occurred, and this too crashed:
$ addr2line -C -f -i -p -e /usr/bin/cygz.dll 0x3e7931080
Segmentation fault (core dumped)
That's as far as I've gotten.
Ken
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: program exit code, "at exit" handler and explicit close of shared objects
2019-10-29 14:53 ` Ken Brown
@ 2019-10-29 15:31 ` Ken Brown
2019-11-05 19:32 ` Roumen Petrov
0 siblings, 1 reply; 4+ messages in thread
From: Ken Brown @ 2019-10-29 15:31 UTC (permalink / raw)
To: cygwin
On 10/29/2019 10:53 AM, Ken Brown wrote:
> On 10/26/2019 11:07 AM, Roumen Petrov wrote:
>>
>> After additional tests (research) I was able to isolate issues to simple test
>> case. Please find attached "test-dlclose.c" and "Makefile".
>> First test is as is:
>>
>> $ make
>> cc -g -Wall -Wextra test-dlclose.c -o test-dlclose
>> ./test-dlclose
>> exit with code 33
>> make: [Makefile:4: all] Error 33 (ignored)
>>
>> For next test change test-dlclose.c to define DLCLOSE_ATEXIT ( s/#if 0/#if 1/ ):
>> $ make
>> cc -g -Wall -Wextra test-dlclose.c -o test-dlclose
>> ./test-dlclose
>> exit with code 33
>
> I ran this second version of test-dlclose (with DLCLOSE_ATEXIT defined) under
> strace and got the following:
>
> $ strace -o trace.out ./test-dlclose.exe
> exit with code 33
> Segmentation fault
>
> The strace output ends with
>
> 30 30143 [main] test-dlclose 847 write: 18 = write(1, 0x600061E20, 18)
> --- Process 33456 (pid: 847) unloaded DLL at 00000003e7930000
> --- Process 33456 (pid: 847), exception c0000005 at 00000003e7931080
> --- Process 33456 (pid: 847) thread 26088 exited with status 0xc0000005
> --- Process 33456 (pid: 847) thread 33544 exited with status 0xc0000005
> --- Process 33456 (pid: 847) thread 36020 exited with status 0xc0000005
> --- Process 33456 exited with status 0xc0000005
>
> The address 00000003e7930000 seems to be in /usr/bin/cygz.dll, which is the DLL
Sorry, I meant to say 00000003e7931080; 00000003e7930000 is the start of cygz.dll.
> that got unloaded. After installing zlib-debuginfo, I ran addr2line to see
> where the crash occurred, and this too crashed:
>
> $ addr2line -C -f -i -p -e /usr/bin/cygz.dll 0x3e7931080
> Segmentation fault (core dumped)
>
> That's as far as I've gotten.
>
> Ken
>
> --
> Problem reports: http://cygwin.com/problems.html
> FAQ: http://cygwin.com/faq/
> Documentation: http://cygwin.com/docs.html
> Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
>
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: program exit code, "at exit" handler and explicit close of shared objects
2019-10-29 15:31 ` Ken Brown
@ 2019-11-05 19:32 ` Roumen Petrov
0 siblings, 0 replies; 4+ messages in thread
From: Roumen Petrov @ 2019-11-05 19:32 UTC (permalink / raw)
To: cygwin
Hello,
As non-regular user I did tests when I have access to environment.
Ken Brown wrote:
> On 10/29/2019 10:53 AM, Ken Brown wrote:
>> On 10/26/2019 11:07 AM, Roumen Petrov wrote:
>>> First test is as is:
>>> [SNIP]
>>> I ran this second version of test-dlclose (with DLCLOSE_ATEXIT defined) under
>>> strace and got the following:
>>>
>>> $ strace -o trace.out ./test-dlclose.exe
>>> exit with code 33
>>> Segmentation fault
>>>
>>> The strace output ends with
>>>
>>> 30 30143 [main] test-dlclose 847 write: 18 = write(1, 0x600061E20, 18)
>>> --- Process 33456 (pid: 847) unloaded DLL at 00000003e7930000
>>> --- Process 33456 (pid: 847), exception c0000005 at 00000003e7931080
>>> --- Process 33456 (pid: 847) thread 26088 exited with status 0xc0000005
>>> --- Process 33456 (pid: 847) thread 33544 exited with status 0xc0000005
>>> --- Process 33456 (pid: 847) thread 36020 exited with status 0xc0000005
>>> --- Process 33456 exited with status 0xc0000005
>>>
>>> The address 00000003e7930000 seems to be in /usr/bin/cygz.dll, which is the DLL
> Sorry, I meant to say 00000003e7931080; 00000003e7930000 is the start of cygz.dll.
>
>> that got unloaded. After installing zlib-debuginfo, I ran addr2line to see
>> where the crash occurred, and this too crashed:
>>
>> $ addr2line -C -f -i -p -e /usr/bin/cygz.dll 0x3e7931080
>> Segmentation fault (core dumped)
The test was with compression library because this is default OpenSSL
configuration - dynamic loading of compression library.
It seems to me issue could be reproduced with other libraries as well.
For instance I get the same with ssh ("libssh-4.so") or bz2 ("libbz2-1.so").
>> That's as far as I've gotten.
>>
>> Ken
Regards,
Roumen Petrov
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-11-05 19:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-26 15:07 program exit code, "at exit" handler and explicit close of shared objects Roumen Petrov
2019-10-29 14:53 ` Ken Brown
2019-10-29 15:31 ` Ken Brown
2019-11-05 19:32 ` Roumen Petrov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).