History log of /openbsd-current/lib/csu/crt0.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.18 27-Jul-2023 kettenis

Make _eprol (and _etext) hidden. Fixes "cc -pg" on arm64 where the
current code which has a local _eprol label in the inline asm and a
global _eprol declaration results in an incorrect relocation. This
also removes an unnecessary relocation on hppa (and possible on
other architectures as well).

ok guenther@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.17 12-Jan-2022 guenther

Lift the '#ifdef RCRT0' conditional out of boot*.h to crt0.c

Prep for dropping #includes from archdep.h: pull in <machine/reloc.h>
and declare _dl_exit() in boot*.h

ok kettenis@


# 1.16 14-Nov-2021 guenther

Split out the hppa and mips64 versions of boot.h similar to how I
split ld.so/boot.c in 2019:
* delete extraneous #includes
* delete jmprel handling on non-hppa
* delete RELOC_GOT() and DT_PROC bits on non-mips64

ok visa@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.15 14-Oct-2020 deraadt

use symbolic SYS_exit instead of the value 1
ok kettenis


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.14 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@


# 1.13 08-May-2019 guenther

Call _csu_finish() before {pre,}init_array functions so that in static
executables the TIB and __progname are set up before they can be used.

problem noted by ori@
ok millert@ kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.12 09-Jan-2019 visa

Use static consistently with definitions of functions that have been
declared static.

OK guenther@


# 1.11 21-Dec-2018 guenther

Add support for {preinit,init,fini}_array sections in static binaries

ok kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.10 21-Jan-2017 guenther

Pull in declarations for main() and __init() to make clang happy.
Mark __init() as hidden

ok kettenis@ deraadt@


# 1.9 19-Jan-2017 guenther

MD_START is now always ___start, so expand and eliminate it

ok phessler@ deraadt@


# 1.8 26-Sep-2016 kettenis

Now that vax has been removed, nothing defined MD_NO_CLEANUP anymore.

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.7 07-May-2016 guenther

Declare moncontrol(3) APIs in <sys/gmon.h>
Export _gmonparam again.
Make gcrt0.o use an reserved name for _monstartup()

ok millert@


# 1.6 20-Mar-2016 guenther

Rearrange C runtime bits: now that ld.so exports environ and __progname,
move their definitions and initialization in static links to libc.a
Make crt0 always invoke a new func _csu_finish() in libc to process the auxv
and to either register the ld.so cleanup function (in dynamic links) or
initialize environ and __progname and do MC_DISABLE_KBIND (in static links).
In libc, get pagesize from auxv; cache that between getpagesize() and
sysconf(_SC_PAGESIZE)

ok mpi@ "good time" deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.5 01-Sep-2015 guenther

In static binaries, invoke kbind() once to disable it.

With much assistance from miod@
ok deraadt@@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.4 27-Dec-2014 kettenis

Only include "boot.h" if MD_RCRT0_START is defined. Should fix build on vax.

ok miod@


# 1.3 22-Dec-2014 kurt

Introduce new csu0 variant for -static -pie binaries to use called
rcsu0.o where the initial 'r' is for relocatable. rcsu0.o performs
self-relocation on static pie binaries by calling a slightly modified
copy of ld.so's _dl_boot_bind() in boot.h.

The first arch implementatation is also included for amd64 where
__start calls _dl_boot_bind() and then calls ___start(). Includes
parts from kettenis@ to help get R_X86_64_64 relocations working
and proper handling for undefined weak symbols.

This is the first part of several to get static pie self-relocating
binaries working. binutils, gcc and kernel changes are forthcoming
to complete the solution, then per-arch implementations are needed
for MD_RCRT0_START in csu.

okay kettenis@ pascal@ deraadt@


# 1.2 12-Dec-2013 guenther

Fix static linking of libpthread: have crt0 invoke __init_tcb() if it's
defined and we don't think ld.so has already done the TCB setup.

ok and much discussion miod@


# 1.1 03-Dec-2013 guenther

Merge the per-arch crt0.c files into common_elf/crt0.c, with MD macros in
the md_init.h files.

Worked out with and ok miod@; ok matthew@


