From c5cc3359fe6fb92473040ef2f783d6188748c50e Mon Sep 17 00:00:00 2001 From: deraadt Date: Mon, 27 Feb 2023 14:59:33 +0000 Subject: [PATCH] Calculate the size of the static (and profiled static) execve syscall stub and store it in a const variable for use by crt0. help from kettenis and miod --- lib/libc/sys/Makefile.inc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index 931ed89a83e..4d2e9b89f7d 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.172 2023/02/21 14:39:35 deraadt Exp $ +# $OpenBSD: Makefile.inc,v 1.173 2023/02/27 14:59:33 deraadt Exp $ # $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $ # @(#)Makefile.inc 8.1 (Berkeley) 6/17/93 @@ -23,6 +23,23 @@ SRCS+= ptrace.c semctl.c \ # stack protector helper functions SRCS+= stack_protector.c +# Extract execve stub size for static binary pinsyscall(2) in dlfcn/init.c +SRCS+= _execvesize.c +CLEANFILES+=_execvesize.c +_execvesize.c: execve.o execve.po + readelf -s execve.po | awk \ + '/ execve$$/{ printf("#ifdef _PROFILE\nconst int _execve_size = %d;\n", $$3); }' > $@ + readelf -s execve.o | awk \ + '/ execve$$/{ printf("#else\nconst int _execve_size = %d;\n#endif\n", $$3); }' >> $@ + +# _libc_preinit() needs to know if compiled with or without profiling +_execvesize.po: + @echo "${COMPILE.c} -D_PROFILE ${.IMPSRC} -o ${.TARGET}" + @${COMPILE.c} ${DFLAGS} -D_PROFILE ${.IMPSRC} -o ${.TARGET}.o + @-mv $@.d $*.d + @${LD} -X -r ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + # cancelation details SRCS+= canceled.c -- 2.20.1