From 922a84d50fe004716b999164e214c18ee88fe3bf Mon Sep 17 00:00:00 2001 From: sthen Date: Sat, 20 Aug 2022 14:13:48 +0000 Subject: [PATCH] add ld.so RTLD_NOLOAD regress tests, ok jca@ guenther@ --- regress/libexec/ld.so/Makefile | 4 +-- regress/libexec/ld.so/noload/Makefile | 5 +++ regress/libexec/ld.so/noload/liba/Makefile | 9 ++++++ regress/libexec/ld.so/noload/liba/liba.c | 4 +++ .../libexec/ld.so/noload/liba/shlib_version | 2 ++ regress/libexec/ld.so/noload/libb/Makefile | 9 ++++++ regress/libexec/ld.so/noload/libb/libb.c | 4 +++ .../libexec/ld.so/noload/libb/shlib_version | 2 ++ regress/libexec/ld.so/noload/test1/Makefile | 32 +++++++++++++++++++ regress/libexec/ld.so/noload/test1/test1.c | 26 +++++++++++++++ 10 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 regress/libexec/ld.so/noload/Makefile create mode 100644 regress/libexec/ld.so/noload/liba/Makefile create mode 100644 regress/libexec/ld.so/noload/liba/liba.c create mode 100644 regress/libexec/ld.so/noload/liba/shlib_version create mode 100644 regress/libexec/ld.so/noload/libb/Makefile create mode 100644 regress/libexec/ld.so/noload/libb/libb.c create mode 100644 regress/libexec/ld.so/noload/libb/shlib_version create mode 100644 regress/libexec/ld.so/noload/test1/Makefile create mode 100644 regress/libexec/ld.so/noload/test1/test1.c diff --git a/regress/libexec/ld.so/Makefile b/regress/libexec/ld.so/Makefile index 1b169b5dc2f..e4c908ddaaf 100644 --- a/regress/libexec/ld.so/Makefile +++ b/regress/libexec/ld.so/Makefile @@ -1,10 +1,10 @@ -# $OpenBSD: Makefile,v 1.18 2021/06/02 07:32:34 semarie Exp $ +# $OpenBSD: Makefile,v 1.19 2022/08/20 14:13:48 sthen Exp $ SUBDIR+= elf hidden weak dlsym dlopen dlclose lazy SUBDIR+= constructor SUBDIR+= link-order edgecases initfirst SUBDIR+= df_1_noopen randomdata subst dependencies -SUBDIR+= init-env nodelete +SUBDIR+= init-env nodelete noload install: diff --git a/regress/libexec/ld.so/noload/Makefile b/regress/libexec/ld.so/noload/Makefile new file mode 100644 index 00000000000..913ea617158 --- /dev/null +++ b/regress/libexec/ld.so/noload/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2022/08/20 14:13:48 sthen Exp $ + +SUBDIR += liba libb test1 + +.include diff --git a/regress/libexec/ld.so/noload/liba/Makefile b/regress/libexec/ld.so/noload/liba/Makefile new file mode 100644 index 00000000000..2329888a384 --- /dev/null +++ b/regress/libexec/ld.so/noload/liba/Makefile @@ -0,0 +1,9 @@ +# $OpenBSD: Makefile,v 1.1 2022/08/20 14:13:48 sthen Exp $ + +LIB = a +SRCS = liba.c + +regress: all + +.include + diff --git a/regress/libexec/ld.so/noload/liba/liba.c b/regress/libexec/ld.so/noload/liba/liba.c new file mode 100644 index 00000000000..bfe6c3047e5 --- /dev/null +++ b/regress/libexec/ld.so/noload/liba/liba.c @@ -0,0 +1,4 @@ +void +functiona(void) +{ +} diff --git a/regress/libexec/ld.so/noload/liba/shlib_version b/regress/libexec/ld.so/noload/liba/shlib_version new file mode 100644 index 00000000000..97c9f92d6b8 --- /dev/null +++ b/regress/libexec/ld.so/noload/liba/shlib_version @@ -0,0 +1,2 @@ +major=0 +minor=0 diff --git a/regress/libexec/ld.so/noload/libb/Makefile b/regress/libexec/ld.so/noload/libb/Makefile new file mode 100644 index 00000000000..5933e46aa1f --- /dev/null +++ b/regress/libexec/ld.so/noload/libb/Makefile @@ -0,0 +1,9 @@ +# $OpenBSD: Makefile,v 1.1 2022/08/20 14:13:48 sthen Exp $ + +LIB = b +SRCS = libb.c + +regress: all + +.include + diff --git a/regress/libexec/ld.so/noload/libb/libb.c b/regress/libexec/ld.so/noload/libb/libb.c new file mode 100644 index 00000000000..959caedfd07 --- /dev/null +++ b/regress/libexec/ld.so/noload/libb/libb.c @@ -0,0 +1,4 @@ +void +functionb(void) +{ +} diff --git a/regress/libexec/ld.so/noload/libb/shlib_version b/regress/libexec/ld.so/noload/libb/shlib_version new file mode 100644 index 00000000000..97c9f92d6b8 --- /dev/null +++ b/regress/libexec/ld.so/noload/libb/shlib_version @@ -0,0 +1,2 @@ +major=0 +minor=0 diff --git a/regress/libexec/ld.so/noload/test1/Makefile b/regress/libexec/ld.so/noload/test1/Makefile new file mode 100644 index 00000000000..321c14114a3 --- /dev/null +++ b/regress/libexec/ld.so/noload/test1/Makefile @@ -0,0 +1,32 @@ +# $OpenBSD: Makefile,v 1.1 2022/08/20 14:13:48 sthen Exp $ + +.include + +PROG = test1 + +LIBADIR != if test -d ${.CURDIR}/../liba/${__objdir}; then \ + echo "${.CURDIR}/../liba/${__objdir}"; \ + else \ + echo "${.CURDIR}/../liba"; \ + fi + +LIBBDIR != if test -d ${.CURDIR}/../libb/${__objdir}; then \ + echo "${.CURDIR}/../libb/${__objdir}"; \ + else \ + echo "${.CURDIR}/../libb"; \ + fi + +LIBANAME = ${LIBADIR}/liba.so.0.0 +LIBBNAME = ${LIBBDIR}/libb.so.0.0 + +CFLAGS += -DLIBANAME=\"${LIBANAME}\" \ + -DLIBBNAME=\"${LIBBNAME}\" + +REGRESS_TARGETS += run-regress + +run-regress: ${PROG} + if ./${PROG} | grep found; then echo failed; exit 1; fi + LD_PRELOAD=${LIBANAME} ./${PROG} | grep ${LIBANAME}.found + LD_PRELOAD=${LIBBNAME} ./${PROG} | grep ${LIBBNAME}.found + +.include diff --git a/regress/libexec/ld.so/noload/test1/test1.c b/regress/libexec/ld.so/noload/test1/test1.c new file mode 100644 index 00000000000..869b9e36ee0 --- /dev/null +++ b/regress/libexec/ld.so/noload/test1/test1.c @@ -0,0 +1,26 @@ + +#include +#include +#include + +#ifndef LIBANAME +#error "LIBANAME undefined" +#endif + +#ifndef LIBBNAME +#error "LIBBNAME undefined" +#endif + +int +main(int argc, char *argv[]) +{ + void *handle; + + printf("opening\n"); + if ((handle = dlopen(LIBANAME, RTLD_NOW|RTLD_NOLOAD))) + printf("%s found\n", LIBANAME); + else if ((handle = dlopen(LIBBNAME, RTLD_NOW|RTLD_NOLOAD))) + printf("%s found\n", LIBBNAME); + + return 0; +} -- 2.20.1