# 1.17 12-Jan-2022 guenther

Lift the '#ifdef RCRT0' conditional out of boot*.h to crt0.c

Prep for dropping #includes from archdep.h: pull in <machine/reloc.h>
and declare _dl_exit() in boot*.h

ok kettenis@


# 1.16 14-Nov-2021 guenther

Split out the hppa and mips64 versions of boot.h similar to how I
split ld.so/boot.c in 2019:
* delete extraneous #includes
* delete jmprel handling on non-hppa
* delete RELOC_GOT() and DT_PROC bits on non-mips64

ok visa@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.15 14-Oct-2020 deraadt

use symbolic SYS_exit instead of the value 1
ok kettenis


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.14 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@


# 1.13 08-May-2019 guenther

Call _csu_finish() before {pre,}init_array functions so that in static
executables the TIB and __progname are set up before they can be used.

problem noted by ori@
ok millert@ kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.12 09-Jan-2019 visa

Use static consistently with definitions of functions that have been
declared static.

OK guenther@


# 1.11 21-Dec-2018 guenther

Add support for {preinit,init,fini}_array sections in static binaries

ok kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.10 21-Jan-2017 guenther

Pull in declarations for main() and __init() to make clang happy.
Mark __init() as hidden

ok kettenis@ deraadt@


# 1.9 19-Jan-2017 guenther

MD_START is now always ___start, so expand and eliminate it

ok phessler@ deraadt@


# 1.8 26-Sep-2016 kettenis

Now that vax has been removed, nothing defined MD_NO_CLEANUP anymore.

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.7 07-May-2016 guenther

Declare moncontrol(3) APIs in <sys/gmon.h>
Export _gmonparam again.
Make gcrt0.o use an reserved name for _monstartup()

ok millert@


# 1.6 20-Mar-2016 guenther

Rearrange C runtime bits: now that ld.so exports environ and __progname,
move their definitions and initialization in static links to libc.a
Make crt0 always invoke a new func _csu_finish() in libc to process the auxv
and to either register the ld.so cleanup function (in dynamic links) or
initialize environ and __progname and do MC_DISABLE_KBIND (in static links).
In libc, get pagesize from auxv; cache that between getpagesize() and
sysconf(_SC_PAGESIZE)

ok mpi@ "good time" deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.5 01-Sep-2015 guenther

In static binaries, invoke kbind() once to disable it.

With much assistance from miod@
ok deraadt@@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.4 27-Dec-2014 kettenis

Only include "boot.h" if MD_RCRT0_START is defined. Should fix build on vax.

ok miod@


# 1.3 22-Dec-2014 kurt

Introduce new csu0 variant for -static -pie binaries to use called
rcsu0.o where the initial 'r' is for relocatable. rcsu0.o performs
self-relocation on static pie binaries by calling a slightly modified
copy of ld.so's _dl_boot_bind() in boot.h.

The first arch implementatation is also included for amd64 where
__start calls _dl_boot_bind() and then calls ___start(). Includes
parts from kettenis@ to help get R_X86_64_64 relocations working
and proper handling for undefined weak symbols.

This is the first part of several to get static pie self-relocating
binaries working. binutils, gcc and kernel changes are forthcoming
to complete the solution, then per-arch implementations are needed
for MD_RCRT0_START in csu.

okay kettenis@ pascal@ deraadt@


# 1.2 12-Dec-2013 guenther

Fix static linking of libpthread: have crt0 invoke __init_tcb() if it's
defined and we don't think ld.so has already done the TCB setup.

ok and much discussion miod@


# 1.1 03-Dec-2013 guenther

Merge the per-arch crt0.c files into common_elf/crt0.c, with MD macros in
the md_init.h files.

Worked out with and ok miod@; ok matthew@


# 1.16 14-Nov-2021 guenther

Split out the hppa and mips64 versions of boot.h similar to how I
split ld.so/boot.c in 2019:
* delete extraneous #includes
* delete jmprel handling on non-hppa
* delete RELOC_GOT() and DT_PROC bits on non-mips64

ok visa@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.15 14-Oct-2020 deraadt

