Bug 254286

Summary: usage of initial-exec prevents dlopen of the libwebkit shared object outside of GLIBC on linux
Product: WebKit Reporter: alice
Component: WebKitGTKAssignee: Nobody <webkit-unassigned>
Severity: Normal CC: bugs-noreply, mcatanzaro
Priority: P2    
Version: Other   
Hardware: PC   
OS: Linux   
See Also: https://bugs.webkit.org/show_bug.cgi?id=240392
Description Flags
a fix for this issue none

Description alice 2023-03-22 14:13:37 PDT
Created attachment 465547 [details]
a fix for this issue

usage of initial-exec prevents valid dlopen of the library later. this works on glibc, because glibc reserves some memory for initial-exec variables in dlopen'd objects.

on other libcs, this doesn't work. for instance:

$ cat main.c 
#include <dlfcn.h>
#include <stdio.h>

int main() {
  void *h = dlopen("libwebkit2gtk-4.0.so.37", 0);

  if(!h) {
    fprintf(stderr, "%s\n", dlerror());
    return 1;

  return 0;
$ gcc main.c 
$ ./a.out 
Error relocating /usr/lib/libwebkit2gtk-4.0.so.37: lroundf: initial-exec TLS resolves to dynamic definition in /usr/lib/libwebkit2gtk-4.0.so.37
$ ldd --version
musl libc (x86_64)
Version 1.2.3
Dynamic Program Loader
Usage: /lib/ld-musl-x86_64.so.1 [options] [--] pathname

utilising initial-exec only when __GLIBC__ is defined fixes this.
Comment 1 alice 2023-03-23 13:43:18 PDT
the patch of course has a typo in it- it's #endif not #fi
Comment 2 Michael Catanzaro 2023-09-06 14:45:20 PDT
Closing since TLS_MODEL_INITIAL_EXEC is no longer used anywhere in WebKit. The entire file that you patched was deleted at some point between then and now.
Comment 3 alice 2023-09-06 14:49:03 PDT
looks to have been https://github.com/WebKit/WebKit/commit/b30a03a4c8a229deacb72a6e4fa46f6469df634f, seems fine to me. thanks for following up :)