History log of /openbsd-current/libexec/ld.so/util.h
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.40 08-Dec-2023 deraadt

locally us MAXIMUM() rather than MAX()
ok tb gnezdo


Revision tags: OPENBSD_7_4_BASE
# 1.39 15-Aug-2023 guenther

Improve handling of dlopen(RTLD_TRACE) aka ldd, of a library that
is already loaded:
* add a 'trace' argument to _dl_show_objects() and exit the
walk-the-objects loop if you hit that traced object
* in dlopen(), pass the trace object to _dl_show_objects()
* also, invoke _dl_show_objects() + exit if the object was
already opened
* pass NULL to _dl_show_objects() for all the other calls
* oh hey, _dl_tracelib is now superfluous: _dl_show_objects()
should do the walk-the-objects loop only if trace is not NULL.

Problem noted by gnezdo@
ok millert@


Revision tags: OPENBSD_7_3_BASE
# 1.38 29-Jan-2023 gnezdo

Unite all nitems copies in ld.so/util.h

OK deraadt


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.37 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_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.36 14-Jul-2019 guenther

ld.so's $ORIGIN handling when argv[0] is a relative path was broken by
the change in __getcwd(2)'s return value. Fix it by switching to the
__realpath(2) syscall, eliminating the ld.so copy of realpath().

problem caught by regress and noted by bluhm@
ok deraadt@


# 1.35 10-May-2019 guenther

ld.so boot cleanup support:
- put functions and data which are only used before calling the executable's
start function into their own page-aligned segments for unmapping
(only done on amd64, arm64, armv7, powerpc, and sparc64 so far)
- pass .init_array and .preinit_array functions an addition argument which
is a callback to get a structure which includes a function that frees
the boot text and data
- sometimes delay doing RELRO processing: for a shared-object marked
DF_1_INITFIRST do it after the object's .init_array, for the executable
do it after the .preinit_array
- improve test-ld.so to link against libpthread and trigger its initialization
late
libc changes to use this will come later

ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.34 25-Jan-2019 millert

I am retiring my old email address; replace it with my OpenBSD one.


# 1.33 23-Oct-2018 guenther

Delay processing of ld.so's own PT_GNU_RELRO section until after environment
processing and malloc initialization, and then move variables set by those
steps, including malloc's mopts structure, into the .data.rel.ro segment.
This protects more data and eliminates the extra padding of the mopts.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.32 01-Dec-2017 guenther

Redo the calculation of the alignment and placement of static TLS data to
correctly take into account the segment p_align. Previously, anything
with a size belong the natural alignment or with alignment larger than
the natural one would either not be intialized correctly, be misaligned,
or result in the TIB being misaligned.

Problems reported by Charles Collicutt (charles (at) collicutt.co.uk)
ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.31 29-Aug-2017 deraadt

rename *fdprint function to *dprintf, like libc version


Revision tags: OPENBSD_6_1_BASE
# 1.30 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.29 23-Jan-2017 guenther

Wrap function declarations with __{BEGIN,END}_HIDDEN_DECLS to reduce
relocations inside ld.so that it has to bootstrap

ok kettenis@


# 1.28 27-Aug-2016 guenther

Pull in <stddef.h> for NULL
(not stdio, because ld.so has a reduced library behind it)


# 1.27 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


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.26 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@


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

improve some types


# 1.24 27-Nov-2013 deraadt

make the _dl_isalnum() resemble the ctype version
prodding from kettenis


Revision tags: OPENBSD_5_4_BASE
# 1.23 05-Apr-2013 kurt

- Add ORIGIN, OSNAME, OSREL and PLATFORM substitution support for rpaths.
Improvements and okay matthew@, millert@, guenther@


Revision tags: OPENBSD_5_3_BASE
# 1.22 07-Aug-2012 matthew

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


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.21 18-May-2009 deraadt

make _dl_wrstderr() not call write per-character; ok drahn


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE
# 1.20 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_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.19 17-Oct-2004 drahn

Fix some problems related to LD_LIBRARY_PATH parsing where it would not
correctly deal with current directory searches specified by "::", ":foo" or
"foo:"


Revision tags: OPENBSD_3_6_BASE
# 1.18 25-May-2004 mickey

provide one version of _dl_bcopy instead of copy in every arch; drahn@ ok


Revision tags: OPENBSD_3_5_BASE
# 1.17 11-Nov-2003 drahn

Better fix to the library name parsing. now correctly handles
libpython2.2.so.0.0 vs libpython2.1.so.0.0. Clean up a potential
memory leak if the filename is not a valid library.
ok brad@


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 11-Jun-2003 deraadt

no more register


# 1.14 09-Jun-2003 deraadt

pefo 3/4 licence cleanups


# 1.13 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_2_BASE OPENBSD_3_3_BASE
# 1.12 31-Aug-2002 drahn