use symbolic SYS_exit instead of the value 1
ok kettenis


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.14 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@


# 1.13 08-May-2019 guenther

Call _csu_finish() before {pre,}init_array functions so that in static
executables the TIB and __progname are set up before they can be used.

problem noted by ori@
ok millert@ kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.12 09-Jan-2019 visa

Use static consistently with definitions of functions that have been
declared static.

OK guenther@


# 1.11 21-Dec-2018 guenther

Add support for {preinit,init,fini}_array sections in static binaries

ok kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.10 21-Jan-2017 guenther

Pull in declarations for main() and __init() to make clang happy.
Mark __init() as hidden

ok kettenis@ deraadt@


# 1.9 19-Jan-2017 guenther

MD_START is now always ___start, so expand and eliminate it

ok phessler@ deraadt@


# 1.8 26-Sep-2016 kettenis

Now that vax has been removed, nothing defined MD_NO_CLEANUP anymore.

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.7 07-May-2016 guenther

Declare moncontrol(3) APIs in <sys/gmon.h>
Export _gmonparam again.
Make gcrt0.o use an reserved name for _monstartup()

ok millert@


# 1.6 20-Mar-2016 guenther

Rearrange C runtime bits: now that ld.so exports environ and __progname,
move their definitions and initialization in static links to libc.a
Make crt0 always invoke a new func _csu_finish() in libc to process the auxv
and to either register the ld.so cleanup function (in dynamic links) or
initialize environ and __progname and do MC_DISABLE_KBIND (in static links).
In libc, get pagesize from auxv; cache that between getpagesize() and
sysconf(_SC_PAGESIZE)

ok mpi@ "good time" deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.5 01-Sep-2015 guenther

In static binaries, invoke kbind() once to disable it.

With much assistance from miod@
ok deraadt@@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.4 27-Dec-2014 kettenis

Only include "boot.h" if MD_RCRT0_START is defined. Should fix build on vax.

ok miod@


# 1.3 22-Dec-2014 kurt

Introduce new csu0 variant for -static -pie binaries to use called
rcsu0.o where the initial 'r' is for relocatable. rcsu0.o performs
self-relocation on static pie binaries by calling a slightly modified
copy of ld.so's _dl_boot_bind() in boot.h.

The first arch implementatation is also included for amd64 where
__start calls _dl_boot_bind() and then calls ___start(). Includes
parts from kettenis@ to help get R_X86_64_64 relocations working
and proper handling for undefined weak symbols.

This is the first part of several to get static pie self-relocating
binaries working. binutils, gcc and kernel changes are forthcoming
to complete the solution, then per-arch implementations are needed
for MD_RCRT0_START in csu.

okay kettenis@ pascal@ deraadt@


# 1.2 12-Dec-2013 guenther

Fix static linking of libpthread: have crt0 invoke __init_tcb() if it's
defined and we don't think ld.so has already done the TCB setup.

ok and much discussion miod@


# 1.1 03-Dec-2013 guenther

Merge the per-arch crt0.c files into common_elf/crt0.c, with MD macros in
the md_init.h files.

Worked out with and ok miod@; ok matthew@


# 1.15 14-Oct-2020 deraadt

use symbolic SYS_exit instead of the value 1
ok kettenis


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.14 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@


# 1.13 08-May-2019 guenther

Call _csu_finish() before {pre,}init_array functions so that in static
executables the TIB and __progname are set up before they can be used.

problem noted by ori@
ok millert@ kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.12 09-Jan-2019 visa

Use static consistently with definitions of functions that have been
declared static.

OK guenther@


# 1.11 21-Dec-2018 guenther

Add support for {preinit,init,fini}_array sections in static binaries

ok kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.10 21-Jan-2017 guenther

Pull in declarations for main() and __init() to make clang happy.
Mark __init() as hidden

ok kettenis@ deraadt@


# 1.9 19-Jan-2017 guenther

MD_START is now always ___start, so expand and eliminate it

ok phessler@ deraadt@


# 1.8 26-Sep-2016 kettenis

Now that vax has been removed, nothing defined MD_NO_CLEANUP anymore.

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.7 07-May-2016 guenther

