1. 24 9月, 2015 1 次提交
    • R
      fix signal return for sh/fdpic · b61df229
      Rich Felker 提交于
      the restorer function pointer provided in the kernel sigaction
      structure is interpreted by the kernel as a raw code address, not a
      function descriptor.
      
      this commit moves the declarations of the __restore and __restore_rt
      symbols to ksigaction.h so that arch versions of the file can override
      them, and introduces a version for sh which declares them as objects
      rather than functions.
      
      an alternate solution would have been defining SA_RESTORER to 0 so
      that the functions are not used, but this both requires executable
      stack (since the sh kernel does not have a vdso page with permanent
      restorer functions) and crashes on qemu user-level emulation.
      b61df229
  2. 23 9月, 2015 7 次提交
    • R
      fix dlsym RTLD_NEXT behavior for fdpic · 6c5cad2a
      Rich Felker 提交于
      lookup the dso an address falls in based on the loadmap and not just a
      base/length. fix the main app's fake loadmap used when loaded by a
      non-fdpic-aware loader so that it does not cover the whole memory
      space.
      
      function descriptor addresses are also matched for future use by
      dladdr, but reverse lookups of function descriptors via dladdr have
      not been implemented yet. some revisions may be needed in the future
      once reclaim_gaps supports fdpic, so that function descriptors
      allocated in reclaimed heap space do not get detected as belonging to
      the module whose gaps they were allocated in.
      6c5cad2a
    • R
      fix dlsym lookup of function symbols on fdpic · d47d9a50
      Rich Felker 提交于
      previously these resolved to the code address rather than the address
      of the function descriptor.
      
      the conditions for accepting or rejecting symbols are quite
      inconsistent between the different points in the dynamic linker code
      where such decisions are made. this commit attempts to be at least as
      correct as anything already there, but does not improve consistency.
      it has been tested to correctly avoid symbols that are merely
      references to functions defined in other modules, at least in simple
      usage, but at some point all symbol lookup logic should be reviewed
      and refactored/unified.
      d47d9a50
    • R
      have sh/fdpic entry point set fdpic personality if needed · e9e770df
      Rich Felker 提交于
      the entry point code supports being loaded by a loader which is not
      fdpic-aware (in practice, either kernel with mmu or qemu without fdpic
      support). this mostly just works, but signal handling will wrongly use
      a function descriptor address as a code address if the personality is
      not adjusted to fdpic.
      
      ideally this code could be placed with sigaction so that it's not
      needed except if/when a signal handler is installed. however,
      personality is incorrectly maintained per-thread by the kernel, rather
      than per-process, so it's necessary to correct the personality before
      any threads are started. also, in order to skip the personality
      syscall when an fdpic-aware loader is used, we need to be able to
      detect how the program was loaded, and this information is only
      readily available at the entry point.
      e9e770df
    • R
      move calls to application init functions after crt1 entry point · c87a5210
      Rich Felker 提交于
      this change is needed to be compatible with fdpic, where some of the
      main application's relocations may be performed as part of the crt1
      entry point. if we call init functions before passing control, these
      relocations will not yet have been performed, and the init code will
      potentially make use of invalid pointers.
      
      conceptually, no code provided by the application or third-party
      libraries should run before the application entry point. the
      difference is not observable to programs using the crt1 we provide,
      but it could come into play if custom entry point code is used, so
      it's better to be doing this right anyway.
      c87a5210
    • R
      fix breakage in non-fdpic dynamic linker init/fini processing · 78f43029
      Rich Felker 提交于
      a mistaken #ifdef instead of #if caused conversion of code addresses
      to function descriptors to be performed even on non-fdpic.
      78f43029
    • R
      30fdc06b
    • R
      add real fdpic loading of shared libraries · eaf7ab6e
      Rich Felker 提交于
      previously, the normal ELF library loading code was used even for
      fdpic, so only the kernel-loaded dynamic linker and main app could
      benefit from separate placement of segments and shared text.
      eaf7ab6e
  3. 22 9月, 2015 7 次提交
    • R
      try to suppress linking libc.so if there are undefined symbols · 2462370b
      Rich Felker 提交于
      this is always an error and usually results from failure to find/link
      the compiler runtime library, but it could also result from
      implementation errors in libc, using functions that don't (yet) exist.
      either way the resulting libc.so will crash mysteriously at runtime.
      the crash happens too early to produce a meaningful error, so these
      crashes are very confusing to users and waste a lot of debugging time.
      this commit should ensure that they do not happen.
      2462370b
    • R
    • R
      size-optimize sh/fdpic dynamic entry point · 7f9086df
      Rich Felker 提交于
      the __fdpic_fixup code is not needed for ET_DYN executables, which
      instead use reloctions, so we can omit it from the dynamic linker and
      static-pie entry point and save some code size.
      7f9086df
    • R
      work around breakage in sh/fdpic __unmapself function · cab2b1f9
      Rich Felker 提交于
      the C implementation of __unmapself used for potentially-nommu sh
      assumed CRTJMP takes a function descriptor rather than a code address;
      however, the actual dynamic linker needs a code address, and so commit
      7a9669e9 changed the definition of the
      macro in reloc.h. this commit puts the old macro back in a place where
      it only affects __unmapself.
      
      this is an ugly workaround and should be cleaned up at some point, but
      at least it's well isolated.
      cab2b1f9
    • R
      add general fdpic support in dynamic linker and arch support for sh · 7a9669e9
      Rich Felker 提交于
      at this point not all functionality is complete. the dynamic linker
      itself, and main app if it is also loaded by the kernel, take
      advantage of fdpic and do not need constant displacement between
      segments, but additional libraries loaded by the dynamic linker follow
      normal ELF semantics for mapping still. this fully works, but does not
      admit shared text on nommu.
      
      in terms of actual functional correctness, dlsym's results are
      presently incorrect for function symbols, RTLD_NEXT fails to identify
      the caller correctly, and dladdr fails almost entirely.
      
      with the dynamic linker entry point working, support for static pie is
      automatically included, but linking the main application as ET_DYN
      (pie) probably does not make sense for fdpic anyway. ET_EXEC is
      equally relocatable but more efficient at representing relocations.
      7a9669e9
    • R
      factor symbol counting out of dladdr as its own function · 3958144e
      Rich Felker 提交于
      the fdpic code will need to count symbols, and it may be useful
      elsewhere in the future too. counting is trivial as long as sysv hash
      is present, but for gnu-hash-only libraries it's complex.
      
      the behavior of the count is changed slightly: we now include symbols
      that are not accessible by the gnu hash table in the count. this may
      make dladdr slightly slower. if this is a problem, dladdr can subtract
      out the part that should not be accessible. unlike in the old code,
      subtracting this out is easy even in the fast path where sysv hash is
      available too.
      3958144e
    • R
      d8740645
  4. 18 9月, 2015 5 次提交
  5. 17 9月, 2015 8 次提交
    • R
      remove old dlstart stage-2 symbolic lookup code; add new generic · 6fc30c24
      Rich Felker 提交于
      this new generic version of the stage-2 function lookup should work
      for any arch where static data is accessible via got-relative or
      pc-relative addressing, using approximately the technique described in
      the log message for commit 2907afb8.
      
      since all the mips-like archs that need got slots fo access static
      data have already transitioned to the new stage chaining scheme, the
      old dynamic symbol lookup code is now removed.
      
      aarch64, arm, and sh have not yet transitioned; with this commit, they
      are now using the new generic code.
      6fc30c24
    • R
      new dlstart stage-2 chaining for x86_64 and x32 · 12b0b7d8
      Rich Felker 提交于
      12b0b7d8
    • R
      new dlstart stage-2 chaining for powerpc · c1618268
      Rich Felker 提交于
      c1618268
    • R
      new dlstart stage-2 chaining for or1k · 4761e63b
      Rich Felker 提交于
      4761e63b
    • R
      new dlstart stage-2 chaining for mips · cd7159e7
      Rich Felker 提交于
      cd7159e7
    • R
      new dlstart stage-2 chaining for microblaze · 57e2dce7
      Rich Felker 提交于
      57e2dce7
    • 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
  6. 16 9月, 2015 3 次提交
  7. 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
  8. 11 9月, 2015 1 次提交
  9. 09 9月, 2015 2 次提交
    • 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