From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13404 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Problems with pthreads from a shared object? Date: Wed, 7 Nov 2018 18:31:42 -0500 Message-ID: <20181107233142.GV5150@brightrain.aerifal.cx> References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1541633390 25716 195.159.176.226 (7 Nov 2018 23:29:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 7 Nov 2018 23:29:50 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-13420-gllmg-musl=m.gmane.org@lists.openwall.com Thu Nov 08 00:29:46 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 1gKXGc-0006bJ-Jj for gllmg-musl@m.gmane.org; Thu, 08 Nov 2018 00:29:46 +0100 Original-Received: (qmail 17766 invoked by uid 550); 7 Nov 2018 23:31:55 -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 17745 invoked from network); 7 Nov 2018 23:31:55 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:13404 Archived-At: 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