Declare moncontrol(3) APIs in <sys/gmon.h>
Export _gmonparam again.
Make gcrt0.o use an reserved name for _monstartup()

ok millert@


# 1.6 20-Mar-2016 guenther

Rearrange C runtime bits: now that ld.so exports environ and __progname,
move their definitions and initialization in static links to libc.a
Make crt0 always invoke a new func _csu_finish() in libc to process the auxv
and to either register the ld.so cleanup function (in dynamic links) or
initialize environ and __progname and do MC_DISABLE_KBIND (in static links).
In libc, get pagesize from auxv; cache that between getpagesize() and
sysconf(_SC_PAGESIZE)

ok mpi@ "good time" deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.5 01-Sep-2015 guenther

In static binaries, invoke kbind() once to disable it.

With much assistance from miod@
ok deraadt@@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.4 27-Dec-2014 kettenis

Only include "boot.h" if MD_RCRT0_START is defined. Should fix build on vax.

ok miod@


# 1.3 22-Dec-2014 kurt

Introduce new csu0 variant for -static -pie binaries to use called
rcsu0.o where the initial 'r' is for relocatable. rcsu0.o performs
self-relocation on static pie binaries by calling a slightly modified
copy of ld.so's _dl_boot_bind() in boot.h.

The first arch implementatation is also included for amd64 where
__start calls _dl_boot_bind() and then calls ___start(). Includes
parts from kettenis@ to help get R_X86_64_64 relocations working
and proper handling for undefined weak symbols.

This is the first part of several to get static pie self-relocating
binaries working. binutils, gcc and kernel changes are forthcoming
to complete the solution, then per-arch implementations are needed
for MD_RCRT0_START in csu.

okay kettenis@ pascal@ deraadt@


# 1.2 12-Dec-2013 guenther

Fix static linking of libpthread: have crt0 invoke __init_tcb() if it's
defined and we don't think ld.so has already done the TCB setup.

ok and much discussion miod@


# 1.1 03-Dec-2013 guenther

Merge the per-arch crt0.c files into common_elf/crt0.c, with MD macros in
the md_init.h files.

Worked out with and ok miod@; ok matthew@


# 1.14 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@


# 1.13 08-May-2019 guenther

Call _csu_finish() before {pre,}init_array functions so that in static
executables the TIB and __progname are set up before they can be used.

problem noted by ori@
ok millert@ kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.12 09-Jan-2019 visa

Use static consistently with definitions of functions that have been
declared static.

OK guenther@


# 1.11 21-Dec-2018 guenther

Add support for {preinit,init,fini}_array sections in static binaries

ok kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.10 21-Jan-2017 guenther

Pull in declarations for main() and __init() to make clang happy.
Mark __init() as hidden

ok kettenis@ deraadt@


# 1.9 19-Jan-2017 guenther

MD_START is now always ___start, so expand and eliminate it

ok phessler@ deraadt@


# 1.8 26-Sep-2016 kettenis

Now that vax has been removed, nothing defined MD_NO_CLEANUP anymore.

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.7 07-May-2016 guenther

Declare moncontrol(3) APIs in <sys/gmon.h>
Export _gmonparam again.
Make gcrt0.o use an reserved name for _monstartup()

ok millert@


# 1.6 20-Mar-2016 guenther

Rearrange C runtime bits: now that ld.so exports environ and __progname,
move their definitions and initialization in static links to libc.a
Make crt0 always invoke a new func _csu_finish() in libc to process the auxv
and to either register the ld.so cleanup function (in dynamic links) or
initialize environ and __progname and do MC_DISABLE_KBIND (in static links).
In libc, get pagesize from auxv; cache that between getpagesize() and
sysconf(_SC_PAGESIZE)

ok mpi@ "good time" deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.5 01-Sep-2015 guenther

In static binaries, invoke kbind() once to disable it.

With much assistance from miod@
ok deraadt@@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.4 27-Dec-2014 kettenis

Only include "boot.h" if MD_RCRT0_START is defined. Should fix build on vax.

ok miod@


# 1.3 22-Dec-2014 kurt