argh, include prototype for dl_fdprintf(), missed by myself and reviewers.


# 1.11 24-Jul-2002 deraadt

use real clones of the libc functions


# 1.10 24-Jul-2002 deraadt

ok i found it


# 1.9 24-Jul-2002 deraadt

back out broken stuff until it is fixed


# 1.8 24-Jul-2002 deraadt

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


# 1.7 23-Jul-2002 mickey

match _dl_ syscall prototypes w/ the real syscalls prototypes, including args and return values; art@ ok


# 1.6 28-May-2002 deraadt

proto _dl_show_objects() in one place


# 1.5 27-May-2002 deraadt

left over __P removals


# 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.39 15-Aug-2023 guenther

Improve handling of dlopen(RTLD_TRACE) aka ldd, of a library that
is already loaded:
* add a 'trace' argument to _dl_show_objects() and exit the
walk-the-objects loop if you hit that traced object
* in dlopen(), pass the trace object to _dl_show_objects()
* also, invoke _dl_show_objects() + exit if the object was
already opened
* pass NULL to _dl_show_objects() for all the other calls
* oh hey, _dl_tracelib is now superfluous: _dl_show_objects()
should do the walk-the-objects loop only if trace is not NULL.

Problem noted by gnezdo@
ok millert@


Revision tags: OPENBSD_7_3_BASE
# 1.38 29-Jan-2023 gnezdo

Unite all nitems copies in ld.so/util.h

OK deraadt


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.37 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_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.36 14-Jul-2019 guenther

ld.so's $ORIGIN handling when argv[0] is a relative path was broken by
the change in __getcwd(2)'s return value. Fix it by switching to the
__realpath(2) syscall, eliminating the ld.so copy of realpath().

problem caught by regress and noted by bluhm@
ok deraadt@


# 1.35 10-May-2019 guenther

ld.so boot cleanup support:
- put functions and data which are only used before calling the executable's
start function into their own page-aligned segments for unmapping
(only done on amd64, arm64, armv7, powerpc, and sparc64 so far)
- pass .init_array and .preinit_array functions an addition argument which
is a callback to get a structure which includes a function that frees
the boot text and data
- sometimes delay doing RELRO processing: for a shared-object marked
DF_1_INITFIRST do it after the object's .init_array, for the executable
do it after the .preinit_array
- improve test-ld.so to link against libpthread and trigger its initialization
late
libc changes to use this will come later

ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.34 25-Jan-2019 millert

I am retiring my old email address; replace it with my OpenBSD one.


# 1.33 23-Oct-2018 guenther

Delay processing of ld.so's own PT_GNU_RELRO section until after environment
processing and malloc initialization, and then move variables set by those
steps, including malloc's mopts structure, into the .data.rel.ro segment.
This protects more data and eliminates the extra padding of the mopts.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.32 01-Dec-2017 guenther

Redo the calculation of the alignment and placement of static TLS data to
correctly take into account the segment p_align. Previously, anything
with a size belong the natural alignment or with alignment larger than
the natural one would either not be intialized correctly, be misaligned,
or result in the TIB being misaligned.

Problems reported by Charles Collicutt (charles (at) collicutt.co.uk)
ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.31 29-Aug-2017 deraadt

rename *fdprint function to *dprintf, like libc version


Revision tags: OPENBSD_6_1_BASE
# 1.30 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.29 23-Jan-2017 guenther

Wrap function declarations with __{BEGIN,END}_HIDDEN_DECLS to reduce
relocations inside ld.so that it has to bootstrap

ok kettenis@


# 1.28 27-Aug-2016 guenther

Pull in <stddef.h> for NULL
(not stdio, because ld.so has a reduced library behind it)


# 1.27 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


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.26 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@


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

improve some types


# 1.24 27-Nov-2013 deraadt

make the _dl_isalnum() resemble the ctype version
prodding from kettenis


Revision tags: OPENBSD_5_4_BASE
# 1.23 05-Apr-2013 kurt

- Add ORIGIN, OSNAME, OSREL and PLATFORM substitution support for rpaths.
Improvements and okay matthew@, millert@, guenther@


Revision tags: OPENBSD_5_3_BASE
# 1.22 07-Aug-2012 matthew

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


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.21 18-May-2009 deraadt

make _dl_wrstderr() not call write per-character; ok drahn


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE
# 1.20 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_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.19 17-Oct-2004 drahn

Fix some problems related to LD_LIBRARY_PATH parsing where it would not
correctly deal with current directory searches specified by "::", ":foo" or
"foo:"


Revision tags: OPENBSD_3_6_BASE
# 1.18 25-May-2004 mickey

provide one version of _dl_bcopy instead of copy in every arch; drahn@ ok


Revision tags: OPENBSD_3_5_BASE
# 1.17 11-Nov-2003 drahn

