public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "alxchk at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug nptl/24776] pthread_key_create, pthread_setspecific are incompatible with dlmopen
Date: Sun, 08 Aug 2021 05:15:24 +0000	[thread overview]
Message-ID: <bug-24776-131-XRGdUyGF8A@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-24776-131@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=24776

Oleksii Shevchuk <alxchk at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alxchk at gmail dot com

--- Comment #11 from Oleksii Shevchuk <alxchk at gmail dot com> ---
/tmp > cat ldr.c 
#define _GNU_SOURCE
#include <dlfcn.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

int main() {
    pthread_key_t key = 0xFFFFFFFF;
    pthread_key_create(&key, NULL);
    pthread_setspecific(key, (void*) 0xDEADBEEF);
    printf("[tid=%lx] Key created: %u with value %p\n", pthread_self(), key,
pthread_getspecific(key));

    printf("[New LMID]\n");
    void *ldr2 = dlmopen(LM_ID_NEWLM, "./ldr2.so", RTLD_NOW | RTLD_LOCAL);
    if (!ldr2) {
        printf("ERR: %s\n", dlerror());
        return -1;
    }

    printf("[Base LMID]\n");
    ldr2 = dlmopen(LM_ID_BASE, "./ldr2.so", RTLD_NOW | RTLD_LOCAL);
    if (!ldr2) {
        printf("ERR: %s\n", dlerror());
        return -1;
    }

    return 0;
}


/tmp > cat ldr2.c
#define _GNU_SOURCE
#include <pthread.h>
#include <stdio.h>

void init(int, char*[], char*[]) {
    pthread_key_t key = 0xFFFFFFFF;
    pthread_key_create(&key, NULL);
    printf("[tid=%lx] Key created: %u\n", pthread_self(), key);
    printf("[tid=%lx] Key value: %p\n", pthread_self(),
pthread_getspecific(key));
}

__attribute__((section(".init_array"))) void (* __init)(int, char*[], char*[])
= init;


/tmp > gcc -o ldr ldr.c -pthread  -ldl
/tmp > gcc -shared -o ldr2.so ldr2.c -pthread     
/tmp > ./ldr
[tid=7fe649b0a740] Key created: 0 with value 0xdeadbeef
[New LMID]
[tid=7fe649b0a740] Key created: 0
[tid=7fe649b0a740] Key value: 0xdeadbeef
[Base LMID]
[tid=7fe649b0a740] Key created: 2
[tid=7fe649b0a740] Key value: (nil)


Pain..

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2021-08-08  5:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-24776-131@http.sourceware.org/bugzilla/>
2021-04-21 19:40 ` fweimer at redhat dot com
2021-05-31 18:10 ` fweimer at redhat dot com
2021-05-31 18:10 ` fweimer at redhat dot com
2021-08-08  5:15 ` alxchk at gmail dot com [this message]
2021-08-08 11:06 ` sware at reimardoeffinger dot de
2021-11-20 16:37 ` ppluzhnikov at google dot com
2022-10-01 17:16 ` jadahl at gmail dot com
2023-04-24 12:17 ` kristofer.berggren at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-24776-131-XRGdUyGF8A@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).