Introduce new csu0 variant for -static -pie binaries to use called
rcsu0.o where the initial 'r' is for relocatable. rcsu0.o performs
self-relocation on static pie binaries by calling a slightly modified
copy of ld.so's _dl_boot_bind() in boot.h.

The first arch implementatation is also included for amd64 where
__start calls _dl_boot_bind() and then calls ___start(). Includes
parts from kettenis@ to help get R_X86_64_64 relocations working
and proper handling for undefined weak symbols.

This is the first part of several to get static pie self-relocating
binaries working. binutils, gcc and kernel changes are forthcoming
to complete the solution, then per-arch implementations are needed
for MD_RCRT0_START in csu.

okay kettenis@ pascal@ deraadt@


# 1.2 12-Dec-2013 guenther

Fix static linking of libpthread: have crt0 invoke __init_tcb() if it's
defined and we don't think ld.so has already done the TCB setup.

ok and much discussion miod@


# 1.1 03-Dec-2013 guenther

Merge the per-arch crt0.c files into common_elf/crt0.c, with MD macros in
the md_init.h files.

Worked out with and ok miod@; ok matthew@


# 1.13 08-May-2019 guenther

Call _csu_finish() before {pre,}init_array functions so that in static
executables the TIB and __progname are set up before they can be used.

problem noted by ori@
ok millert@ kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.12 09-Jan-2019 visa

Use static consistently with definitions of functions that have been
declared static.

OK guenther@


# 1.11 21-Dec-2018 guenther

Add support for {preinit,init,fini}_array sections in static binaries

ok kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.10 21-Jan-2017 guenther

Pull in declarations for main() and __init() to make clang happy.
Mark __init() as hidden

ok kettenis@ deraadt@


# 1.9 19-Jan-2017 guenther

MD_START is now always ___start, so expand and eliminate it

ok phessler@ deraadt@


# 1.8 26-Sep-2016 kettenis

Now that vax has been removed, nothing defined MD_NO_CLEANUP anymore.

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.7 07-May-2016 guenther

Declare moncontrol(3) APIs in <sys/gmon.h>
Export _gmonparam again.
Make gcrt0.o use an reserved name for _monstartup()

ok millert@


# 1.6 20-Mar-2016 guenther

Rearrange C runtime bits: now that ld.so exports environ and __progname,
move their definitions and initialization in static links to libc.a
Make crt0 always invoke a new func _csu_finish() in libc to process the auxv
and to either register the ld.so cleanup function (in dynamic links) or
initialize environ and __progname and do MC_DISABLE_KBIND (in static links).
In libc, get pagesize from auxv; cache that between getpagesize() and
sysconf(_SC_PAGESIZE)

ok mpi@ "good time" deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.5 01-Sep-2015 guenther

In static binaries, invoke kbind() once to disable it.

With much assistance from miod@
ok deraadt@@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.4 27-Dec-2014 kettenis

Only include "boot.h" if MD_RCRT0_START is defined. Should fix build on vax.

ok miod@


# 1.3 22-Dec-2014 kurt

Introduce new csu0 variant for -static -pie binaries to use called
rcsu0.o where the initial 'r' is for relocatable. rcsu0.o performs
self-relocation on static pie binaries by calling a slightly modified
copy of ld.so's _dl_boot_bind() in boot.h.

The first arch implementatation is also included for amd64 where
__start calls _dl_boot_bind() and then calls ___start(). Includes
parts from kettenis@ to help get R_X86_64_64 relocations working
and proper handling for undefined weak symbols.

This is the first part of several to get static pie self-relocating
binaries working. binutils, gcc and kernel changes are forthcoming
to complete the solution, then per-arch implementations are needed
for MD_RCRT0_START in csu.

okay kettenis@ pascal@ deraadt@


# 1.2 12-Dec-2013 guenther

Fix static linking of libpthread: have crt0 invoke __init_tcb() if it's
defined and we don't think ld.so has already done the TCB setup.

ok and much discussion miod@


# 1.1 03-Dec-2013 guenther

Merge the per-arch crt0.c files into common_elf/crt0.c, with MD macros in
the md_init.h files.