Better fix to the library name parsing. now correctly handles
libpython2.2.so.0.0 vs libpython2.1.so.0.0. Clean up a potential
memory leak if the filename is not a valid library.
ok brad@


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 11-Jun-2003 deraadt

no more register


# 1.14 09-Jun-2003 deraadt

pefo 3/4 licence cleanups


# 1.13 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_2_BASE OPENBSD_3_3_BASE
# 1.12 31-Aug-2002 drahn

argh, include prototype for dl_fdprintf(), missed by myself and reviewers.


# 1.11 24-Jul-2002 deraadt

use real clones of the libc functions


# 1.10 24-Jul-2002 deraadt

ok i found it


# 1.9 24-Jul-2002 deraadt

back out broken stuff until it is fixed


# 1.8 24-Jul-2002 deraadt

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


# 1.7 23-Jul-2002 mickey

match _dl_ syscall prototypes w/ the real syscalls prototypes, including args and return values; art@ ok


# 1.6 28-May-2002 deraadt

proto _dl_show_objects() in one place


# 1.5 27-May-2002 deraadt

left over __P removals


# 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.38 29-Jan-2023 gnezdo

Unite all nitems copies in ld.so/util.h

OK deraadt


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.37 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_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.36 14-Jul-2019 guenther

ld.so's $ORIGIN handling when argv[0] is a relative path was broken by
the change in __getcwd(2)'s return value. Fix it by switching to the
__realpath(2) syscall, eliminating the ld.so copy of realpath().

problem caught by regress and noted by bluhm@
ok deraadt@


# 1.35 10-May-2019 guenther

ld.so boot cleanup support:
- put functions and data which are only used before calling the executable's
start function into their own page-aligned segments for unmapping
(only done on amd64, arm64, armv7, powerpc, and sparc64 so far)
- pass .init_array and .preinit_array functions an addition argument which
is a callback to get a structure which includes a function that frees
the boot text and data
- sometimes delay doing RELRO processing: for a shared-object marked
DF_1_INITFIRST do it after the object's .init_array, for the executable
do it after the .preinit_array
- improve test-ld.so to link against libpthread and trigger its initialization
late
libc changes to use this will come later

ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.34 25-Jan-2019 millert

I am retiring my old email address; replace it with my OpenBSD one.


# 1.33 23-Oct-2018 guenther

Delay processing of ld.so's own PT_GNU_RELRO section until after environment
processing and malloc initialization, and then move variables set by those
steps, including malloc's mopts structure, into the .data.rel.ro segment.
This protects more data and eliminates the extra padding of the mopts.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.32 01-Dec-2017 guenther

Redo the calculation of the alignment and placement of static TLS data to
correctly take into account the segment p_align. Previously, anything
with a size belong the natural alignment or with alignment larger than
the natural one would either not be intialized correctly, be misaligned,
or result in the TIB being misaligned.

Problems reported by Charles Collicutt (charles (at) collicutt.co.uk)
ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.31 29-Aug-2017 deraadt

rename *fdprint function to *dprintf, like libc version


Revision tags: OPENBSD_6_1_BASE
# 1.30 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.29 23-Jan-2017 guenther

Wrap function declarations with __{BEGIN,END}_HIDDEN_DECLS to reduce
relocations inside ld.so that it has to bootstrap

ok kettenis@


# 1.28 27-Aug-2016 guenther

Pull in <stddef.h> for NULL
(not stdio, because ld.so has a reduced library behind it)


# 1.27 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


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.26 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@


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

improve some types


# 1.24 27-Nov-2013 deraadt

make the _dl_isalnum() resemble the ctype version
prodding from kettenis


Revision tags: OPENBSD_5_4_BASE
# 1.23 05-Apr-2013 kurt

- Add ORIGIN, OSNAME, OSREL and PLATFORM substitution support for rpaths.
Improvements and okay matthew@, millert@, guenther@


Revision tags: OPENBSD_5_3_BASE
# 1.22 07-Aug-2012 matthew

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


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.21 18-May-2009 deraadt

make _dl_wrstderr() not call write per-character; ok drahn


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE
# 1.20 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_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.19 17-Oct-2004 drahn

Fix some problems related to LD_LIBRARY_PATH parsing where it would not
correctly deal with current directory searches specified by "::", ":foo" or
"foo:"


Revision tags: OPENBSD_3_6_BASE
# 1.18 25-May-2004 mickey

provide one version of _dl_bcopy instead of copy in every arch; drahn@ ok


Revision tags: OPENBSD_3_5_BASE
# 1.17 11-Nov-2003 drahn

Better fix to the library name parsing. now correctly handles
libpython2.2.so.0.0 vs libpython2.1.so.0.0. Clean up a potential
memory leak if the filename is not a valid library.
ok brad@


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 11-Jun-2003 deraadt

