|
Message-ID: <b9f28430-ee74-dae2-05d7-2de474f9b0be@kazimierczak.name> Date: Tue, 24 May 2022 07:54:43 +0200 From: Kuba Kazimierczak <kuba@...imierczak.name> To: musl@...ts.openwall.com Subject: Linking musl with -shared -static - is this supported? Hi, I'm on Alpine Linux, musl version 1.2.2. I'm attempting to create a statically-linked shared object using "-shared -static" and use it in a driver program as follows: /tmp # cat lib.c #include <stdlib.h> unsigned int add(unsigned int a, unsigned int b) { free(malloc(1)); return (a+b); } /tmp # cat main.c #include <stdio.h> extern unsigned int add(unsigned int a, unsigned int b); int main(void) { printf("%d\n", add(1,2)); return 0; } /tmp # clang-14 -g -c -fPIC lib.c /tmp # clang-14 -shared -static -o liblib.so lib.o /tmp # clang-14 -g -L. main.c -o main -llib /tmp # LD_LIBRARY_PATH=$PWD ./main Segmentation fault The segfault happens in musl's malloc implementation internals: #0 0x00007f9c882adc7a in get_random_secret () at src/malloc/mallocng/glue.h:45 #1 __malloc_alloc_meta () at src/malloc/mallocng/malloc.c:50 #2 0x00007f9c882ae11b in alloc_group (req=1, sc=0) at src/malloc/mallocng/malloc.c:179 #3 alloc_slot (sc=sc@...ry=0, req=req@...ry=1) at src/malloc/mallocng/malloc.c:291 #4 0x00007f9c882ae646 in __libc_malloc_impl (n=1) at src/malloc/mallocng/malloc.c:369 #5 0x00007f9c882ad208 in add (a=1, b=2) at lib.c:5 #6 0x000055909082f22e in main () at main.c:7 I see get_random_secret is trying to use struct __libc.argv, which is probably not initialized in this case. Is this use case supported at all?
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.