Worked out with and ok miod@; ok matthew@


# 1.12 09-Jan-2019 visa

Use static consistently with definitions of functions that have been
declared static.

OK guenther@


# 1.11 21-Dec-2018 guenther

Add support for {preinit,init,fini}_array sections in static binaries

ok kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.10 21-Jan-2017 guenther

Pull in declarations for main() and __init() to make clang happy.
Mark __init() as hidden

ok kettenis@ deraadt@


# 1.9 19-Jan-2017 guenther

MD_START is now always ___start, so expand and eliminate it

ok phessler@ deraadt@


# 1.8 26-Sep-2016 kettenis

Now that vax has been removed, nothing defined MD_NO_CLEANUP anymore.

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.7 07-May-2016 guenther

Declare moncontrol(3) APIs in <sys/gmon.h>
Export _gmonparam again.
Make gcrt0.o use an reserved name for _monstartup()

ok millert@


# 1.6 20-Mar-2016 guenther

Rearrange C runtime bits: now that ld.so exports environ and __progname,
move their definitions and initialization in static links to libc.a
Make crt0 always invoke a new func _csu_finish() in libc to process the auxv
and to either register the ld.so cleanup function (in dynamic links) or
initialize environ and __progname and do MC_DISABLE_KBIND (in static links).
In libc, get pagesize from auxv; cache that between getpagesize() and
sysconf(_SC_PAGESIZE)

ok mpi@ "good time" deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.5 01-Sep-2015 guenther

In static binaries, invoke kbind() once to disable it.

With much assistance from miod@
ok deraadt@@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.4 27-Dec-2014 kettenis

Only include "boot.h" if MD_RCRT0_START is defined. Should fix build on vax.

ok miod@


# 1.3 22-Dec-2014 kurt

Introduce new csu0 variant for -static -pie binaries to use called
rcsu0.o where the initial 'r' is for relocatable. rcsu0.o performs
self-relocation on static pie binaries by calling a slightly modified
copy of ld.so's _dl_boot_bind() in boot.h.

The first arch implementatation is also included for amd64 where
__start calls _dl_boot_bind() and then calls ___start(). Includes
parts from kettenis@ to help get R_X86_64_64 relocations working
and proper handling for undefined weak symbols.

This is the first part of several to get static pie self-relocating
binaries working. binutils, gcc and kernel changes are forthcoming
to complete the solution, then per-arch implementations are needed
for MD_RCRT0_START in csu.

okay kettenis@ pascal@ deraadt@


# 1.2 12-Dec-2013 guenther

Fix static linking of libpthread: have crt0 invoke __init_tcb() if it's
defined and we don't think ld.so has already done the TCB setup.

ok and much discussion miod@


# 1.1 03-Dec-2013 guenther

Merge the per-arch crt0.c files into common_elf/crt0.c, with MD macros in
the md_init.h files.

Worked out with and ok miod@; ok matthew@


# 1.11 21-Dec-2018 guenther

Add support for {preinit,init,fini}_array sections in static binaries

ok kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.10 21-Jan-2017 guenther

Pull in declarations for main() and __init() to make clang happy.
Mark __init() as hidden

ok kettenis@ deraadt@


# 1.9 19-Jan-2017 guenther

MD_START is now always ___start, so expand and eliminate it

ok phessler@ deraadt@


# 1.8 26-Sep-2016 kettenis

Now that vax has been removed, nothing defined MD_NO_CLEANUP anymore.

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.7 07-May-2016 guenther

Declare moncontrol(3) APIs in <sys/gmon.h>
Export _gmonparam again.
Make gcrt0.o use an reserved name for _monstartup()

ok millert@


# 1.6 20-Mar-2016 guenther

Rearrange C runtime bits: now that ld.so exports environ and __progname,
move their definitions and initialization in static links to libc.a
Make crt0 always invoke a new func _csu_finish() in libc to process the auxv
and to either register the ld.so cleanup function (in dynamic links) or
initialize environ and __progname and do MC_DISABLE_KBIND (in static links).
In libc, get pagesize from auxv; cache that between getpagesize() and
sysconf(_SC_PAGESIZE)

