History log of /openbsd-current/libexec/ld.so/util.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.49 08-Jan-2022 guenther

Prep .c files for removing the #includes from */archdep.h
* replace #include "archdep.h" with #includes of what is used, pulling in
"syscall.h", "util.h", and "archdep.h" as needed
* delete #include <sys/syscall.h> from syscall.h
* only pull in <sys/stat.h> to the three files that use _dl_fstat(),
forward declare struct stat in syscall.h for the others
* NBBY is for <sys/select.h> macros; just use '8' in dl_printf.c
* <machine/vmparam.h> is only needed on i386; conditionalize it
* stop using __LDPGSZ: use _MAX_PAGE_SHIFT (already used by malloc.c)
where necessary
* delete other bogus #includes, order legit per style: <sys/*> then
<*/*>, then <*>, then "*"

dir.c improvement from jsg@
ok and testing assistance deraadt@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.48 15-Oct-2020 deraadt

make three mib[] arrays const, as was done in libc


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.47 27-Mar-2020 matthieu

Add missing space in stack smash handler error message.
ok kettenis@, deraadt@


Revision tags: OPENBSD_6_6_BASE
# 1.46 08-May-2019 deraadt

On retguard systems, remove the ld.so-local stack-protector handling
functions because retguard uses hard-traps instead.
ok mortimer.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.45 09-Feb-2018 mortimer

Use a static chacha instance to fill randomdata sections. Avoids looping
over a syscall for randomdata sections larger than 256B.

ok djm@ deraadt@ kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.44 24-Jan-2017 guenther

On fatal errors, kill ourselves with thrkill(0,9,NULL) instead of
simply exiting, via helper functions _dl_die(), _dl_diedie(), and
_dl_oom().

prompted by a complaint from jsing@
ok jsing@ deraadt@


# 1.43 12-Aug-2016 deraadt

the slimmed down random functions inside ld.so are strict clones of the
libc arc4random API, so call them _dl_{arc4random,arcrandombuf}
ok tedu guenther


# 1.42 05-Aug-2016 tedu

use a larger chunk for getentropy() and save some for next time.
coalesces some syscalls instead of one per random number.
ok deraadt


Revision tags: OPENBSD_6_0_BASE
# 1.41 21-Mar-2016 bluhm

Rename the system call sendsyslog2 to sendsyslog. Keep the old one
as osendsyslog for a while. The three argument variant is the only
one that will stay.
input kettenis@; OK deraadt@


# 1.40 21-Mar-2016 guenther

Switch ld.so's stack smash handler from sendsyslog to sendsyslog2
and pass the LOG_CONS flag like libc's handler.

ok deraadt@ bluhm@ (who had a similar diff)


# 1.39 20-Mar-2016 guenther

Export environ and __progname, making the latter a copy of just the filename
portion like crt0 does. This is prep for eliminating _dl_fixup_user_env()
Mark almost everything in resolve.h as hidden, to improve code generation.

ok kettenis@ mpi@ "good time" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.38 20-Jan-2015 deraadt

If _dl_progname exceeds half the syslog buffer, truncate it with "...",
so that the remaining information is more visible
ok kettenis miod


# 1.37 16-Jan-2015 deraadt

<sys/param.h> to <limits.h> conversion. Verified binaries
ok millert, thanks to doug for process advice


# 1.36 09-Dec-2014 tedu

avoid void arithmetic. from david carlier


Revision tags: OPENBSD_5_6_BASE
# 1.35 14-Jul-2014 deraadt

Now that we have sendsyslog(2), we can directly use it in the
(previously completely retarded) stack_smash_handler of ld.so
ok beck miod tedu


# 1.34 06-Jul-2014 otto

rm unneeded includes; prompted (partly) by kettenis@


# 1.33 06-Jul-2014 otto

move from sysclt(KERN_ARND) to getentropy(2); ok miod@, kettenis@


# 1.32 21-Jun-2014 otto

Move to a non-zeroing _dl_malloc, a _dl_calloc and _dl_reallocarry and
fix _dl_strdup to return NULL instead of crash; ok deraadt@


# 1.31 14-Jun-2014 miod

Make _dl_randombuf invoke sysctl KERN_ARND in 256-byte chunks, for this is
(currently) the largest output you can get from it.

ok deraadt@


# 1.30 05-Jun-2014 otto

Move to (slightly stripped) version of libc malloc; ok deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.29 23-Jan-2014 deraadt

improve some types


# 1.28 28-Dec-2013 deraadt

Do not need __guard anymore
Discussion with miod
ok kettenis


# 1.27 13-Nov-2013 deraadt

prototype & void * math cleanup
ok guenther


Revision tags: OPENBSD_5_4_BASE
# 1.26 09-Jun-2013 miod

Constify the mib argument of sysctl().
ok matthew@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.25 23-Jan-2013 miod

Cache flush .plt after updating its pointers to .got during the initial
object relocation, if loaded at a different address than the one it was
compiled for; unsurprisingly fixes some spurious crashes.


# 1.24 28-Aug-2012 matthew

Add __guard_local as a hidden symbol to ld.so, kernel, and every
executable and DSO (via crtbegin.c/crtbeginS.c). Not used yet, but
needed before GCC can start emitting -fstack-protector code that uses
them instead of __guard.


# 1.23 22-Aug-2012 matthew

Change ld.so and libc to use .openbsd.randomdata on ELF platforms for
initializing their __guard values. For the time being, we're leaving
libc's constructor method as a backup to make sure __guard actually
gets initialized and to emit syslog warnings when it's not.

Not really an ABI change, so no shlib bump... "hold on to your butts"

ok deraadt, kettenis


# 1.22 07-Aug-2012 matthew

Factor out a _dl_randombuf() method from _dl_random().


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.21 30-Oct-2010 deraadt

fix a 10 year old bug in the memory allocator, which affected only sparc.
sparc has 4 byte long, but needs 8 byte alignment. recently the DIR
struct was changed to contain some off_t, which needs 8 byte alignment.
turns out the allocator calculated the bias for alignment, and then
subtracted out it's private linkage storage afterwards. on hppa this
worked because a 8-byte object can be loaded at a 4-byte boundary; on
all other architectures the situation was either 4/4 or 8/8.
thanks for a bit of help from drahn


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.20 02-Oct-2008 kurt

Fix mmap() error checking to be correct 64-bit addresses. Consistently
use _dl_mmap_error() to check for mmap() errors. Adjust datatypes of
some local vars for 64-bit safety.

okay millert@ drahn@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.19 09-Feb-2007 drahn

readdir buffers should not get a fixed buffer size, but should be dependant
on the block size of the filesystem. Rounded up to page size for efficiency.
similar to change in libc yesterday. Should fix PR 5364.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 14-Jun-2004 millert

Make _dl_malloc() deal with allocations > 4096 correctly. Also place
unused memory chunks on the free list when making a large allocation.
OK drahn@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.17 25-Feb-2004 drahn

Fix this assumed sizeof(long) == 4 error. Would very occasionally cause
the code to attempt to zero 4 bytes of the next page.


Revision tags: OPENBSD_3_4_BASE
# 1.16 06-Jul-2003 deraadt

various proto, ansi, and knf repair. tested on all architectures that
use it. (build may require make cleandir because of .depend balony)


# 1.15 09-Jun-2003 deraadt

pefo 3/4 licence cleanups


# 1.14 30-May-2003 drahn

When loading a shared object or libraries dependant object, load them
in random order. This will reduce the possiblity of a buffer overflow
being able to predict the addresss of useful code. Can be disabled
with the LD_NORANDOM environment variable for debugging purposes.
ok deraadt.


Revision tags: OPENBSD_3_3_BASE
# 1.13 02-Feb-2003 deraadt

knf & ansi; drahn ok


# 1.12 02-Dec-2002 deraadt

KNF; openbsd@davidkrause.com


# 1.11 02-Dec-2002 naddy

typo; ok miod@


# 1.10 02-Dec-2002 miod

Import propolice (http://www.trl.ibm.com/projects/security/ssp), a stack
attack protection scheme, into gcc.

This protection is enabled by default. It can be turned off by using the
-fno-stack-protector flag.

Code by Hiroaki Etoh (etoh at jp dot ibm dot com); work on openbsd-specific
integration by fgsch@, deraadt@ and myself; tests by fgsch@, naddy@ and
myself; beer drinking by myself.

Please note that system upgrades with this new code will require a new
libc and ld.so to be build and installed before the propolice-enabled
compiler can be installed.


Revision tags: OPENBSD_3_2_BASE
# 1.9 24-Jul-2002 deraadt

ok i found it


# 1.8 24-Jul-2002 deraadt

back out broken stuff until it is fixed


# 1.7 24-Jul-2002 deraadt

make more _dl_*() func params like real ones in libc


# 1.6 07-Jul-2002 jufi

typos/grammar/better words
in comments.


# 1.5 28-May-2002 deraadt

more KNF


# 1.4 24-May-2002 drahn

Change _dl_strcpy() to _dl_strlcpy(), implementation taken from libc.


# 1.3 24-May-2002 deraadt

various KNF


Revision tags: OPENBSD_3_1_BASE
# 1.2 09-Apr-2002 drahn

Add the Copyrights from the respective files the code came from. ok deraadt@


# 1.1 21-Feb-2002 drahn

cleanup of MD/MI ld.so (elf), most changes by art@ cleanup by me.
tested on alpha sparc64 powerpc.


# 1.48 15-Oct-2020 deraadt

make three mib[] arrays const, as was done in libc


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.47 27-Mar-2020 matthieu

Add missing space in stack smash handler error message.
ok kettenis@, deraadt@


Revision tags: OPENBSD_6_6_BASE
# 1.46 08-May-2019 deraadt

On retguard systems, remove the ld.so-local stack-protector handling
functions because retguard uses hard-traps instead.
ok mortimer.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.45 09-Feb-2018 mortimer

Use a static chacha instance to fill randomdata sections. Avoids looping
over a syscall for randomdata sections larger than 256B.

ok djm@ deraadt@ kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.44 24-Jan-2017 guenther

On fatal errors, kill ourselves with thrkill(0,9,NULL) instead of
simply exiting, via helper functions _dl_die(), _dl_diedie(), and
_dl_oom().

prompted by a complaint from jsing@
ok jsing@ deraadt@


# 1.43 12-Aug-2016 deraadt

the slimmed down random functions inside ld.so are strict clones of the
libc arc4random API, so call them _dl_{arc4random,arcrandombuf}
ok tedu guenther


# 1.42 05-Aug-2016 tedu

use a larger chunk for getentropy() and save some for next time.
coalesces some syscalls instead of one per random number.
ok deraadt


Revision tags: OPENBSD_6_0_BASE
# 1.41 21-Mar-2016 bluhm

Rename the system call sendsyslog2 to sendsyslog. Keep the old one
as osendsyslog for a while. The three argument variant is the only
one that will stay.
input kettenis@; OK deraadt@


# 1.40 21-Mar-2016 guenther

Switch ld.so's stack smash handler from sendsyslog to sendsyslog2
and pass the LOG_CONS flag like libc's handler.

ok deraadt@ bluhm@ (who had a similar diff)


# 1.39 20-Mar-2016 guenther

Export environ and __progname, making the latter a copy of just the filename
portion like crt0 does. This is prep for eliminating _dl_fixup_user_env()
Mark almost everything in resolve.h as hidden, to improve code generation.

ok kettenis@ mpi@ "good time" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.38 20-Jan-2015 deraadt

If _dl_progname exceeds half the syslog buffer, truncate it with "...",
so that the remaining information is more visible
ok kettenis miod


# 1.37 16-Jan-2015 deraadt

<sys/param.h> to <limits.h> conversion. Verified binaries
ok millert, thanks to doug for process advice


# 1.36 09-Dec-2014 tedu

avoid void arithmetic. from david carlier


Revision tags: OPENBSD_5_6_BASE
# 1.35 14-Jul-2014 deraadt

Now that we have sendsyslog(2), we can directly use it in the
(previously completely retarded) stack_smash_handler of ld.so
ok beck miod tedu


# 1.34 06-Jul-2014 otto

rm unneeded includes; prompted (partly) by kettenis@


# 1.33 06-Jul-2014 otto

move from sysclt(KERN_ARND) to getentropy(2); ok miod@, kettenis@


# 1.32 21-Jun-2014 otto

Move to a non-zeroing _dl_malloc, a _dl_calloc and _dl_reallocarry and
fix _dl_strdup to return NULL instead of crash; ok deraadt@


# 1.31 14-Jun-2014 miod

Make _dl_randombuf invoke sysctl KERN_ARND in 256-byte chunks, for this is
(currently) the largest output you can get from it.

ok deraadt@


# 1.30 05-Jun-2014 otto

Move to (slightly stripped) version of libc malloc; ok deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.29 23-Jan-2014 deraadt

improve some types


# 1.28 28-Dec-2013 deraadt

Do not need __guard anymore
Discussion with miod
ok kettenis


# 1.27 13-Nov-2013 deraadt

prototype & void * math cleanup
ok guenther


Revision tags: OPENBSD_5_4_BASE
# 1.26 09-Jun-2013 miod

Constify the mib argument of sysctl().
ok matthew@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.25 23-Jan-2013 miod

Cache flush .plt after updating its pointers to .got during the initial
object relocation, if loaded at a different address than the one it was
compiled for; unsurprisingly fixes some spurious crashes.


# 1.24 28-Aug-2012 matthew

Add __guard_local as a hidden symbol to ld.so, kernel, and every
executable and DSO (via crtbegin.c/crtbeginS.c). Not used yet, but
needed before GCC can start emitting -fstack-protector code that uses
them instead of __guard.


# 1.23 22-Aug-2012 matthew

Change ld.so and libc to use .openbsd.randomdata on ELF platforms for
initializing their __guard values. For the time being, we're leaving
libc's constructor method as a backup to make sure __guard actually
gets initialized and to emit syslog warnings when it's not.

Not really an ABI change, so no shlib bump... "hold on to your butts"

ok deraadt, kettenis


# 1.22 07-Aug-2012 matthew

Factor out a _dl_randombuf() method from _dl_random().


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.21 30-Oct-2010 deraadt

fix a 10 year old bug in the memory allocator, which affected only sparc.
sparc has 4 byte long, but needs 8 byte alignment. recently the DIR
struct was changed to contain some off_t, which needs 8 byte alignment.
turns out the allocator calculated the bias for alignment, and then
subtracted out it's private linkage storage afterwards. on hppa this
worked because a 8-byte object can be loaded at a 4-byte boundary; on
all other architectures the situation was either 4/4 or 8/8.
thanks for a bit of help from drahn


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.20 02-Oct-2008 kurt

Fix mmap() error checking to be correct 64-bit addresses. Consistently
use _dl_mmap_error() to check for mmap() errors. Adjust datatypes of
some local vars for 64-bit safety.

okay millert@ drahn@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.19 09-Feb-2007 drahn

readdir buffers should not get a fixed buffer size, but should be dependant
on the block size of the filesystem. Rounded up to page size for efficiency.
similar to change in libc yesterday. Should fix PR 5364.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 14-Jun-2004 millert

Make _dl_malloc() deal with allocations > 4096 correctly. Also place
unused memory chunks on the free list when making a large allocation.
OK drahn@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.17 25-Feb-2004 drahn

Fix this assumed sizeof(long) == 4 error. Would very occasionally cause
the code to attempt to zero 4 bytes of the next page.


Revision tags: OPENBSD_3_4_BASE
# 1.16 06-Jul-2003 deraadt

various proto, ansi, and knf repair. tested on all architectures that
use it. (build may require make cleandir because of .depend balony)


# 1.15 09-Jun-2003 deraadt

pefo 3/4 licence cleanups


# 1.14 30-May-2003 drahn

When loading a shared object or libraries dependant object, load them
in random order. This will reduce the possiblity of a buffer overflow
being able to predict the addresss of useful code. Can be disabled
with the LD_NORANDOM environment variable for debugging purposes.
ok deraadt.


Revision tags: OPENBSD_3_3_BASE
# 1.13 02-Feb-2003 deraadt

knf & ansi; drahn ok


# 1.12 02-Dec-2002 deraadt

KNF; openbsd@davidkrause.com


# 1.11 02-Dec-2002 naddy

typo; ok miod@


# 1.10 02-Dec-2002 miod

Import propolice (http://www.trl.ibm.com/projects/security/ssp), a stack
attack protection scheme, into gcc.

This protection is enabled by default. It can be turned off by using the
-fno-stack-protector flag.

Code by Hiroaki Etoh (etoh at jp dot ibm dot com); work on openbsd-specific
integration by fgsch@, deraadt@ and myself; tests by fgsch@, naddy@ and
myself; beer drinking by myself.

Please note that system upgrades with this new code will require a new
libc and ld.so to be build and installed before the propolice-enabled
compiler can be installed.


Revision tags: OPENBSD_3_2_BASE
# 1.9 24-Jul-2002 deraadt

ok i found it


# 1.8 24-Jul-2002 deraadt

back out broken stuff until it is fixed


# 1.7 24-Jul-2002 deraadt

make more _dl_*() func params like real ones in libc


# 1.6 07-Jul-2002 jufi

typos/grammar/better words
in comments.


# 1.5 28-May-2002 deraadt

more KNF


# 1.4 24-May-2002 drahn

Change _dl_strcpy() to _dl_strlcpy(), implementation taken from libc.


# 1.3 24-May-2002 deraadt

various KNF


Revision tags: OPENBSD_3_1_BASE
# 1.2 09-Apr-2002 drahn

Add the Copyrights from the respective files the code came from. ok deraadt@


# 1.1 21-Feb-2002 drahn

cleanup of MD/MI ld.so (elf), most changes by art@ cleanup by me.
tested on alpha sparc64 powerpc.


# 1.47 27-Mar-2020 matthieu

Add missing space in stack smash handler error message.
ok kettenis@, deraadt@


Revision tags: OPENBSD_6_6_BASE
# 1.46 08-May-2019 deraadt

On retguard systems, remove the ld.so-local stack-protector handling
functions because retguard uses hard-traps instead.
ok mortimer.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.45 09-Feb-2018 mortimer

Use a static chacha instance to fill randomdata sections. Avoids looping
over a syscall for randomdata sections larger than 256B.

ok djm@ deraadt@ kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.44 24-Jan-2017 guenther

On fatal errors, kill ourselves with thrkill(0,9,NULL) instead of
simply exiting, via helper functions _dl_die(), _dl_diedie(), and
_dl_oom().

prompted by a complaint from jsing@
ok jsing@ deraadt@


# 1.43 12-Aug-2016 deraadt

the slimmed down random functions inside ld.so are strict clones of the
libc arc4random API, so call them _dl_{arc4random,arcrandombuf}
ok tedu guenther


# 1.42 05-Aug-2016 tedu

use a larger chunk for getentropy() and save some for next time.
coalesces some syscalls instead of one per random number.
ok deraadt


Revision tags: OPENBSD_6_0_BASE
# 1.41 21-Mar-2016 bluhm

Rename the system call sendsyslog2 to sendsyslog. Keep the old one
as osendsyslog for a while. The three argument variant is the only
one that will stay.
input kettenis@; OK deraadt@


# 1.40 21-Mar-2016 guenther

Switch ld.so's stack smash handler from sendsyslog to sendsyslog2
and pass the LOG_CONS flag like libc's handler.

ok deraadt@ bluhm@ (who had a similar diff)


# 1.39 20-Mar-2016 guenther

Export environ and __progname, making the latter a copy of just the filename
portion like crt0 does. This is prep for eliminating _dl_fixup_user_env()
Mark almost everything in resolve.h as hidden, to improve code generation.

ok kettenis@ mpi@ "good time" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.38 20-Jan-2015 deraadt

If _dl_progname exceeds half the syslog buffer, truncate it with "...",
so that the remaining information is more visible
ok kettenis miod


# 1.37 16-Jan-2015 deraadt

<sys/param.h> to <limits.h> conversion. Verified binaries
ok millert, thanks to doug for process advice


# 1.36 09-Dec-2014 tedu

avoid void arithmetic. from david carlier


Revision tags: OPENBSD_5_6_BASE
# 1.35 14-Jul-2014 deraadt

Now that we have sendsyslog(2), we can directly use it in the
(previously completely retarded) stack_smash_handler of ld.so
ok beck miod tedu


# 1.34 06-Jul-2014 otto

rm unneeded includes; prompted (partly) by kettenis@


# 1.33 06-Jul-2014 otto

move from sysclt(KERN_ARND) to getentropy(2); ok miod@, kettenis@


# 1.32 21-Jun-2014 otto

Move to a non-zeroing _dl_malloc, a _dl_calloc and _dl_reallocarry and
fix _dl_strdup to return NULL instead of crash; ok deraadt@


# 1.31 14-Jun-2014 miod

Make _dl_randombuf invoke sysctl KERN_ARND in 256-byte chunks, for this is
(currently) the largest output you can get from it.

ok deraadt@


# 1.30 05-Jun-2014 otto

Move to (slightly stripped) version of libc malloc; ok deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.29 23-Jan-2014 deraadt

improve some types


# 1.28 28-Dec-2013 deraadt

Do not need __guard anymore
Discussion with miod
ok kettenis


# 1.27 13-Nov-2013 deraadt

prototype & void * math cleanup
ok guenther


Revision tags: OPENBSD_5_4_BASE
# 1.26 09-Jun-2013 miod

Constify the mib argument of sysctl().
ok matthew@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.25 23-Jan-2013 miod

Cache flush .plt after updating its pointers to .got during the initial
object relocation, if loaded at a different address than the one it was
compiled for; unsurprisingly fixes some spurious crashes.


# 1.24 28-Aug-2012 matthew

Add __guard_local as a hidden symbol to ld.so, kernel, and every
executable and DSO (via crtbegin.c/crtbeginS.c). Not used yet, but
needed before GCC can start emitting -fstack-protector code that uses
them instead of __guard.


# 1.23 22-Aug-2012 matthew

Change ld.so and libc to use .openbsd.randomdata on ELF platforms for
initializing their __guard values. For the time being, we're leaving
libc's constructor method as a backup to make sure __guard actually
gets initialized and to emit syslog warnings when it's not.

Not really an ABI change, so no shlib bump... "hold on to your butts"

ok deraadt, kettenis


# 1.22 07-Aug-2012 matthew

Factor out a _dl_randombuf() method from _dl_random().


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.21 30-Oct-2010 deraadt

fix a 10 year old bug in the memory allocator, which affected only sparc.
sparc has 4 byte long, but needs 8 byte alignment. recently the DIR
struct was changed to contain some off_t, which needs 8 byte alignment.
turns out the allocator calculated the bias for alignment, and then
subtracted out it's private linkage storage afterwards. on hppa this
worked because a 8-byte object can be loaded at a 4-byte boundary; on
all other architectures the situation was either 4/4 or 8/8.
thanks for a bit of help from drahn


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.20 02-Oct-2008 kurt

Fix mmap() error checking to be correct 64-bit addresses. Consistently
use _dl_mmap_error() to check for mmap() errors. Adjust datatypes of
some local vars for 64-bit safety.

okay millert@ drahn@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.19 09-Feb-2007 drahn

readdir buffers should not get a fixed buffer size, but should be dependant
on the block size of the filesystem. Rounded up to page size for efficiency.
similar to change in libc yesterday. Should fix PR 5364.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 14-Jun-2004 millert

Make _dl_malloc() deal with allocations > 4096 correctly. Also place
unused memory chunks on the free list when making a large allocation.
OK drahn@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.17 25-Feb-2004 drahn

Fix this assumed sizeof(long) == 4 error. Would very occasionally cause
the code to attempt to zero 4 bytes of the next page.


Revision tags: OPENBSD_3_4_BASE
# 1.16 06-Jul-2003 deraadt

various proto, ansi, and knf repair. tested on all architectures that
use it. (build may require make cleandir because of .depend balony)


# 1.15 09-Jun-2003 deraadt

pefo 3/4 licence cleanups


# 1.14 30-May-2003 drahn

When loading a shared object or libraries dependant object, load them
in random order. This will reduce the possiblity of a buffer overflow
being able to predict the addresss of useful code. Can be disabled
with the LD_NORANDOM environment variable for debugging purposes.
ok deraadt.


Revision tags: OPENBSD_3_3_BASE
# 1.13 02-Feb-2003 deraadt

knf & ansi; drahn ok


# 1.12 02-Dec-2002 deraadt

KNF; openbsd@davidkrause.com


# 1.11 02-Dec-2002 naddy

typo; ok miod@


# 1.10 02-Dec-2002 miod

Import propolice (http://www.trl.ibm.com/projects/security/ssp), a stack
attack protection scheme, into gcc.

This protection is enabled by default. It can be turned off by using the
-fno-stack-protector flag.

Code by Hiroaki Etoh (etoh at jp dot ibm dot com); work on openbsd-specific
integration by fgsch@, deraadt@ and myself; tests by fgsch@, naddy@ and
myself; beer drinking by myself.

Please note that system upgrades with this new code will require a new
libc and ld.so to be build and installed before the propolice-enabled
compiler can be installed.


Revision tags: OPENBSD_3_2_BASE
# 1.9 24-Jul-2002 deraadt

ok i found it


# 1.8 24-Jul-2002 deraadt

back out broken stuff until it is fixed


# 1.7 24-Jul-2002 deraadt

make more _dl_*() func params like real ones in libc


# 1.6 07-Jul-2002 jufi

typos/grammar/better words
in comments.


# 1.5 28-May-2002 deraadt

more KNF


# 1.4 24-May-2002 drahn

Change _dl_strcpy() to _dl_strlcpy(), implementation taken from libc.


# 1.3 24-May-2002 deraadt

various KNF


Revision tags: OPENBSD_3_1_BASE
# 1.2 09-Apr-2002 drahn

Add the Copyrights from the respective files the code came from. ok deraadt@


# 1.1 21-Feb-2002 drahn

cleanup of MD/MI ld.so (elf), most changes by art@ cleanup by me.
tested on alpha sparc64 powerpc.


# 1.46 08-May-2019 deraadt

On retguard systems, remove the ld.so-local stack-protector handling
functions because retguard uses hard-traps instead.
ok mortimer.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.45 09-Feb-2018 mortimer

Use a static chacha instance to fill randomdata sections. Avoids looping
over a syscall for randomdata sections larger than 256B.

ok djm@ deraadt@ kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.44 24-Jan-2017 guenther

On fatal errors, kill ourselves with thrkill(0,9,NULL) instead of
simply exiting, via helper functions _dl_die(), _dl_diedie(), and
_dl_oom().

prompted by a complaint from jsing@
ok jsing@ deraadt@


# 1.43 12-Aug-2016 deraadt

the slimmed down random functions inside ld.so are strict clones of the
libc arc4random API, so call them _dl_{arc4random,arcrandombuf}
ok tedu guenther


# 1.42 05-Aug-2016 tedu

use a larger chunk for getentropy() and save some for next time.
coalesces some syscalls instead of one per random number.
ok deraadt


Revision tags: OPENBSD_6_0_BASE
# 1.41 21-Mar-2016 bluhm

Rename the system call sendsyslog2 to sendsyslog. Keep the old one
as osendsyslog for a while. The three argument variant is the only
one that will stay.
input kettenis@; OK deraadt@


# 1.40 21-Mar-2016 guenther

Switch ld.so's stack smash handler from sendsyslog to sendsyslog2
and pass the LOG_CONS flag like libc's handler.

ok deraadt@ bluhm@ (who had a similar diff)


# 1.39 20-Mar-2016 guenther

Export environ and __progname, making the latter a copy of just the filename
portion like crt0 does. This is prep for eliminating _dl_fixup_user_env()
Mark almost everything in resolve.h as hidden, to improve code generation.

ok kettenis@ mpi@ "good time" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.38 20-Jan-2015 deraadt

If _dl_progname exceeds half the syslog buffer, truncate it with "...",
so that the remaining information is more visible
ok kettenis miod


# 1.37 16-Jan-2015 deraadt

<sys/param.h> to <limits.h> conversion. Verified binaries
ok millert, thanks to doug for process advice


# 1.36 09-Dec-2014 tedu

avoid void arithmetic. from david carlier


Revision tags: OPENBSD_5_6_BASE
# 1.35 14-Jul-2014 deraadt

Now that we have sendsyslog(2), we can directly use it in the
(previously completely retarded) stack_smash_handler of ld.so
ok beck miod tedu


# 1.34 06-Jul-2014 otto

rm unneeded includes; prompted (partly) by kettenis@


# 1.33 06-Jul-2014 otto

move from sysclt(KERN_ARND) to getentropy(2); ok miod@, kettenis@


# 1.32 21-Jun-2014 otto

Move to a non-zeroing _dl_malloc, a _dl_calloc and _dl_reallocarry and
fix _dl_strdup to return NULL instead of crash; ok deraadt@


# 1.31 14-Jun-2014 miod

Make _dl_randombuf invoke sysctl KERN_ARND in 256-byte chunks, for this is
(currently) the largest output you can get from it.

ok deraadt@


# 1.30 05-Jun-2014 otto

Move to (slightly stripped) version of libc malloc; ok deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.29 23-Jan-2014 deraadt

improve some types


# 1.28 28-Dec-2013 deraadt

Do not need __guard anymore
Discussion with miod
ok kettenis


# 1.27 13-Nov-2013 deraadt

prototype & void * math cleanup
ok guenther


Revision tags: OPENBSD_5_4_BASE
# 1.26 09-Jun-2013 miod

Constify the mib argument of sysctl().
ok matthew@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.25 23-Jan-2013 miod

Cache flush .plt after updating its pointers to .got during the initial
object relocation, if loaded at a different address than the one it was
compiled for; unsurprisingly fixes some spurious crashes.


# 1.24 28-Aug-2012 matthew

Add __guard_local as a hidden symbol to ld.so, kernel, and every
executable and DSO (via crtbegin.c/crtbeginS.c). Not used yet, but
needed before GCC can start emitting -fstack-protector code that uses
them instead of __guard.


# 1.23 22-Aug-2012 matthew

Change ld.so and libc to use .openbsd.randomdata on ELF platforms for
initializing their __guard values. For the time being, we're leaving
libc's constructor method as a backup to make sure __guard actually
gets initialized and to emit syslog warnings when it's not.

Not really an ABI change, so no shlib bump... "hold on to your butts"

ok deraadt, kettenis


# 1.22 07-Aug-2012 matthew

Factor out a _dl_randombuf() method from _dl_random().


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.21 30-Oct-2010 deraadt

fix a 10 year old bug in the memory allocator, which affected only sparc.
sparc has 4 byte long, but needs 8 byte alignment. recently the DIR
struct was changed to contain some off_t, which needs 8 byte alignment.
turns out the allocator calculated the bias for alignment, and then
subtracted out it's private linkage storage afterwards. on hppa this
worked because a 8-byte object can be loaded at a 4-byte boundary; on
all other architectures the situation was either 4/4 or 8/8.
thanks for a bit of help from drahn


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.20 02-Oct-2008 kurt

Fix mmap() error checking to be correct 64-bit addresses. Consistently
use _dl_mmap_error() to check for mmap() errors. Adjust datatypes of
some local vars for 64-bit safety.

okay millert@ drahn@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.19 09-Feb-2007 drahn

readdir buffers should not get a fixed buffer size, but should be dependant
on the block size of the filesystem. Rounded up to page size for efficiency.
similar to change in libc yesterday. Should fix PR 5364.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 14-Jun-2004 millert

Make _dl_malloc() deal with allocations > 4096 correctly. Also place
unused memory chunks on the free list when making a large allocation.
OK drahn@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.17 25-Feb-2004 drahn

Fix this assumed sizeof(long) == 4 error. Would very occasionally cause
the code to attempt to zero 4 bytes of the next page.


Revision tags: OPENBSD_3_4_BASE
# 1.16 06-Jul-2003 deraadt

various proto, ansi, and knf repair. tested on all architectures that
use it. (build may require make cleandir because of .depend balony)


# 1.15 09-Jun-2003 deraadt

pefo 3/4 licence cleanups


# 1.14 30-May-2003 drahn

When loading a shared object or libraries dependant object, load them
in random order. This will reduce the possiblity of a buffer overflow
being able to predict the addresss of useful code. Can be disabled
with the LD_NORANDOM environment variable for debugging purposes.
ok deraadt.


Revision tags: OPENBSD_3_3_BASE
# 1.13 02-Feb-2003 deraadt

knf & ansi; drahn ok


# 1.12 02-Dec-2002 deraadt

KNF; openbsd@davidkrause.com


# 1.11 02-Dec-2002 naddy

typo; ok miod@


# 1.10 02-Dec-2002 miod

Import propolice (http://www.trl.ibm.com/projects/security/ssp), a stack
attack protection scheme, into gcc.

This protection is enabled by default. It can be turned off by using the
-fno-stack-protector flag.

Code by Hiroaki Etoh (etoh at jp dot ibm dot com); work on openbsd-specific
integration by fgsch@, deraadt@ and myself; tests by fgsch@, naddy@ and
myself; beer drinking by myself.

Please note that system upgrades with this new code will require a new
libc and ld.so to be build and installed before the propolice-enabled
compiler can be installed.


Revision tags: OPENBSD_3_2_BASE
# 1.9 24-Jul-2002 deraadt

ok i found it


# 1.8 24-Jul-2002 deraadt

back out broken stuff until it is fixed


# 1.7 24-Jul-2002 deraadt

make more _dl_*() func params like real ones in libc


# 1.6 07-Jul-2002 jufi

typos/grammar/better words
in comments.


# 1.5 28-May-2002 deraadt

more KNF


# 1.4 24-May-2002 drahn

Change _dl_strcpy() to _dl_strlcpy(), implementation taken from libc.


# 1.3 24-May-2002 deraadt

various KNF


Revision tags: OPENBSD_3_1_BASE
# 1.2 09-Apr-2002 drahn

Add the Copyrights from the respective files the code came from. ok deraadt@


# 1.1 21-Feb-2002 drahn

cleanup of MD/MI ld.so (elf), most changes by art@ cleanup by me.
tested on alpha sparc64 powerpc.


# 1.45 09-Feb-2018 mortimer

Use a static chacha instance to fill randomdata sections. Avoids looping
over a syscall for randomdata sections larger than 256B.

ok djm@ deraadt@ kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.44 24-Jan-2017 guenther

On fatal errors, kill ourselves with thrkill(0,9,NULL) instead of
simply exiting, via helper functions _dl_die(), _dl_diedie(), and
_dl_oom().

prompted by a complaint from jsing@
ok jsing@ deraadt@


# 1.43 12-Aug-2016 deraadt

the slimmed down random functions inside ld.so are strict clones of the
libc arc4random API, so call them _dl_{arc4random,arcrandombuf}
ok tedu guenther


# 1.42 05-Aug-2016 tedu

use a larger chunk for getentropy() and save some for next time.
coalesces some syscalls instead of one per random number.
ok deraadt


Revision tags: OPENBSD_6_0_BASE
# 1.41 21-Mar-2016 bluhm

Rename the system call sendsyslog2 to sendsyslog. Keep the old one
as osendsyslog for a while. The three argument variant is the only
one that will stay.
input kettenis@; OK deraadt@


# 1.40 21-Mar-2016 guenther

Switch ld.so's stack smash handler from sendsyslog to sendsyslog2
and pass the LOG_CONS flag like libc's handler.

ok deraadt@ bluhm@ (who had a similar diff)


# 1.39 20-Mar-2016 guenther

Export environ and __progname, making the latter a copy of just the filename
portion like crt0 does. This is prep for eliminating _dl_fixup_user_env()
Mark almost everything in resolve.h as hidden, to improve code generation.

ok kettenis@ mpi@ "good time" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.38 20-Jan-2015 deraadt

If _dl_progname exceeds half the syslog buffer, truncate it with "...",
so that the remaining information is more visible
ok kettenis miod


# 1.37 16-Jan-2015 deraadt

<sys/param.h> to <limits.h> conversion. Verified binaries
ok millert, thanks to doug for process advice


# 1.36 09-Dec-2014 tedu

avoid void arithmetic. from david carlier


Revision tags: OPENBSD_5_6_BASE
# 1.35 14-Jul-2014 deraadt

Now that we have sendsyslog(2), we can directly use it in the
(previously completely retarded) stack_smash_handler of ld.so
ok beck miod tedu


# 1.34 06-Jul-2014 otto

rm unneeded includes; prompted (partly) by kettenis@


# 1.33 06-Jul-2014 otto

move from sysclt(KERN_ARND) to getentropy(2); ok miod@, kettenis@


# 1.32 21-Jun-2014 otto

Move to a non-zeroing _dl_malloc, a _dl_calloc and _dl_reallocarry and
fix _dl_strdup to return NULL instead of crash; ok deraadt@


# 1.31 14-Jun-2014 miod

Make _dl_randombuf invoke sysctl KERN_ARND in 256-byte chunks, for this is
(currently) the largest output you can get from it.

ok deraadt@


# 1.30 05-Jun-2014 otto

Move to (slightly stripped) version of libc malloc; ok deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.29 23-Jan-2014 deraadt

improve some types


# 1.28 28-Dec-2013 deraadt

Do not need __guard anymore
Discussion with miod
ok kettenis


# 1.27 13-Nov-2013 deraadt

prototype & void * math cleanup
ok guenther


Revision tags: OPENBSD_5_4_BASE
# 1.26 09-Jun-2013 miod

Constify the mib argument of sysctl().
ok matthew@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.25 23-Jan-2013 miod

Cache flush .plt after updating its pointers to .got during the initial
object relocation, if loaded at a different address than the one it was
compiled for; unsurprisingly fixes some spurious crashes.


# 1.24 28-Aug-2012 matthew

Add __guard_local as a hidden symbol to ld.so, kernel, and every
executable and DSO (via crtbegin.c/crtbeginS.c). Not used yet, but
needed before GCC can start emitting -fstack-protector code that uses
them instead of __guard.


# 1.23 22-Aug-2012 matthew

Change ld.so and libc to use .openbsd.randomdata on ELF platforms for
initializing their __guard values. For the time being, we're leaving
libc's constructor method as a backup to make sure __guard actually
gets initialized and to emit syslog warnings when it's not.

Not really an ABI change, so no shlib bump... "hold on to your butts"

ok deraadt, kettenis


# 1.22 07-Aug-2012 matthew

Factor out a _dl_randombuf() method from _dl_random().


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.21 30-Oct-2010 deraadt

fix a 10 year old bug in the memory allocator, which affected only sparc.
sparc has 4 byte long, but needs 8 byte alignment. recently the DIR
struct was changed to contain some off_t, which needs 8 byte alignment.
turns out the allocator calculated the bias for alignment, and then
subtracted out it's private linkage storage afterwards. on hppa this
worked because a 8-byte object can be loaded at a 4-byte boundary; on
all other architectures the situation was either 4/4 or 8/8.
thanks for a bit of help from drahn


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.20 02-Oct-2008 kurt

Fix mmap() error checking to be correct 64-bit addresses. Consistently
use _dl_mmap_error() to check for mmap() errors. Adjust datatypes of
some local vars for 64-bit safety.

okay millert@ drahn@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.19 09-Feb-2007 drahn

readdir buffers should not get a fixed buffer size, but should be dependant
on the block size of the filesystem. Rounded up to page size for efficiency.
similar to change in libc yesterday. Should fix PR 5364.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 14-Jun-2004 millert

Make _dl_malloc() deal with allocations > 4096 correctly. Also place
unused memory chunks on the free list when making a large allocation.
OK drahn@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.17 25-Feb-2004 drahn

Fix this assumed sizeof(long) == 4 error. Would very occasionally cause
the code to attempt to zero 4 bytes of the next page.


Revision tags: OPENBSD_3_4_BASE
# 1.16 06-Jul-2003 deraadt

various proto, ansi, and knf repair. tested on all architectures that
use it. (build may require make cleandir because of .depend balony)


# 1.15 09-Jun-2003 deraadt

pefo 3/4 licence cleanups


# 1.14 30-May-2003 drahn

When loading a shared object or libraries dependant object, load them
in random order. This will reduce the possiblity of a buffer overflow
being able to predict the addresss of useful code. Can be disabled
with the LD_NORANDOM environment variable for debugging purposes.
ok deraadt.


Revision tags: OPENBSD_3_3_BASE
# 1.13 02-Feb-2003 deraadt

knf & ansi; drahn ok


# 1.12 02-Dec-2002 deraadt

KNF; openbsd@davidkrause.com


# 1.11 02-Dec-2002 naddy

typo; ok miod@


# 1.10 02-Dec-2002 miod

Import propolice (http://www.trl.ibm.com/projects/security/ssp), a stack
attack protection scheme, into gcc.

This protection is enabled by default. It can be turned off by using the
-fno-stack-protector flag.

Code by Hiroaki Etoh (etoh at jp dot ibm dot com); work on openbsd-specific
integration by fgsch@, deraadt@ and myself; tests by fgsch@, naddy@ and
myself; beer drinking by myself.

Please note that system upgrades with this new code will require a new
libc and ld.so to be build and installed before the propolice-enabled
compiler can be installed.


Revision tags: OPENBSD_3_2_BASE
# 1.9 24-Jul-2002 deraadt

ok i found it


# 1.8 24-Jul-2002 deraadt

back out broken stuff until it is fixed


# 1.7 24-Jul-2002 deraadt

make more _dl_*() func params like real ones in libc


# 1.6 07-Jul-2002 jufi

typos/grammar/better words
in comments.


# 1.5 28-May-2002 deraadt

more KNF


# 1.4 24-May-2002 drahn

Change _dl_strcpy() to _dl_strlcpy(), implementation taken from libc.


# 1.3 24-May-2002 deraadt

various KNF


Revision tags: OPENBSD_3_1_BASE
# 1.2 09-Apr-2002 drahn

Add the Copyrights from the respective files the code came from. ok deraadt@


# 1.1 21-Feb-2002 drahn

cleanup of MD/MI ld.so (elf), most changes by art@ cleanup by me.
tested on alpha sparc64 powerpc.


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.44 24-Jan-2017 guenther

On fatal errors, kill ourselves with thrkill(0,9,NULL) instead of
simply exiting, via helper functions _dl_die(), _dl_diedie(), and
_dl_oom().

prompted by a complaint from jsing@
ok jsing@ deraadt@


# 1.43 12-Aug-2016 deraadt

the slimmed down random functions inside ld.so are strict clones of the
libc arc4random API, so call them _dl_{arc4random,arcrandombuf}
ok tedu guenther


# 1.42 05-Aug-2016 tedu

use a larger chunk for getentropy() and save some for next time.
coalesces some syscalls instead of one per random number.
ok deraadt


Revision tags: OPENBSD_6_0_BASE
# 1.41 21-Mar-2016 bluhm

Rename the system call sendsyslog2 to sendsyslog. Keep the old one
as osendsyslog for a while. The three argument variant is the only
one that will stay.
input kettenis@; OK deraadt@


# 1.40 21-Mar-2016 guenther

Switch ld.so's stack smash handler from sendsyslog to sendsyslog2
and pass the LOG_CONS flag like libc's handler.

ok deraadt@ bluhm@ (who had a similar diff)


# 1.39 20-Mar-2016 guenther

Export environ and __progname, making the latter a copy of just the filename
portion like crt0 does. This is prep for eliminating _dl_fixup_user_env()
Mark almost everything in resolve.h as hidden, to improve code generation.

ok kettenis@ mpi@ "good time" deraadt@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.38 20-Jan-2015 deraadt

If _dl_progname exceeds half the syslog buffer, truncate it with "...",
so that the remaining information is more visible
ok kettenis miod


# 1.37 16-Jan-2015 deraadt

<sys/param.h> to <limits.h> conversion. Verified binaries
ok millert, thanks to doug for process advice


# 1.36 09-Dec-2014 tedu

avoid void arithmetic. from david carlier


Revision tags: OPENBSD_5_6_BASE
# 1.35 14-Jul-2014 deraadt

Now that we have sendsyslog(2), we can directly use it in the
(previously completely retarded) stack_smash_handler of ld.so
ok beck miod tedu


# 1.34 06-Jul-2014 otto

rm unneeded includes; prompted (partly) by kettenis@


# 1.33 06-Jul-2014 otto

move from sysclt(KERN_ARND) to getentropy(2); ok miod@, kettenis@


# 1.32 21-Jun-2014 otto

Move to a non-zeroing _dl_malloc, a _dl_calloc and _dl_reallocarry and
fix _dl_strdup to return NULL instead of crash; ok deraadt@


# 1.31 14-Jun-2014 miod

Make _dl_randombuf invoke sysctl KERN_ARND in 256-byte chunks, for this is
(currently) the largest output you can get from it.

ok deraadt@


# 1.30 05-Jun-2014 otto

Move to (slightly stripped) version of libc malloc; ok deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.29 23-Jan-2014 deraadt

improve some types


# 1.28 28-Dec-2013 deraadt

Do not need __guard anymore
Discussion with miod
ok kettenis


# 1.27 13-Nov-2013 deraadt

prototype & void * math cleanup
ok guenther


Revision tags: OPENBSD_5_4_BASE
# 1.26 09-Jun-2013 miod

Constify the mib argument of sysctl().
ok matthew@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.25 23-Jan-2013 miod

Cache flush .plt after updating its pointers to .got during the initial
object relocation, if loaded at a different address than the one it was
compiled for; unsurprisingly fixes some spurious crashes.


# 1.24 28-Aug-2012 matthew

Add __guard_local as a hidden symbol to ld.so, kernel, and every
executable and DSO (via crtbegin.c/crtbeginS.c). Not used yet, but
needed before GCC can start emitting -fstack-protector code that uses
them instead of __guard.


# 1.23 22-Aug-2012 matthew

Change ld.so and libc to use .openbsd.randomdata on ELF platforms for
initializing their __guard values. For the time being, we're leaving
libc's constructor method as a backup to make sure __guard actually
gets initialized and to emit syslog warnings when it's not.

Not really an ABI change, so no shlib bump... "hold on to your butts"

ok deraadt, kettenis


# 1.22 07-Aug-2012 matthew

Factor out a _dl_randombuf() method from _dl_random().


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.21 30-Oct-2010 deraadt

fix a 10 year old bug in the memory allocator, which affected only sparc.
sparc has 4 byte long, but needs 8 byte alignment. recently the DIR
struct was changed to contain some off_t, which needs 8 byte alignment.
turns out the allocator calculated the bias for alignment, and then
subtracted out it's private linkage storage afterwards. on hppa this
worked because a 8-byte object can be loaded at a 4-byte boundary; on
all other architectures the situation was either 4/4 or 8/8.
thanks for a bit of help from drahn


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.20 02-Oct-2008 kurt

Fix mmap() error checking to be correct 64-bit addresses. Consistently
use _dl_mmap_error() to check for mmap() errors. Adjust datatypes of
some local vars for 64-bit safety.

okay millert@ drahn@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.19 09-Feb-2007 drahn

readdir buffers should not get a fixed buffer size, but should be dependant
on the block size of the filesystem. Rounded up to page size for efficiency.
similar to change in libc yesterday. Should fix PR 5364.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.18 14-Jun-2004 millert

Make _dl_malloc() deal with allocations > 4096 correctly. Also place
unused memory chunks on the free list when making a large allocation.
OK drahn@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.17 25-Feb-2004 drahn

Fix this assumed sizeof(long) == 4 error. Would very occasionally cause
the code to attempt to zero 4 bytes of the next page.


Revision tags: OPENBSD_3_4_BASE
# 1.16 06-Jul-2003 deraadt

various proto, ansi, and knf repair. tested on all architectures that
use it. (build may require make cleandir because of .depend balony)


# 1.15 09-Jun-2003 deraadt

pefo 3/4 licence cleanups


# 1.14 30-May-2003 drahn

When loading a shared object or libraries dependant object, load them
in random order. This will reduce the possiblity of a buffer overflow
being able to predict the addresss of useful code. Can be disabled
with the LD_NORANDOM environment variable for debugging purposes.
ok deraadt.


Revision tags: OPENBSD_3_3_BASE
# 1.13 02-Feb-2003 deraadt

knf & ansi; drahn ok


# 1.12 02-Dec-2002 deraadt

KNF; openbsd@davidkrause.com


# 1.11 02-Dec-2002 naddy

typo; ok miod@


# 1.10 02-Dec-2002 miod

Import propolice (http://www.trl.ibm.com/projects/security/ssp), a stack
attack protection scheme, into gcc.

This protection is enabled by default. It can be turned off by using the
-fno-stack-protector flag.

Code by Hiroaki Etoh (etoh at jp dot ibm dot com); work on openbsd-specific
integration by fgsch@, deraadt@ and myself; tests by fgsch@, naddy@ and
myself; beer drinking by myself.

Please note that system upgrades with this new code will require a new
libc and ld.so to be build and installed before the propolice-enabled
compiler can be installed.


Revision tags: OPENBSD_3_2_BASE
# 1.9 24-Jul-2002 deraadt

ok i found it


# 1.8 24-Jul-2002 deraadt

back out broken stuff until it is fixed


# 1.7 24-Jul-2002 deraadt

make more _dl_*() func params like real ones in libc


# 1.6 07-Jul-2002 jufi

typos/grammar/better words
in comments.


# 1.5 28-May-2002 deraadt

more KNF


# 1.4 24-May-2002 drahn

Change _dl_strcpy() to _dl_strlcpy(), implementation taken from libc.


# 1.3 24-May-2002 deraadt

various KNF


Revision tags: OPENBSD_3_1_BASE
# 1.2 09-Apr-2002 drahn

Add the Copyrights from the respective files the code came from. ok deraadt@


# 1.1 21-Feb-2002 drahn

cleanup of MD/MI ld.so (elf), most changes by art@ cleanup by me.
tested on alpha sparc64 powerpc.