1. 17 9月, 2015 2 次提交
    • R
      introduce new symbol-lookup-free rcrt1/dlstart stage chaining · 2907afb8
      Rich Felker 提交于
      previously, the call into stage 2 was made by looking up the symbol
      name "__dls2" (which was chosen short to be easy to look up) from the
      dynamic symbol table. this was no problem for the dynamic linker,
      since it always exports all its symbols. in the case of the static pie
      entry point, however, the dynamic symbol table does not contain the
      necessary symbol unless -rdynamic/-E was used when linking. this
      linking requirement is a major obstacle both to practical use of
      static-pie as a nommu binary format (since it greatly enlarges the
      file) and to upstream toolchain support for static-pie (adding -E to
      default linking specs is not reasonable).
      
      this patch replaces the runtime symbolic lookup with a link-time
      lookup via an inline asm fragment, which reloc.h is responsible for
      providing. in this initial commit, the asm is provided only for i386,
      and the old lookup code is left in place as a fallback for archs that
      have not yet transitioned.
      
      modifying crt_arch.h to pass the stage-2 function pointer as an
      argument was considered as an alternative, but such an approach would
      not be compatible with fdpic, where it's impossible to compute
      function pointers without already having performed relocations. it was
      also deemed desirable to keep crt_arch.h as simple/minimal as
      possible.
      
      in principle, archs with pc-relative or got-relative addressing of
      static variables could instead load the stage-2 function pointer from
      a static volatile object. that does not work for fdpic, and is not
      safe against reordering on mips-like archs that use got slots even for
      static functions, but it's a valid on i386 and many others, and could
      provide a reasonable default implementation in the future.
      2907afb8
    • R
      remove attribute((const)) from pthread_self and errno location decls · a603a75a
      Rich Felker 提交于
      this attribute was applied to pthread_self and the functions providing
      the locations for errno and h_errno as an optimization; however, it is
      subtly incorrect. as specified, it means the return value will always
      be the same, which is not true; it varies per-thread.
      
      this attribute also implies that the function does not depend on any
      state, and that calls to it can safely be reordered across any other
      code. however such reordering is unsafe for these functions: they
      break when reordered before initialization of the thread pointer. such
      breakage was actually observed when compiled by libfirm/cparser.
      
      to some extent the reordering problem could be solved with strong
      compiler barriers between the stages of early startup code, but the
      specified meaning of of attribute((const)) is sufficiently strong that
      a compiler would theoretically be justified inserting gratuitous calls
      to attribute((const)) const functions at random locations (e.g. to
      save the value in static storage for later use).
      
      this reverts commit cbf35978.
      a603a75a
  2. 16 9月, 2015 3 次提交
  3. 12 9月, 2015 6 次提交
    • R
      add sh fdpic subarch variants · d4c82d05
      Rich Felker 提交于
      with this commit it should be possible to produce a working
      static-linked fdpic libc and application binaries for sh.
      
      the changes in reloc.h are largely unused at this point since dynamic
      linking is not supported, but the CRTJMP macro is used one place
      outside of dynamic linking, in __unmapself.
      d4c82d05
    • R
      add fdpic version of entry point code for sh · 4ccc1a01
      Rich Felker 提交于
      this version of the entry point is only suitable for static linking in
      ET_EXEC form. neither dynamic linking nor pie is supported yet. at
      some point in the future the fdpic and non-fdpic versions of this code
      may be unified but for now it's easiest to work with them separately.
      4ccc1a01
    • R
      provide arch-generic fdpic self-relocation code for crt1 to use · 6d03c4ee
      Rich Felker 提交于
      this file is intended to be included by crt_arch.h on fdpic-based
      targets and needs to be called from the entry point asm.
      6d03c4ee
    • 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
    • R
      make sh crti/crtn init/fini fragments setup proper stack frame · ad5d8a2b
      Rich Felker 提交于
      for fdpic support is is essential that the got pointer be saved at a
      known, ABI-dictated offset from the frame pointer, since there is no
      way to recover it once it's lost.
      ad5d8a2b
    • R
      add sh relocation types needed for fdpic to elf.h · 17cdbc4e
      Rich Felker 提交于
      17cdbc4e
  4. 11 9月, 2015 1 次提交
  5. 09 9月, 2015 5 次提交
    • R
      fix missing earlyclobber flag in i386 a_ctz_64 asm · 878887c5
      Rich Felker 提交于
      this error was only found by reading the code, but it seems to have
      been causing gcc to produce wrong code in malloc: the same register
      was used for the output and the high word of the input. in principle
      this could have caused an infinite loop searching for an available
      bin, but in practice most x86 models seem to implement the "undefined"
      result of the bsf instruction as "unchanged".
      878887c5
    • R
      remove unused (and invalid) C version of sigsetjmp · deb85ab4
      Rich Felker 提交于
      originally, the comment in this code was correct and it would likely
      work if the compiler generated a tail call to setjmp. however, commit
      583e5512 redesigned sigsetjmp and
      siglongjmp such that the old C implementation (which was not intended
      to be used) is not even conceptually correct. remove it in the
      interest of avoiding confusion when porting to new archs.
      deb85ab4
    • R
      fix breakage in nl_langinfo from previous commit · 58f6259d
      Rich Felker 提交于
      58f6259d
    • R
      make nl_langinfo(CODESET) always return "UTF-8" · 844212d9
      Rich Felker 提交于
      this restores the original behavior prior to the addition of the
      byte-based C locale and fixes what is effectively a regression in
      musl's property of always providing working UTF-8 support.
      
      commit 1507ebf8 introduced the codeset
      name "UTF-8-CODE-UNITS" for the byte-based C locale to represent that
      the semantic content is UTF-8 but that it is being processed as code
      units (bytes) rather than whole multibyte characters. however, many
      programs assume that the codeset name is usable with iconv and/or
      comes from a set of standard/widely-used names known to the
      application. such programs are likely to produce warnings or errors,
      run with reduced functionality, or mangle character data when run
      explicitly in the C locale.
      
      the standard places basically no requirements for the string returned
      by nl_langinfo(CODESET) and how it interacts with other interfaces, so
      returning "UTF-8" is permissible. moreover, it seems like the right
      thing to do, since the identity of the character encoding as "UTF-8"
      is independent of whether it is being processed as bytes of characters
      by the standard library functions.
      844212d9
    • R
      fix fclose of permanent (stdin/out/err) streams · 426a0e29
      Rich Felker 提交于
      this fixes a bug reported by Nuno Gonçalves. previously, calling
      fclose on stdin or stdout resulted in deadlock at exit time, since
      __stdio_exit attempts to lock these streams to flush/seek them, and
      has no easy way of knowing that they were closed.
      
      conceptually, leaving a FILE stream locked on fclose is valid since,
      in the abstract machine, it ceases to exist. but to satisfy the
      implementation-internal assumption in __stdio_exit that it can access
      these streams unconditionally, we need to unlock them.
      
      it's also necessary that fclose leaves permanent streams in a state
      where __stdio_exit will not attempt any further operations on them.
      fortunately, the call to fflush already yields this property.
      426a0e29
  6. 31 8月, 2015 2 次提交
    • T
      implement arm eabi mem* functions · d8be1bc0
      Timo Teräs 提交于
      these functions are part of the ARM EABI, meaning compilers may
      generate references to them. known versions of gcc do not use them,
      but llvm does. they are not provided by libgcc, and the de facto
      standard seems to be that libc provides them.
      d8be1bc0
    • R
      remove use of buggy .SECONDARY special target in makefile · d18cf76d
      Rich Felker 提交于
      this functionality is affected by GNU make bug #30653, "intermediate
      files incorrectly pruned in parallel builds". on affected versions of
      make, parallel builds attempt to compile source files before
      alltypes.h is generated.
      
      as noted with commit a91ebdcf, which
      added the use of .SECONDARY, suppression of removal of "intermediate"
      files does not seem to be needed at present. if it is needed in the
      future, it should be achievable by explicitly mentioning their names
      as targets or prerequisites.
      d18cf76d
  7. 30 8月, 2015 1 次提交
  8. 28 8月, 2015 1 次提交
    • R
      fix makefile suppression of intermediate file removal · a91ebdcf
      Rich Felker 提交于
      at one point, GNU make was removing crt/*.o after producing the copies
      in lib/ due to an arcane misfeature for handling "intermediate" files.
      the circumstances that caused this are no longer present in our
      makefile, but the previous workaround using .PRECIOUS was wrong and
      could result in corrupt/partial files being left behind during an
      interrupted build. using .SECONDARY is the correct, documented fix
      that will prevent deletion of "intermediate" files from ever
      resurfacing.
      a91ebdcf
  9. 26 8月, 2015 1 次提交
    • A
      Build process uses script to add CFI directives to x86 asm · 35b3312b
      Alex Dowad 提交于
      Some functions implemented in asm need to use EBP for purposes other
      than acting as a frame pointer. (Notably, it is used for the 6th
      argument to syscalls with 6 arguments.) Without frame pointers, GDB
      can only show backtraces if it gets CFI information from a
      .debug_frame or .eh_frame ELF section.
      
      Rather than littering our asm with ugly .cfi directives, use an awk
      script to insert them in the right places during the build process, so
      GDB can keep track of where the current stack frame is relative to the
      stack pointer. This means GDB can produce beautiful stack traces at
      any given point when single-stepping through asm functions.
      
      Additionally, when registers are saved on the stack and later
      overwritten, emit ..cfi directives so GDB will know where they were
      saved relative to the stack pointer. This way, when you look back up
      the stack from within an asm function, you can still reliably print
      the values of local variables in the caller.
      
      If this awk script were to understand every possible wild and crazy
      contortion that an asm programmer can do with the stack and registers,
      and always emit the exact ..cfi directives needed for GDB to know what
      the register values were in the preceding stack frame, it would
      necessarily be as complex as a full x86 emulator. That way lies
      madness.
      
      Hence, we assume that the stack pointer will _only_ ever be adjusted
      using push/pop or else add/sub with a constant. We do not attempt to
      detect every possible way that a register value could be saved for
      later use, just the simple and common ways.
      
      Thanks to Szabolcs Nagy for suggesting numerous improvements to this
      code.
      35b3312b
  10. 21 8月, 2015 1 次提交
  11. 17 8月, 2015 1 次提交
    • R
      mitigate performance regression in libc-internal locks on x86_64 · 5a9c8c05
      Rich Felker 提交于
      commit 3c43c076 fixed missing
      synchronization in the atomic store operation for i386 and x86_64, but
      opted to use mfence for the barrier on x86_64 where it's always
      available. however, in practice mfence is significantly slower than
      the barrier approach used on i386 (a nop-like lock orl operation).
      this commit changes x86_64 (and x32) to use the faster barrier.
      5a9c8c05
  12. 14 8月, 2015 1 次提交
    • N
      match historical behavior for tm_gmtoff member of struct tm · c13f2af1
      Natanael Copa 提交于
      tm_gmtoff is a nonstandard field, but on historical systems which have
      this field, it stores the offset of the local time zone from GMT or
      UTC. this is the opposite of the POSIX extern long timezone object and
      the offsets used in POSIX-form TZ strings, which represent the offset
      from local time to UTC. previously we were storing these negated
      offsets in tm_gmtoff too.
      
      programs which only used this field indirectly via strftime were not
      affected since strftime performed the negation for presentation.
      however, some programs and libraries accesse tm_gmtoff directly and
      were obtaining negated time zone offsets.
      c13f2af1
  13. 12 8月, 2015 1 次提交
    • S
      aarch64: fix 64-bit syscall argument passing · e5b086e1
      Szabolcs Nagy 提交于
      On 32bit systems long long arguments are passed in a special way
      to some syscalls; this accidentally got copied to the AArch64 port.
      
      The following interfaces were broken: fallocate, fanotify, ftruncate,
      posix_fadvise, posix_fallocate, pread, pwrite, readahead,
      sync_file_range, truncate.
      e5b086e1
  14. 10 8月, 2015 1 次提交
  15. 08 8月, 2015 1 次提交
    • R
      mitigate blow-up of heap size under malloc/free contention · c3761622
      Rich Felker 提交于
      during calls to free, any free chunks adjacent to the chunk being
      freed are momentarily held in allocated state for the purpose of
      merging, possibly leaving little or no available free memory for other
      threads to allocate. under this condition, other threads will attempt
      to expand the heap rather than waiting to use memory that will soon be
      available. the race window where this happens is normally very small,
      but became huge when free chooses to use madvise to release unused
      physical memory, causing unbounded heap size growth.
      
      this patch drastically shrinks the race window for unwanted heap
      expansion by performing madvise with the bin lock held and marking the
      bin non-empty in the binmask before making the expensive madvise
      syscall. testing by Timo Teräs has shown this approach to be a
      suitable mitigation.
      
      more invasive changes to the synchronization between malloc and free
      would be needed to completely eliminate the problem. it's not clear
      whether such changes would improve or worsen typical-case performance,
      or whether this would be a worthwhile direction to take malloc
      development.
      c3761622
  16. 29 7月, 2015 1 次提交
    • R
      fix missing synchronization in atomic store on i386 and x86_64 · 3c43c076
      Rich Felker 提交于
      despite being strongly ordered, the x86 memory model does not preclude
      reordering of loads across earlier stores. while a plain store
      suffices as a release barrier, we actually need a full barrier, since
      users of a_store subsequently load a waiter count to determine whether
      to issue a futex wait, and using a stale count will result in soft
      (fail-to-wake) deadlocks. these deadlocks were observed in malloc and
      possible with stdio locks and other libc-internal locking.
      
      on i386, an atomic operation on the caller's stack is used as the
      barrier rather than performing the store itself using xchg; this
      avoids the need to read the cache line on which the store is being
      performed. mfence is used on x86_64 where it's always available, and
      could be used on i386 with the appropriate cpu model checks if it's
      shown to perform better.
      3c43c076
  17. 25 7月, 2015 2 次提交
    • R
      fe7582f4
    • R
      fix atexit when it is called from an atexit handler · 57243b30
      Rich Felker 提交于
      The old code accepted atexit handlers after exit, but did not run them
      reliably. C11 seems to explicitly allow atexit to fail (and report
      such failure) in this case, but this situation can easily come up in
      C++ if a destructor has a local static object with a destructor so it
      should be handled.
      
      Note that the memory usage can grow linearly with the overall number
      of registered atexit handlers instead of with the worst case list
      length. (This only matters if atexit handlers keep registering atexit
      handlers which should not happen in practice).
      
      Commit message/rationale based on text by Szabolcs Nagy.
      57243b30
  18. 22 7月, 2015 3 次提交
  19. 10 7月, 2015 2 次提交
    • R
      handle loss of syslog socket connection · 0f9c2666
      Rich Felker 提交于
      when traditional syslogd implementations are restarted, the old server
      socket ceases to exist and a new unix socket with the same pathname is
      created. when this happens, the default destination address associated
      with the client socket via connect is no longer valid, and attempts to
      send produce errors. this happens despite the socket being datagram
      type, and is in contrast to the behavior that would be seen with an IP
      datagram (UDP) socket.
      
      in order to avoid a situation where the application is unable to send
      further syslog messages without calling closelog, this patch makes
      syslog attempt to reconnect the socket when send returns an error
      indicating a lost connection.
      
      additionally, initial failure to connect the socket no longer results
      in the socket being closed. this ensures that an application which
      calls openlog to reserve the socket file descriptor will not run into
      a situation where transient connection failure (e.g. due to syslogd
      restart) prevents fd reservation. however, applications which may be
      unable to connect the socket later (e.g. due to chroot, restricted
      permissions, seccomp, etc.) will still fail to log if the syslog
      socket cannot be connected at openlog time or if it has to be
      reconnected later.
      0f9c2666
    • R
      fix incorrect void return type for syncfs function · 11894f6d
      Rich Felker 提交于
      being nonstandard, the closest thing to a specification for this
      function is its man page, which documents it as returning int. it can
      fail with EBADF if the file descriptor passed is invalid.
      11894f6d
  20. 08 7月, 2015 1 次提交
  21. 07 7月, 2015 3 次提交
    • S
      add musl-clang, a wrapper for system clang installs · fb58545f
      Shiz 提交于
      musl-clang allows the user to compile musl-powered programs using their
      already existent clang install, without the need of a special cross compiler.
      it achieves this by wrapping around both the system clang install and the
      linker and passing them special flags to re-target musl at runtime.
      it does only affect invocations done through the special musl-clang wrapper
      script, so that the user setup remains fully intact otherwise.
      
      the clang wrapper consists of the compiler frontend wrapper script,
      musl-clang, and the linker wrapper script, ld.musl-clang.
      musl-clang makes sure clang invokes ld.musl-clang to link objects; neither
      script needs to be in PATH for the wrapper to work.
      fb58545f
    • S
      build: fix musl-targeting toolchain test · f8db6f74
      Shiz 提交于
      the old test was broken in that it would never fail on a toolchains built
      without dynamic linking support, leading to the wrapper script possibly being
      installed on compilers that do not support it. in addition, the new test is
      portable across compilers: the old test only worked on GCC.
      
      the new test works by testing whether the toolchain libc defines __GLIBC__:
      most non-musl Linux libc's do define this for compatibility even when they
      are not glibc, so this is a safe bet to check for musl. in addition, the
      compiler runtime would need to have a somewhat glibc-compatible ABI in the
      first place, so any non-glibc compatible libc's compiler runtime might not
      work. it is safer to disable these cases by default and have the user enable
      the wrappers manually there using --enable-wrapper if they certain it works.
      f8db6f74
    • S
      build: overhaul wrapper script system for multiple wrapper support · b3cd7d13
      Shiz 提交于
      this overhauls part of the build system in order to support multiple
      toolchain wrapper scripts, as opposed to solely the musl-gcc wrapper as
      before. it thereby replaces --enable-gcc-wrapper with --enable-wrapper=...,
      which has the options 'auto' (the default, detect whether to use wrappers),
      'all' (build and install all wrappers), 'no' (don't build any) and finally
      the options named after the individual compiler scripts (currently only
      'gcc' is available) to build and install only that wrapper.
      the old --enable-gcc-wrapper is removed from --help, but still available.
      
      it also modifies the wrappers to use the C compiler specified to the build
      system as 'inner' compiler, when applicable. as wrapper detection works by
      probing this compiler, it may not work with any other.
      b3cd7d13