no more register


# 1.14 09-Jun-2003 deraadt

pefo 3/4 licence cleanups


# 1.13 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_2_BASE OPENBSD_3_3_BASE
# 1.12 31-Aug-2002 drahn

argh, include prototype for dl_fdprintf(), missed by myself and reviewers.


# 1.11 24-Jul-2002 deraadt

use real clones of the libc functions


# 1.10 24-Jul-2002 deraadt

ok i found it


# 1.9 24-Jul-2002 deraadt

back out broken stuff until it is fixed


# 1.8 24-Jul-2002 deraadt

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


# 1.7 23-Jul-2002 mickey

match _dl_ syscall prototypes w/ the real syscalls prototypes, including args and return values; art@ ok


# 1.6 28-May-2002 deraadt

proto _dl_show_objects() in one place


# 1.5 27-May-2002 deraadt

left over __P removals


# 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.37 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_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.36 14-Jul-2019 guenther

ld.so's $ORIGIN handling when argv[0] is a relative path was broken by
the change in __getcwd(2)'s return value. Fix it by switching to the
__realpath(2) syscall, eliminating the ld.so copy of realpath().

problem caught by regress and noted by bluhm@
ok deraadt@


# 1.35 10-May-2019 guenther

ld.so boot cleanup support:
- put functions and data which are only used before calling the executable's
start function into their own page-aligned segments for unmapping
(only done on amd64, arm64, armv7, powerpc, and sparc64 so far)
- pass .init_array and .preinit_array functions an addition argument which
is a callback to get a structure which includes a function that frees
the boot text and data
- sometimes delay doing RELRO processing: for a shared-object marked
DF_1_INITFIRST do it after the object's .init_array, for the executable
do it after the .preinit_array
- improve test-ld.so to link against libpthread and trigger its initialization
late
libc changes to use this will come later

ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.34 25-Jan-2019 millert

I am retiring my old email address; replace it with my OpenBSD one.


# 1.33 23-Oct-2018 guenther

Delay processing of ld.so's own PT_GNU_RELRO section until after environment
processing and malloc initialization, and then move variables set by those
steps, including malloc's mopts structure, into the .data.rel.ro segment.
This protects more data and eliminates the extra padding of the mopts.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.32 01-Dec-2017 guenther

Redo the calculation of the alignment and placement of static TLS data to
correctly take into account the segment p_align. Previously, anything
with a size belong the natural alignment or with alignment larger than
the natural one would either not be intialized correctly, be misaligned,
or result in the TIB being misaligned.

Problems reported by Charles Collicutt (charles (at) collicutt.co.uk)
ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.31 29-Aug-2017 deraadt

rename *fdprint function to *dprintf, like libc version


Revision tags: OPENBSD_6_1_BASE
# 1.30 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.29 23-Jan-2017 guenther

Wrap function declarations with __{BEGIN,END}_HIDDEN_DECLS to reduce
relocations inside ld.so that it has to bootstrap

ok kettenis@


# 1.28 27-Aug-2016 guenther

Pull in <stddef.h> for NULL
(not stdio, because ld.so has a reduced library behind it)


# 1.27 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


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.26 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@


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

improve some types


# 1.24 27-Nov-2013 deraadt

make the _dl_isalnum() resemble the ctype version
prodding from kettenis


Revision tags: OPENBSD_5_4_BASE
# 1.23 05-Apr-2013 kurt

- Add ORIGIN, OSNAME, OSREL and PLATFORM substitution support for rpaths.
Improvements and okay matthew@, millert@, guenther@


Revision tags: OPENBSD_5_3_BASE
# 1.22 07-Aug-2012 matthew

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


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.21 18-May-2009 deraadt

make _dl_wrstderr() not call write per-character; ok drahn


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE
# 1.20 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_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.19 17-Oct-2004 drahn

Fix some problems related to LD_LIBRARY_PATH parsing where it would not
correctly deal with current directory searches specified by "::", ":foo" or
"foo:"


Revision tags: OPENBSD_3_6_BASE
# 1.18 25-May-2004 mickey

provide one version of _dl_bcopy instead of copy in every arch; drahn@ ok


Revision tags: OPENBSD_3_5_BASE
# 1.17 11-Nov-2003 drahn

Better fix to the library name parsing. now correctly handles
libpython2.2.so.0.0 vs libpython2.1.so.0.0. Clean up a potential
memory leak if the filename is not a valid library.
ok brad@


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 11-Jun-2003 deraadt

no more register


# 1.14 09-Jun-2003 deraadt

pefo 3/4 licence cleanups


# 1.13 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_2_BASE OPENBSD_3_3_BASE
# 1.12 31-Aug-2002 drahn

argh, include prototype for dl_fdprintf(), missed by myself and reviewers.


