Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <CABkUXbe_GXr8MEkNn6ABObxPvZQhbDSjnExeMLtcZT5fSQEvMQ@mail.gmail.com>
Date: Tue, 14 Jul 2020 17:32:42 -0700
From: Simon <simonhf@...il.com>
To: musl@...ts.openwall.com
Subject: musl attribute constructor does not pass argc and argv as expected?

Hello!

I tried compiling the test.c snippet here [1] with glibc and musl under
Alpine 3.12 and get the following results:

$ gcc -std=c99 -o test test.c # glibc
$ ldd ./test
        linux-vdso.so.1 (0x00007ffd0bfc9000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd1e9363000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fd1e9572000)
$ ./test arg1 arg2
stuff: argv[0] = './test'
stuff: argv[1] = 'arg1'
stuff: argv[2] = 'arg2'
main: argv[0] = './test'
main: argv[1] = 'arg1'
main: argv[2] = 'arg2'

$ gcc -static -std=c99 -o test test.c # musl
$ ldd ./test
        statically linked
$ ./test arg1 arg2
Segmentation fault (core dumped)
$ ./test arg1 arg2
main: argv[0] = './test'
main: argv[1] = 'arg1'
main: argv[2] = 'arg2'

Very infrequently when I run the musl compiled code then I get the seg
fault. And the rest of the time only main() is run.

If I compile without static then same thing:

$ gcc -std=c99 -o test test.c # musl
$ ldd ./test
        linux-vdso.so.1 (0x00007ffed4193000)
        libc.musl-x86_64.so.1 => not found
$ ./test arg1 arg2
main: argv[0] = './test'
main: argv[1] = 'arg1'
main: argv[2] = 'arg2'
$ ./test arg1 arg2
Segmentation fault (core dumped)

If I add the following line of code both functions and recompile with musl
under Alpine:

    printf("- argc=%d\n", argc);

Then the it seems that argc is being passed but the wrong value:

$ ./test arg1 arg2
- argc=-1988853488
- argc=3
main: argv[0] = './test'
main: argv[1] = 'arg1'
main: argv[2] = 'arg2'
$ ./test arg1 arg2
- argc=1409286416
Segmentation fault (core dumped)

Seems like a bug in musl, or what am I doing wrong?

Thanks in advance!

[1] https://stackoverflow.com/a/37012337/1547069

Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.