1. 24 7月, 2014 1 次提交
    • R
      implement locale file loading and state for remaining locale categories · 6cb4f91d
      Rich Felker 提交于
      there is still no code which actually uses the loaded locale files, so
      the main observable effect of this commit is that calls to setlocale
      store and give back the names of the selected locales for the
      remaining categories (LC_TIME, LC_COLLATE, LC_MONETARY) if a locale
      file by the requested name could be loaded.
      6cb4f91d
  2. 19 7月, 2014 1 次提交
    • S
      add or1k (OpenRISC 1000) architecture port · 200d1547
      Stefan Kristiansson 提交于
      With the exception of a fenv implementation, the port is fully featured.
      The port has been tested in or1ksim, the golden reference functional
      simulator for OpenRISC 1000.
      It passes all libc-test tests (except the math tests that
      requires a fenv implementation).
      
      The port assumes an or1k implementation that has support for
      atomic instructions (l.lwa/l.swa).
      
      Although it passes all the libc-test tests, the port is still
      in an experimental state, and has yet experienced very little
      'real-world' use.
      200d1547
  3. 03 7月, 2014 1 次提交
    • R
      add locale framework · 0bc03091
      Rich Felker 提交于
      this commit adds non-stub implementations of setlocale, duplocale,
      newlocale, and uselocale, along with the data structures and minimal
      code needed for representing the active locale on a per-thread basis
      and optimizing the common case where thread-local locale settings are
      not in use.
      
      at this point, the data structures only contain what is necessary to
      represent LC_CTYPE (a single flag) and LC_MESSAGES (a name for use in
      finding message translation files). representation for the other
      categories will be added later; the expectation is that a single
      pointer will suffice for each.
      
      for LC_CTYPE, the strings "C" and "POSIX" are treated as special; any
      other string is accepted and treated as "C.UTF-8". for other
      categories, any string is accepted after being truncated to a maximum
      supported length (currently 15 bytes). for LC_MESSAGES, the name is
      kept regardless of whether libc itself can use such a message
      translation locale, since applications using catgets or gettext should
      be able to use message locales libc is not aware of. for other
      categories, names which are not successfully loaded as locales (which,
      at present, means all names) are treated as aliases for "C". setlocale
      never fails.
      
      locale settings are not yet used anywhere, so this commit should have
      no visible effects except for the contents of the string returned by
      setlocale.
      0bc03091
  4. 10 6月, 2014 1 次提交
    • R
      simplify errno implementation · ac31bf27
      Rich Felker 提交于
      the motivation for the errno_ptr field in the thread structure, which
      this commit removes, was to allow the main thread's errno to keep its
      address when lazy thread pointer initialization was used. &errno was
      evaluated prior to setting up the thread pointer and stored in
      errno_ptr for the main thread; subsequently created threads would have
      errno_ptr pointing to their own errno_val in the thread structure.
      
      since lazy initialization was removed, there is no need for this extra
      level of indirection; __errno_location can simply return the address
      of the thread's errno_val directly. this does cause &errno to change,
      but the change happens before entry to application code, and thus is
      not observable.
      ac31bf27
  5. 30 5月, 2014 3 次提交
    • S
      fix for broken kernel side RLIM_INFINITY on mips · 8258014f
      Szabolcs Nagy 提交于
      On 32 bit mips the kernel uses -1UL/2 to mark RLIM_INFINITY (and
      this is the definition in the userspace api), but since it is in
      the middle of the valid range of limits and limits are often
      compared with relational operators, various kernel side logic is
      broken if larger than -1UL/2 limits are used. So we truncate the
      limits to -1UL/2 in get/setrlimit and prlimit.
      
      Even if the kernel side logic consistently treated -1UL/2 as greater
      than any other limit value, there wouldn't be any clean workaround
      that allowed using large limits:
      * using -1UL/2 as RLIM_INFINITY in userspace would mean different
      infinity value for get/setrlimt and prlimit (where infinity is always
      -1ULL) and userspace logic could break easily (just like the kernel
      is broken now) and more special case code would be needed for mips.
      * translating -1UL/2 kernel side value to -1ULL in userspace would
      mean that -1UL/2 limit cannot be set (eg. -1UL/2+1 had to be passed
      to the kernel instead).
      8258014f
    • R
      break down coarse-grained 64-bit-off_t syscall remappings · 106e65d6
      Rich Felker 提交于
      using the existence of SYS_stat64 as the condition for remapping other
      related syscalls is no longer valid, since new archs that omit the old
      syscalls will not have SYS_stat or SYS_stat64, but still potentially
      need SYS_fstat and others remapped. it would probably be possible to
      get by with just one or two extra conditionals, but just breaking them
      all down into separate conditions is robust and not significantly
      heavier for the preprocessor.
      106e65d6
    • R
      fix sendfile syscall to use 64-bit off_t · 55f45bc7
      Rich Felker 提交于
      somehow the remapping of this syscall to the 64-bit version was
      overlooked. the issue was found, and patch provided, by Stefan
      Kristiansson. presumably the reason this bug was not caught earlier is
      that the syscall takes a pointer to off_t rather than a value, so on
      little-endian systems, everything appears to work as long as the
      offset value fits in the low 31 bits. on big-endian systems, though,
      sendfile was presumably completely non-functional.
      55f45bc7
  6. 27 5月, 2014 2 次提交
  7. 25 5月, 2014 1 次提交
    • R
      support kernels with no SYS_open syscall, only SYS_openat · 594c827a
      Rich Felker 提交于
      open is handled specially because it is used from so many places, in
      so many variants (2 or 3 arguments, setting errno or not, and
      cancellable or not). trying to do it as a function would not only
      increase bloat, but would also risk subtle breakage.
      
      this is the first step towards supporting "new" archs where linux
      lacks "old" syscalls.
      594c827a
  8. 18 4月, 2014 1 次提交
  9. 16 4月, 2014 1 次提交
    • R
      add working vdso clock_gettime support, including static linking · 58e75db4
      Rich Felker 提交于
      the vdso symbol lookup code is based on the original 2011 patch by
      Nicholas J. Kain, with some streamlining, pointer arithmetic fixes,
      and one symbol version matching fix.
      
      on the consumer side (clock_gettime), per-arch macros for the
      particular symbol name and version to lookup are added in
      syscall_arch.h, and no vdso code is pulled in on archs which do not
      define these macros. at this time, vdso is enabled only on x86_64.
      
      the vdso support at the dynamic linker level is no longer useful to
      libc, but is left in place for the sake of debuggers (which may need
      the vdso in the link map to find its functions) and possibly use with
      dlsym.
      58e75db4
  10. 12 4月, 2014 1 次提交
    • 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
  11. 25 3月, 2014 1 次提交
    • 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
  12. 24 3月, 2014 1 次提交
    • 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
  13. 28 2月, 2014 1 次提交
    • R
      rename superh port to "sh" for consistency · aacd3486
      Rich Felker 提交于
      linux, gcc, etc. all use "sh" as the name for the superh arch. there
      was already some inconsistency internally in musl: the dynamic linker
      was searching for "ld-musl-sh.path" as its path file despite its own
      name being "ld-musl-superh.so.1". there was some sentiment in both
      directions as to how to resolve the inconsistency, but overall "sh"
      was favored.
      aacd3486
  14. 24 2月, 2014 1 次提交
  15. 23 2月, 2014 2 次提交
  16. 22 2月, 2014 2 次提交
    • R
      internal/syscall.h: add syscall_arg_t macro · 5cc1d920
      rofl0r 提交于
      some 32-on-64 archs require that the actual syscall args be long long.
      in that case syscall_arch.h can define syscall_arg_t to whatever it needs
      and syscall.h picks it up.
      all other archs just use long as usual.
      5cc1d920
    • R
      internal/syscall.h: use a macro for the syscall args casts · bf84967c
      rofl0r 提交于
      this allows syscall_arch.h to define the macro __scc if special
      casting is needed, as is the case for x32, where the actual syscall
      arguments are 64bit, but, in case of pointers, would get sign-extended
      and thus become invalid.
      bf84967c
  17. 07 2月, 2014 1 次提交
    • R
      fix ftello result for append streams with unflushed output · 3af2edee
      Rich Felker 提交于
      when there is unflushed output, ftello (and ftell) compute the logical
      stream position as the underlying file descriptor's offset plus an
      adjustment for the amount of buffered data. however, this can give the
      wrong result for append-mode streams where the unflushed writes should
      adjust the logical position to be at the end of the file, as if a seek
      to end-of-file takes place before the write.
      
      the solution turns out to be a simple trick: when ftello (indirectly)
      calls lseek to determine the current file offset, use SEEK_END instead
      of SEEK_CUR if the stream is append-mode and there's unwritten
      buffered data.
      
      the ISO C rules regarding switching between reading and writing for a
      stream opened in an update mode, along with the POSIX rules regarding
      switching "active handles", conveniently leave undefined the
      hypothetical usage cases where this fix might lead to observably
      incorrect offsets.
      
      the bug being fixed was discovered via the test case for glibc issue
      3af2edee
  18. 12 12月, 2013 1 次提交
  19. 02 12月, 2013 1 次提交
  20. 20 9月, 2013 1 次提交
    • R
      fix potential deadlock bug in libc-internal locking logic · e803829e
      Rich Felker 提交于
      if a multithreaded program became non-multithreaded (i.e. all other
      threads exited) while one thread held an internal lock, the remaining
      thread would fail to release the lock. the the program then became
      multithreaded again at a later time, any further attempts to obtain
      the lock would deadlock permanently.
      
      the underlying cause is that the value of libc.threads_minus_1 at
      unlock time might not match the value at lock time. one solution would
      be returning a flag to the caller indicating whether the lock was
      taken and needs to be unlocked, but there is a simpler solution: using
      the lock itself as such a flag.
      
      note that this flag is not needed anyway for correctness; if the lock
      is not held, the unlock code is harmless. however, the memory
      synchronization properties associated with a_store are costly on some
      archs, so it's best to avoid executing the unlock code when it is
      unnecessary.
      e803829e
  21. 15 9月, 2013 1 次提交
    • S
      support configurable page size on mips, powerpc and microblaze · b20760c0
      Szabolcs Nagy 提交于
      PAGE_SIZE was hardcoded to 4096, which is historically what most
      systems use, but on several archs it is a kernel config parameter,
      user space can only know it at execution time from the aux vector.
      
      PAGE_SIZE and PAGESIZE are not defined on archs where page size is
      a runtime parameter, applications should use sysconf(_SC_PAGE_SIZE)
      to query it. Internally libc code defines PAGE_SIZE to libc.page_size,
      which is set to aux[AT_PAGESZ] in __init_libc and early in __dynlink
      as well. (Note that libc.page_size can be accessed without GOT, ie.
      before relocations are done)
      
      Some fpathconf settings are hardcoded to 4096, these should be actually
      queried from the filesystem using statfs.
      b20760c0
  22. 07 9月, 2013 1 次提交
    • S
      math: remove STRICT_ASSIGN macro · 9b0fcb44
      Szabolcs Nagy 提交于
      gcc did not always drop excess precision according to c99 at assignments
      before version 4.5 even if -std=c99 was requested which caused badly
      broken mathematical functions on i386 when FLT_EVAL_METHOD!=0
      
      but STRICT_ASSIGN was not used consistently and it is worked around for
      old compilers with -ffloat-store so it is no longer needed
      
      the new convention is to get the compiler respect c99 semantics and when
      excess precision is not harmful use float_t or double_t or to specialize
      code using FLT_EVAL_METHOD
      9b0fcb44
  23. 05 9月, 2013 5 次提交
  24. 04 8月, 2013 1 次提交
    • R
      fix multiple bugs in SIGEV_THREAD timers · 7356c255
      Rich Felker 提交于
      1. the thread result field was reused for storing a kernel timer id,
      but would be overwritten if the application code exited or cancelled
      the thread.
      
      2. low pointer values were used as the indicator that the timer id is
      a kernel timer id rather than a thread id. this is not portable, as
      mmap may return low pointers on some conditions. instead, use the fact
      that pointers must be aligned and kernel timer ids must be
      non-negative to map pointers into the negative integer space.
      
      3. signals were not blocked until after the timer thread started, so a
      race condition could allow a signal handler to run in the timer thread
      when it's not supposed to exist. this is mainly problematic if the
      calling thread was the only thread where the signal was unblocked and
      the signal handler assumes it runs in that thread.
      7356c255
  25. 03 8月, 2013 1 次提交
  26. 22 7月, 2013 1 次提交
    • R
      refactor headers, especially alltypes.h, and improve C++ ABI compat · 9448b051
      Rich Felker 提交于
      the arch-specific bits/alltypes.h.sh has been replaced with a generic
      alltypes.h.in and minimal arch-specific bits/alltypes.h.in.
      
      this commit is intended to have no functional changes except:
      - exposing additional symbols that POSIX allows but does not require
      - changing the C++ name mangling for some types
      - fixing the signedness of blksize_t on powerpc (POSIX requires signed)
      - fixing the limit macros for sig_atomic_t on x86_64
      - making dev_t an unsigned type (ABI matching goal, and more logical)
      
      in addition, some types that were wrongly defined with long on 32-bit
      archs were changed to int, and vice versa; this change is
      non-functional except for the possibility of making pointer types
      mismatch, and only affects programs that were using them incorrectly,
      and only at build-time, not runtime.
      
      the following changes were made in the interest of moving
      non-arch-specific types out of the alltypes system and into the
      headers they're associated with, and also will tend to improve
      application compatibility:
      - netdb.h now includes netinet/in.h (for socklen_t and uint32_t)
      - netinet/in.h now includes sys/socket.h and inttypes.h
      - sys/resource.h now includes sys/time.h (for struct timeval)
      - sys/wait.h now includes signal.h (for siginfo_t)
      - langinfo.h now includes nl_types.h (for nl_item)
      
      for the types in stdint.h:
      - types which are of no interest to other headers were moved out of
        the alltypes system.
      - fast types for 8- and 64-bit are hard-coded (at least for now); only
        the 16- and 32-bit ones have reason to vary by arch.
      
      and the following types have been changed for C++ ABI purposes;
      - mbstate_t now has a struct tag, __mbstate_t
      - FILE's struct tag has been changed to _IO_FILE
      - DIR's struct tag has been changed to __dirstream
      - locale_t's struct tag has been changed to __locale_struct
      - pthread_t is defined as unsigned long in C++ mode only
      - fpos_t now has a struct tag, _G_fpos64_t
      - fsid_t's struct tag has been changed to __fsid_t
      - idtype_t has been made an enum type (also required by POSIX)
      - nl_catd has been changed from long to void *
      - siginfo_t's struct tag has been removed
      - sigset_t's has been given a struct tag, __sigset_t
      - stack_t has been given a struct tag, sigaltstack
      - suseconds_t has been changed to long on 32-bit archs
      - [u]intptr_t have been changed from long to int rank on 32-bit archs
      - dev_t has been made unsigned
      
      summary of tests that have been performed against these changes:
      - nsz's libc-test (diff -u before and after)
      - C++ ABI check symbol dump (diff -u before, after, glibc)
      - grepped for __NEED, made sure types needed are still in alltypes
      - built gcc 3.4.6
      9448b051
  27. 21 7月, 2013 1 次提交
    • R
      add support for init/fini array in main program, and greatly simplify · 7586360b
      Rich Felker 提交于
      modern (4.7.x and later) gcc uses init/fini arrays, rather than the
      legacy _init/_fini function pasting and crtbegin/crtend ctors/dtors
      system, on most or all archs. some archs had already switched a long
      time ago. without following this change, global ctors/dtors will cease
      to work under musl when building with new gcc versions.
      
      the most surprising part of this patch is that it actually reduces the
      size of the init code, for both static and shared libc. this is
      achieved by (1) unifying the handling main program and shared
      libraries in the dynamic linker, and (2) eliminating the
      glibc-inspired rube goldberg machine for passing around init and fini
      function pointers. to clarify, some background:
      
      the function signature for __libc_start_main was based on glibc, as
      part of the original goal of being able to run some glibc-linked
      binaries. it worked by having the crt1 code, which is linked into
      every application, static or dynamic, obtain and pass pointers to the
      init and fini functions, which __libc_start_main is then responsible
      for using and recording for later use, as necessary. however, in
      neither the static-linked nor dynamic-linked case do we actually need
      crt1.o's help. with dynamic linking, all the pointers are available in
      the _DYNAMIC block. with static linking, it's safe to simply access
      the _init/_fini and __init_array_start, etc. symbols directly.
      
      obviously changing the __libc_start_main function signature in an
      incompatible way would break both old musl-linked programs and
      glibc-linked programs, so let's not do that. instead, the function can
      just ignore the information it doesn't need. new archs need not even
      provide the useless args in their versions of crt1.o. existing archs
      should continue to provide it as long as there is an interest in
      having newly-linked applications be able to run on old versions of
      musl; at some point in the future, this support can be removed.
      7586360b
  28. 17 7月, 2013 1 次提交
  29. 30 6月, 2013 1 次提交
  30. 23 6月, 2013 1 次提交
    • R
      fix major scanf breakage with unbuffered streams, fmemopen, etc. · c2080450
      Rich Felker 提交于
      the shgetc api, used internally in scanf and int/float scanning code
      to handle field width limiting and pushback, was designed assuming
      that pushback could be achieved via a simple decrement on the file
      buffer pointer. this only worked by chance for regular FILE streams,
      due to the linux readv bug workaround in __stdio_read which moves the
      last requested byte through the buffer rather than directly back to
      the caller. for unbuffered streams and streams not using __stdio_read
      but some other underlying read function, the first character read
      could be completely lost, and replaced by whatever junk happened to be
      in the unget buffer.
      
      to fix this, simply have shgetc, when it performs an underlying read
      operation on the stream, store the character read at the -1 offset
      from the read buffer pointer. this is valid even for unbuffered
      streams, as they have an unget buffer located just below the start of
      the zero-length buffer. the check to avoid storing the character when
      it is already there is to handle the possibility of read-only buffers.
      no application-exposed FILE types are allowed to use read-only
      buffers, but sscanf and strto* may use them internally when calling
      functions which use the shgetc api.
      c2080450
  31. 27 4月, 2013 1 次提交
    • R
      transition to using functions for internal signal blocking/restoring · 2c074b0d
      Rich Felker 提交于
      there are several reasons for this change. one is getting rid of the
      repetition of the syscall signature all over the place. another is
      sharing the constant masks without costly GOT accesses in PIC.
      
      the main motivation, however, is accurately representing whether we
      want to block signals that might be handled by the application, or all
      signals.
      2c074b0d