mailing list of musl libc
 help / color / mirror / code / Atom feed
* Program with constructor function segfaults frequently with musl
@ 2018-03-15 10:38 Bracken Dawson
  2018-03-15 11:01 ` Szabolcs Nagy
  0 siblings, 1 reply; 7+ messages in thread
From: Bracken Dawson @ 2018-03-15 10:38 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 2436 bytes --]

I have been having trouble getting a cgo program to run with musl, it has
been segfaulting frequently and with 'No stack' when run under gdb.

I have managed to reproduce such a failure in pure c with a very small
example:

```
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>

__attribute__((constructor)) void enter_namespace(int argc, char *argv[]) {
    struct option long_options[] = {
        {"some-option", required_argument, 0, 's'},
        {0,0,0,0}
    };
    int option_index, c, pid;
    while ((c = getopt_long_only(argc, argv, "m:", long_options,
&option_index)) != -1) {
        switch (c) {
            case 's':
                pid = atoi(optarg);
                if (pid < 1) {
                    fprintf(stderr, "Invalid some-option: %s\n", optarg);
                    exit(1);
                }
                break;
            case 0:
                break;
        }
    }
}

int main(void) {
  return 0;
}
```

Run with or without options will segfault frequently:
```
~ # gcc -g test.c
~ # ./a.out
Segmentation fault
~ # ./a.out
~ # ./a.out
~ # ./a.out
~ # ./a.out
Segmentation fault
~ #
~ # gdb ./a.out
GNU gdb (GDB) 7.12.1
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html
>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-alpine-linux-musl".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...done.
(gdb) r
Starting program: /root/a.out
warning: Error disabling address space randomization: Operation not
permitted
During startup program terminated with signal SIGSEGV, Segmentation fault.
(gdb) bt
No stack.
(gdb)
```
It appears that having any code in a constructor function leads to this
problem, having the same code in the main function does not segfault.

I'm not sure how to take this any further without a backtrace.

I am using musl 1.1.16-r14 on alpine 3.6.0. The code above works with glibc.

Regards,
Bracken Dawson.

:wq

[-- Attachment #2: Type: text/html, Size: 6654 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-03-15 20:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-15 10:38 Program with constructor function segfaults frequently with musl Bracken Dawson
2018-03-15 11:01 ` Szabolcs Nagy
2018-03-15 11:17   ` Szabolcs Nagy
2018-03-15 11:28     ` Bracken Dawson
2018-03-15 12:12       ` Szabolcs Nagy
2018-03-15 15:35       ` Rich Felker
2018-03-15 20:34       ` Markus Wichmann

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).