summaryrefslogtreecommitdiff
path: root/regress/libexec
diff options
context:
space:
mode:
authorGreg Steuck <gnezdo@cvs.openbsd.org>2023-04-09 23:41:49 +0000
committerGreg Steuck <gnezdo@cvs.openbsd.org>2023-04-09 23:41:49 +0000
commit72997f6aae1a50d3c6c67fb0125418e9fe77a56e (patch)
tree6b769fd27a04a1efde26cca670fe4723e457068e /regress/libexec
parent6c5c2ff6b963e0fa73cd13d8c4a4eb9ca4559eaa (diff)
Treat symlinks better in $ORIGIN determination in ld.so
Now symlinking an executable away from the rest of its installation tree no longer prevents it from finding the libraries. This matches the behavior of other OS linkers. Prompted by a behavior change in lang/ghc test suite. Swapped the order of dirname/realpath in _dl_origin_path. Added some regress tests that pass and then bin3 that fails without this change and reflects the behavior needd for lang/ghc. Suggestion by semarie@, OK deraadt@
Diffstat (limited to 'regress/libexec')
-rw-r--r--regress/libexec/ld.so/subst/Makefile4
-rw-r--r--regress/libexec/ld.so/subst/prog2/Makefile38
-rw-r--r--regress/libexec/ld.so/subst/prog2/main.c25
3 files changed, 65 insertions, 2 deletions
diff --git a/regress/libexec/ld.so/subst/Makefile b/regress/libexec/ld.so/subst/Makefile
index 580eb59d5f6..f15700e18fa 100644
--- a/regress/libexec/ld.so/subst/Makefile
+++ b/regress/libexec/ld.so/subst/Makefile
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile,v 1.1 2013/03/30 22:03:51 kurt Exp $
+# $OpenBSD: Makefile,v 1.2 2023/04/09 23:41:48 gnezdo Exp $
-SUBDIR+= libaa prog1
+SUBDIR+= libaa prog1 prog2
install:
diff --git a/regress/libexec/ld.so/subst/prog2/Makefile b/regress/libexec/ld.so/subst/prog2/Makefile
new file mode 100644
index 00000000000..3881c6759a8
--- /dev/null
+++ b/regress/libexec/ld.so/subst/prog2/Makefile
@@ -0,0 +1,38 @@
+# $OpenBSD: Makefile,v 1.1 2023/04/09 23:41:48 gnezdo Exp $
+
+.include <bsd.obj.mk>
+
+AA_DIR=${.CURDIR}/../libaa
+
+AA_OBJDIR!= if [ -d $(AA_DIR)/${__objdir} ]; then \
+ echo "$(AA_DIR)/${__objdir}"; \
+ else \
+ echo "$(AA_DIR)"; \
+ fi
+
+PROG= prog2
+SRCS= main.c
+CPPFLAGS+= -I$(AA_DIR)
+LDADD+= -laa
+LDFLAGS+= -Wl,-z,origin,-rpath,'$$ORIGIN/../lib'
+LDFLAGS+= -L$(AA_OBJDIR)
+
+REGRESS_TARGETS = test
+
+.PHONY: test
+test: $(PROG)
+ mkdir -p lib bin bin2 bin3/bin
+ cp $(AA_OBJDIR)/libaa.so* lib
+ cp ./$(PROG) bin
+ bin/$(PROG)
+ ln -sf ../bin bin2/bin
+ bin2/bin/$(PROG)
+ ln -sf $$(realpath bin/$(PROG)) bin3/bin/$(PROG)
+ bin3/bin/$(PROG)
+
+clean:
+ rm -f a.out [Ee]rrs mklog *.core y.tab.h \
+ ${PROG} ${OBJS} ${_LEXINTM} ${_YACCINTM} ${CLEANFILES}
+ rm -rf lib bin bin2 bin3
+
+.include <bsd.regress.mk>
diff --git a/regress/libexec/ld.so/subst/prog2/main.c b/regress/libexec/ld.so/subst/prog2/main.c
new file mode 100644
index 00000000000..76485e24e65
--- /dev/null
+++ b/regress/libexec/ld.so/subst/prog2/main.c
@@ -0,0 +1,25 @@
+/* $OpenBSD: main.c,v 1.1 2023/04/09 23:41:48 gnezdo Exp $ */
+
+/*
+ * Copyright (c) 2013 Kurt Miller <kurt@intricatesoftware.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "aa.h"
+
+int
+main()
+{
+ return (aa());
+}