1. 28 6月, 2016 1 次提交
    • R
      fix failure to obtain EOWNERDEAD status for process-shared robust mutexes · 384d103d
      Rich Felker 提交于
      Linux's documentation (robust-futex-ABI.txt) claims that, when a
      process dies with a futex on the robust list, bit 30 (0x40000000) is
      set to indicate the status. however, what actually happens is that
      bits 0-30 are replaced with the value 0x40000000, i.e. bits 0-29
      (containing the old owner tid) are cleared at the same time bit 30 is
      set.
      
      our userspace-side code for robust mutexes was written based on that
      documentation, assuming that kernel would never produce a futex value
      of 0x40000000, since the low (owner) bits would always be non-zero.
      commit d338b506 introduced this
      assumption explicitly while fixing another bug in how non-recoverable
      status for robust mutexes was tracked. presumably the tests conducted
      at that time only checked non-process-shared robust mutexes, which are
      handled in pthread_exit (which implemented the documented kernel
      protocol, not the actual one) rather than by the kernel.
      
      change pthread_exit robust list processing to match the kernel
      behavior, clearing bits 0-29 while setting bit 30, and use the value
      0x7fffffff instead of 0x40000000 to encode non-recoverable status. the
      choice of value here is arbitrary; any value with at least one of bits
      0-29 set should work just as well,
      384d103d
  2. 09 5月, 2016 1 次提交
  3. 26 4月, 2016 1 次提交
    • R
      fix thread structure/dtv-pointer corruption on powerpc · be999f7a
      Rich Felker 提交于
      per the powerpc psabi, offset 4 of the stack at call time belongs to
      the callee and is used for spilling lr (return address). in addition,
      offset 0 on the stack must contain a pointer to the previous stack
      frame, or a null pointer for the initial stack frame of a thread.
      __clone failed to setup any stack frame on the new thread's stack,
      thereby allowing the start function it called to clobber offset 4 of
      the new thread's struct __pthread, which contains the dtv pointer.
      
      add code to setup a proper stack frame and align the stack pointer to
      a multiple of 16 (also an abi requirement) if it was not already
      aligned.
      be999f7a
  4. 18 4月, 2016 1 次提交
  5. 07 3月, 2016 1 次提交
    • R
      add mips64 port · 83933573
      Rich Felker 提交于
      patch by Mahesh Bodapati and Jaydeep Patil of Imagination
      Technologies.
      83933573
  6. 09 2月, 2016 1 次提交
    • R
      remove workaround for broken mips assemblers · 869a9df5
      Rich Felker 提交于
      the workaround was for a bug that botched .gpword references to local
      labels, applying a nonsensical random offset of -0x4000 to them.
      
      this reverses commit 5e396fb9 and a
      removes a similar hack that was added to syscall_cp.s in the later
      commit 756c8af8. it turns out one
      additional instance of the same idiom, the GETFUNCSYM macro in
      arch/mips/reloc.h, was still affected by the assembler bug and does
      not admit an easy workaround without making assumptions about how the
      macro is used. the previous workarounds made static linking work but
      left the early-stage dynamic linker broken and thus had limited
      usefulness.
      
      instead, affected users (using binutils versions older than 2.20) will
      need to fix the bug on the binutils side; the trivial patch is commit
      453f5985b13e35161984bf1bf657bbab11515aa4 in the binutils-gdb
      repository.
      869a9df5
  7. 05 2月, 2016 2 次提交
    • R
      in mips cancellable syscall asm, don't assume gp register is valid · 756c8af8
      Rich Felker 提交于
      the old __cp_cancel code path loaded the address of __cancel from the
      GOT using the $gp register, which happened to be set to point to the
      correct GOT by the calling C function, but there is no ABI requirement
      that this happen. instead, go the roundabout way and compute the
      address of __cancel via pc-relative and gp-relative addressing
      starting with a fake return address generated by a bal instruction,
      which is the same trick crt1 uses to bootstrap.
      756c8af8
    • R
      avoid using signals when a thread attempts to cancel itself · aecda353
      Rich Felker 提交于
      not only is pthread_kill expensive in this case; it also breaks
      testing under qemu app-level emulation.
      aecda353
  8. 31 1月, 2016 1 次提交
    • R
      fix misaligned pointer-like objects in arm atomics asm source file · 9ee57db8
      Rich Felker 提交于
      this file's .data section was not aligned, and just happened to get
      the correct alignment with past builds. it's likely that the move of
      atomic.s from arch/arm/src to src/thread/arm caused the change in
      alignment, which broke the atomic and thread-pointer access fragments
      on actual armv5 hardware.
      9ee57db8
  9. 22 1月, 2016 4 次提交
    • R
      230bfe1a
    • R
      move x32 sysinfo impl and syscall fixup code out of arch/x32/src · 66215afc
      Rich Felker 提交于
      all such arch-specific translation units are being moved to
      appropriate arch dirs under the main src tree.
      66215afc
    • R
      move arm-specific translation units out of arch/arm/src, to src/*/arm · e617b9ee
      Rich Felker 提交于
      this is possible with the new build system that allows src/*/$(ARCH)/*
      files which do not shadow a file in the parent directory, and yields a
      more logical organization. eventually it will be possible to remove
      arch/*/src from the build system.
      e617b9ee
    • R
      overhaul sh atomics for new atomics framework, add j-core cas.l backend · 61b1e75f
      Rich Felker 提交于
      sh needs runtime-selected atomic backends since there are a number of
      supported models that use non-forwards-compatible (non-smp-compatible)
      atomic mechanisms. previously, the code paths for this were highly
      inefficient since they involved C function calls with multiple
      branches in the callee and heavy spills in the caller. the new code
      performs calls the runtime-selected asm fragment from inline asm with
      extremely minimal clobbers, rather than using a function call.
      
      for the sh4a case where the atomic mechanism is known and there is no
      forward-compatibility issue, the movli.l and movco.l instructions are
      provided as a_ll and a_sc, allowing the new shared atomic.h to
      generate efficient inline versions of all the basic atomic operations
      without needing a cas loop.
      61b1e75f
  10. 12 11月, 2015 2 次提交
    • R
      eliminate use of SHARED macro in __tls_get_addr · 4aaf879e
      Rich Felker 提交于
      this was only a tiny optimization, and static-linked binaries should
      not be calling __tls_get_addr anyway since the linker is supposed to
      perform relaxation, resulting in use of the local-exec TLS model.
      4aaf879e
    • R
      eliminate use of SHARED macro to suppress visibility attributes · 8a8fdf63
      Rich Felker 提交于
      this is the first and simplest stage of removal of the SHARED macro,
      which will eventually allow libc.a and libc.so to be produced from the
      same object files.
      
      the original motivation for these #ifdefs which are now being removed
      was to allow building a static-only libc using a compiler that does
      not support visibility. however, SHARED was the wrong condition to
      test for this anyway; various assembly-language sources refer to
      hidden symbols and declare them with the .hidden directive, making it
      wrong to define the referenced symbols as non-hidden. if there is a
      need in the future to build libc using compilers that lack visibility,
      support could be moved to the build system or perhaps the __PIC__
      macro could be checked instead of SHARED.
      8a8fdf63
  11. 10 11月, 2015 2 次提交
    • R
      explicitly assemble all arm asm sources as UAL · 4e73d121
      Rich Felker 提交于
      these files are all accepted as legacy arm syntax when producing arm
      code, but legacy syntax cannot be used for producing thumb2 with
      access to the full ISA. even after switching to UAL, some asm source
      files contain instructions which are not valid in thumb mode, so these
      will need to be addressed separately.
      4e73d121
    • R
      remove non-working pre-armv4t support from arm asm · 9f290a49
      Rich Felker 提交于
      the idea of the three-instruction sequence being removed was to be
      able to return to thumb code when used on armv4t+ from a thumb caller,
      but also to be able to run on armv4 without the bx instruction
      available (in which case the low bit of lr would always be 0).
      however, without compiler support for generating such a sequence from
      C code, which does not exist and which there is unlikely to be
      interest in implementing, there is little point in having it in the
      asm, and it would likely be easier to add pre-armv4t support via
      enhanced linker handling of R_ARM_V4BX than at the compiler level.
      
      removing this code simplifies adding support for building libc in
      thumb2-only form (for cortex-m).
      9f290a49
  12. 03 11月, 2015 2 次提交
    • R
      use explicit __cp_cancel label in cancellable syscall asm for all archs · 36e8b6a2
      Rich Felker 提交于
      previously, only archs that needed to do stack cleanup defined a
      __cp_cancel label for acting on cancellation in their syscall asm, and
      a default definition was provided by a weak alias to __cancel, the C
      function. this resulted in wrong codegen for arm on gcc versions
      affected by pr 68178 and possibly similar issues (like pr 66609) on
      other archs, and also created an inconsistency where the __cp_begin
      and __cp_end labels were treated as const data but __cp_cancel was
      treated as a function. this in turn caused incorrect code generation
      on archs where function pointers point to function descriptors rather
      than code (for now, only sh/fdpic).
      36e8b6a2
    • R
      properly access mcontext_t program counter in cancellation handler · cb1bf2f3
      Rich Felker 提交于
      using the actual mcontext_t definition rather than an overlaid pointer
      array both improves correctness/readability and eliminates some ugly
      hacks for archs with 64-bit registers bit 32-bit program counter.
      
      also fix UB due to comparison of pointers not in a common array
      object.
      cb1bf2f3
  13. 16 10月, 2015 1 次提交
    • B
      add missing memory barrier to pthread_join · 53cd8c5a
      Bobby Bingham 提交于
      POSIX requires pthread_join to synchronize memory on success.  The
      futex wait inside __timedwait_cp cannot handle this because it's not
      called in all cases.  Also, in the case of a spurious wake, tid can
      become zero between the wake and when the joining thread checks it.
      53cd8c5a
  14. 12 9月, 2015 1 次提交
    • R
      make sh clone asm fdpic-compatible · 234c5846
      Rich Felker 提交于
      clone calls back to a function pointer provided by the caller, which
      will actually be a pointer to a function descriptor on fdpic. the
      obvious solution is to have a separate version of clone for fdpic, but
      I have taken a simpler approach to go around the problem. instead of
      calling the pointed-to function from asm, a direct call is made to an
      internal C function which then calls the pointed-to function. this
      lets the C compiler generate the appropriate calling convention for an
      indirect call with no need for ABI-specific assembly.
      234c5846
  15. 26 6月, 2015 1 次提交
    • R
      fix local-dynamic model TLS on mips and powerpc · 6ba5517a
      Rich Felker 提交于
      the TLS ABI spec for mips, powerpc, and some other (presently
      unsupported) RISC archs has the return value of __tls_get_addr offset
      by +0x8000 and the result of DTPOFF relocations offset by -0x8000. I
      had previously assumed this part of the ABI was actually just an
      implementation detail, since the adjustments cancel out. however, when
      the local dynamic model is used for accessing TLS that's known to be
      in the same DSO, either of the following may happen:
      
      1. the -0x8000 offset may already be applied to the argument structure
      passed to __tls_get_addr at ld time, without any opportunity for
      runtime relocations.
      
      2. __tls_get_addr may be used with a zero offset argument to obtain a
      base address for the module's TLS, to which the caller then applies
      immediate offsets for individual objects accessed using the local
      dynamic model. since the immediate offsets have the -0x8000 adjustment
      applied to them, the base address they use needs to include the
      +0x8000 offset.
      
      it would be possible, but more complex, to store the pointers in the
      dtv[] array with the +0x8000 offset pre-applied, to avoid the runtime
      cost of adding 0x8000 on each call to __tls_get_addr. this change
      could be made later if measurements show that it would help.
      6ba5517a
  16. 20 6月, 2015 1 次提交
    • R
      work around mips detached thread exit breakage due to kernel regression · ce3688ec
      Rich Felker 提交于
      linux kernel commit 46e12c07b3b9603c60fc1d421ff18618241cb081 caused
      the mips syscall mechanism to fail with EFAULT when the userspace
      stack pointer is invalid, breaking __unmapself used for detached
      thread exit. the workaround is to set $sp to a known-valid, readable
      address, and the simplest one to obtain is the address of the current
      function, which is available (per o32 calling convention) in $25.
      ce3688ec
  17. 18 6月, 2015 1 次提交
  18. 16 6月, 2015 4 次提交
    • R
      switch to using trap number 31 for syscalls on sh · 10d0268c
      Rich Felker 提交于
      nominally the low bits of the trap number on sh are the number of
      syscall arguments, but they have never been used by the kernel, and
      some code making syscalls does not even know the number of arguments
      and needs to pass an arbitrary high number anyway.
      
      sh3/sh4 traditionally used the trap range 16-31 for syscalls, but part
      of this range overlapped with hardware exceptions/interrupts on sh2
      hardware, so an incompatible range 32-47 was chosen for sh2.
      
      using trap number 31 everywhere, since it's in the existing sh3/sh4
      range and does not conflict with sh2 hardware, is a proposed
      unification of the kernel syscall convention that will allow binaries
      to be shared between sh2 and sh3/sh4. if this is not accepted into the
      kernel, we can refit the sh2 target with runtime selection mechanisms
      for the trap number, but doing so would be invasive and would entail
      non-trivial overhead.
      10d0268c
    • R
      switch sh port's __unmapself to generic version when running on sh2/nommu · 3366a99b
      Rich Felker 提交于
      due to the way the interrupt and syscall trap mechanism works,
      userspace on sh2 must never set the stack pointer to an invalid value.
      thus, the approach used on most archs, where __unmapself executes with
      no stack for the interval between SYS_munmap and SYS_exit, is not
      viable on sh2.
      
      in order not to pessimize sh3/sh4, the sh asm version of __unmapself
      is not removed. instead it's renamed and redirected through code that
      calls either the generic (safe) __unmapself or the sh3/sh4 asm,
      depending on compile-time and run-time conditions.
      3366a99b
    • R
      add support for sh2 interrupt-masking-based atomics to sh port · f9d84554
      Rich Felker 提交于
      the sh2 target is being considered an ISA subset of sh3/sh4, in the
      sense that binaries built for sh2 are intended to be usable on later
      cpu models/kernels with mmu support. so rather than hard-coding
      sh2-specific atomics, the runtime atomic selection mechanisms that was
      already in place has been extended to add sh2 atomics.
      
      at this time, the sh2 atomics are not SMP-compatible; since the ISA
      lacks actual atomic operations, the new code instead masks interrupts
      for the duration of the atomic operation, producing an atomic result
      on single-core. this is only possible because the kernel/hardware does
      not impose protections against userspace doing so. additional changes
      will be needed to support future SMP systems.
      
      care has been taken to avoid producing significant additional code
      size in the case where it's known at compile-time that the target is
      not sh2 and does not need sh2-specific code.
      f9d84554
    • R
      refactor stdio open file list handling, move it out of global libc struct · 1b0cdc87
      Rich Felker 提交于
      functions which open in-memory FILE stream variants all shared a tail
      with __fdopen, adding the FILE structure to stdio's open file list.
      replacing this common tail with a function call reduces code size and
      duplication of logic. the list is also partially encapsulated now.
      
      function signatures were chosen to facilitate tail call optimization
      and reduce the need for additional accessor functions.
      
      with these changes, static linked programs that do not use stdio no
      longer have an open file list at all.
      1b0cdc87
  19. 10 6月, 2015 1 次提交
    • R
      implement arch-generic version of __unmapself · c30cbcb0
      Rich Felker 提交于
      this can be used to put off writing an asm version of __unmapself for
      new archs, or as a permanent solution on archs where it's not
      practical or even possible to run momentarily with no stack.
      
      the concept here is simple: the caller takes a lock on a global shared
      stack and uses it to make the munmap and exit syscalls. the only trick
      is unlocking, which must be done after the thread exits, and this is
      achieved by using the set_tid_address syscall to have the kernel zero
      and futex-wake the lock word as part of the exit syscall.
      c30cbcb0
  20. 26 5月, 2015 1 次提交
  21. 16 5月, 2015 2 次提交
    • R
      eliminate costly tricks to avoid TLS access for current locale state · 68630b55
      Rich Felker 提交于
      the code being removed used atomics to track whether any threads might
      be using a locale other than the current global locale, and whether
      any threads might have abstract 8-bit (non-UTF-8) LC_CTYPE active, a
      feature which was never committed (still pending). the motivations
      were to support early execution prior to setup of the thread pointer,
      to partially support systems (ancient kernels) where thread pointer
      setup is not possible, and to avoid high performance cost on archs
      where accessing the thread pointer may be very slow.
      
      since commit 19a1fe67, the thread
      pointer is always available, so these hacks are no longer needed.
      removing them greatly simplifies the affected code.
      68630b55
    • R
      in i386 __set_thread_area, don't assume %gs register is initially zero · 707d7c30
      Rich Felker 提交于
      commit f630df09 added logic to handle
      the case where __set_thread_area is called more than once by reusing
      the GDT slot already in the %gs register, and only setting up a new
      GDT slot when %gs is zero. this created a hidden assumption that %gs
      is zero when a new process image starts, which is true in practice on
      Linux, but does not seem to be documented ABI, and fails to hold under
      qemu app-level emulation.
      
      while it would in theory be possible to zero %gs in the entry point
      code, this code is shared between static and dynamic binaries, and
      dynamic binaries must not clobber the value of %gs already setup by
      the dynamic linker.
      
      the alternative solution implemented in this commit simply uses global
      data to store the GDT index that's selected. __set_thread_area should
      only be called in the initial thread anyway (subsequent threads get
      their thread pointer setup by __clone), but even if it were called by
      another thread, it would simply read and write back the same GDT index
      that was already assigned to the initial thread, and thus (in the x86
      memory model) there is no data race.
      707d7c30
  22. 07 5月, 2015 1 次提交
    • R
      fix stack protector crashes on x32 & powerpc due to misplaced TLS canary · 484194db
      Rich Felker 提交于
      i386, x86_64, x32, and powerpc all use TLS for stack protector canary
      values in the default stack protector ABI, but the location only
      matched the ABI on i386 and x86_64. on x32, the expected location for
      the canary contained the tid, thus producing spurious mismatches
      (resulting in process termination) upon fork. on powerpc, the expected
      location contained the stdio_locks list head, so returning from a
      function after calling flockfile produced spurious mismatches. in both
      cases, the random canary was not present, and a predictable value was
      used instead, making the stack protector hardening much less effective
      than it should be.
      
      in the current fix, the thread structure has been expanded to have
      canary fields at all three possible locations, and archs that use a
      non-default location must define a macro in pthread_arch.h to choose
      which location is used. for most archs (which lack TLS canary ABI) the
      choice does not matter.
      484194db
  23. 02 5月, 2015 1 次提交
  24. 22 4月, 2015 3 次提交
  25. 19 4月, 2015 1 次提交
    • R
      make dlerror state and message thread-local and dynamically-allocated · 01d42747
      Rich Felker 提交于
      this fixes truncation of error messages containing long pathnames or
      symbol names.
      
      the dlerror state was previously required by POSIX to be global. the
      resolution of bug 97 relaxed the requirements to allow thread-safe
      implementations of dlerror with thread-local state and message buffer.
      01d42747
  26. 18 4月, 2015 2 次提交