1. 07 10月, 2012 1 次提交
  2. 06 10月, 2012 4 次提交
    • R
      fix symbol acceptance/rejection rules for TLS · bd17431a
      Rich Felker 提交于
      symbol value of 0 is not "undefined" for TLS; it's the address of the
      first symbol in the TLS segment. however, non-definition TLS
      references also have values of 0, so check the section.
      
      hopefully the new logic is more clear, too.
      bd17431a
    • R
      TLS fixes, mainly alignment handling · cf3fd3d0
      Rich Felker 提交于
      compute offsets from the thread pointer statically when loading the
      library, rather than repeating the logic on each thread creation. not
      only is the latter less efficient at runtime; it also fails to provide
      solid guarantees that the offsets will remain the same when the
      initial alignment of memory is different. the new alignment handling
      is both more rigorous and simpler.
      
      the old code was also clobbering TLS bss with random image data in
      some cases due to using tls_size (size of TLS segment) instead of
      tls_len (length of the TLS data image).
      cf3fd3d0
    • R
      fix/improve shared library ctor/dtor handling, allow recursive dlopen · f4f77c06
      Rich Felker 提交于
      some libraries call dlopen from their constructors, resulting in
      recursive calls to dlopen. previously, this resulted in deadlock. I'm
      now unlocking the dlopen lock before running constructors (this is
      especially important since the lock also blocked pthread_create and
      was being held while application code runs!) and using a separate
      recursive mutex protecting the ctor/dtor state instead.
      
      in order to prevent the same ctor from being called more than once, a
      module is considered "constructed" just before the ctor runs.
      
      also, switch from using atexit to register each dtor to using a single
      atexit call to register the dynamic linker's dtor processing as just
      one handler. this is necessary because atexit performs allocation and
      may fail, but the library has already been loaded and cannot be
      backed-out at the time dtor registration is performed. this change
      also ensures that all dtors run after all atexit functions, rather
      than in mixed order.
      f4f77c06
    • R
      small dynamic linker module search fix · 5f88c0ed
      Rich Felker 提交于
      libraries loaded more than once by pathname should not get shortnames
      that would cause them to later be used to satisfy non-pathname load
      requests.
      5f88c0ed
  3. 05 10月, 2012 7 次提交
    • R
      support for TLS in dynamic-loaded (dlopen) modules · dcd60371
      Rich Felker 提交于
      unlike other implementations, this one reserves memory for new TLS in
      all pre-existing threads at dlopen-time, and dlopen will fail with no
      resources consumed and no new libraries loaded if memory is not
      available. memory is not immediately distributed to running threads;
      that would be too complex and too costly. instead, assurances are made
      that threads needing the new TLS can obtain it in an async-signal-safe
      way from a buffer belonging to the dynamic linker/new module (via
      atomic fetch-and-add based allocator).
      
      I've re-appropriated the lock that was previously used for __synccall
      (synchronizing set*id() syscalls between threads) as a general
      pthread_create lock. it's a "backwards" rwlock where the "read"
      operation is safe atomic modification of the live thread count, which
      multiple threads can perform at the same time, and the "write"
      operation is making sure the count does not increase during an
      operation that depends on it remaining bounded (__synccall or dlopen).
      in static-linked programs that don't use __synccall, this lock is a
      no-op and has no cost.
      dcd60371
    • R
      fix race condition in dlopen · 642b7593
      Rich Felker 提交于
      orig_tail was being saved before the lock was obtained, allowing
      dlopen failure to roll-back other dlopens that had succeeded.
      642b7593
    • R
      dynamic-linked TLS support for everything but dlopen'd libs · 9c74856a
      Rich Felker 提交于
      currently, only i386 is tested. x86_64 and arm should probably work.
      the necessary relocation types for mips and microblaze have not been
      added because I don't understand how they're supposed to work, and I'm
      not even sure if it's defined yet on microblaze. I may be able to
      reverse engineer the requirements out of gcc/binutils output.
      9c74856a
    • R
      remove freeing of dynamic linker data when dlopen/dlsym are not used · c91aa03d
      Rich Felker 提交于
      this was an optimization to save/recover a minimal amount of extra
      memory for use by malloc, that's becoming increasingly costly to keep
      around. freeing this data:
      
      1. breaks debugging with gdb (it can't find library symbols)
      2. breaks thread-local storage in shared libraries
      
      it would be possible to disable freeing when TLS is used, but in
      addition to the above breakages, tracking whether dlopen/dlsym is used
      adds a cost to every symbol lookup, possibly making program startup
      slower for large programs. combined with the complexity, it's not
      worth it. we already save/recover plenty of memory in the dynamic
      linker with reclaim_gaps.
      c91aa03d
    • R
      beginnings of full TLS support in shared libraries · 9b153c04
      Rich Felker 提交于
      this code will not work yet because the necessary relocations are not
      supported, and cannot be supported without some internal changes to
      how relocation processing works (coming soon).
      9b153c04
    • R
      partial TLS support for dynamic-linked programs · bc6a35fb
      Rich Felker 提交于
      only TLS in the main program is supported so far; TLS defined in
      shared libraries will not work yet.
      bc6a35fb
    • R
      TLS (GNU/C11 thread-local storage) support for static-linked programs · 8431d797
      Rich Felker 提交于
      the design for TLS in dynamic-linked programs is mostly complete too,
      but I have not yet implemented it. cost is nonzero but still low for
      programs which do not use TLS and/or do not use threads (a few hundred
      bytes of new code, plus dependency on memcpy). i believe it can be
      made smaller at some point by merging __init_tls and __init_security
      into __libc_start_main and avoiding duplicate auxv-parsing code.
      
      at the same time, I've also slightly changed the logic pthread_create
      uses to allocate guard pages to ensure that guard pages are not
      counted towards commit charge.
      8431d797
  4. 30 9月, 2012 2 次提交
  5. 29 9月, 2012 1 次提交
    • R
      microblaze port · 8c0a3d9e
      Rich Felker 提交于
      based on initial work by rdp, with heavy modifications. some features
      including threads are untested because qemu app-level emulation seems
      to be broken and I do not have a proper system image for testing.
      8c0a3d9e
  6. 07 9月, 2012 1 次提交
    • R
      use restrict everywhere it's required by c99 and/or posix 2008 · 400c5e5c
      Rich Felker 提交于
      to deal with the fact that the public headers may be used with pre-c99
      compilers, __restrict is used in place of restrict, and defined
      appropriately for any supported compiler. we also avoid the form
      [restrict] since older versions of gcc rejected it due to a bug in the
      original c99 standard, and instead use the form *restrict.
      400c5e5c
  7. 27 8月, 2012 2 次提交
  8. 26 8月, 2012 5 次提交
  9. 19 8月, 2012 1 次提交
    • R
      make dynamic linker report all failures before exiting · 04109502
      Rich Felker 提交于
      before, only the first library that failed to load or symbol that
      failed to resolve was reported, and then the dynamic linker
      immediately exited. when attempting to fix a library compatibility
      issue, this is about the worst possible behavior. now we print all
      errors as they occur and exit at the very end if errors were
      encountered.
      04109502
  10. 18 8月, 2012 1 次提交
  11. 08 8月, 2012 1 次提交
  12. 06 8月, 2012 4 次提交
    • R
      dlsym RTLD_NEXT support for mips · 3a1e7566
      Rich Felker 提交于
      untested
      3a1e7566
    • R
      7d9a5c6a
    • R
      59f4086c
    • R
      mips dynamic linker support · babf8201
      Rich Felker 提交于
      not heavily tested, but the basics are working. the basic concept is
      that the dynamic linker entry point code invokes a pure-PIC (no global
      accesses) C function in reloc.h to perform the early GOT relocations
      needed to make the dynamic linker itself functional, then invokes
      __dynlink like on other archs. since mips uses some ugly arch-specific
      hacks to optimize relocating the GOT (rather than just using the
      normal DT_REL[A] tables like on other archs), the dynamic linker has
      been modified slightly to support calling arch-specific relocation
      code in reloc.h.
      
      most of the actual mips-specific behavior was developed by reading the
      output of readelf on libc.so and simple executable files. i could not
      find good reference information on which relocation types need to be
      supported or their semantics, so it's possible that some legitimate
      usage cases will not work yet.
      babf8201
  13. 05 8月, 2012 3 次提交
  14. 13 7月, 2012 1 次提交
  15. 11 7月, 2012 2 次提交
    • R
      make dynamic linker depend on -DSHARED not -fPIC · e864a290
      Rich Felker 提交于
      if libc.a is compiled PIC for use in static PIE code, this should not
      cause the dynamic linker (which still does not support static-linked
      main program) to be built into libc.a.
      e864a290
    • R
      fix lots of breakage on dlopen, mostly with explicit pathnames · 0420b874
      Rich Felker 提交于
      most importantly, the name for such libs was being set from an
      uninitialized buffer. also, shortname always had an initial '/'
      character, making it useless for looking up already-loaded libraries
      by name, and thus causing repeated searches through the library path.
      
      major changes now:
      
      - shortname is the base name for library lookups with no explicit
        pathname. it's initially clear for libraries loaded with an explicit
        pathname (and for the main program), but will be set if the same
        library (detected via inodes match) is later found by a search.
      
      - exact name match is never used to identify libraries loaded with an
        explicit pathname. in this case, there's no explicit search, so we
        can just stat the file and check for inode match.
      0420b874
  16. 08 7月, 2012 1 次提交
    • R
      fix dlsym RTLD_NEXT support · d93e028c
      Rich Felker 提交于
      previously this was being handled the same as a library-specific,
      dependency-order lookup on the next library in the global chain, which
      is likely to be utterly meaningless. instead the lookup needs to be in
      the global namespace, but omitting the initial portion of the global
      library chain up through the calling library.
      d93e028c
  17. 10 6月, 2012 1 次提交
  18. 06 6月, 2012 1 次提交
    • R
      treat failure of mprotect in map_library as a fatal load failure · f7d15dcc
      Rich Felker 提交于
      the error will propagate up and be printed to the user at program
      start time; at runtime, dlopen will just fail and leave a message for
      dlerror.
      
      previously, if mprotect failed, subsequent attempts to perform
      relocations would crash the program. this was resulting in an
      increasing number of false bug reports on grsec systems where rwx
      permission is not possible in cases where users were wrongly
      attempting to use non-PIC code in shared libraries. supporting that
      usage is in theory possible, but the x86_64 toolchain does not even
      support textrels, and the cost of keeping around the necessary
      information to handle textrels without rwx permissions is
      disproportionate to the benefit (which is essentially just supporting
      broken library setups on grsec machines).
      
      also, i unified the error-out code in map_library now that there are 3
      places from which munmap might have to be called.
      f7d15dcc
  19. 28 5月, 2012 1 次提交