1. 16 4月, 2014 3 次提交
    • R
      add namespace-protected name for sysinfo function · de20a8ff
      Rich Felker 提交于
      it will be needed to implement some things in sysconf, and the syscall
      can't easily be used directly because the x32 syscall uses the wrong
      structure layout. the l (uncreative, for "linux") prefix is used since
      the symbol name __sysinfo is already taken for AT_SYSINFO from the aux
      vector.
      
      the way the x32 override of this function works is also changed to be
      simpler and avoid the useless jump instruction.
      de20a8ff
    • R
      in sysconf, use getrlimit function rather than raw syscall for rlimits · 6cf7d17f
      Rich Felker 提交于
      the syscall is deprecated (replaced by prlimit64) and does not work
      correctly on x32. this change mildly increases size, but is likely
      needed anyway for newer archs that might omit deprecated syscalls.
      6cf7d17f
    • R
      avoid linear-time if/else special cases in sysconf · 233767b4
      Rich Felker 提交于
      the previous handling of cases that could not fit in the 16-bit table
      or which required non-constant results was extremely ugly and could
      not scale. the new code remaps these keys into a contiguous range
      that's efficient for a switch statement.
      233767b4
  2. 15 4月, 2014 1 次提交
  3. 12 4月, 2014 2 次提交
    • R
      use hidden visibility rather than protected for syscall internals · 83c98aac
      Rich Felker 提交于
      the use of visibility at all is purely an optimization to avoid the
      need for the caller to load the GOT register or similar to prepare for
      a call via the PLT. there is no reason for these symbols to be
      externally visible, so hidden works just as well as protected, and
      using protected visibility is undesirable due to toolchain bugs and
      the lack of testing it receives.
      
      in particular, GCC's microblaze target is known to generate symbolic
      relocations in the GOT for functions with protected visibility. this
      in turn results in a dynamic linker which crashes under any nontrivial
      usage that requires making a syscall before symbolic relocations are
      processed.
      83c98aac
    • S
      math: fix aliasing violation in long double wrappers · 73c870ed
      Szabolcs Nagy 提交于
      modfl and sincosl were passing long double* instead of double*
      to the wrapped double precision functions (on archs where long
      double and double have the same size).
      This is fixed now by using temporaries (this is not optimized
      to a single branch so the generated code is a bit bigger).
      Found by Morten Welinder.
      73c870ed
  4. 10 4月, 2014 1 次提交
    • T
      fix search past the end of haystack in memmem · 6fbdeff0
      Timo Teräs 提交于
      to optimize the search, memchr is used to find the first occurrence of
      the first character of the needle in the haystack before switching to
      a search for the full needle. however, the number of characters
      skipped by this first step were not subtracted from the haystack
      length, causing memmem to search past the end of the haystack.
      6fbdeff0
  5. 08 4月, 2014 1 次提交
    • R
      fix printf rounding with %g for some corner case midpoints · e94d0692
      Rich Felker 提交于
      the subsequent rounding code assumes the end pointer (z) accurately
      reflects the end of significance in the decimal expansion, but for
      certain large integers, spurious trailing zero slots were left behind
      when applying the binary exponent.
      
      issue reported by Morten Welinder; the analysis of the cause was
      performed by nsz, who also proposed this change.
      e94d0692
  6. 07 4月, 2014 4 次提交
    • R
      add getauxval function · 21ada94c
      Rich Felker 提交于
      in a sense this implementation is incomplete since it doesn't provide
      the HWCAP_* macros for use with AT_HWCAP, which is perhaps the most
      important intended usage case for getauxval. they will be added at a
      later time.
      21ada94c
    • R
      fix failure of printf %g to strip trailing zeros in some cases · 89740868
      Rich Felker 提交于
      the code to strip trailing zeros was only looking in the last slot for
      up to 9 zeros, assuming that the rounding code had already removed
      fully-zero slots from the end. however, this ignored cases where the
      rounding code did not run at all, which occur when the value being
      printed is exactly representable in the requested precision.
      
      the simplest solution is to move the code that strips trailing zero
      slots to run unconditionally, immediately after rounding, rather than
      as the last step of rounding.
      89740868
    • R
      fix carry into uninitialized slots during printf floating point rounding · 109048e0
      Rich Felker 提交于
      in cases where rounding caused a carry, the slot into which the carry
      was taking place was unconditionally treated as valid, despite the
      possibility that it could be a new slot prior to the beginning of the
      existing non-rounded number. in theory this could lead to unbounded
      runaway carry, but in order for that to happen, the whole
      uninitialized buffer would need to have been pre-filled with 32-bit
      integer values greater than or equal to 999999999.
      
      patch based on proposed fix by Morten Welinder, who also discovered
      and reported the bug.
      109048e0
    • R
      remove some cruft from libc/tls init code · 7e8b0761
      Rich Felker 提交于
      7e8b0761
  7. 05 4月, 2014 1 次提交
  8. 03 4月, 2014 4 次提交
    • R
      add __sigsetjmp ABI-compat alias for sigsetjmp · b9b2db2f
      Rich Felker 提交于
      b9b2db2f
    • S
      remove struct elem entirely from hsearch.c · 141d3b5c
      sin 提交于
      There are two changes here, both of which make sense to be done in a
      single patch:
      
      - Remove hash from struct elem and compute it at runtime wherever
        necessary.
      - Eliminate struct elem and use ENTRY directly.
      
      As a result we cut down on the memory usage as each element in the
      hash table now contains only an ENTRY not an ENTRY + size_t for the
      hash. The downside is that the hash needs to be computed at runtime.
      141d3b5c
    • S
      implement hcreate_r, hdestroy_r and hsearch_r · fe1ba7db
      sin 提交于
      the size and alignment of struct hsearch_data are matched to the glibc
      definition for binary compatibility. the members of the structure do
      not match, which should not be a problem as long as applications
      correctly treat the structure as opaque.
      
      unlike the glibc implementation, this version of hcreate_r does not
      require the caller to zero-fill the structure before use.
      fe1ba7db
    • R
      avoid malloc failure for small requests when brk can't be extended · 54463033
      Rich Felker 提交于
      this issue mainly affects PIE binaries and execution of programs via
      direct invocation of the dynamic linker binary: depending on kernel
      behavior, in these cases the initial brk may be placed at at location
      where it cannot be extended, due to conflicting adjacent maps.
      
      when brk fails, mmap is used instead to expand the heap. in order to
      avoid expensive bookkeeping for managing fragmentation by merging
      these new heap regions, the minimum size for new heap regions
      increases exponentially in the number of regions. this limits the
      number of regions, and thereby the number of fixed fragmentation
      points, to a quantity which is logarithmic with respect to the size of
      virtual address space and thus negligible. the exponential growth is
      tuned so as to avoid expanding the heap by more than approximately 50%
      of its current total size.
      54463033
  9. 26 3月, 2014 5 次提交
  10. 25 3月, 2014 3 次提交
    • R
      fix pointer type mismatch and misplacement of const · 689e0e6b
      Rich Felker 提交于
      689e0e6b
    • T
      fix confstr return value · 0a8d9828
      Timo Teräs 提交于
      per the specification, the terminating null byte is counted.
      0a8d9828
    • R
      always initialize thread pointer at program start · dab441ae
      Rich Felker 提交于
      this is the first step in an overhaul aimed at greatly simplifying and
      optimizing everything dealing with thread-local state.
      
      previously, the thread pointer was initialized lazily on first access,
      or at program startup if stack protector was in use, or at certain
      random places where inconsistent state could be reached if it were not
      initialized early. while believed to be fully correct, the logic was
      fragile and non-obvious.
      
      in the first phase of the thread pointer overhaul, support is retained
      (and in some cases improved) for systems/situation where loading the
      thread pointer fails, e.g. old kernels.
      
      some notes on specific changes:
      
      - the confusing use of libc.main_thread as an indicator that the
        thread pointer is initialized is eliminated in favor of an explicit
        has_thread_pointer predicate.
      
      - sigaction no longer needs to ensure that the thread pointer is
        initialized before installing a signal handler (this was needed to
        prevent a situation where the signal handler caused the thread
        pointer to be initialized and the subsequent sigreturn cleared it
        again) but it still needs to ensure that implementation-internal
        thread-related signals are not blocked.
      
      - pthread tsd initialization for the main thread is deferred in a new
        manner to minimize bloat in the static-linked __init_tp code.
      
      - pthread_setcancelstate no longer needs special handling for the
        situation before the thread pointer is initialized. it simply fails
        on systems that cannot support a thread pointer, which are
        non-conforming anyway.
      
      - pthread_cleanup_push/pop now check for missing thread pointer and
        nop themselves out in this case, so stdio no longer needs to avoid
        the cancellable path when the thread pointer is not available.
      
      a number of cases remain where certain interfaces may crash if the
      system does not support a thread pointer. at this point, these should
      be limited to pthread interfaces, and the number of such cases should
      be fewer than before.
      dab441ae
  11. 24 3月, 2014 2 次提交
    • R
      reduce static linking overhead from TLS support by inlining mmap syscall · 98221c36
      Rich Felker 提交于
      the external mmap function is heavy because it has to handle error
      reporting that the kernel cannot do, and has to do some locking for
      arcane race-condition-avoidance purposes. for allocating initial TLS,
      we do not need any of that; the raw syscall suffices.
      
      on i386, this change shaves off 13% of the size of .text for the empty
      program.
      98221c36
    • R
      include header that declares __syscall_ret where it's defined · 30c1205a
      Rich Felker 提交于
      in general, we aim to always include the header that's declaring a
      function before defining it so that the compiler can check that
      prototypes match.
      
      additionally, the internal syscall.h declares __syscall_ret with a
      visibility attribute to improve code generation for shared libc (to
      prevent gratuitous GOT-register loads). this declaration should be
      visible at the point where __syscall_ret is defined, too, or the
      inconsistency could theoretically lead to problems at link-time.
      30c1205a
  12. 19 3月, 2014 2 次提交
  13. 17 3月, 2014 1 次提交
    • R
      fix negated error codes from ptsname_r · 66193171
      Rich Felker 提交于
      the incorrect error codes also made their way into errno when
      __ptsname_r was called by plain ptsname, which reports errors via
      errno rather than a return value.
      66193171
  14. 14 3月, 2014 1 次提交
    • R
      semctl: fix UB causing crashes on powerpc · 2b47a7af
      rofl0r 提交于
      it's UB to fetch variadic args when none are passed, and this caused
      real crashes on ppc due to its calling convention, which defines that
      for variadic functions aggregate types be passed as pointers.
      the assignment caused that pointer to get dereferenced, resulting in
      a crash.
      2b47a7af
  15. 09 3月, 2014 2 次提交
    • R
      fix incorrect rounding in printf floating point corner cases · 9743a399
      Rich Felker 提交于
      the printf floating point formatting code contains an optimization to
      avoid computing digits that will be thrown away by rounding at the
      specified (or default) precision. while it was correctly retaining all
      places up to the last decimal place to be printed, it was not
      retaining enough precision to see the next nonzero decimal place in
      all cases. this could cause incorrect rounding down in round-to-even
      (default) rounding mode, for example, when printing 0.5+DBL_EPSILON
      with "%.0f".
      
      in the fix, LDBL_MANT_DIG/3 is a lazy (non-sharp) upper bound on the
      number of zeros between any two nonzero decimal digits.
      9743a399
    • R
      fix buffer overflow in printf formatting of denormals with low bit set · ba231cf9
      Rich Felker 提交于
      empirically the overflow was an off-by-one, and it did not seem to be
      overwriting meaningful data. rather than simply increasing the buffer
      size by one, however, I have attempted to make the size obviously
      correct in terms of bounds on the number of iterations for the loops
      that fill the buffer. this still results in no more than a negligible
      size increase of the buffer on the stack (6-7 32-bit slots) and is a
      "safer" fix unless/until somebody wants to do the proof that a smaller
      buffer would suffice.
      ba231cf9
  16. 08 3月, 2014 1 次提交
    • R
      in fcntl, use unsigned long instead of long for variadic argument type · b576766d
      Rich Felker 提交于
      neither is correct; different commands take different argument types,
      and some take no arguments at all. I have a much larger overhaul of
      fcntl prepared to address this, but it's not appropriate to commit
      during freeze.
      
      the immediate problem being addressed affects forward-compatibility on
      x32: if new commands are added and they take pointers, but the
      libc-level fcntl function is not aware of them, using long would
      sign-extend the pointer to 64 bits and give the kernel an invalid
      pointer. on the kernel side, the argument to fcntl is always treated
      as unsigned long, so no harm is done by treating possibly-signed
      integer arguments as unsigned. for every command that takes an integer
      argument except for F_SETOWN, large integer arguments and negative
      arguments are handled identically anyway. in the case of F_SETOWN, the
      kernel is responsible for converting the argument which it received as
      unsigned long to int, so the sign of negative arguments is recovered.
      
      the other problem that will be addressed later is that the type passed
      to va_arg does not match the type in the caller of fcntl. an advanced
      compiler doing cross-translation-unit analysis could potentially see
      this mismatch and issue warnings or otherwise make trouble.
      
      on i386, this patch was confirmed not to alter the code generated by
      gcc 4.7.3. in principle the generated code should not be affected on
      any arch except x32.
      b576766d
  17. 06 3月, 2014 2 次提交
    • R
      x32: fix sysinfo() · dae8ca73
      rofl0r 提交于
      the kernel uses long longs in the struct, but the documentation
      says they're long. so we need to fixup the mismatch between the
      userspace and kernelspace structs.
      since the struct offers a mem_unit member, we can avoid truncation
      by adjusting that value.
      dae8ca73
    • R
      fix strerror on mips: one error code is out of the 8-bit table range · abdd2e48
      Rich Felker 提交于
      if we ever encounter other targets where error codes don't fit in the
      8-bit range, the table should probably just be bumped to 16-bit, but
      for now I don't want to increase the table size on all archs just
      because of a bug in the mips abi.
      abdd2e48
  18. 28 2月, 2014 2 次提交
  19. 26 2月, 2014 1 次提交
    • R
      fix readdir not to set ENOENT when directory is removed while reading · b9f7f2e8
      Rich Felker 提交于
      per POSIX, ENOENT is reserved for invalid stream position; it is an
      optional error and would only happen if the application performs
      invalid seeks on the underlying file descriptor. however, linux's
      getdents syscall also returns ENOENT if the directory was removed
      between the time it was opened and the time of the read. we need to
      catch this case and remap it to simple end-of-file condition (null
      pointer return value like an error, but no change to errno). this
      issue reportedly affects GNU make in certain corner cases.
      
      rather than backing up and restoring errno, I've just changed the
      syscall to be made in a way that doesn't affect errno (via an inline
      syscall rather than a call to the __getdents function). the latter
      still exists for the purpose of providing the public getdents alias
      which sets errno.
      b9f7f2e8
  20. 25 2月, 2014 1 次提交