# 1.11 24-Jul-2002 deraadt

use real clones of the libc functions


# 1.10 24-Jul-2002 deraadt

ok i found it


# 1.9 24-Jul-2002 deraadt

back out broken stuff until it is fixed


# 1.8 24-Jul-2002 deraadt

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


# 1.7 23-Jul-2002 mickey

match _dl_ syscall prototypes w/ the real syscalls prototypes, including args and return values; art@ ok


# 1.6 28-May-2002 deraadt

proto _dl_show_objects() in one place


# 1.5 27-May-2002 deraadt

left over __P removals


# 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.36 14-Jul-2019 guenther

ld.so's $ORIGIN handling when argv[0] is a relative path was broken by
the change in __getcwd(2)'s return value. Fix it by switching to the
__realpath(2) syscall, eliminating the ld.so copy of realpath().

problem caught by regress and noted by bluhm@
ok deraadt@


# 1.35 10-May-2019 guenther

ld.so boot cleanup support:
- put functions and data which are only used before calling the executable's
start function into their own page-aligned segments for unmapping
(only done on amd64, arm64, armv7, powerpc, and sparc64 so far)
- pass .init_array and .preinit_array functions an addition argument which
is a callback to get a structure which includes a function that frees
the boot text and data
- sometimes delay doing RELRO processing: for a shared-object marked
DF_1_INITFIRST do it after the object's .init_array, for the executable
do it after the .preinit_array
- improve test-ld.so to link against libpthread and trigger its initialization
late
libc changes to use this will come later

ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.34 25-Jan-2019 millert

I am retiring my old email address; replace it with my OpenBSD one.


# 1.33 23-Oct-2018 guenther

Delay processing of ld.so's own PT_GNU_RELRO section until after environment
processing and malloc initialization, and then move variables set by those
steps, including malloc's mopts structure, into the .data.rel.ro segment.
This protects more data and eliminates the extra padding of the mopts.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.32 01-Dec-2017 guenther

Redo the calculation of the alignment and placement of static TLS data to
correctly take into account the segment p_align. Previously, anything
with a size belong the natural alignment or with alignment larger than
the natural one would either not be intialized correctly, be misaligned,
or result in the TIB being misaligned.

Problems reported by Charles Collicutt (charles (at) collicutt.co.uk)
ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.31 29-Aug-2017 deraadt

rename *fdprint function to *dprintf, like libc version


Revision tags: OPENBSD_6_1_BASE
# 1.30 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.29 23-Jan-2017 guenther

Wrap function declarations with __{BEGIN,END}_HIDDEN_DECLS to reduce
relocations inside ld.so that it has to bootstrap

ok kettenis@


# 1.28 27-Aug-2016 guenther

Pull in <stddef.h> for NULL
(not stdio, because ld.so has a reduced library behind it)


# 1.27 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


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.26 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@


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

improve some types


# 1.24 27-Nov-2013 deraadt

make the _dl_isalnum() resemble the ctype version
prodding from kettenis


Revision tags: OPENBSD_5_4_BASE
# 1.23 05-Apr-2013 kurt

- Add ORIGIN, OSNAME, OSREL and PLATFORM substitution support for rpaths.
Improvements and okay matthew@, millert@, guenther@


Revision tags: OPENBSD_5_3_BASE
# 1.22 07-Aug-2012 matthew

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


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.21 18-May-2009 deraadt

make _dl_wrstderr() not call write per-character; ok drahn


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE
# 1.20 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_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.19 17-Oct-2004 drahn

Fix some problems related to LD_LIBRARY_PATH parsing where it would not
correctly deal with current directory searches specified by "::", ":foo" or
"foo:"


Revision tags: OPENBSD_3_6_BASE
# 1.18 25-May-2004 mickey

provide one version of _dl_bcopy instead of copy in every arch; drahn@ ok


Revision tags: OPENBSD_3_5_BASE
# 1.17 11-Nov-2003 drahn

Better fix to the library name parsing. now correctly handles
libpython2.2.so.0.0 vs libpython2.1.so.0.0. Clean up a potential
memory leak if the filename is not a valid library.
ok brad@


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 11-Jun-2003 deraadt

no more register


# 1.14 09-Jun-2003 deraadt

pefo 3/4 licence cleanups


# 1.13 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_2_BASE OPENBSD_3_3_BASE
# 1.12 31-Aug-2002 drahn

argh, include prototype for dl_fdprintf(), missed by myself and reviewers.


# 1.11 24-Jul-2002 deraadt

use real clones of the libc functions


# 1.10 24-Jul-2002 deraadt

ok i found it


# 1.9 24-Jul-2002 deraadt

back out broken stuff until it is fixed


# 1.8 24-Jul-2002 deraadt

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


# 1.7 23-Jul-2002 mickey

