summaryrefslogtreecommitdiffstats
path: root/libexec
diff options
context:
space:
mode:
authorsjg <sjg@FreeBSD.org>2014-08-19 06:50:54 +0000
committersjg <sjg@FreeBSD.org>2014-08-19 06:50:54 +0000
commitd7cd1d425cc1ea9451fa235e3af9b6625c3e0de2 (patch)
treeb04f4bd7cd887f50e7d98af35f46b9834ff86c80 /libexec
parent3c8e37b1d04827f33c0c9a7594bd1b1ef7cdb3d3 (diff)
parent4fbde208c6460d576f64d6dc3cdc6cab085a4283 (diff)
downloadFreeBSD-src-d7cd1d425cc1ea9451fa235e3af9b6625c3e0de2.zip
FreeBSD-src-d7cd1d425cc1ea9451fa235e3af9b6625c3e0de2.tar.gz
Merge head from 7/28
Diffstat (limited to 'libexec')
-rw-r--r--libexec/atf/Makefile2
-rw-r--r--libexec/atf/Makefile.inc2
-rw-r--r--libexec/atf/atf-check/Makefile5
-rw-r--r--libexec/atf/atf-sh/Makefile55
-rw-r--r--libexec/atf/atf-sh/Makefile.depend24
-rw-r--r--libexec/atf/atf-sh/tests/Makefile31
-rw-r--r--libexec/bootpd/bootpd.816
-rw-r--r--libexec/bootpd/tools/bootptest/bootptest.82
-rw-r--r--libexec/mail.local/Makefile2
-rw-r--r--libexec/mknetid/mknetid.82
-rw-r--r--libexec/mknetid/netid.52
-rw-r--r--libexec/pppoed/pppoed.82
-rw-r--r--libexec/revnetgroup/revnetgroup.82
-rw-r--r--libexec/rtld-elf/Makefile6
-rw-r--r--libexec/rtld-elf/Makefile.depend1
-rw-r--r--libexec/rtld-elf/arm/rtld_start.S7
-rw-r--r--libexec/rtld-elf/ia64/Makefile.inc1
-rw-r--r--libexec/rtld-elf/ia64/reloc.c658
-rw-r--r--libexec/rtld-elf/ia64/rtld_machdep.h72
-rw-r--r--libexec/rtld-elf/ia64/rtld_start.S252
-rw-r--r--libexec/rtld-elf/libmap.c6
-rw-r--r--libexec/rtld-elf/rtld.111
-rw-r--r--libexec/rtld-elf/rtld.c162
-rw-r--r--libexec/rtld-elf/rtld_lock.c16
-rw-r--r--libexec/rtld-elf/rtld_printf.c12
-rw-r--r--libexec/rtld-elf/rtld_printf.h2
-rw-r--r--libexec/rtld-elf/tests/Makefile14
-rw-r--r--libexec/rtld-elf/tests/ld_library_pathfds.c220
-rw-r--r--libexec/rtld-elf/tests/libpythagoras/Makefile16
-rw-r--r--libexec/rtld-elf/tests/libpythagoras/pythagoras.c42
-rw-r--r--libexec/rtld-elf/tests/libpythagoras/pythagoras.h28
-rw-r--r--libexec/rtld-elf/tests/target/Makefile13
-rw-r--r--libexec/rtld-elf/tests/target/target.c39
-rwxr-xr-xlibexec/save-entropy/save-entropy.sh2
-rw-r--r--libexec/smrsh/Makefile2
-rw-r--r--libexec/telnetd/Makefile9
-rw-r--r--libexec/telnetd/Makefile.depend1
-rw-r--r--libexec/ypxfr/ypxfr.82
38 files changed, 699 insertions, 1042 deletions
diff --git a/libexec/atf/Makefile b/libexec/atf/Makefile
index 6749db5..db7554d 100644
--- a/libexec/atf/Makefile
+++ b/libexec/atf/Makefile
@@ -25,6 +25,6 @@
#
# $FreeBSD$
-SUBDIR= atf-check tests
+SUBDIR= atf-check atf-sh tests
.include <bsd.subdir.mk>
diff --git a/libexec/atf/Makefile.inc b/libexec/atf/Makefile.inc
index 392bbb2..2521be6 100644
--- a/libexec/atf/Makefile.inc
+++ b/libexec/atf/Makefile.inc
@@ -28,3 +28,5 @@
CFLAGS+= -DHAVE_CONFIG_H
WARNS?= 3
+
+.include "../Makefile.inc"
diff --git a/libexec/atf/atf-check/Makefile b/libexec/atf/atf-check/Makefile
index 093de06..fa7fabe 100644
--- a/libexec/atf/atf-check/Makefile
+++ b/libexec/atf/atf-check/Makefile
@@ -31,18 +31,17 @@
ATF= ${.CURDIR:H:H:H}/contrib/atf
.PATH: ${ATF}/atf-sh
-BINDIR= /usr/libexec
PROG_CXX= atf-check
SRCS= atf-check.cpp
MAN= atf-check.1
CFLAGS+= -I${ATF}
-DPADD+= ${LIBATF_CXX} ${LIBATF_C}
-
LDFLAGS+= -L${.OBJDIR}/../../../lib/atf/libatf-c++
LDFLAGS+= -L${.OBJDIR}/../../../lib/atf/libatf-c
+DPADD+= ${LIBATF_CXX} ${LIBATF_C}
LDADD+= -latf-c++ -latf-c
+USEPRIVATELIB= atf-c++ atf-c
.if ${MK_TESTS} != "no"
SUBDIR+= tests
diff --git a/libexec/atf/atf-sh/Makefile b/libexec/atf/atf-sh/Makefile
new file mode 100644
index 0000000..3f461fd
--- /dev/null
+++ b/libexec/atf/atf-sh/Makefile
@@ -0,0 +1,55 @@
+#-
+# Copyright (c) 2011 Google, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+
+.include <src.opts.mk>
+.include <bsd.init.mk>
+
+ATF= ${.CURDIR:H:H:H}/contrib/atf
+.PATH: ${ATF}/atf-sh
+
+PROG_CXX= atf-sh
+SRCS= atf-sh.cpp
+MAN= atf-sh.1 atf-sh-api.3
+
+CFLAGS+= -DHAVE_CONFIG_H
+CFLAGS+= -I${ATF}
+
+DPADD+= ${LIBATF_C} ${LIBATF_CXX}
+LDADD+= -latf-c++ -latf-c
+USEPRIVATELIB= atf-c++ atf-c
+
+FILESGROUPS= SUBR
+
+SUBRDIR= ${SHAREDIR}/atf
+SUBR= libatf-sh.subr
+
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
+.include "../../../lib/atf/common.mk"
+.include <bsd.prog.mk>
diff --git a/libexec/atf/atf-sh/Makefile.depend b/libexec/atf/atf-sh/Makefile.depend
new file mode 100644
index 0000000..72e04cf
--- /dev/null
+++ b/libexec/atf/atf-sh/Makefile.depend
@@ -0,0 +1,24 @@
+# Autogenerated - do NOT edit!
+
+DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
+
+DIRDEPS = \
+ gnu/lib/csu \
+ gnu/lib/libgcc \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/atf/libatf-c \
+ lib/atf/libatf-c++ \
+ lib/libc \
+ lib/libc++ \
+ lib/libcompiler_rt \
+ lib/libcxxrt \
+ lib/msun \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/libexec/atf/atf-sh/tests/Makefile b/libexec/atf/atf-sh/tests/Makefile
new file mode 100644
index 0000000..e71b6b5
--- /dev/null
+++ b/libexec/atf/atf-sh/tests/Makefile
@@ -0,0 +1,31 @@
+# $FreeBSD$
+
+.include <bsd.init.mk>
+
+TESTSDIR= ${TESTSBASE}/libexec/atf/atf-sh
+
+ATF= ${.CURDIR:H:H:H:H}/contrib/atf
+.PATH: ${ATF}/atf-sh
+
+ATF_TESTS_SH+= atf_check_test
+ATF_TESTS_SH+= config_test
+ATF_TESTS_SH+= integration_test
+ATF_TESTS_SH+= normalize_test
+ATF_TESTS_SH+= tc_test
+ATF_TESTS_SH+= tp_test
+
+integration_test: Makefile
+ATF_TESTS_SH_SED_integration_test= \
+ -e 's,atf_check,PATH=/usr/libexec:$${PATH} atf_check,g' \
+ -e 's,/usr/bin/env *atf-sh,/usr/libexec/atf-sh,g'
+
+SCRIPTS+= misc_helpers
+SCRIPTSDIR_misc_helpers=${TESTSDIR}
+CLEANFILES+= misc_helpers misc_helpers.tmp
+misc_helpers: misc_helpers.sh
+ echo '#! /usr/libexec/atf-sh' >${.TARGET}.tmp
+ cat ${.ALLSRC} >>${.TARGET}.tmp
+ chmod +x ${.TARGET}.tmp
+ mv ${.TARGET}.tmp ${.TARGET}
+
+.include <bsd.test.mk>
diff --git a/libexec/bootpd/bootpd.8 b/libexec/bootpd/bootpd.8
index 78afa37..d124800 100644
--- a/libexec/bootpd/bootpd.8
+++ b/libexec/bootpd/bootpd.8
@@ -279,7 +279,7 @@ DHCP Options and BOOTP Vendor Extensions
.El
.Sh AUTHORS
This distribution is currently maintained by
-.An Walter L. Wimer Aq walt+@cmu.edu .
+.An Walter L. Wimer Aq Mt walt+@cmu.edu .
.Pp
The original BOOTP server was created by
.An Bill Croft
@@ -299,12 +299,12 @@ Enhancements and bug-fixes have been contributed by:
(in alphabetical order)
.Pp
.An -split
-.An Danny Backx Aq db@sunbim.be
-.An John Brezak Aq brezak@ch.hp.com
-.An Frank da Cruz Aq fdc@cc.columbia.edu
-.An David R. Linn Aq drl@vuse.vanderbilt.edu
-.An Jim McKim Aq mckim@lerc.nasa.gov
-.An Gordon W. Ross Aq gwr@mc.com
-.An Jason Zions Aq jazz@hal.com .
+.An Danny Backx Aq Mt db@sunbim.be
+.An John Brezak Aq Mt brezak@ch.hp.com
+.An Frank da Cruz Aq Mt fdc@cc.columbia.edu
+.An David R. Linn Aq Mt drl@vuse.vanderbilt.edu
+.An Jim McKim Aq Mt mckim@lerc.nasa.gov
+.An Gordon W. Ross Aq Mt gwr@mc.com
+.An Jason Zions Aq Mt jazz@hal.com .
.Sh BUGS
Individual host entries must not exceed 1024 characters.
diff --git a/libexec/bootpd/tools/bootptest/bootptest.8 b/libexec/bootpd/tools/bootptest/bootptest.8
index 888ff22..4ba2724 100644
--- a/libexec/bootpd/tools/bootptest/bootptest.8
+++ b/libexec/bootpd/tools/bootptest/bootptest.8
@@ -62,7 +62,7 @@ utility is a combination of original and derived works.
The main program module
.Pq Pa bootptest.c
is original work by
-.An "Gordon W. Ross" Aq gwr@mc.com .
+.An Gordon W. Ross Aq Mt gwr@mc.com .
The packet printing module
.Pq Pa print\-bootp.c
is a slightly modified
diff --git a/libexec/mail.local/Makefile b/libexec/mail.local/Makefile
index 3e59609..dff4238 100644
--- a/libexec/mail.local/Makefile
+++ b/libexec/mail.local/Makefile
@@ -9,6 +9,8 @@ SRCS= mail.local.c
MAN= mail.local.8
CFLAGS+=-I${SENDMAIL_DIR}/include -I.
+NO_PIE= yes
+
WARNS?= 2
WFORMAT=0
diff --git a/libexec/mknetid/mknetid.8 b/libexec/mknetid/mknetid.8
index e70dc00..08b8e74 100644
--- a/libexec/mknetid/mknetid.8
+++ b/libexec/mknetid/mknetid.8
@@ -149,4 +149,4 @@ the default netid database file
.Xr yp 8 ,
.Xr yp_mkdb 8
.Sh AUTHORS
-.An Bill Paul Aq wpaul@ctr.columbia.edu
+.An Bill Paul Aq Mt wpaul@ctr.columbia.edu
diff --git a/libexec/mknetid/netid.5 b/libexec/mknetid/netid.5
index 011d8f5..b2ec827 100644
--- a/libexec/mknetid/netid.5
+++ b/libexec/mknetid/netid.5
@@ -88,4 +88,4 @@ unix.jodie@kaka 0:jodie
.Xr mknetid 8 ,
.Xr yp 8
.Sh AUTHORS
-.An Mats O Jansson Aq moj@stacken.kth.se
+.An Mats O Jansson Aq Mt moj@stacken.kth.se
diff --git a/libexec/pppoed/pppoed.8 b/libexec/pppoed/pppoed.8
index 2f78353..6841bfd 100644
--- a/libexec/pppoed/pppoed.8
+++ b/libexec/pppoed/pppoed.8
@@ -206,7 +206,7 @@ and the following to
The
.Nm
utility was written by
-.An Brian Somers Aq brian@Awfulhak.org
+.An Brian Somers Aq Mt brian@Awfulhak.org
and first appeared in
.Fx 3.4 .
.Sh BUGS
diff --git a/libexec/revnetgroup/revnetgroup.8 b/libexec/revnetgroup/revnetgroup.8
index f48c327..a17d966 100644
--- a/libexec/revnetgroup/revnetgroup.8
+++ b/libexec/revnetgroup/revnetgroup.8
@@ -156,4 +156,4 @@ master server
.Xr yp 8 ,
.Xr yp_mkdb 8
.Sh AUTHORS
-.An Bill Paul Aq wpaul@ctr.columbia.edu
+.An Bill Paul Aq Mt wpaul@ctr.columbia.edu
diff --git a/libexec/rtld-elf/Makefile b/libexec/rtld-elf/Makefile
index 21e2219..48e86f7 100644
--- a/libexec/rtld-elf/Makefile
+++ b/libexec/rtld-elf/Makefile
@@ -78,5 +78,11 @@ beforeinstall:
.PATH: ${.CURDIR}/${RTLD_ARCH}
+NO_PIE= yes
+
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
.include <bsd.symver.mk>
.include <bsd.prog.mk>
diff --git a/libexec/rtld-elf/Makefile.depend b/libexec/rtld-elf/Makefile.depend
index ea133a6..c4bbe3a 100644
--- a/libexec/rtld-elf/Makefile.depend
+++ b/libexec/rtld-elf/Makefile.depend
@@ -3,6 +3,7 @@
DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
DIRDEPS = \
+ bin/cat.host \
include \
include/xlocale \
lib/libc \
diff --git a/libexec/rtld-elf/arm/rtld_start.S b/libexec/rtld-elf/arm/rtld_start.S
index 7a4fae4..c482808 100644
--- a/libexec/rtld-elf/arm/rtld_start.S
+++ b/libexec/rtld-elf/arm/rtld_start.S
@@ -77,7 +77,7 @@ __FBSDID("$FreeBSD$");
* lr = &GOT[2]
*/
_rtld_bind_start:
- stmdb sp!,{r0-r4,sl,fp}
+ stmdb sp!,{r0-r5,sl,fp}
sub r1, ip, lr /* r1 = 4 * (n + 1) */
sub r1, r1, #4 /* r1 = 4 * n */
@@ -86,11 +86,14 @@ _rtld_bind_start:
ldr r0, [lr, #-4] /* get obj ptr from GOT[1] */
mov r4, ip /* save GOT location */
+ mov r5, sp /* Save the stack pointer */
+ bic sp, sp, #7 /* Align the stack pointer */
bl _rtld_bind /* Call the binder */
+ mov sp, r5 /* Restore the old stack pointer */
str r0, [r4] /* save address in GOT */
mov ip, r0 /* save new address */
- ldmia sp!,{r0-r4,sl,fp,lr} /* restore the stack */
+ ldmia sp!,{r0-r5,sl,fp,lr} /* restore the stack */
mov pc, ip /* jump to the new address */
diff --git a/libexec/rtld-elf/ia64/Makefile.inc b/libexec/rtld-elf/ia64/Makefile.inc
deleted file mode 100644
index e8c0da7..0000000
--- a/libexec/rtld-elf/ia64/Makefile.inc
+++ /dev/null
@@ -1 +0,0 @@
-# $FreeBSD$
diff --git a/libexec/rtld-elf/ia64/reloc.c b/libexec/rtld-elf/ia64/reloc.c
deleted file mode 100644
index 1a41cb3..0000000
--- a/libexec/rtld-elf/ia64/reloc.c
+++ /dev/null
@@ -1,658 +0,0 @@
-/*-
- * Copyright 1996, 1997, 1998, 1999 John D. Polstra.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-/*
- * Dynamic linker for ELF.
- *
- * John Polstra <jdp@polstra.com>.
- */
-
-#include <sys/param.h>
-#include <sys/mman.h>
-#include <machine/ia64_cpu.h>
-
-#include <dlfcn.h>
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "debug.h"
-#include "rtld.h"
-
-extern Elf_Dyn _DYNAMIC;
-
-/*
- * Macros for loading/storing unaligned 64-bit values. These are
- * needed because relocations can point to unaligned data. This
- * occurs in the DWARF2 exception frame tables generated by the
- * compiler, for instance.
- *
- * We don't use these when relocating jump slots and GOT entries,
- * since they are guaranteed to be aligned.
- *
- * XXX dfr stub for now.
- */
-#define load64(p) (*(u_int64_t *) (p))
-#define store64(p, v) (*(u_int64_t *) (p) = (v))
-
-/* Allocate an @fptr. */
-
-#define FPTR_CHUNK_SIZE 64
-
-struct fptr_chunk {
- struct fptr fptrs[FPTR_CHUNK_SIZE];
-};
-
-static struct fptr_chunk first_chunk;
-static struct fptr_chunk *current_chunk = &first_chunk;
-static struct fptr *next_fptr = &first_chunk.fptrs[0];
-static struct fptr *last_fptr = &first_chunk.fptrs[FPTR_CHUNK_SIZE];
-
-/*
- * We use static storage initially so that we don't have to call
- * malloc during init_rtld().
- */
-static struct fptr *
-alloc_fptr(Elf_Addr target, Elf_Addr gp)
-{
- struct fptr* fptr;
-
- if (next_fptr == last_fptr) {
- current_chunk = xmalloc(sizeof(struct fptr_chunk));
- next_fptr = &current_chunk->fptrs[0];
- last_fptr = &current_chunk->fptrs[FPTR_CHUNK_SIZE];
- }
- fptr = next_fptr;
- next_fptr++;
- fptr->target = target;
- fptr->gp = gp;
- return fptr;
-}
-
-static struct fptr **
-alloc_fptrs(Obj_Entry *obj, bool mapped)
-{
- struct fptr **fptrs;
- size_t fbytes;
-
- fbytes = obj->dynsymcount * sizeof(struct fptr *);
-
- /*
- * Avoid malloc, if requested. Happens when relocating
- * rtld itself on startup.
- */
- if (mapped) {
- fptrs = mmap(NULL, fbytes, PROT_READ|PROT_WRITE,
- MAP_ANON, -1, 0);
- if (fptrs == MAP_FAILED)
- fptrs = NULL;
- } else {
- fptrs = xcalloc(1, fbytes);
- }
-
- /*
- * This assertion is necessary to guarantee function pointer
- * uniqueness
- */
- assert(fptrs != NULL);
-
- return (obj->priv = fptrs);
-}
-
-static void
-free_fptrs(Obj_Entry *obj, bool mapped)
-{
- struct fptr **fptrs;
- size_t fbytes;
-
- fptrs = obj->priv;
- if (fptrs == NULL)
- return;
-
- fbytes = obj->dynsymcount * sizeof(struct fptr *);
- if (mapped)
- munmap(fptrs, fbytes);
- else
- free(fptrs);
- obj->priv = NULL;
-}
-
-/* Relocate a non-PLT object with addend. */
-static int
-reloc_non_plt_obj(Obj_Entry *obj_rtld, Obj_Entry *obj, const Elf_Rela *rela,
- SymCache *cache, int flags, RtldLockState *lockstate)
-{
- struct fptr **fptrs;
- Elf_Addr *where = (Elf_Addr *) (obj->relocbase + rela->r_offset);
-
- switch (ELF_R_TYPE(rela->r_info)) {
- case R_IA_64_REL64LSB:
- /*
- * We handle rtld's relocations in rtld_start.S
- */
- if (obj != obj_rtld)
- store64(where,
- load64(where) + (Elf_Addr) obj->relocbase);
- break;
-
- case R_IA_64_DIR64LSB: {
- const Elf_Sym *def;
- const Obj_Entry *defobj;
- Elf_Addr target;
-
- def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
- flags, cache, lockstate);
- if (def == NULL)
- return -1;
-
- target = (def->st_shndx != SHN_UNDEF)
- ? (Elf_Addr)(defobj->relocbase + def->st_value) : 0;
- store64(where, target + rela->r_addend);
- break;
- }
-
- case R_IA_64_FPTR64LSB: {
- /*
- * We have to make sure that all @fptr references to
- * the same function are identical so that code can
- * compare function pointers.
- */
- const Elf_Sym *def;
- const Obj_Entry *defobj;
- struct fptr *fptr = 0;
- Elf_Addr target, gp;
- int sym_index;
-
- def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
- SYMLOOK_IN_PLT | flags, cache, lockstate);
- if (def == NULL) {
- /*
- * XXX r_debug_state is problematic and find_symdef()
- * returns NULL for it. This probably has something to
- * do with symbol versioning (r_debug_state is in the
- * symbol map). If we return -1 in that case we abort
- * relocating rtld, which typically is fatal. So, for
- * now just skip the symbol when we're relocating
- * rtld. We don't care about r_debug_state unless we
- * are being debugged.
- */
- if (obj != obj_rtld)
- return -1;
- break;
- }
-
- if (def->st_shndx != SHN_UNDEF) {
- target = (Elf_Addr)(defobj->relocbase + def->st_value);
- gp = (Elf_Addr)defobj->pltgot;
-
- /* rtld is allowed to reference itself only */
- assert(!obj->rtld || obj == defobj);
- fptrs = defobj->priv;
- if (fptrs == NULL)
- fptrs = alloc_fptrs((Obj_Entry *) defobj,
- obj->rtld);
-
- sym_index = def - defobj->symtab;
-
- /*
- * Find the @fptr, using fptrs as a helper.
- */
- if (fptrs)
- fptr = fptrs[sym_index];
- if (!fptr) {
- fptr = alloc_fptr(target, gp);
- if (fptrs)
- fptrs[sym_index] = fptr;
- }
- } else
- fptr = NULL;
-
- store64(where, (Elf_Addr)fptr);
- break;
- }
-
- case R_IA_64_IPLTLSB: {
- /*
- * Relocation typically used to populate C++ virtual function
- * tables. It creates a 128-bit function descriptor at the
- * specified memory address.
- */
- const Elf_Sym *def;
- const Obj_Entry *defobj;
- struct fptr *fptr;
- Elf_Addr target, gp;
-
- def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
- flags, cache, lockstate);
- if (def == NULL)
- return -1;
-
- if (def->st_shndx != SHN_UNDEF) {
- target = (Elf_Addr)(defobj->relocbase + def->st_value);
- gp = (Elf_Addr)defobj->pltgot;
- } else {
- target = 0;
- gp = 0;
- }
-
- fptr = (void*)where;
- store64(&fptr->target, target);
- store64(&fptr->gp, gp);
- break;
- }
-
- case R_IA_64_DTPMOD64LSB: {
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
- flags, cache, lockstate);
- if (def == NULL)
- return -1;
-
- store64(where, defobj->tlsindex);
- break;
- }
-
- case R_IA_64_DTPREL64LSB: {
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
- flags, cache, lockstate);
- if (def == NULL)
- return -1;
-
- store64(where, def->st_value + rela->r_addend);
- break;
- }
-
- case R_IA_64_TPREL64LSB: {
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
- flags, cache, lockstate);
- if (def == NULL)
- return -1;
-
- /*
- * We lazily allocate offsets for static TLS as we
- * see the first relocation that references the
- * TLS block. This allows us to support (small
- * amounts of) static TLS in dynamically loaded
- * modules. If we run out of space, we generate an
- * error.
- */
- if (!defobj->tls_done) {
- if (!allocate_tls_offset((Obj_Entry*) defobj)) {
- _rtld_error("%s: No space available for static "
- "Thread Local Storage", obj->path);
- return -1;
- }
- }
-
- store64(where, defobj->tlsoffset + def->st_value + rela->r_addend);
- break;
- }
-
- case R_IA_64_NONE:
- break;
-
- default:
- _rtld_error("%s: Unsupported relocation type %u"
- " in non-PLT relocations\n", obj->path,
- (unsigned int)ELF_R_TYPE(rela->r_info));
- return -1;
- }
-
- return(0);
-}
-
-/* Process the non-PLT relocations. */
-int
-reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags,
- RtldLockState *lockstate)
-{
- const Elf_Rel *rellim;
- const Elf_Rel *rel;
- const Elf_Rela *relalim;
- const Elf_Rela *rela;
- SymCache *cache;
- int bytes = obj->dynsymcount * sizeof(SymCache);
- int r = -1;
-
- /*
- * The dynamic loader may be called from a thread, we have
- * limited amounts of stack available so we cannot use alloca().
- */
- cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
- if (cache == MAP_FAILED)
- cache = NULL;
-
- /* Perform relocations without addend if there are any: */
- rellim = (const Elf_Rel *) ((caddr_t) obj->rel + obj->relsize);
- for (rel = obj->rel; obj->rel != NULL && rel < rellim; rel++) {
- Elf_Rela locrela;
-
- locrela.r_info = rel->r_info;
- locrela.r_offset = rel->r_offset;
- locrela.r_addend = 0;
- if (reloc_non_plt_obj(obj_rtld, obj, &locrela, cache, flags,
- lockstate))
- goto done;
- }
-
- /* Perform relocations with addend if there are any: */
- relalim = (const Elf_Rela *) ((caddr_t) obj->rela + obj->relasize);
- for (rela = obj->rela; obj->rela != NULL && rela < relalim; rela++) {
- if (reloc_non_plt_obj(obj_rtld, obj, rela, cache, flags,
- lockstate))
- goto done;
- }
-
- r = 0;
-done:
- if (cache)
- munmap(cache, bytes);
-
- /*
- * Release temporarily mapped fptrs if relocating
- * rtld object itself. A new table will be created
- * in make_function_pointer using malloc when needed.
- */
- if (obj->rtld && obj->priv)
- free_fptrs(obj, true);
-
- return (r);
-}
-
-/* Process the PLT relocations. */
-int
-reloc_plt(Obj_Entry *obj)
-{
- /* All PLT relocations are the same kind: Elf_Rel or Elf_Rela. */
- if (obj->pltrelsize != 0) {
- const Elf_Rel *rellim;
- const Elf_Rel *rel;
-
- rellim = (const Elf_Rel *)
- ((char *)obj->pltrel + obj->pltrelsize);
- for (rel = obj->pltrel; rel < rellim; rel++) {
- Elf_Addr *where;
-
- assert(ELF_R_TYPE(rel->r_info) == R_IA_64_IPLTLSB);
-
- /* Relocate the @fptr pointing into the PLT. */
- where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
- *where += (Elf_Addr)obj->relocbase;
- }
- } else {
- const Elf_Rela *relalim;
- const Elf_Rela *rela;
-
- relalim = (const Elf_Rela *)
- ((char *)obj->pltrela + obj->pltrelasize);
- for (rela = obj->pltrela; rela < relalim; rela++) {
- Elf_Addr *where;
-
- assert(ELF_R_TYPE(rela->r_info) == R_IA_64_IPLTLSB);
-
- /* Relocate the @fptr pointing into the PLT. */
- where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
- *where += (Elf_Addr)obj->relocbase;
- }
- }
- return 0;
-}
-
-int
-reloc_iresolve(Obj_Entry *obj, struct Struct_RtldLockState *lockstate)
-{
-
- /* XXX not implemented */
- return (0);
-}
-
-int
-reloc_gnu_ifunc(Obj_Entry *obj, int flags,
- struct Struct_RtldLockState *lockstate)
-{
-
- /* XXX not implemented */
- return (0);
-}
-
-/* Relocate the jump slots in an object. */
-int
-reloc_jmpslots(Obj_Entry *obj, int flags, RtldLockState *lockstate)
-{
- if (obj->jmpslots_done)
- return 0;
- /* All PLT relocations are the same kind: Elf_Rel or Elf_Rela. */
- if (obj->pltrelsize != 0) {
- const Elf_Rel *rellim;
- const Elf_Rel *rel;
-
- rellim = (const Elf_Rel *)
- ((char *)obj->pltrel + obj->pltrelsize);
- for (rel = obj->pltrel; rel < rellim; rel++) {
- Elf_Addr *where;
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- assert(ELF_R_TYPE(rel->r_info) == R_IA_64_IPLTLSB);
- where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
- def = find_symdef(ELF_R_SYM(rel->r_info), obj,
- &defobj, SYMLOOK_IN_PLT | flags, NULL, lockstate);
- if (def == NULL)
- return -1;
- reloc_jmpslot(where,
- (Elf_Addr)(defobj->relocbase
- + def->st_value),
- defobj, obj, rel);
- }
- } else {
- const Elf_Rela *relalim;
- const Elf_Rela *rela;
-
- relalim = (const Elf_Rela *)
- ((char *)obj->pltrela + obj->pltrelasize);
- for (rela = obj->pltrela; rela < relalim; rela++) {
- Elf_Addr *where;
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
- def = find_symdef(ELF_R_SYM(rela->r_info), obj,
- &defobj, SYMLOOK_IN_PLT | flags, NULL, lockstate);
- if (def == NULL)
- return -1;
- reloc_jmpslot(where,
- (Elf_Addr)(defobj->relocbase
- + def->st_value),
- defobj, obj, (Elf_Rel *)rela);
- }
- }
- obj->jmpslots_done = true;
- return 0;
-}
-
-/* Fixup the jump slot at "where" to transfer control to "target". */
-Elf_Addr
-reloc_jmpslot(Elf_Addr *where, Elf_Addr target, const Obj_Entry *obj,
- const Obj_Entry *refobj, const Elf_Rel *rel)
-{
- Elf_Addr stubaddr;
-
- dbg(" reloc_jmpslot: where=%p, target=%p, gp=%p",
- (void *)where, (void *)target, (void *)obj->pltgot);
- stubaddr = *where;
- if (stubaddr != target) {
-
- /*
- * Point this @fptr directly at the target. Update the
- * gp value first so that we don't break another cpu
- * which is currently executing the PLT entry.
- */
- where[1] = (Elf_Addr) obj->pltgot;
- ia64_mf();
- where[0] = target;
- ia64_mf();
- }
-
- /*
- * The caller needs an @fptr for the adjusted entry. The PLT
- * entry serves this purpose nicely.
- */
- return (Elf_Addr) where;
-}
-
-/*
- * XXX ia64 doesn't seem to have copy relocations.
- *
- * Returns 0 on success, -1 on failure.
- */
-int
-do_copy_relocations(Obj_Entry *dstobj)
-{
-
- return 0;
-}
-
-/*
- * Return the @fptr representing a given function symbol.
- */
-void *
-make_function_pointer(const Elf_Sym *sym, const Obj_Entry *obj)
-{
- struct fptr **fptrs = obj->priv;
- int index = sym - obj->symtab;
-
- if (!fptrs) {
- /*
- * This should only happen for something like
- * dlsym("dlopen"). Actually, I'm not sure it can ever
- * happen.
- */
- fptrs = alloc_fptrs((Obj_Entry *) obj, false);
- }
- if (!fptrs[index]) {
- Elf_Addr target, gp;
- target = (Elf_Addr) (obj->relocbase + sym->st_value);
- gp = (Elf_Addr) obj->pltgot;
- fptrs[index] = alloc_fptr(target, gp);
- }
- return fptrs[index];
-}
-
-void
-call_initfini_pointer(const Obj_Entry *obj, Elf_Addr target)
-{
- struct fptr fptr;
-
- fptr.gp = (Elf_Addr) obj->pltgot;
- fptr.target = target;
- dbg(" initfini: target=%p, gp=%p",
- (void *) fptr.target, (void *) fptr.gp);
- ((InitFunc) &fptr)();
-}
-
-void
-call_init_pointer(const Obj_Entry *obj, Elf_Addr target)
-{
- struct fptr fptr;
-
- fptr.gp = (Elf_Addr) obj->pltgot;
- fptr.target = target;
- dbg(" initfini: target=%p, gp=%p",
- (void *) fptr.target, (void *) fptr.gp);
- ((InitArrFunc) &fptr)(main_argc, main_argv, environ);
-}
-
-/* Initialize the special PLT entries. */
-void
-init_pltgot(Obj_Entry *obj)
-{
- const Elf_Dyn *dynp;
- Elf_Addr *pltres = 0;
-
- /*
- * When there are no PLT relocations, the DT_IA_64_PLT_RESERVE entry
- * is bogus. Do not setup the BOR pointers in that case. An example
- * of where this happens is /usr/lib/libxpg4.so.3.
- */
- if (obj->pltrelasize == 0 && obj->pltrelsize == 0)
- return;
-
- /*
- * Find the PLT RESERVE section.
- */
- for (dynp = obj->dynamic; dynp->d_tag != DT_NULL; dynp++) {
- if (dynp->d_tag == DT_IA_64_PLT_RESERVE)
- pltres = (u_int64_t *)
- (obj->relocbase + dynp->d_un.d_ptr);
- }
- if (!pltres)
- errx(1, "Can't find DT_IA_64_PLT_RESERVE entry");
-
- /*
- * The PLT RESERVE section is used to get values to pass to
- * _rtld_bind when lazy binding.
- */
- pltres[0] = (Elf_Addr) obj;
- pltres[1] = FPTR_TARGET(_rtld_bind_start);
- pltres[2] = FPTR_GP(_rtld_bind_start);
-}
-
-void
-allocate_initial_tls(Obj_Entry *list)
-{
- void *tpval;
-
- /*
- * Fix the size of the static TLS block by using the maximum
- * offset allocated so far and adding a bit for dynamic modules to
- * use.
- */
- tls_static_space = tls_last_offset + tls_last_size + RTLD_STATIC_TLS_EXTRA;
-
- tpval = allocate_tls(list, NULL, TLS_TCB_SIZE, 16);
- __asm __volatile("mov r13 = %0" :: "r"(tpval));
-}
-
-void *__tls_get_addr(unsigned long module, unsigned long offset)
-{
- register Elf_Addr** tp __asm__("r13");
-
- return tls_get_addr_common(tp, module, offset);
-}
diff --git a/libexec/rtld-elf/ia64/rtld_machdep.h b/libexec/rtld-elf/ia64/rtld_machdep.h
deleted file mode 100644
index 4a68ff7..0000000
--- a/libexec/rtld-elf/ia64/rtld_machdep.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000 John D. Polstra.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef RTLD_MACHDEP_H
-#define RTLD_MACHDEP_H 1
-
-#include <sys/types.h>
-#include <machine/atomic.h>
-
-/*
- * Macros for cracking ia64 function pointers.
- */
-struct fptr {
- Elf_Addr target;
- Elf_Addr gp;
-};
-
-#define FPTR_TARGET(f) (((struct fptr *) (f))->target)
-#define FPTR_GP(f) (((struct fptr *) (f))->gp)
-
-/* Return the address of the .dynamic section in the dynamic linker. */
-#define rtld_dynamic(obj) (&_DYNAMIC)
-
-struct Struct_Obj_Entry;
-
-Elf_Addr reloc_jmpslot(Elf_Addr *, Elf_Addr, const struct Struct_Obj_Entry *,
- const struct Struct_Obj_Entry *, const Elf_Rel *);
-void *make_function_pointer(const Elf_Sym *, const struct Struct_Obj_Entry *);
-void call_initfini_pointer(const struct Struct_Obj_Entry *, Elf_Addr);
-void call_init_pointer(const struct Struct_Obj_Entry *, Elf_Addr);
-
-#define TLS_TCB_SIZE 16
-
-#define round(size, align) \
- (((size) + (align) - 1) & ~((align) - 1))
-#define calculate_first_tls_offset(size, align) \
- round(TLS_TCB_SIZE, align)
-#define calculate_tls_offset(prev_offset, prev_size, size, align) \
- round(prev_offset + prev_size, align)
-#define calculate_tls_end(off, size) ((off) + (size))
-
-extern void *__tls_get_addr(unsigned long module, unsigned long offset);
-
-#define RTLD_DEFAULT_STACK_PF_EXEC 0
-#define RTLD_DEFAULT_STACK_EXEC 0
-
-#endif
diff --git a/libexec/rtld-elf/ia64/rtld_start.S b/libexec/rtld-elf/ia64/rtld_start.S
deleted file mode 100644
index f41e5e5..0000000
--- a/libexec/rtld-elf/ia64/rtld_start.S
+++ /dev/null
@@ -1,252 +0,0 @@
-/* $FreeBSD$ */
-/* From: NetBSD: rtld_start.S,v 1.1 1996/12/16 20:38:09 cgd Exp */
-
-/*
- * Copyright 1996 Matt Thomas <matt@3am-software.com>
- * Copyright 2000 John D. Polstra
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/asm.h>
-#include <sys/syscall.h>
-
-ENTRY(_rtld_start, 0)
- alloc r2=ar.pfs,3,0,3,0
- ;;
-1: mov r14=ip // calculate gp
- addl r3=@gprel(1b),r0
- ;;
- sub gp=r14,r3
- ;;
- .section .sdata
-2: data4 @ltv(1b) // unrelocated address of 1b
- .align 8
- .previous
- add r15=@gprel(2b),gp
- ;;
- ld8 r15=[r15]
- ;;
- sub out0=r14,r15 // out0 is image base address
- br.call.sptk.many rp=_rtld_reloc // fixup image
-
- add sp=-16,sp // 16 bytes for us, 16 for _rtld
- ;;
- mov out0=in0
- add out1=16,sp // address for exit proc
- add out2=24,sp // address for obj_main
-
- br.call.sptk.many rp=_rtld // r8=_rtld(sp, &exit_proc, &obj_main)
-
- add r16=16,sp // address for exit proc
- ;;
- ld8 r15=[r16] // read exit proc
- add sp=16,sp // readjust stack
- mov b7=r8 // address of real _start
- ;;
- alloc r2=ar.pfs,0,0,3,0 // dump register frame
- mov out2=r15
- ;;
- br.call.sptk.many rp=b7 // transfer to main program
- br.call.sptk.many rp=exit // die
-END(_rtld_start)
-
-/*
- * _rtld_bind_start: lookup a lazy binding and transfer to real target
- *
- * Arguments:
- * r1 gp value for rtld
- * r15 Index in plt
- * r16 Obj_Entry of caller
- * in0-in7 Arguments for target procedure
- * rp Return address back to caller
- */
-ENTRY(_rtld_bind_start, 0)
-{ .mii
- alloc loc0=ar.pfs,8,6,3,0 // space to save r8-r11
- add r17=16-8*16,sp // leave 16 bytes for _rtld_bind
- add r18=32-8*16,sp
- ;;
-} { .mii
- mov loc2=r8 // structure return address
- add sp=-8*16,sp // space to save f8-f15
- mov loc1=rp
- ;;
-} { .mii
- stf.spill [r17]=f8,32 // save float arguments
- mov loc3=r9 // language specific
- mov loc4=r10 // language specific
-} { .mii
- stf.spill [r18]=f9,32
- mov loc5=r11 // language specific
- shl out1=r15,4 // 16 * index
- ;;
-} { .mmi
- stf.spill [r17]=f10,32
- stf.spill [r18]=f11,32
- mov out0=r16 // Obj_Entry for caller
- ;;
-} { .mmi
- stf.spill [r17]=f12,32
- stf.spill [r18]=f13,32
- shladd out1=r15,3,out1 // rela offset = 24 * index
- ;;
-} { .mmb
- stf.spill [r17]=f14,32
- stf.spill [r18]=f15,32
- br.call.sptk.many rp=_rtld_bind
-} { .mii
- ld8 r14=[r8],8 // target address
- add r17=16,sp
- add r18=32,sp
- ;;
-} { .mii
- ld8 r1=[r8] // target gp
- mov ar.pfs=loc0 // clean up
- mov rp=loc1
-} { .mmi
- ldf.fill f8=[r17],32 // restore float arguments
- ldf.fill f9=[r18],32
- mov r8=loc2 // restore structure pointer
- ;;
-} { .mmi
- ldf.fill f10=[r17],32
- ldf.fill f11=[r18],32
- mov r9=loc3
- ;;
-} { .mmi
- ldf.fill f12=[r17],32
- ldf.fill f13=[r18],32
- mov r10=loc4
- ;;
-} { .mmi
- ldf.fill f14=[r17],32
- ldf.fill f15=[r18],32
- mov r11=loc5
- ;;
-} { .mii
- nop.m 0
- mov b7=r14
- add sp=8*16,sp
- ;;
-} { .mib
- alloc r14=ar.pfs,0,0,8,0 // drop our register frame
- nop.i 0
- br.sptk.many b7 // jump to target
-}
-END(_rtld_bind_start)
-
-#define DT_NULL 0 /* Terminating entry. */
-#define DT_RELA 7 /* Address of ElfNN_Rela relocations. */
-#define DT_RELASZ 8 /* Total size of ElfNN_Rela relocations. */
-#define DT_RELAENT 9 /* Size of each ElfNN_Rela relocation entry. */
-
-#define R_IA_64_NONE 0 /* None */
-#define R_IA_64_DIR64LSB 0x27 /* word64 LSB S + A */
-#define R_IA_64_REL64LSB 0x6f /* word64 LSB BD + A */
-
-/*
- * _rtld_reloc: relocate the rtld image, apart from @fptrs.
- *
- * Assumes that rtld was linked at zero and that we only need to
- * handle REL64LSB and DIR64LSB relocations.
- *
- * Arguments:
- * r1 gp value for rtld
- * in0 rtld base address
- */
-STATIC_ENTRY(_rtld_reloc, 1)
- alloc loc0=ar.pfs,1,2,0,0
- mov loc1=rp
- ;;
- movl r15=@gprel(_DYNAMIC) // find _DYNAMIC etc.
- ;;
- add r15=r15,gp // relocate _DYNAMIC etc.
- ;;
-1: ld8 r16=[r15],8 // read r15->d_tag
- ;;
- ld8 r17=[r15],8 // and r15->d_val
- ;;
- cmp.eq p6,p0=DT_NULL,r16 // done?
-(p6) br.cond.dpnt.few 2f
- ;;
- cmp.eq p6,p0=DT_RELA,r16
- ;;
-(p6) add r18=r17,in0 // found rela section
- ;;
- cmp.eq p6,p0=DT_RELASZ,r16
- ;;
-(p6) mov r19=r17 // found rela size
- ;;
- cmp.eq p6,p0=DT_RELAENT,r16
- ;;
-(p6) mov r22=r17 // found rela entry size
- ;;
- br.sptk.few 1b
-
-2:
- ld8 r15=[r18],8 // read r_offset
- ;;
- ld8 r16=[r18],8 // read r_info
- add r15=r15,in0 // relocate r_offset
- ;;
- ld8 r17=[r18],8 // read r_addend
- sub r19=r19,r22 // update relasz
-
- extr.u r23=r16,0,32 // ELF64_R_TYPE(r16)
- ;;
- cmp.eq p6,p0=R_IA_64_NONE,r23
-(p6) br.cond.dpnt.few 3f
- ;;
- cmp.eq p6,p0=R_IA_64_DIR64LSB,r23
- ;;
-(p6) br.cond.dptk.few 4f
- ;;
- cmp.eq p6,p0=R_IA_64_REL64LSB,r23
- ;;
-(p6) br.cond.dptk.few 4f
- ;;
-
-3: cmp.ltu p6,p0=0,r19 // more?
-(p6) br.cond.dptk.few 2b // loop
-
- mov r8=0 // success return value
- ;;
- br.cond.sptk.few 9f // done
-
-4:
- ld8 r16=[r15] // read value
- ;;
- add r16=r16,in0 // relocate it
- ;;
- st8 [r15]=r16 // and store it back
- br.cond.sptk.few 3b
-
-9:
- mov ar.pfs=loc0
- mov rp=loc1
- ;;
- br.ret.sptk.few rp
-
-END(_rtld_reloc)
diff --git a/libexec/rtld-elf/libmap.c b/libexec/rtld-elf/libmap.c
index 2e1f3c6..8b5faf8 100644
--- a/libexec/rtld-elf/libmap.c
+++ b/libexec/rtld-elf/libmap.c
@@ -80,7 +80,7 @@ lm_init(char *libmap_override)
if (libmap_override) {
/*
- * Do some character replacement to make $LIBMAP look
+ * Do some character replacement to make $LDLIBMAP look
* like a text file, then parse it.
*/
libmap_override = xstrdup(libmap_override);
@@ -94,8 +94,8 @@ lm_init(char *libmap_override)
break;
}
}
- lmc_parse(p, strlen(p));
- free(p);
+ lmc_parse(libmap_override, p - libmap_override);
+ free(libmap_override);
}
return (lm_count == 0);
diff --git a/libexec/rtld-elf/rtld.1 b/libexec/rtld-elf/rtld.1
index 703a462..a8e9d68 100644
--- a/libexec/rtld-elf/rtld.1
+++ b/libexec/rtld-elf/rtld.1
@@ -28,7 +28,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd June 28, 2012
+.Dd June 20, 2014
.Dt RTLD 1
.Os
.Sh NAME
@@ -192,6 +192,13 @@ the directories specified by
will be searched first
followed by the set of built-in standard directories.
This variable is unset for set-user-ID and set-group-ID programs.
+.Ev LD_LIBRARY_PATH_FDS
+A colon separated list of file descriptor numbers for library directories.
+This is intended for use within
+.Xr capsicum 4
+sandboxes, when global namespaces such as the filesystem are unavailable.
+It is consulted just after LD_LIBRARY_PATH.
+This variable is unset for set-user-ID and set-group-ID programs.
.It Ev LD_BIND_NOW
When set to a nonempty string, causes
.Nm
@@ -260,7 +267,6 @@ If set,
.Nm
will log events such as the loading and unloading of shared objects via
.Xr utrace 2 .
-.Pp
.It Ev LD_LOADFLTR
If set,
.Nm
@@ -283,6 +289,7 @@ The libmap configuration file for 32-bit binaries on 64-bit system.
.Sh SEE ALSO
.Xr ld 1 ,
.Xr ldd 1 ,
+.Xr capsicum 4 ,
.Xr elf 5 ,
.Xr libmap.conf 5 ,
.Xr ldconfig 8
diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index 443767d..03c92d0 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -94,7 +94,7 @@ static bool donelist_check(DoneList *, const Obj_Entry *);
static void errmsg_restore(char *);
static char *errmsg_save(void);
static void *fill_search_info(const char *, size_t, void *);
-static char *find_library(const char *, const Obj_Entry *);
+static char *find_library(const char *, const Obj_Entry *, int *);
static const char *gethints(bool);
static void init_dag(Obj_Entry *);
static void init_pagesizes(Elf_Auxinfo **aux_info);
@@ -119,6 +119,7 @@ static void objlist_push_head(Objlist *, Obj_Entry *);
static void objlist_push_tail(Objlist *, Obj_Entry *);
static void objlist_put_after(Objlist *, Obj_Entry *, Obj_Entry *);
static void objlist_remove(Objlist *, Obj_Entry *);
+static int parse_libdir(const char *);
static void *path_enumerate(const char *, path_enum_proc, void *);
static int relocate_object_dag(Obj_Entry *root, bool bind_now,
Obj_Entry *rtldobj, int flags, RtldLockState *lockstate);
@@ -133,6 +134,7 @@ static int rtld_dirname_abs(const char *, char *);
static void *rtld_dlopen(const char *name, int fd, int mode);
static void rtld_exit(void);
static char *search_library_path(const char *, const char *);
+static char *search_library_pathfds(const char *, const char *, int *);
static const void **get_program_var_addr(const char *, RtldLockState *);
static void set_program_var(const char *, const void *);
static int symlook_default(SymLook *, const Obj_Entry *refobj);
@@ -178,6 +180,7 @@ static bool dangerous_ld_env; /* True if environment variables have been
static char *ld_bind_now; /* Environment variable for immediate binding */
static char *ld_debug; /* Environment variable for debugging */
static char *ld_library_path; /* Environment variable for search path */
+static char *ld_library_dirs; /* Environment variable for library descriptors */
static char *ld_preload; /* Environment variable for libraries to
load first */
static char *ld_elf_hints_path; /* Environment variable for alternative hints path */
@@ -401,7 +404,8 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp)
*/
if (!trust) {
if (unsetenv(LD_ "PRELOAD") || unsetenv(LD_ "LIBMAP") ||
- unsetenv(LD_ "LIBRARY_PATH") || unsetenv(LD_ "LIBMAP_DISABLE") ||
+ unsetenv(LD_ "LIBRARY_PATH") || unsetenv(LD_ "LIBRARY_PATH_FDS") ||
+ unsetenv(LD_ "LIBMAP_DISABLE") ||
unsetenv(LD_ "DEBUG") || unsetenv(LD_ "ELF_HINTS_PATH") ||
unsetenv(LD_ "LOADFLTR") || unsetenv(LD_ "LIBRARY_PATH_RPATH")) {
_rtld_error("environment corrupt; aborting");
@@ -412,6 +416,7 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp)
libmap_disable = getenv(LD_ "LIBMAP_DISABLE") != NULL;
libmap_override = getenv(LD_ "LIBMAP");
ld_library_path = getenv(LD_ "LIBRARY_PATH");
+ ld_library_dirs = getenv(LD_ "LIBRARY_PATH_FDS");
ld_preload = getenv(LD_ "PRELOAD");
ld_elf_hints_path = getenv(LD_ "ELF_HINTS_PATH");
ld_loadfltr = getenv(LD_ "LOADFLTR") != NULL;
@@ -1417,6 +1422,7 @@ gnu_hash(const char *s)
return (h & 0xffffffff);
}
+
/*
* Find the library with the given name, and return its full pathname.
* The returned string is dynamically allocated. Generates an error
@@ -1425,6 +1431,10 @@ gnu_hash(const char *s)
* If the second argument is non-NULL, then it refers to an already-
* loaded shared object, whose library search path will be searched.
*
+ * If a library is successfully located via LD_LIBRARY_PATH_FDS, its
+ * descriptor (which is close-on-exec) will be passed out via the third
+ * argument.
+ *
* The search order is:
* DT_RPATH in the referencing file _unless_ DT_RUNPATH is present (1)
* DT_RPATH of the main object if DSO without defined DT_RUNPATH (1)
@@ -1437,7 +1447,7 @@ gnu_hash(const char *s)
* (1) Handled in digest_dynamic2 - rpath left NULL if runpath defined.
*/
static char *
-find_library(const char *xname, const Obj_Entry *refobj)
+find_library(const char *xname, const Obj_Entry *refobj, int *fdp)
{
char *pathname;
char *name;
@@ -1474,6 +1484,7 @@ find_library(const char *xname, const Obj_Entry *refobj)
if ((pathname = search_library_path(name, ld_library_path)) != NULL ||
(refobj != NULL &&
(pathname = search_library_path(name, refobj->rpath)) != NULL) ||
+ (pathname = search_library_pathfds(name, ld_library_dirs, fdp)) != NULL ||
(pathname = search_library_path(name, gethints(false))) != NULL ||
(pathname = search_library_path(name, STANDARD_LIBRARY_PATH)) != NULL)
return (pathname);
@@ -1486,6 +1497,7 @@ find_library(const char *xname, const Obj_Entry *refobj)
(pathname = search_library_path(name, ld_library_path)) != NULL ||
(objgiven &&
(pathname = search_library_path(name, refobj->runpath)) != NULL) ||
+ (pathname = search_library_pathfds(name, ld_library_dirs, fdp)) != NULL ||
(pathname = search_library_path(name, gethints(nodeflib))) != NULL ||
(objgiven && !nodeflib &&
(pathname = search_library_path(name, STANDARD_LIBRARY_PATH)) != NULL))
@@ -1790,6 +1802,11 @@ init_rtld(caddr_t mapbase, Elf_Auxinfo **aux_info)
const Elf_Dyn *dyn_soname;
const Elf_Dyn *dyn_runpath;
+#ifdef RTLD_INIT_PAGESIZES_EARLY
+ /* The page size is required by the dynamic memory allocator. */
+ init_pagesizes(aux_info);
+#endif
+
/*
* Conjure up an Obj_Entry structure for the dynamic linker.
*
@@ -1826,8 +1843,10 @@ init_rtld(caddr_t mapbase, Elf_Auxinfo **aux_info)
/* Now that non-local variables can be accesses, copy out obj_rtld. */
memcpy(&obj_rtld, &objtmp, sizeof(obj_rtld));
+#ifndef RTLD_INIT_PAGESIZES_EARLY
/* The page size is required by the dynamic memory allocator. */
init_pagesizes(aux_info);
+#endif
if (aux_info[AT_OSRELDATE] != NULL)
osreldate = aux_info[AT_OSRELDATE]->a_un.a_val;
@@ -2085,29 +2104,34 @@ load_object(const char *name, int fd_u, const Obj_Entry *refobj, int flags)
struct stat sb;
char *path;
+ fd = -1;
if (name != NULL) {
for (obj = obj_list->next; obj != NULL; obj = obj->next) {
if (object_match_name(obj, name))
return (obj);
}
- path = find_library(name, refobj);
+ path = find_library(name, refobj, &fd);
if (path == NULL)
return (NULL);
} else
path = NULL;
- /*
- * If we didn't find a match by pathname, or the name is not
- * supplied, open the file and check again by device and inode.
- * This avoids false mismatches caused by multiple links or ".."
- * in pathnames.
- *
- * To avoid a race, we open the file and use fstat() rather than
- * using stat().
- */
- fd = -1;
- if (fd_u == -1) {
+ if (fd >= 0) {
+ /*
+ * search_library_pathfds() opens a fresh file descriptor for the
+ * library, so there is no need to dup().
+ */
+ } else if (fd_u == -1) {
+ /*
+ * If we didn't find a match by pathname, or the name is not
+ * supplied, open the file and check again by device and inode.
+ * This avoids false mismatches caused by multiple links or ".."
+ * in pathnames.
+ *
+ * To avoid a race, we open the file and use fstat() rather than
+ * using stat().
+ */
if ((fd = open(path, O_RDONLY | O_CLOEXEC)) == -1) {
_rtld_error("Cannot open \"%s\"", path);
free(path);
@@ -2745,6 +2769,69 @@ search_library_path(const char *name, const char *path)
return (p);
}
+
+/*
+ * Finds the library with the given name using the directory descriptors
+ * listed in the LD_LIBRARY_PATH_FDS environment variable.
+ *
+ * Returns a freshly-opened close-on-exec file descriptor for the library,
+ * or -1 if the library cannot be found.
+ */
+static char *
+search_library_pathfds(const char *name, const char *path, int *fdp)
+{
+ char *envcopy, *fdstr, *found, *last_token;
+ size_t len;
+ int dirfd, fd;
+
+ dbg("%s('%s', '%s', fdp)\n", __func__, name, path);
+
+ /* Don't load from user-specified libdirs into setuid binaries. */
+ if (!trust)
+ return (NULL);
+
+ /* We can't do anything if LD_LIBRARY_PATH_FDS isn't set. */
+ if (path == NULL)
+ return (NULL);
+
+ /* LD_LIBRARY_PATH_FDS only works with relative paths. */
+ if (name[0] == '/') {
+ dbg("Absolute path (%s) passed to %s", name, __func__);
+ return (NULL);
+ }
+
+ /*
+ * Use strtok_r() to walk the FD:FD:FD list. This requires a local
+ * copy of the path, as strtok_r rewrites separator tokens
+ * with '\0'.
+ */
+ found = NULL;
+ envcopy = xstrdup(path);
+ for (fdstr = strtok_r(envcopy, ":", &last_token); fdstr != NULL;
+ fdstr = strtok_r(NULL, ":", &last_token)) {
+ dirfd = parse_libdir(fdstr);
+ if (dirfd < 0)
+ break;
+ fd = openat(dirfd, name, O_RDONLY | O_CLOEXEC);
+ if (fd >= 0) {
+ *fdp = fd;
+ len = strlen(fdstr) + strlen(name) + 3;
+ found = xmalloc(len);
+ if (rtld_snprintf(found, len, "#%d/%s", dirfd, name) < 0) {
+ _rtld_error("error generating '%d/%s'",
+ dirfd, name);
+ die();
+ }
+ dbg("open('%s') => %d", found, fd);
+ break;
+ }
+ }
+ free(envcopy);
+
+ return (found);
+}
+
+
int
dlclose(void *handle)
{
@@ -2997,9 +3084,7 @@ do_dlsym(void *handle, const char *name, void *retaddr, const Ver_Entry *ve,
const Elf_Sym *def;
SymLook req;
RtldLockState lockstate;
-#ifndef __ia64__
tls_index ti;
-#endif
int res;
def = NULL;
@@ -3104,24 +3189,17 @@ do_dlsym(void *handle, const char *name, void *retaddr, const Ver_Entry *ve,
/*
* The value required by the caller is derived from the value
- * of the symbol. For the ia64 architecture, we need to
- * construct a function descriptor which the caller can use to
- * call the function with the right 'gp' value. For other
- * architectures and for non-functions, the value is simply
- * the relocated value of the symbol.
+ * of the symbol. this is simply the relocated value of the
+ * symbol.
*/
if (ELF_ST_TYPE(def->st_info) == STT_FUNC)
return (make_function_pointer(def, defobj));
else if (ELF_ST_TYPE(def->st_info) == STT_GNU_IFUNC)
return (rtld_resolve_ifunc(defobj, def));
else if (ELF_ST_TYPE(def->st_info) == STT_TLS) {
-#ifdef __ia64__
- return (__tls_get_addr(defobj->tlsindex, def->st_value));
-#else
ti.ti_module = defobj->tlsindex;
ti.ti_offset = def->st_value;
return (__tls_get_addr(&ti));
-#endif
} else
return (defobj->relocbase + def->st_value);
}
@@ -4254,7 +4332,7 @@ tls_get_addr_common(Elf_Addr **dtvp, int index, size_t offset)
return (tls_get_addr_slow(dtvp, index, offset));
}
-#if defined(__arm__) || defined(__ia64__) || defined(__mips__) || defined(__powerpc__)
+#if defined(__arm__) || defined(__mips__) || defined(__powerpc__)
/*
* Allocate Static TLS using the Variant I method.
@@ -4835,6 +4913,36 @@ symlook_init_from_req(SymLook *dst, const SymLook *src)
dst->lockstate = src->lockstate;
}
+
+/*
+ * Parse a file descriptor number without pulling in more of libc (e.g. atoi).
+ */
+static int
+parse_libdir(const char *str)
+{
+ static const int RADIX = 10; /* XXXJA: possibly support hex? */
+ const char *orig;
+ int fd;
+ char c;
+
+ orig = str;
+ fd = 0;
+ for (c = *str; c != '\0'; c = *++str) {
+ if (c < '0' || c > '9')
+ return (-1);
+
+ fd *= RADIX;
+ fd += c - '0';
+ }
+
+ /* Make sure we actually parsed something. */
+ if (str == orig) {
+ _rtld_error("failed to parse directory FD from '%s'", str);
+ return (-1);
+ }
+ return (fd);
+}
+
/*
* Overrides for libc_pic-provided functions.
*/
diff --git a/libexec/rtld-elf/rtld_lock.c b/libexec/rtld-elf/rtld_lock.c
index d1563e5..ea16c4d 100644
--- a/libexec/rtld-elf/rtld_lock.c
+++ b/libexec/rtld-elf/rtld_lock.c
@@ -365,8 +365,19 @@ _rtld_atfork_pre(int *locks)
{
RtldLockState ls[2];
+ if (locks == NULL)
+ return;
+
+ /*
+ * Warning: this does not work with the rtld compat locks
+ * above, since the thread signal mask is corrupted (set to
+ * all signals blocked) if two locks are taken in write mode.
+ * The caller of the _rtld_atfork_pre() must provide the
+ * working implementation of the locks, and libthr locks are
+ * fine.
+ */
wlock_acquire(rtld_phdr_lock, &ls[0]);
- rlock_acquire(rtld_bind_lock, &ls[1]);
+ wlock_acquire(rtld_bind_lock, &ls[1]);
/* XXXKIB: I am really sorry for this. */
locks[0] = ls[1].lockstate;
@@ -378,6 +389,9 @@ _rtld_atfork_post(int *locks)
{
RtldLockState ls[2];
+ if (locks == NULL)
+ return;
+
bzero(ls, sizeof(ls));
ls[0].lockstate = locks[2];
ls[1].lockstate = locks[0];
diff --git a/libexec/rtld-elf/rtld_printf.c b/libexec/rtld-elf/rtld_printf.c
index eb4514a..9d945dc 100644
--- a/libexec/rtld-elf/rtld_printf.c
+++ b/libexec/rtld-elf/rtld_printf.c
@@ -429,6 +429,18 @@ number:
}
int
+rtld_snprintf(char *buf, size_t bufsize, const char *fmt, ...)
+{
+ va_list ap;
+ int retval;
+
+ va_start(ap, fmt);
+ retval = rtld_vsnprintf(buf, bufsize, fmt, ap);
+ va_end(ap);
+ return (retval);
+}
+
+int
rtld_vsnprintf(char *buf, size_t bufsize, const char *fmt, va_list ap)
{
struct snprintf_arg info;
diff --git a/libexec/rtld-elf/rtld_printf.h b/libexec/rtld-elf/rtld_printf.h
index 6125732..aaf2971 100644
--- a/libexec/rtld-elf/rtld_printf.h
+++ b/libexec/rtld-elf/rtld_printf.h
@@ -31,6 +31,8 @@
#include <sys/cdefs.h>
#include <unistd.h>
+int rtld_snprintf(char *buf, size_t bufsize, const char *fmt, ...)
+ __printflike(3, 4);
int rtld_vsnprintf(char *buf, size_t bufsize, const char *fmt, va_list ap);
int rtld_vfdprintf(int fd, const char *fmt, va_list ap);
int rtld_fdprintf(int fd, const char *fmt, ...) __printflike(2, 3);
diff --git a/libexec/rtld-elf/tests/Makefile b/libexec/rtld-elf/tests/Makefile
new file mode 100644
index 0000000..5e57f60
--- /dev/null
+++ b/libexec/rtld-elf/tests/Makefile
@@ -0,0 +1,14 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+TESTSDIR= ${TESTSBASE}/libexec/rtld-elf
+SUBDIR+= libpythagoras target
+
+.PATH: ${.CURDIR:H:H:H:H}/tests
+
+ATF_TESTS_C= ld_library_pathfds
+
+CFLAGS+= -DTESTSDIR="\"${TESTSDIR}\""
+
+.include <bsd.test.mk>
diff --git a/libexec/rtld-elf/tests/ld_library_pathfds.c b/libexec/rtld-elf/tests/ld_library_pathfds.c
new file mode 100644
index 0000000..274b5e8
--- /dev/null
+++ b/libexec/rtld-elf/tests/ld_library_pathfds.c
@@ -0,0 +1,220 @@
+/*-
+ * Copyright 2014 Jonathan Anderson.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <atf-c.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+
+struct descriptors {
+ int binary;
+ int testdir;
+ int root;
+ int etc;
+ int usr;
+};
+
+static void setup(struct descriptors *);
+static void expect_success(int binary, char *pathfds);
+static void expect_missing_library(int binary, char *pathfds);
+
+static void try_to_run(int binary, int expected_exit_status,
+ char * const *env, const char *expected_out, const char *expected_err);
+static int opendir(const char *name);
+static int opendirat(int parent, const char *name);
+
+
+ATF_TC_WITHOUT_HEAD(missing_library);
+ATF_TC_BODY(missing_library, tc)
+{
+ struct descriptors files;
+
+ setup(&files);
+ expect_missing_library(files.binary, NULL);
+}
+
+
+ATF_TC_WITHOUT_HEAD(wrong_library_directories);
+ATF_TC_BODY(wrong_library_directories, tc)
+{
+ struct descriptors files;
+ char *pathfds;
+
+ setup(&files);
+ ATF_REQUIRE(
+ asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=%d", files.etc) > 0);
+
+ expect_missing_library(files.binary, pathfds);
+}
+
+
+ATF_TC_WITHOUT_HEAD(bad_library_directories);
+ATF_TC_BODY(bad_library_directories, tc)
+{
+ struct descriptors files;
+ char *pathfds;
+
+ setup(&files);
+ ATF_REQUIRE(asprintf(&pathfds, "::", files.etc) > 0);
+
+ expect_missing_library(files.binary, pathfds);
+}
+
+
+ATF_TC_WITHOUT_HEAD(single_library_directory);
+ATF_TC_BODY(single_library_directory, tc)
+{
+ struct descriptors files;
+ char *pathfds;
+
+ setup(&files);
+ ATF_REQUIRE(
+ asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=%d", files.testdir) > 0);
+
+ expect_success(files.binary, pathfds);
+}
+
+
+ATF_TC_WITHOUT_HEAD(first_library_directory);
+ATF_TC_BODY(first_library_directory, tc)
+{
+ struct descriptors files;
+ char *pathfds;
+
+ setup(&files);
+ ATF_REQUIRE(
+ asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=%d:%d",
+ files.testdir, files.etc) > 0);
+
+ expect_success(files.binary, pathfds);
+}
+
+
+ATF_TC_WITHOUT_HEAD(middle_library_directory);
+ATF_TC_BODY(middle_library_directory, tc)
+{
+ struct descriptors files;
+ char *pathfds;
+
+ setup(&files);
+ ATF_REQUIRE(
+ asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=%d:%d:%d",
+ files.root, files.testdir, files.usr) > 0);
+
+ expect_success(files.binary, pathfds);
+}
+
+
+ATF_TC_WITHOUT_HEAD(last_library_directory);
+ATF_TC_BODY(last_library_directory, tc)
+{
+ struct descriptors files;
+ char *pathfds;
+
+ setup(&files);
+ ATF_REQUIRE(
+ asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=%d:%d",
+ files.root, files.testdir) > 0);
+
+ expect_success(files.binary, pathfds);
+}
+
+
+
+/* Register test cases with ATF. */
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, missing_library);
+ ATF_TP_ADD_TC(tp, wrong_library_directories);
+ ATF_TP_ADD_TC(tp, bad_library_directories);
+ ATF_TP_ADD_TC(tp, single_library_directory);
+ ATF_TP_ADD_TC(tp, first_library_directory);
+ ATF_TP_ADD_TC(tp, middle_library_directory);
+ ATF_TP_ADD_TC(tp, last_library_directory);
+
+ return atf_no_error();
+}
+
+
+static void
+setup(struct descriptors *dp)
+{
+
+ ATF_REQUIRE((dp->testdir = opendir(TESTSDIR)) >= 0);
+ ATF_REQUIRE(
+ (dp->binary = openat(dp->testdir, "target", O_RDONLY)) >= 0);
+
+ ATF_REQUIRE((dp->root = opendir("/")) >= 0);
+ ATF_REQUIRE((dp->etc = opendirat(dp->root, "etc")) >= 0);
+ ATF_REQUIRE((dp->usr = opendirat(dp->root, "usr")) >= 0);
+}
+
+static void
+expect_success(int binary, char *pathfds)
+{
+ char * const env[] = { pathfds, NULL };
+ try_to_run(binary, 0, env, "the hypotenuse of 3 and 4 is 5\n", "");
+}
+
+static void
+expect_missing_library(int binary, char *pathfds)
+{
+ char * const env[] = { pathfds, NULL };
+ try_to_run(binary, 1, env, "",
+ "Shared object \"libpythagoras.so.0\" not found,"
+ " required by \"target\"\n");
+}
+
+
+static void
+try_to_run(int binary, int exit_status, char * const *env,
+ const char *expected_out, const char *expected_err)
+{
+ pid_t child = atf_utils_fork();
+
+ if (child == 0) {
+ char * const args[] = { "target", NULL };
+
+ fexecve(binary, args, env);
+ atf_tc_fail("fexecve() failed");
+ }
+
+ atf_utils_wait(child, exit_status, expected_out, expected_err);
+}
+
+
+static int
+opendir(const char *name)
+{
+ return open(name, O_RDONLY | O_DIRECTORY);
+}
+
+static int
+opendirat(int parent, const char *name)
+{
+ return openat(parent, name, O_RDONLY | O_DIRECTORY);
+}
diff --git a/libexec/rtld-elf/tests/libpythagoras/Makefile b/libexec/rtld-elf/tests/libpythagoras/Makefile
new file mode 100644
index 0000000..09b67c9
--- /dev/null
+++ b/libexec/rtld-elf/tests/libpythagoras/Makefile
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= pythagoras
+SHLIB_MAJOR= 0
+
+LIBDIR= ${TESTSBASE}${TESTSDIR}/libexec/rtld-elf
+SHLIBDIR= ${TESTSBASE}${TESTSDIR}/libexec/rtld-elf
+
+SRCS= pythagoras.c
+
+DPADD= ${LIBM}
+LDADD= -lm
+
+.include <bsd.lib.mk>
diff --git a/libexec/rtld-elf/tests/libpythagoras/pythagoras.c b/libexec/rtld-elf/tests/libpythagoras/pythagoras.c
new file mode 100644
index 0000000..c7fa604
--- /dev/null
+++ b/libexec/rtld-elf/tests/libpythagoras/pythagoras.c
@@ -0,0 +1,42 @@
+/*-
+ * Copyright 2014 Jonathan Anderson.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <errno.h>
+#include <math.h>
+
+#include "pythagoras.h"
+
+double
+pythagorean_theorem(double a, double b)
+{
+
+ if (a <= 0 || b <= 0) {
+ errno = ERANGE;
+ return (-1.0);
+ }
+ return (sqrt(pow(a, 2) + pow(b, 2)));
+}
diff --git a/libexec/rtld-elf/tests/libpythagoras/pythagoras.h b/libexec/rtld-elf/tests/libpythagoras/pythagoras.h
new file mode 100644
index 0000000..ef5379c
--- /dev/null
+++ b/libexec/rtld-elf/tests/libpythagoras/pythagoras.h
@@ -0,0 +1,28 @@
+/*-
+ * Copyright 2014 Jonathan Anderson.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+double pythagorean_theorem(double, double);
diff --git a/libexec/rtld-elf/tests/target/Makefile b/libexec/rtld-elf/tests/target/Makefile
new file mode 100644
index 0000000..0ae8c1d
--- /dev/null
+++ b/libexec/rtld-elf/tests/target/Makefile
@@ -0,0 +1,13 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+PROG= target
+BINDIR= ${TESTSBASE}${TESTSDIR}/libexec/rtld-elf
+
+CFLAGS+= -I${.CURDIR}/../libpythagoras
+LDADD= -L${.OBJDIR}/../libpythagoras -lpythagoras
+
+MAN=
+
+.include <bsd.prog.mk>
diff --git a/libexec/rtld-elf/tests/target/target.c b/libexec/rtld-elf/tests/target/target.c
new file mode 100644
index 0000000..e88b899
--- /dev/null
+++ b/libexec/rtld-elf/tests/target/target.c
@@ -0,0 +1,39 @@
+/*-
+ * Copyright 2014 Jonathan Anderson.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include "pythagoras.h"
+
+#include <stdio.h>
+
+int
+main(int argc, char *argv[])
+{
+ float hypotenuse = pythagorean_theorem(3, 4);
+ printf("the hypotenuse of 3 and 4 is %d\n", (int) hypotenuse);
+
+ return 0;
+}
diff --git a/libexec/save-entropy/save-entropy.sh b/libexec/save-entropy/save-entropy.sh
index e96b543..880a988 100755
--- a/libexec/save-entropy/save-entropy.sh
+++ b/libexec/save-entropy/save-entropy.sh
@@ -42,6 +42,8 @@ elif [ -r /etc/rc.conf ]; then
. /etc/rc.conf 2>/dev/null
fi
+[ $(/sbin/sysctl -n security.jail.jailed) = 0 ] || exit 0
+
case ${entropy_dir} in
[Nn][Oo])
exit 0
diff --git a/libexec/smrsh/Makefile b/libexec/smrsh/Makefile
index ae86155..9f0bfd4 100644
--- a/libexec/smrsh/Makefile
+++ b/libexec/smrsh/Makefile
@@ -9,6 +9,8 @@ SRCS= smrsh.c
MAN= smrsh.8
CFLAGS+=-I${SENDMAIL_DIR}/src -I${SENDMAIL_DIR}/include -I.
+NO_PIE= yes
+
LIBSMDIR= ${.OBJDIR}/../../lib/libsm
LIBSM= ${LIBSMDIR}/libsm.a
diff --git a/libexec/telnetd/Makefile b/libexec/telnetd/Makefile
index 99f023f..f80bf5c 100644
--- a/libexec/telnetd/Makefile
+++ b/libexec/telnetd/Makefile
@@ -20,6 +20,8 @@ WFORMAT?= 0
CFLAGS+= -DLINEMODE -DUSE_TERMIO -DDIAGNOSTICS -DOLD_ENVIRON \
-DENV_HACK -DSTREAMSPTY
+NO_PIE= yes
+
.if ${MK_INET6_SUPPORT} != "no"
CFLAGS+= -DINET6
.endif
@@ -28,11 +30,9 @@ CFLAGS+= -I${TELNETDIR}
LIBTELNET= ${.OBJDIR}/../../lib/libtelnet/libtelnet.a
-DPADD= ${LIBUTIL} ${LIBTERMCAP} ${LIBTELNET}
-LDADD= -lutil -ltermcap ${LIBTELNET}
+DPADD= ${LIBUTIL} ${LIBTERMCAPW} ${LIBTELNET}
+LDADD= -lutil -ltermcapw ${LIBTELNET}
-# XXX for src/release/picobsd
-.if !defined(RELEASE_CRUNCH)
.if ${MK_OPENSSL} != "no"
SRCS+= authenc.c
CFLAGS+= -DAUTHENTICATION -DENCRYPTION
@@ -45,6 +45,5 @@ CFLAGS+= -DKRB5 -DFORWARD -Dnet_write=telnet_net_write
DPADD+= ${LIBKRB5} ${LIBHX509} ${LIBASN1} ${LIBROKEN} ${LIBCOM_ERR}
LDADD+= -lkrb5 -lhx509 -lasn1 -lroken -lcom_err
.endif
-.endif
.include <bsd.prog.mk>
diff --git a/libexec/telnetd/Makefile.depend b/libexec/telnetd/Makefile.depend
index e2ee38e..ccb80ea 100644
--- a/libexec/telnetd/Makefile.depend
+++ b/libexec/telnetd/Makefile.depend
@@ -25,7 +25,6 @@ DIRDEPS = \
lib/libtelnet \
lib/libthr \
lib/libutil \
- lib/ncurses/ncurses \
lib/ncurses/ncursesw \
secure/lib/libcrypto \
diff --git a/libexec/ypxfr/ypxfr.8 b/libexec/ypxfr/ypxfr.8
index 281e31a..3e07586 100644
--- a/libexec/ypxfr/ypxfr.8
+++ b/libexec/ypxfr/ypxfr.8
@@ -305,4 +305,4 @@ domain.
.Xr yppush 8 ,
.Xr ypserv 8
.Sh AUTHORS
-.An Bill Paul Aq wpaul@ctr.columbia.edu
+.An Bill Paul Aq Mt wpaul@ctr.columbia.edu
OpenPOWER on IntegriCloud