ok mpi@ "good time" deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.5 01-Sep-2015 guenther

In static binaries, invoke kbind() once to disable it.

With much assistance from miod@
ok deraadt@@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.4 27-Dec-2014 kettenis

Only include "boot.h" if MD_RCRT0_START is defined. Should fix build on vax.

ok miod@


# 1.3 22-Dec-2014 kurt

Introduce new csu0 variant for -static -pie binaries to use called
rcsu0.o where the initial 'r' is for relocatable. rcsu0.o performs
self-relocation on static pie binaries by calling a slightly modified
copy of ld.so's _dl_boot_bind() in boot.h.

The first arch implementatation is also included for amd64 where
__start calls _dl_boot_bind() and then calls ___start(). Includes
parts from kettenis@ to help get R_X86_64_64 relocations working
and proper handling for undefined weak symbols.

This is the first part of several to get static pie self-relocating
binaries working. binutils, gcc and kernel changes are forthcoming
to complete the solution, then per-arch implementations are needed
for MD_RCRT0_START in csu.

okay kettenis@ pascal@ deraadt@


# 1.2 12-Dec-2013 guenther

Fix static linking of libpthread: have crt0 invoke __init_tcb() if it's
defined and we don't think ld.so has already done the TCB setup.

ok and much discussion miod@


# 1.1 03-Dec-2013 guenther

Merge the per-arch crt0.c files into common_elf/crt0.c, with MD macros in
the md_init.h files.

Worked out with and ok miod@; ok matthew@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.10 21-Jan-2017 guenther

Pull in declarations for main() and __init() to make clang happy.
Mark __init() as hidden

ok kettenis@ deraadt@


# 1.9 19-Jan-2017 guenther

MD_START is now always ___start, so expand and eliminate it

ok phessler@ deraadt@


# 1.8 26-Sep-2016 kettenis

Now that vax has been removed, nothing defined MD_NO_CLEANUP anymore.

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.7 07-May-2016 guenther

Declare moncontrol(3) APIs in <sys/gmon.h>
Export _gmonparam again.
Make gcrt0.o use an reserved name for _monstartup()

ok millert@


# 1.6 20-Mar-2016 guenther

Rearrange C runtime bits: now that ld.so exports environ and __progname,
move their definitions and initialization in static links to libc.a
Make crt0 always invoke a new func _csu_finish() in libc to process the auxv
and to either register the ld.so cleanup function (in dynamic links) or
initialize environ and __progname and do MC_DISABLE_KBIND (in static links).
In libc, get pagesize from auxv; cache that between getpagesize() and
sysconf(_SC_PAGESIZE)

ok mpi@ "good time" deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.5 01-Sep-2015 guenther

In static binaries, invoke kbind() once to disable it.

With much assistance from miod@
ok deraadt@@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.4 27-Dec-2014 kettenis

Only include "boot.h" if MD_RCRT0_START is defined. Should fix build on vax.

ok miod@


# 1.3 22-Dec-2014 kurt

Introduce new csu0 variant for -static -pie binaries to use called
rcsu0.o where the initial 'r' is for relocatable. rcsu0.o performs
self-relocation on static pie binaries by calling a slightly modified
copy of ld.so's _dl_boot_bind() in boot.h.

The first arch implementatation is also included for amd64 where
__start calls _dl_boot_bind() and then calls ___start(). Includes
parts from kettenis@ to help get R_X86_64_64 relocations working
and proper handling for undefined weak symbols.

This is the first part of several to get static pie self-relocating
binaries working. binutils, gcc and kernel changes are forthcoming
to complete the solution, then per-arch implementations are needed
for MD_RCRT0_START in csu.

okay kettenis@ pascal@ deraadt@


# 1.2 12-Dec-2013 guenther

Fix static linking of libpthread: have crt0 invoke __init_tcb() if it's
defined and we don't think ld.so has already done the TCB setup.

ok and much discussion miod@


# 1.1 03-Dec-2013 guenther

Merge the per-arch crt0.c files into common_elf/crt0.c, with MD macros in
the md_init.h files.

Worked out with and ok miod@; ok matthew@