From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13405 Path: news.gmane.org!.POSTED!not-for-mail From: Barry Flartus Newsgroups: gmane.linux.lib.musl.general Subject: Re: Problems with pthreads from a shared object? Date: Wed, 7 Nov 2018 18:40:35 -0500 Message-ID: References: <20181107233142.GV5150@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000b5f9f4057a1ba5b6" X-Trace: blaine.gmane.org 1541633934 1199 195.159.176.226 (7 Nov 2018 23:38:54 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 7 Nov 2018 23:38:54 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-13421-gllmg-musl=m.gmane.org@lists.openwall.com Thu Nov 08 00:38:50 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1gKXPN-0000EU-My for gllmg-musl@m.gmane.org; Thu, 08 Nov 2018 00:38:49 +0100 Original-Received: (qmail 28353 invoked by uid 550); 7 Nov 2018 23:40:58 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 28335 invoked from network); 7 Nov 2018 23:40:58 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=nnhwYPZWeNKSPApSjH2eSMMKA0+MDq80bkNc3w9Q9vc=; b=rlYuzLI8nlQfHdbxwV8dtbRZI2jG4xRMQ/4RjsQLaqZBOlM4/boVDxNJDJZdTqiKAQ 54jZZmRjwUTh+649KbBe+CmFpNq+ZSU5ZaP8lSmTI8IeumEpNJ4dXsv8l1XZ1v+xfWOl UiNRhNgtjfN3HlwtT/tDHyTnAEZ+BFbV8I7CvMX9iH/bZNfFegLNGlrJoOsIrYXuCPtb 6X9E7fS3j+XEHaiU3hPBdHdvN/pQq/xpszkToj5cJSEzQlAKpSBvzOgF159QfV89Hb8K WBfcLmyJzCGEErnzXC15KEESA2okDLR7Y9IssttRfqboW2vQ1R3v/OZ9P/WOuj0fJyR5 RRxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=nnhwYPZWeNKSPApSjH2eSMMKA0+MDq80bkNc3w9Q9vc=; b=tvaFWDxyha/9/9fo3SbLkcEeEgPQHVJ8+YQLZPjqnbSEiQ+Hvm2AzcKAFQvqQEnEdy HAtcKo/lzUWbgEvi0aeqG2YBTizcYlcZIK2vodQzCdcSHqVmFD6DnWfr2MPsZYL/h4+s 5H6q2DrggsL5xFWx0MOeLQEMHscunXIFGLA3udGZf8oDADztIgbtihxRIkdkN5mpfJ6+ CBrOEo2s7q9ZX6t5Hc8bRtmIX7tGTIqV9kc1d81uOBaaOtFnWxtWbDYC4vgZT3o/+QJ3 3OkLQhO+ACs+vcKyLkyAxQS8gCtYpTl5H2AdXMXv+UoO5nNkQk3pc7NsKp9ApShqyOJ8 1qzA== X-Gm-Message-State: AGRZ1gJ7/qGtqJ48aWbCG9a3j9NSBmwId9xQd48qyxSGTUtyZSMRpYsU z72dzsLLL/ZJ6LeiHxzkuPc8ne7h8gRb6qnScvRoy2Z0qtU= X-Google-Smtp-Source: AJdET5fHhTYNC/SdfyOra9S6PFwxsV1kOXBUqQ69WfSNr9P8alwgx2Pe7FrZWBrN9+JBOkdGu5IUuo1CyDzr+Rltg+0= X-Received: by 2002:a02:84ce:: with SMTP id f72-v6mr2311961jai.38.1541634046424; Wed, 07 Nov 2018 15:40:46 -0800 (PST) In-Reply-To: <20181107233142.GV5150@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:13405 Archived-At: --000000000000b5f9f4057a1ba5b6 Content-Type: text/plain; charset="UTF-8" Nope! Linux ubuntu-x64 4.4.0-116-generic - this is just the kernel from a default Ubuntu 16.04 install. On Wed, Nov 7, 2018 at 6:31 PM Rich Felker wrote: > On Wed, Nov 07, 2018 at 06:00:14PM -0500, Barry Flartus wrote: > > Hello, > > > > I am encountering some issues that I believe are musl related when > trying to > > use pthreads from a shared object. Below is a minimal example (2 files) > of > > the problem. > > > > ==================== test.c ==================== > > > > // Compile with > > // musl-gcc -Wall -lpthread -shared -fPIC test.c -o test.so > > > > #include > > #include > > > > static void *launch(void *arg); > > int start_thread(void); > > void entry_point(void) __attribute__((constructor)); > > > > static pthread_t gthread; > > > > static void *launch(void *arg) > > { > > for (int i = 0; i < 4; i++){ > > printf("[%d] Hello from the thread\n", i); > > } > > return NULL; > > } > > > > int start_thread(void) > > { > > printf("Starting the thread\n"); > > return pthread_create(>hread, NULL, launch, NULL); > > } > > > > void entry_point(void){ > > puts("Starting Execution"); > > int res = start_thread(); > > printf("start_thread returned %d\n", res); > > if (res == 0){ > > pthread_join(gthread, NULL); > > } else { > > printf("pthread_create() returned an error. Aborting.\n"); > > } > > } > > > > ==================== launch.c ==================== > > > > // Compile with: > > // gcc launch.c -ldl -o launch > > > > #include > > #include > > #include > > > > int main(){ > > void *handle; > > > > puts("\nLaunching test..."); > > handle = dlopen("./test.so", RTLD_NOW); > > if (!handle) { > > fprintf(stderr, "%s\n", dlerror()); > > exit(EXIT_FAILURE); > > } > > dlerror(); > > > > return EXIT_SUCCESS; > > } > > > > When the above examples are compiled with gcc, everything works correctly > > and > > produces the following output: > > > > Launching test... > > Starting Execution > > Starting the threadstart_thread returned 0 > > [0] Hello from the thread > > [1] Hello from the thread > > [2] Hello from the thread > > [3] Hello from the thread > > > > When I switch to musl pthread_create() returns the integer '38', which > is an > > undocumented return value. I assume this corresponds with ENOSYS from > > errno.h > > but I can't seem to figure out why this is happening. > > > > Output: > > > > Launching test... > > Starting Execution > > Starting the thread > > start_thread returned 38 > > pthread_create() returned an error. Aborting. > > > > Is this even supported by musl? If so, where have I gone wrong? > > > > Thanks in advance! > > Are you running on an ancient kernel or a kernel built with a lot of > default functionality configured out? These should be the only > conditions under which pthread_create can return ENOSYS. > > Rich > --000000000000b5f9f4057a1ba5b6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Nope!=C2=A0Linux ubuntu-x64 4.4.0-116-gen= eric -=C2=A0 this is just the kernel from a default Ubuntu 16.04 install.

