Commit Graph

25 Commits

Author SHA1 Message Date
christos c510facea2 Instead of compiling files with -fcommon, create an include file and declare
the 3 symbols that need to be common using an attribute. Put all the 3 symbol
definitions in libc in one place (initfini.c). Reviewed by joerg@
2021-04-20 21:42:31 +00:00
joerg 18796b949c Explicitly use -fcommon for globals shared between libc and CSU. 2020-04-22 23:32:25 +00:00
kamil d92938e14a Add a support to build ubsan.c in libc
Under the condition of MKLIBCSANITIZER==yes link ubsan.c into libc.

This is a clean-room reimplementation from scratch of the Undefined
Behavior runtime called micro-UBSan (or uBSan - user-UBSan).
2018-08-03 04:29:35 +00:00
joerg 54eae2a123 PR 51654: Don't initialize _dlauxinfo for static binaries.
Emacs likes save all memory of the main binary and the first run of
_libc_init via .init will get the wrong (old) value of __ps_strings.
By avoiding the initialization of _dlauxinfo for shared applications,
it will be touched only by the _libc_init call from crt0.o itself,
at which point __ps_strings is correct.
2017-06-17 15:26:44 +00:00
dholland aa08bfea54 More of previous. 2016-11-26 21:17:06 +00:00
dholland a714102aaa fix comment about initialization-time calls; ok joerg 2016-11-26 20:38:20 +00:00
matt 8caf10303e Put the startup code in .text.startup 2013-08-19 22:14:37 +00:00
matt ec3a3eac3f Add ${ARCHDIR}/misc to path 2013-01-29 19:14:02 +00:00
christos c5e820cae4 PR/45989: Martin Husemann: lint invocation does include -w only on i386
- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
  would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
  builds)

approved by core@
2012-03-13 21:13:30 +00:00
joerg 52a4c27e3e Add _dlauxinfo helper function to provide access to the ELF auxilary
vector. This can normally be found via __ps_strings, but libc is
initialised too early when linked dynamically and doesn't have access to
it yet, so provide an alternative mechanism via ld.elf_so.
Bump libc minor.
2012-02-16 23:00:38 +00:00
joerg eb47f1619a Use a constant array for the MIB. Newer LLVM decided that mib[] warranted
stack protections, with the obvious crash after the setup was done.
As a positive side effect, code size shrinks a bit.
2011-12-08 02:27:14 +00:00
joerg 67f518f496 Use __dead 2011-09-16 16:05:58 +00:00
joerg aad599979d Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.
2011-03-09 23:10:05 +00:00
joerg 5c3ccd6eba Pass down ELF Auxillary Vectors for static NetBSD binaries too.
Rename __libc_init to _libc_init and call it explicitly from CSU code.
This enforces the constructor run order for newly linked programs.
Keep it as constructor with run-once semantic for binary compatibility.
Implement dl_iterate_phdr for statically linked programs.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.
2011-03-07 05:09:09 +00:00
joerg cb63bb73c3 Don't use argument as direct format string. 2010-12-07 20:10:53 +00:00
tron fbf4aa1699 Improve and simplify implementation of *env(3) functions:
- Use RB tree to keep track of memory allocated via setenv(3) as
  suggested by Enami Tsugutomo in private e-mail.
  This simplifies the code a lot as we no longer need to keep the size
  of "environ" in sync with an array of allocated environment variables.
  It also makes it possible to free environment variables in unsetenv(3)
  if something has changed the order of the "environ" array.
- Fix a bug in getenv(3) and getenv_r(3) which would return bogus
  results e.g. for " getenv("A=B") " if an environment variable "A"
  with value "B=C" exists.
- Clean up the internal functions:
  - Don't expose the read/write lock for the environment to other parts
    of "libc". Provide locking functions instead.
  - Use "bool" to report success or failure.
  - Use "ssize_t" or "size_t" instead of "int" for indexes.
  - Provide internal functions with simpler interfaces e.g. don't
    combine return values and reference arguments.
  - Don't copy "environ" into an allocated block unless we really need
    to grow it.

Code reviewed by Joerg Sonnenberger and Christos Zoulas, tested by
Joerg Sonnenberger and me. These changes also fix problems in
zsh 4.3.* and pam_ssh according to Joerg.
2010-11-14 18:11:42 +00:00
joerg e883e926df Ensure that initfini.c is referenced by exit.c. The start up code has to
reference the latter as a return of main() results in a call to exit(3),
so this ensures that the libc constructors are run for statically linked
programs. Fixes PR 37454.
2010-06-28 21:58:02 +00:00
drochner f7e3ae7c1f -delete prototypes which are already in <ssp/ssp.h>
-make __fail __noreturn__
2009-11-17 20:46:20 +00:00
ad c984f259af Make threaded programs die correctly:
kill(getpid(), SIGFOO) -> raise(SIGFOO)
2009-01-30 23:21:02 +00:00
ad e54e98d8cc xprintf returns void. 2008-06-03 19:22:37 +00:00
martin ce099b4099 Remove clause 3 and 4 from TNF licenses 2008-04-28 20:22:51 +00:00
xtraeme 95157b046e Make the atexit mutex recursive and initialize it in __libc_init()
as suggested by ad@, based on the patch provided by Sverre Froyen
in lib/37654.

Reviewed by ad@ and jmcneill@.
2008-02-25 14:06:13 +00:00
ad b5b3e9fb51 Enable the atomic ops in userspace. 2008-02-10 18:45:40 +00:00
ad 46f5cd4fb9 - Make it pass lint.
- Add RCSID.
2007-11-13 15:33:55 +00:00
ad ec4d182d4a - stack_protector.c doesn't really belong under sys/. Add a new directory
for misc support routines and put it there.
- Add a libc constructor. Use this to initialize threading and the
  stack protector stuff. libpthread cannot be initialized safely using
  its own constructor because libc and libpthread are deeply intertwined.
  PR bin/37347
2007-11-13 15:21:19 +00:00