match _dl_ syscall prototypes w/ the real syscalls prototypes, including args and return values; art@ ok


# 1.6 28-May-2002 deraadt

proto _dl_show_objects() in one place


# 1.5 27-May-2002 deraadt

left over __P removals


# 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.35 10-May-2019 guenther

ld.so boot cleanup support:
- put functions and data which are only used before calling the executable's
start function into their own page-aligned segments for unmapping
(only done on amd64, arm64, armv7, powerpc, and sparc64 so far)
- pass .init_array and .preinit_array functions an addition argument which
is a callback to get a structure which includes a function that frees
the boot text and data
- sometimes delay doing RELRO processing: for a shared-object marked
DF_1_INITFIRST do it after the object's .init_array, for the executable
do it after the .preinit_array
- improve test-ld.so to link against libpthread and trigger its initialization
late
libc changes to use this will come later

ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.34 25-Jan-2019 millert

I am retiring my old email address; replace it with my OpenBSD one.


# 1.33 23-Oct-2018 guenther

Delay processing of ld.so's own PT_GNU_RELRO section until after environment
processing and malloc initialization, and then move variables set by those
steps, including malloc's mopts structure, into the .data.rel.ro segment.
This protects more data and eliminates the extra padding of the mopts.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.32 01-Dec-2017 guenther

Redo the calculation of the alignment and placement of static TLS data to
correctly take into account the segment p_align. Previously, anything
with a size belong the natural alignment or with alignment larger than
the natural one would either not be intialized correctly, be misaligned,
or result in the TIB being misaligned.

Problems reported by Charles Collicutt (charles (at) collicutt.co.uk)
ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.31 29-Aug-2017 deraadt

rename *fdprint function to *dprintf, like libc version


Revision tags: OPENBSD_6_1_BASE
# 1.30 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.29 23-Jan-2017 guenther

Wrap function declarations with __{BEGIN,END}_HIDDEN_DECLS to reduce
relocations inside ld.so that it has to bootstrap

ok kettenis@


# 1.28 27-Aug-2016 guenther

Pull in <stddef.h> for NULL
(not stdio, because ld.so has a reduced library behind it)


# 1.27 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


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.26 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@


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

improve some types


# 1.24 27-Nov-2013 deraadt

make the _dl_isalnum() resemble the ctype version
prodding from kettenis


Revision tags: OPENBSD_5_4_BASE
# 1.23 05-Apr-2013 kurt

- Add ORIGIN, OSNAME, OSREL and PLATFORM substitution support for rpaths.
Improvements and okay matthew@, millert@, guenther@


Revision tags: OPENBSD_5_3_BASE
# 1.22 07-Aug-2012 matthew

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


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.21 18-May-2009 deraadt

make _dl_wrstderr() not call write per-character; ok drahn


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE
# 1.20 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_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.19 17-Oct-2004 drahn

Fix some problems related to LD_LIBRARY_PATH parsing where it would not
correctly deal with current directory searches specified by "::", ":foo" or
"foo:"


Revision tags: OPENBSD_3_6_BASE
# 1.18 25-May-2004 mickey

provide one version of _dl_bcopy instead of copy in every arch; drahn@ ok


Revision tags: OPENBSD_3_5_BASE
# 1.17 11-Nov-2003 drahn

Better fix to the library name parsing. now correctly handles
libpython2.2.so.0.0 vs libpython2.1.so.0.0. Clean up a potential
memory leak if the filename is not a valid library.
ok brad@


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 11-Jun-2003 deraadt

no more register


# 1.14 09-Jun-2003 deraadt

pefo 3/4 licence cleanups


# 1.13 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_2_BASE OPENBSD_3_3_BASE
# 1.12 31-Aug-2002 drahn

argh, include prototype for dl_fdprintf(), missed by myself and reviewers.


# 1.11 24-Jul-2002 deraadt

use real clones of the libc functions


# 1.10 24-Jul-2002 deraadt

ok i found it


# 1.9 24-Jul-2002 deraadt

back out broken stuff until it is fixed


# 1.8 24-Jul-2002 deraadt

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


# 1.7 23-Jul-2002 mickey

match _dl_ syscall prototypes w/ the real syscalls prototypes, including args and return values; art@ ok


# 1.6 28-May-2002 deraadt

proto _dl_show_objects() in one place


# 1.5 27-May-2002 deraadt

left over __P removals


# 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.34 25-Jan-2019 millert

I am retiring my old email address; replace it with my OpenBSD one.


# 1.33 23-Oct-2018 guenther

Delay processing of ld.so's own PT_GNU_RELRO section until after environment
processing and malloc initialization, and then move variables set by those
steps, including malloc's mopts structure, into the .data.rel.ro segment.
This protects more data and eliminates the extra padding of the mopts.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.32 01-Dec-2017 guenther

