[Bug 252307] dlopen (without RTLD_GLOBAL) overrides weak symbols in libc

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Thu Dec 31 16:08:30 UTC 2020


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=252307

            Bug ID: 252307
           Summary: dlopen (without RTLD_GLOBAL) overrides weak symbols in
                    libc
           Product: Base System
           Version: 12.2-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: bin
          Assignee: bugs at FreeBSD.org
          Reporter: iwtcex at gmail.com

See the comment at https://bugs.winehq.org/show_bug.cgi?id=50257#c20 for
context.

% cat weak_sym_override_test.c 
#include <assert.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>

#if SHLIB
void* calloc(size_t number, size_t size) {
  printf("libc called\n");
  exit(1);
}
#else
int main() {
  assert(dlopen("override.so", RTLD_NOW) != NULL);
  setenv("WHATEVER", "1", 0); // uses calloc internally
  return 0;
}
#endif
% cc -shared -fPIC -DSHLIB weak_sym_override_test.c -o override.so && cc
weak_sym_override_test.c -Wl,-rpath,. -o test
% ./test 
libc called

Doesn't happen with LD_BIND_NOW=1. No idea how that works on Linux, glibc
consistently avoids calling weak symbols it exports, preferring internal
versions prefixed with with __ (two underscores) instead, thus there is no
obvious way to test it.

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list