1. 16 6月, 2015 1 次提交
    • R
      fix btowc corner case · 38e2f727
      Rich Felker 提交于
      btowc is required to interpret its argument by conversion to unsigned
      char, unless the argument is equal to EOF. since the conversion to
      produces a non-character value anyway, we can just unconditionally
      convert, for now.
      38e2f727
  2. 14 6月, 2015 3 次提交
    • S
      arm: add vdso support · ee59c296
      Szabolcs Nagy 提交于
      vdso will be available on arm in linux v4.2, the user-space code
      for it is in kernel commit 8512287a8165592466cb9cb347ba94892e9c56a5
      ee59c296
    • R
      refactor malloc's expand_heap to share with __simple_malloc · e3bc22f1
      Rich Felker 提交于
      this extends the brk/stack collision protection added to full malloc
      in commit 276904c2 to also protect the
      __simple_malloc function used in static-linked programs that don't
      reference the free function.
      
      it also extends support for using mmap when brk fails, which full
      malloc got in commit 54463033, to
      __simple_malloc.
      
      since __simple_malloc may expand the heap by arbitrarily large
      increments, the stack collision detection is enhanced to detect
      interval overlap rather than just proximity of a single address to the
      stack. code size is increased a bit, but this is partly offset by the
      sharing of code between the two malloc implementations, which due to
      linking semantics, both get linked in a program that needs the full
      malloc with realloc/free support.
      e3bc22f1
    • R
      remove cancellation points in stdio · 4ef9b828
      Rich Felker 提交于
      commit 58165923 added these optional
      cancellation points on the basis that cancellable stdio could be
      useful, to unblock threads stuck on stdio operations that will never
      complete. however, the only way to ensure that cancellation can
      achieve this is to violate the rules for side effects when
      cancellation is acted upon, discarding knowledge of any partial data
      transfer already completed. our implementation exhibited this behavior
      and was thus non-conforming.
      
      in addition to improving correctness, removing these cancellation
      points moderately reduces code size, and should significantly improve
      performance on i386, where sysenter/syscall instructions can be used
      instead of "int $128" for non-cancellable syscalls.
      4ef9b828
  3. 13 6月, 2015 3 次提交
    • R
      fix idiom for setting stdio stream orientation to wide · 536c6d5a
      Rich Felker 提交于
      the old idiom, f->mode |= f->mode+1, was adapted from the idiom for
      setting byte orientation, f->mode |= f->mode-1, but the adaptation was
      incorrect. unless the stream was alreasdy set byte-oriented, this code
      incremented f->mode each time it was executed, which would eventually
      lead to overflow. it could be fixed by changing it to f->mode |= 1,
      but upcoming changes will require slightly more work at the time of
      wide orientation, so it makes sense to just call fwide. as an
      optimization in the single-character functions, fwide is only called
      if the stream is not already wide-oriented.
      536c6d5a
    • R
      add printing of null %s arguments as "(null)" in wide printf · f8f565df
      Rich Felker 提交于
      this is undefined, but supported in our implementation of the normal
      printf, so for consistency the wide variant should support it too.
      f8f565df
    • R
      add %m support to wide printf · f9e25d81
      Rich Felker 提交于
      f9e25d81
  4. 11 6月, 2015 1 次提交
  5. 10 6月, 2015 3 次提交
    • 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
    • R
      in malloc, refuse to use brk if it grows into stack · 276904c2
      Rich Felker 提交于
      the linux/nommu fdpic ELF loader sets up the brk range to overlap
      entirely with the main thread's stack (but growing from opposite
      ends), so that the resulting failure mode for malloc is not to return
      a null pointer but to start returning pointers to memory that overlaps
      with the caller's stack. needless to say this extremely dangerous and
      makes brk unusable.
      
      since it's non-trivial to detect execution environments that might be
      affected by this kernel bug, and since the severity of the bug makes
      any sort of detection that might yield false-negatives unsafe, we
      instead check the proximity of the brk to the stack pointer each time
      the brk is to be expanded. both the main thread's stack (where the
      real known risk lies) and the calling thread's stack are checked. an
      arbitrary gap distance of 8 MB is imposed, chosen to be larger than
      linux default main-thread stack reservation sizes and larger than any
      reasonable stack configuration on nommu.
      
      the effeciveness of this patch relies on an assumption that the amount
      by which the brk is being grown is smaller than the gap limit, which
      is always true for malloc's use of brk. reliance on this assumption is
      why the check is being done in malloc-specific code and not in __brk.
      276904c2
    • R
      fix spurious errors from pwd/grp functions when nscd backend is absent · bd1eacea
      Rich Felker 提交于
      for several pwd/grp functions, the only way the caller can distinguish
      between a successful negative result ("no such user/group") and an
      internal error is by clearing errno before the call and checking errno
      afterwards. the nscd backend support code correctly simulated a
      not-found response on systems where such a backend is not running, but
      failed to restore errno.
      
      this commit also fixed an outdated/incorrect comment.
      bd1eacea
  6. 08 6月, 2015 1 次提交
    • R
      fix regression in pre-v7 arm on kernels with kuser helper removed · 75ce4503
      Rich Felker 提交于
      the arm atomics/TLS runtime selection code is called from
      __set_thread_area and depends on having libc.auxv and __hwcap
      available. commit 71f099cb moved the
      first call to __set_thread_area to the top of dynamic linking stage 3,
      before this data is made available, causing the runtime detection code
      to always see __hwcap as zero and thereby select the atomics/TLS
      implementations based on kuser helper.
      
      upcoming work on superh will use similar runtime detection.
      
      ideally this early-init code should be cleanly refactored and shared
      between the dynamic linker and static-linked startup.
      75ce4503
  7. 07 6月, 2015 6 次提交
  8. 05 6月, 2015 2 次提交
  9. 04 6月, 2015 1 次提交
    • R
      fix dynamic linker regression processing R_*_NONE type relocations · b6a6cd70
      Rich Felker 提交于
      commit f3ddd173 inadvertently removed
      the early check for "none" type relocations, causing the address
      dso->base+0 to be dereferenced to obtain an addend. shared libraries,
      (including libc.so) and PIE executables were unaffected, since their
      base addresses are the actual address of their mappings and are
      readable. non-PIE main executables, however, have a base address of 0
      because their load addresses are absolute and not offset at load time.
      
      in practice none-type relocations do not arise with toolchains that
      are in use except on mips, and on mips it's moderately rare for a
      non-PIE executable to have a relocation table, since the mips-specific
      got processing serves in its place for most purposes.
      b6a6cd70
  10. 03 6月, 2015 1 次提交
  11. 29 5月, 2015 2 次提交
    • R
      fix failure of ungetc and ungetwc to work on files in eof status · 2b4fcfda
      Rich Felker 提交于
      these functions were written to handle clearing eof status, but failed
      to account for the __toread function's handling of eof. with this
      patch applied, __toread still returns EOF when the file is in eof
      status, so that read operations will fail, but it also sets up valid
      buffer pointers for read mode, which are set to the end of the buffer
      rather than the beginning in order to make the whole buffer available
      to ungetc/ungetwc.
      
      minor changes to __uflow were needed since it's now possible to have
      non-zero buffer pointers while in eof status. as made, these changes
      remove a 'fast path' bypassing the function call to __toread, which
      could be reintroduced with slightly different logic, but since
      ordinary files have a syscall in f->read, optimizing the code path
      does not seem worthwhile.
      
      the __stdio_read function is also updated not to zero the read buffer
      pointers on eof/error. while not necessary for correctness, this
      change avoids the overhead of calling __toread in ungetc after
      reaching eof, and it also reduces code size and increases consistency
      with the fmemopen read operation which does not zero the pointers.
      2b4fcfda
    • R
      add missing legacy LFS64 macros in sys/resource.h · b6e7c664
      Rich Felker 提交于
      based on patch by Felix Janda, with RLIM64_SAVED_CUR and
      RLIM64_SAVED_MAX added for completeness.
      b6e7c664
  12. 28 5月, 2015 2 次提交
    • S
      configure: work around compilers that merely warn for unknown options · fc431d3f
      Shiz 提交于
      some compilers (such as clang) accept unknown options without error,
      but then print warnings on each invocation, cluttering the build
      output and burying meaningful warnings. this patch makes configure's
      tryflag and tryldflag functions use additional options to turn the
      unknown-option warnings into errors, if available, but only at check
      time. these options are not output in config.mak to avoid the risk of
      spurious build breakage; if they work, they will have already done
      their job at configure time.
      fc431d3f
    • R
      implement fail-safe static locales for newlocale · aeeac9ca
      Rich Felker 提交于
      this frees applications which need to make temporary use of the C
      locale (via uselocale) from the possibility that newlocale might fail.
      
      the C.UTF-8 locale is also provided as a static locale. presently they
      behave the same, but this may change in the future.
      aeeac9ca
  13. 27 5月, 2015 3 次提交
    • R
      rename internal locale file handling locale maps · 11858d31
      Rich Felker 提交于
      since the __setlocalecat function was removed, the filename
      __setlocalecat.c no longer made sense.
      11858d31
    • R
      overhaul locale internals to treat categories roughly uniformly · 61a3364d
      Rich Felker 提交于
      previously, LC_MESSAGES was treated specially as the only category
      which could be set to a locale name without a definition file, in
      order to facilitate gettext message translations when no libc locale
      was available. LC_NUMERIC was completely un-settable, and LC_CTYPE
      stored a flag intended to be used for a possible future byte-based C
      locale, instead of storing a __locale_map pointer like the other
      categories use.
      
      this patch changes all categories to be represented by pointers to
      __locale_map structures, and allows locale names without definition
      files to be treated as valid locales with trivial definition when used
      in any category. outwardly visible functional changes should be minor,
      limited mainly to the strings read back from setlocale and the way
      gettext handles translations in categories other than LC_MESSAGES.
      
      various internal refactoring has also been performed, and improvements
      in const correctness have been made.
      61a3364d
    • R
      replace atomics with locks in locale-setting code · 63c188ec
      Rich Felker 提交于
      this is part of a general program of removing direct use of atomics
      where they are not necessary to meet correctness or performance needs,
      but in this case it's also an optimization. only the global locale
      needs synchronization; allocated locales referenced with locale_t
      handles are immutable during their lifetimes, and using atomics to
      initialize them increases their cost of setup.
      63c188ec
  14. 26 5月, 2015 6 次提交
    • R
      add rcrt1 start file for fully static-linked PIE · dc031ee0
      Rich Felker 提交于
      static-linked PIE files need startup code to relocate themselves, much
      like the dynamic linker does. rcrt1.c reuses the code in dlstart.c,
      stage 1 of the dynamic linker, which in turn reuses crt_arch.h, to
      achieve static PIE with no new code. only relative relocations are
      supported.
      
      existing toolchains that don't yet support static PIE directly can be
      repurposed by passing "-shared -Wl,-Bstatic -Wl,-Bsymbolic" instead of
      "-static -pie" and substituting rcrt1.o in place of crt1.o.
      
      all libraries being linked must be built as PIC/PIE; TEXTRELs are not
      supported at this time.
      dc031ee0
    • R
      fix incorrect application of visibility to Scrt1.o · ed0c8249
      Rich Felker 提交于
      commit de2b67f8 attempted to avoid
      having vis.h affect crt files, but the Makefile variable used,
      CRT_LIBS, refers to the final output copies in the lib directory, not
      the copies in the crt build directory, and thus the -DCRT was not
      applied.
      
      while unlikely to be noticed, this regression probably broke
      production of PIE executables whose main functions are not in the
      executable but rather a shared library.
      ed0c8249
    • R
      reprocess all libc/ldso symbolic relocations in dynamic linking stage 3 · 9bbddf73
      Rich Felker 提交于
      commit f3ddd173 introduced early
      relocations and subsequent reprocessing as part of the dynamic linker
      bootstrap overhaul, to allow use of arbitrary libc functions before
      the main application and libraries are loaded, but only reprocessed
      GOT/PLT relocation types.
      
      commit c093e2e8 added reprocessing of
      non-GOT/PLT relocations to fix an actual regression that was observed
      on powerpc, but only for RELA format tables with out-of-line addends.
      REL table (inline addends at the relocation address) reprocessing is
      trickier because the first relocation pass clobbers the addends.
      
      this patch extends symbolic relocation reprocessing for libc/ldso to
      support all relocation types, whether REL or RELA format tables are
      used. it is believed not to alter behavior on any existing archs for
      the current dynamic linker and libc code. the motivations for this
      change are consistency and future-proofing. it ensures that behavior
      does not differ depending on whether REL or RELA tables are used,
      which could lead to undetected arch-specific bugs. it also ensures
      that, if in the future code depending on additional relocation types
      is added to libc.so, either at the source level or as part of the
      compiler runtime that gets pulled in (for example, soft-float with TLS
      for fenv), the new code will work properly.
      
      the implementation concept is simple: stage 2 of the dynamic linker
      counts the number of symbolic relocations in the libc/ldso REL table
      and allocates a VLA to save their addends into; stage 3 then uses the
      saved addends in place of the inline ones which were clobbered. for
      stack safety, a hard limit (currently 4k) is imposed on the number of
      such addends; this should be a couple orders of magnitude larger than
      the actual need. this number is not a runtime variable that could
      break fail-safety; it is constant for a given libc.so build.
      9bbddf73
    • R
      move call to dynamic linker stage-3 into stage-2 function · 768b82c6
      Rich Felker 提交于
      this move eliminates a duplicate "by-hand" symbol lookup loop from the
      stage-1 code and replaces it with a call to find_sym, which can be
      used once we're in stage 2. it reduces the size of the stage 1 code,
      which is helpful because stage 1 will become the crt start file for
      static-PIE executables, and it will allow stage 3 to access stage 2's
      automatic storage, which will be important in an upcoming commit.
      768b82c6
    • R
      mark mips crt code as code · 967bcbf6
      Rich Felker 提交于
      otherwise disassemblers treat it as data.
      967bcbf6
    • R
      mark mips cancellable syscall code as code · 7b75c487
      Rich Felker 提交于
      otherwise disassemblers treat it as data.
      7b75c487
  15. 25 5月, 2015 3 次提交
    • R
      simplify/shrink relocation processing in dynamic linker stage 1 · 0e0e4942
      Rich Felker 提交于
      the outer-loop approach made sense when we were also processing
      DT_JMPREL, which might be in REL or RELA form, to avoid major code
      duplication. commit 09db855b removed
      processing of DT_JMPREL, and in the remaining two tables, the format
      (REL or RELA) is known by the name of the table. simply writing two
      versions of the loop results in smaller and simpler code.
      0e0e4942
    • R
      remove processing of DT_JMPREL from dynamic linker stage 1 bootstrap · 09db855b
      Rich Felker 提交于
      the DT_JMPREL relocation table necessarily consists entirely of
      JMP_SLOT (REL_PLT in internal nomenclature) relocations, which are
      symbolic; they cannot be resolved in stage 1, so there is no point in
      processing them.
      09db855b
    • R
      fix stack alignment code in mips crt_arch.h · 9f26ebde
      Rich Felker 提交于
      the instruction used to align the stack, "and $sp, $sp, -8", does not
      actually exist; it's expanded to 2 instructions using the 'at'
      (assembler temporary) register, and thus cannot be used in a branch
      delay slot. since alignment mod 16 commutes with subtracting 8, simply
      swapping these two operations fixes the problem.
      
      crt1.o was not affected because it's still being generated from a
      dedicated asm source file. dlstart.lo was not affected because the
      stack pointer it receives is already aligned by the kernel. but
      Scrt1.o was affected in cases where the dynamic linker gave it a
      misaligned stack pointer.
      9f26ebde
  16. 22 5月, 2015 2 次提交