Redo the calculation of the alignment and placement of static TLS data to
correctly take into account the segment p_align. Previously, anything
with a size belong the natural alignment or with alignment larger than
the natural one would either not be intialized correctly, be misaligned,
or result in the TIB being misaligned.

Problems reported by Charles Collicutt (charles (at) collicutt.co.uk)
ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.31 29-Aug-2017 deraadt

rename *fdprint function to *dprintf, like libc version


Revision tags: OPENBSD_6_1_BASE
# 1.30 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.29 23-Jan-2017 guenther

Wrap function declarations with __{BEGIN,END}_HIDDEN_DECLS to reduce
relocations inside ld.so that it has to bootstrap

ok kettenis@


# 1.28 27-Aug-2016 guenther

Pull in <stddef.h> for NULL
(not stdio, because ld.so has a reduced library behind it)


# 1.27 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


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.26 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@


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

improve some types


# 1.24 27-Nov-2013 deraadt

make the _dl_isalnum() resemble the ctype version
prodding from kettenis


Revision tags: OPENBSD_5_4_BASE
# 1.23 05-Apr-2013 kurt

- Add ORIGIN, OSNAME, OSREL and PLATFORM substitution support for rpaths.
Improvements and okay matthew@, millert@, guenther@


Revision tags: OPENBSD_5_3_BASE
# 1.22 07-Aug-2012 matthew

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


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.21 18-May-2009 deraadt

make _dl_wrstderr() not call write per-character; ok drahn


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE
# 1.20 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_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.19 17-Oct-2004 drahn

Fix some problems related to LD_LIBRARY_PATH parsing where it would not
correctly deal with current directory searches specified by "::", ":foo" or
"foo:"


Revision tags: OPENBSD_3_6_BASE
# 1.18 25-May-2004 mickey

provide one version of _dl_bcopy instead of copy in every arch; drahn@ ok


Revision tags: OPENBSD_3_5_BASE
# 1.17 11-Nov-2003 drahn

Better fix to the library name parsing. now correctly handles
libpython2.2.so.0.0 vs libpython2.1.so.0.0. Clean up a potential
memory leak if the filename is not a valid library.
ok brad@


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 11-Jun-2003 deraadt

no more register


# 1.14 09-Jun-2003 deraadt

pefo 3/4 licence cleanups


# 1.13 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_2_BASE OPENBSD_3_3_BASE
# 1.12 31-Aug-2002 drahn

argh, include prototype for dl_fdprintf(), missed by myself and reviewers.


# 1.11 24-Jul-2002 deraadt

use real clones of the libc functions


# 1.10 24-Jul-2002 deraadt

ok i found it


# 1.9 24-Jul-2002 deraadt

back out broken stuff until it is fixed


# 1.8 24-Jul-2002 deraadt

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


# 1.7 23-Jul-2002 mickey

match _dl_ syscall prototypes w/ the real syscalls prototypes, including args and return values; art@ ok


# 1.6 28-May-2002 deraadt

proto _dl_show_objects() in one place


# 1.5 27-May-2002 deraadt

left over __P removals


# 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.33 23-Oct-2018 guenther

Delay processing of ld.so's own PT_GNU_RELRO section until after environment
processing and malloc initialization, and then move variables set by those
steps, including malloc's mopts structure, into the .data.rel.ro segment.
This protects more data and eliminates the extra padding of the mopts.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.32 01-Dec-2017 guenther

Redo the calculation of the alignment and placement of static TLS data to
correctly take into account the segment p_align. Previously, anything
with a size belong the natural alignment or with alignment larger than
the natural one would either not be intialized correctly, be misaligned,
or result in the TIB being misaligned.

Problems reported by Charles Collicutt (charles (at) collicutt.co.uk)
ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.31 29-Aug-2017 deraadt

rename *fdprint function to *dprintf, like libc version


Revision tags: OPENBSD_6_1_BASE
# 1.30 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.29 23-Jan-2017 guenther

Wrap function declarations with __{BEGIN,END}_HIDDEN_DECLS to reduce
relocations inside ld.so that it has to bootstrap

ok kettenis@


# 1.28 27-Aug-2016 guenther

Pull in <stddef.h> for NULL
(not stdio, because ld.so has a reduced library behind it)


# 1.27 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


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.26 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@


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

improve some types


# 1.24 27-Nov-2013 deraadt

make the _dl_isalnum() resemble the ctype version
prodding from kettenis


Revision tags: OPENBSD_5_4_BASE
# 1.23 05-Apr-2013 kurt

- Add ORIGIN, OSNAME, OSREL and PLATFORM substitution support for rpaths.
Improvements and okay matthew@, millert@, guenther@


Revision tags: OPENBSD_5_3_BASE
# 1.22 07-Aug-2012 matthew

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


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.21 18-May-2009 deraadt