On Wed, Nov 7, 20= 18 at 6:31 PM Rich Felker <dalias@lib= c.org> wrote:
On Wed, Nov 07= , 2018 at 06:00:14PM -0500, Barry Flartus wrote:
> Hello,
>
> I am encountering some issues that I believe are musl related when try= ing to
> use pthreads from a shared object. Below is a minimal example (2 files= ) of
> the problem.
>
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D test.c = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> // Compile with
> // musl-gcc -Wall -lpthread -shared -fPIC test.c -o test.so
>
> #include <pthread.h>
> #include <stdio.h>
>
> static void *launch(void *arg);
> int start_thread(void);
> void entry_point(void) __attribute__((constructor));
>
> static pthread_t gthread;
>
> static void *launch(void *arg)
> {
>=C2=A0 =C2=A0 =C2=A0for (int i =3D 0; i < 4; i++){
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0printf("[%d] Hello from the thre= ad\n", i);
>=C2=A0 =C2=A0 =C2=A0}
>=C2=A0 =C2=A0 =C2=A0return NULL;
> }
>
> int start_thread(void)
> {
>=C2=A0 =C2=A0 =C2=A0printf("Starting the thread\n");
>=C2=A0 =C2=A0 =C2=A0return pthread_create(&gthread, NULL, launch, N= ULL);
> }
>
> void entry_point(void){
>=C2=A0 =C2=A0 =C2=A0puts("Starting Execution");
>=C2=A0 =C2=A0 =C2=A0int res =3D start_thread();
>=C2=A0 =C2=A0 =C2=A0printf("start_thread returned %d\n", res)= ;
>=C2=A0 =C2=A0 =C2=A0if (res =3D=3D 0){
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pthread_join(gthread, NULL);
>=C2=A0 =C2=A0 =C2=A0} else {
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0printf("pthread_create() returne= d an error. Aborting.\n");
>=C2=A0 =C2=A0 =C2=A0}
> }
>
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D launch.c = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> // Compile with:
> // gcc launch.c -ldl -o launch
>
> #include <dlfcn.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(){
>=C2=A0 =C2=A0 =C2=A0void *handle;
>
>=C2=A0 =C2=A0 =C2=A0puts("\nLaunching test...");
>=C2=A0 =C2=A0 =C2=A0handle =3D dlopen("./test.so", RTLD_NOW);=
>=C2=A0 =C2=A0 =C2=A0if (!handle) {
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, "%s\n", dle= rror());
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0exit(EXIT_FAILURE);
>=C2=A0 =C2=A0 =C2=A0}
>=C2=A0 =C2=A0 =C2=A0dlerror();
>
>=C2=A0 =C2=A0 =C2=A0return EXIT_SUCCESS;
> }
>
> When the above examples are compiled with gcc, everything works correc= tly
> and
> produces the following output:
>
> Launching test...
> Starting Execution
> Starting the threadstart_thread returned 0
> [0] Hello from the thread
> [1] Hello from the thread
> [2] Hello from the thread
> [3] Hello from the thread
>
> When I switch to musl pthread_create() returns the integer '38'= ;, which is an
> undocumented return value. I assume this corresponds with ENOSYS from<= br> > errno.h
> but I can't seem to figure out why this is happening.
>
> Output:
>
> Launching test...
> Starting Execution
> Starting the thread
> start_thread returned 38
> pthread_create() returned an error. Aborting.
>
> Is this even supported by musl? If so, where have I gone wrong?
>
> Thanks in advance!

Are you running on an ancient kernel or a kernel built with a lot of
default functionality configured out? These should be the only
conditions under which pthread_create can return ENOSYS.

Rich
--000000000000b5f9f4057a1ba5b6--