1. 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
  2. 17 7月, 2013 1 次提交
  3. 30 6月, 2013 1 次提交
  4. 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
  5. 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
  6. 07 4月, 2013 1 次提交
    • R
      add support for program_invocation[_short]_name · b4ea6385
      Rich Felker 提交于
      this is a bit ugly, and the motivation for supporting it is
      questionable. however the main factors were:
      1. it will be useful to have this for certain internal purposes
      anyway -- things like syslog.
      2. applications can just save argv[0] in main, but it's hard to fix
      non-portable library code that's depending on being able to get the
      invocation name without the main application's help.
      b4ea6385
  7. 01 4月, 2013 1 次提交
    • R
      implement pthread_getattr_np · 14a835b3
      Rich Felker 提交于
      this function is mainly (purely?) for obtaining stack address
      information, but we also provide the detach state since it's easy to
      do anyway.
      14a835b3
  8. 27 3月, 2013 1 次提交
    • R
      remove __SYSCALL_SSLEN arch macro in favor of using public _NSIG · ccc7b4c3
      Rich Felker 提交于
      the issue at hand is that many syscalls require as an argument the
      kernel-ABI size of sigset_t, intended to allow the kernel to switch to
      a larger sigset_t in the future. previously, each arch was defining
      this size in syscall_arch.h, which was redundant with the definition
      of _NSIG in bits/signal.h. as it's used in some not-quite-portable
      application code as well, _NSIG is much more likely to be recognized
      and understood immediately by someone reading the code, and it's also
      shorter and less cluttered.
      
      note that _NSIG is actually 65/129, not 64/128, but the division takes
      care of throwing away the off-by-one part.
      ccc7b4c3
  9. 18 2月, 2013 1 次提交
    • R
      consistently use the internal name __environ for environ · 23ccb80f
      Rich Felker 提交于
      patch by Jens Gustedt.
      previously, the intended policy was to use __environ in code that must
      conform to the ISO C namespace requirements, and environ elsewhere.
      this policy was not followed in practice anyway, making things
      confusing. on top of that, Jens reported that certain combinations of
      link-time optimization options were breaking with the inconsistent
      references; this seems to be a compiler or linker bug, but having it
      go away is a nice side effect of the changes made here.
      23ccb80f
  10. 02 2月, 2013 1 次提交
    • R
      replace __wake function with macro that performs direct syscall · facc6acb
      Rich Felker 提交于
      this should generate faster and smaller code, especially with inline
      syscalls. the conditional with cnt is ugly, but thankfully cnt is
      always a constant anyway so it gets evaluated at compile time. it may
      be preferable to make separate __wake and __wakeall macros without a
      count argument.
      
      priv flag is not used yet; private futex support still needs to be
      done at some point in the future.
      facc6acb
  11. 12 12月, 2012 1 次提交
  12. 08 12月, 2012 1 次提交
  13. 14 11月, 2012 3 次提交
  14. 13 11月, 2012 1 次提交
  15. 12 11月, 2012 2 次提交
    • R
      add support for thread scheduling (POSIX TPS option) · 1e21e78b
      Rich Felker 提交于
      linux's sched_* syscalls actually implement the TPS (thread
      scheduling) functionality, not the PS (process scheduling)
      functionality which the sched_* functions are supposed to have.
      omitting support for the PS option (and having the sched_* interfaces
      fail with ENOSYS rather than omitting them, since some broken software
      assumes they exist) seems to be the only conforming way to do this on
      linux.
      1e21e78b
    • R
      fix clobber of edx in i386 vsyscall asm · e9b885ee
      Rich Felker 提交于
      this function does not obey the normal calling convention; like a
      syscall instruction, it's expected not to clobber any registers except
      the return value. clobbering edx could break callers that were reusing
      the value cached in edx after the syscall returns.
      e9b885ee
  16. 09 11月, 2012 2 次提交
    • R
      clean up sloppy nested inclusion from pthread_impl.h · efd4d87a
      Rich Felker 提交于
      this mirrors the stdio_impl.h cleanup. one header which is not
      strictly needed, errno.h, is left in pthread_impl.h, because since
      pthread functions return their error codes rather than using errno,
      nearly every single pthread function needs the errno constants.
      
      in a few places, rather than bringing in string.h to use memset, the
      memset was replaced by direct assignment. this seems to generate much
      better code anyway, and makes many functions which were previously
      non-leaf functions into leaf functions (possibly eliminating a great
      deal of bloat on some platforms where non-leaf functions require ugly
      prologue and/or epilogue).
      efd4d87a
    • R
      clean up stdio_impl.h · 835f9f95
      Rich Felker 提交于
      this header evolved to facilitate the extremely lazy practice of
      omitting explicit includes of the necessary headers in individual
      stdio source files; not only was this sloppy, but it also increased
      build time.
      
      now, stdio_impl.h is only including the headers it needs for its own
      use; any further headers needed by source files are included directly
      where needed.
      835f9f95
  17. 02 11月, 2012 1 次提交
    • R
      fix more unused variable warnings · a617a8e2
      Rich Felker 提交于
      some of these were coming from stdio functions locking files without
      unlocking them. I believe it's useful for this to throw a warning, so
      I added a new macro that's self-documenting that the file will never
      be unlocked to avoid the warning in the few places where it's wrong.
      a617a8e2
  18. 26 10月, 2012 1 次提交
    • R
      use explicit visibility to optimize a few hot-path function calls · 607b05ac
      Rich Felker 提交于
      on x86 and some other archs, functions which make function calls which
      might go through a PLT incur a significant overhead cost loading the
      GOT register prior to making the call. this load is utterly useless in
      musl, since all calls are bound at library-creation time using
      -Bsymbolic-functions, but the compiler has no way of knowing this, and
      attempts to set the default visibility to protected have failed due to
      bugs in GCC and binutils.
      
      this commit simply manually assigns hidden/protected visibility, as
      appropriate, to a few internal-use-only functions which have many
      callers, or which have callers that are hot paths like getc/putc. it
      shaves about 5k off the i386 libc.so with -Os. many of the
      improvements are in syscall wrappers, where the benefit is just size
      and performance improvement is unmeasurable noise amid the syscall
      overhead. however, stdio may be measurably faster.
      
      if in the future there are toolchains that can do the same thing
      globally without introducing linking bugs, it might be worth
      considering removing these workarounds.
      607b05ac
  19. 25 10月, 2012 1 次提交
    • R
      greatly improve freopen behavior · 892cafff
      Rich Felker 提交于
      1. don't open /dev/null just as a basis to copy flags; use shared
      __fmodeflags function to get the right file flags for the mode.
      
      2. handle the case (probably invalid, but whatever) case where the
      original stream's file descriptor was closed; previously, the logic
      re-closed it.
      
      3. accept the "e" mode flag for close-on-exec; update dup3 to fallback
      to using dup2 so we can simply call __dup3 instead of putting fallback
      logic in freopen itself.
      892cafff
  20. 22 10月, 2012 1 次提交
  21. 14 10月, 2012 1 次提交
    • R
      workaround broken hidden-visibility handling in pcc · 36be5284
      Rich Felker 提交于
      with this change, pcc-built musl libc.so seems to work correctly. the
      problem is that pcc generates GOT lookups for external-linkage symbols
      even if they are hidden, rather than using GOT-relative addressing.
      the entire reason we're using hidden visibility on the __libc object
      is to make it accessible prior to relocations -- not to mention
      inexpensive to access. unfortunately, the workaround makes it even
      more expensive on pcc.
      
      when the pcc issue is fixed, an appropriate version test should be
      added so new pcc can use the much more efficient variant.
      36be5284
  22. 12 10月, 2012 2 次提交
  23. 05 10月, 2012 3 次提交
    • 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
      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
      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
  24. 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
  25. 10 9月, 2012 1 次提交
    • R
      add 7-arg syscall support for mips · 9a3bbce4
      Rich Felker 提交于
      no syscalls actually use that many arguments; the issue is that some
      syscalls with 64-bit arguments have them ordered badly so that
      breaking them into aligned 32-bit half-arguments wastes slots with
      padding, and a 7th slot is needed for the last argument.
      9a3bbce4
  26. 09 9月, 2012 2 次提交
    • R
      fix broken mips syscall asm · 21419914
      Rich Felker 提交于
      this code was using $10 to save the syscall number, but $10 is not
      necessarily preserved by the kernel across syscalls. only mattered for
      syscalls that got interrupted by a signal and restarted. as far as i
      can tell, $25 is preserved by the kernel across syscalls.
      21419914
    • R
      syscall organization overhaul · 208eb584
      Rich Felker 提交于
      now public syscall.h only exposes __NR_* and SYS_* constants and the
      variadic syscall function. no macros or inline functions, no
      __syscall_ret or other internal details, no 16-/32-bit legacy syscall
      renaming, etc. this logic has all been moved to src/internal/syscall.h
      with the arch-specific parts in arch/$(ARCH)/syscall_arch.h, and the
      amount of arch-specific stuff has been reduced to a minimum.
      
      changes still need to be reviewed/double-checked. minimal testing on
      i386 and mips has already been performed.
      208eb584
  27. 18 8月, 2012 1 次提交
    • R
      fix float parsing logic for long decimal expansions · 11458e5b
      Rich Felker 提交于
      this affects at least the case of very long inputs, but may also
      affect shorter inputs that become long due to growth while upscaling.
      basically, the logic for the circular buffer indices of the initial
      base-10^9 digit and the slot one past the final digit, and for
      simplicity of the loop logic, assumes an invariant that they're not
      equal. the upscale loop, which can increase the length of the
      base-10^9 representation, attempted to preserve this invariant, but
      was actually only ensuring that the end index did not loop around past
      the start index, not that the two never become equal.
      
      the main (only?) effect of this bug was that subsequent logic treats
      the excessively long number as having no digits, leading to junk
      results.
      11458e5b
  28. 12 8月, 2012 1 次提交
    • R
      add bsd fgetln function · 61718273
      Rich Felker 提交于
      optimized to avoid allocation and return lines directly out of the
      stream buffer whenever possible.
      61718273
  29. 10 8月, 2012 1 次提交
    • R
      fix (hopefully) all hard-coded 8's for kernel sigset_t size · 2f437040
      Rich Felker 提交于
      some minor changes to how hard-coded sets for thread-related purposes
      are handled were also needed, since the old object sizes were not
      necessarily sufficient. things have gotten a bit ugly in this area,
      and i think a cleanup is in order at some point, but for now the goal
      is just to get the code working on all supported archs including mips,
      which was badly broken by linux rejecting syscalls with the wrong
      sigset_t size.
      2f437040
  30. 27 7月, 2012 1 次提交
  31. 12 7月, 2012 2 次提交