make _dl_wrstderr() not call write per-character; ok drahn


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE
# 1.20 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_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.19 17-Oct-2004 drahn

Fix some problems related to LD_LIBRARY_PATH parsing where it would not
correctly deal with current directory searches specified by "::", ":foo" or
"foo:"


Revision tags: OPENBSD_3_6_BASE
# 1.18 25-May-2004 mickey

provide one version of _dl_bcopy instead of copy in every arch; drahn@ ok


Revision tags: OPENBSD_3_5_BASE
# 1.17 11-Nov-2003 drahn

Better fix to the library name parsing. now correctly handles
libpython2.2.so.0.0 vs libpython2.1.so.0.0. Clean up a potential
memory leak if the filename is not a valid library.
ok brad@


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 11-Jun-2003 deraadt

no more register


# 1.14 09-Jun-2003 deraadt

pefo 3/4 licence cleanups


# 1.13 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_2_BASE OPENBSD_3_3_BASE
# 1.12 31-Aug-2002 drahn

argh, include prototype for dl_fdprintf(), missed by myself and reviewers.


# 1.11 24-Jul-2002 deraadt

use real clones of the libc functions


# 1.10 24-Jul-2002 deraadt

ok i found it


# 1.9 24-Jul-2002 deraadt

back out broken stuff until it is fixed


# 1.8 24-Jul-2002 deraadt

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


# 1.7 23-Jul-2002 mickey

match _dl_ syscall prototypes w/ the real syscalls prototypes, including args and return values; art@ ok


# 1.6 28-May-2002 deraadt

proto _dl_show_objects() in one place


# 1.5 27-May-2002 deraadt

left over __P removals


# 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.32 01-Dec-2017 guenther

Redo the calculation of the alignment and placement of static TLS data to
correctly take into account the segment p_align. Previously, anything
with a size belong the natural alignment or with alignment larger than
the natural one would either not be intialized correctly, be misaligned,
or result in the TIB being misaligned.

Problems reported by Charles Collicutt (charles (at) collicutt.co.uk)
ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.31 29-Aug-2017 deraadt

rename *fdprint function to *dprintf, like libc version


Revision tags: OPENBSD_6_1_BASE
# 1.30 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.29 23-Jan-2017 guenther

Wrap function declarations with __{BEGIN,END}_HIDDEN_DECLS to reduce
relocations inside ld.so that it has to bootstrap

ok kettenis@


# 1.28 27-Aug-2016 guenther

Pull in <stddef.h> for NULL
(not stdio, because ld.so has a reduced library behind it)


# 1.27 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


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.26 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@


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

improve some types


# 1.24 27-Nov-2013 deraadt

make the _dl_isalnum() resemble the ctype version
prodding from kettenis


Revision tags: OPENBSD_5_4_BASE
# 1.23 05-Apr-2013 kurt

- Add ORIGIN, OSNAME, OSREL and PLATFORM substitution support for rpaths.
Improvements and okay matthew@, millert@, guenther@


Revision tags: OPENBSD_5_3_BASE
# 1.22 07-Aug-2012 matthew

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


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.21 18-May-2009 deraadt

make _dl_wrstderr() not call write per-character; ok drahn


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE
# 1.20 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_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.19 17-Oct-2004 drahn

Fix some problems related to LD_LIBRARY_PATH parsing where it would not
correctly deal with current directory searches specified by "::", ":foo" or
"foo:"


Revision tags: OPENBSD_3_6_BASE
# 1.18 25-May-2004 mickey

provide one version of _dl_bcopy instead of copy in every arch; drahn@ ok


Revision tags: OPENBSD_3_5_BASE
# 1.17 11-Nov-2003 drahn

Better fix to the library name parsing. now correctly handles
libpython2.2.so.0.0 vs libpython2.1.so.0.0. Clean up a potential
memory leak if the filename is not a valid library.
ok brad@


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 11-Jun-2003 deraadt

no more register


# 1.14 09-Jun-2003 deraadt

pefo 3/4 licence cleanups


# 1.13 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_2_BASE OPENBSD_3_3_BASE
# 1.12 31-Aug-2002 drahn

argh, include prototype for dl_fdprintf(), missed by myself and reviewers.


# 1.11 24-Jul-2002 deraadt

use real clones of the libc functions


# 1.10 24-Jul-2002 deraadt

ok i found it


# 1.9 24-Jul-2002 deraadt

back out broken stuff until it is fixed


# 1.8 24-Jul-2002 deraadt

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


# 1.7 23-Jul-2002 mickey

match _dl_ syscall prototypes w/ the real syscalls prototypes, including args and return values; art@ ok


# 1.6 28-May-2002 deraadt

proto _dl_show_objects() in one place


# 1.5 27-May-2002 deraadt

left over __P removals


# 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.