summaryrefslogtreecommitdiffstats
path: root/libexec
diff options
context:
space:
mode:
authorsjg <sjg@FreeBSD.org>2014-11-19 01:07:58 +0000
committersjg <sjg@FreeBSD.org>2014-11-19 01:07:58 +0000
commitb137080f19736ee33fede2e88bb54438604cf86b (patch)
tree377ac0ac449528621eb192cd245adadb5fd53668 /libexec
parentab21a29eb607d4dfe389b965fbdee27558e791aa (diff)
parent4a8d07956d121238d006d34ffe7d6269744e8b1a (diff)
downloadFreeBSD-src-b137080f19736ee33fede2e88bb54438604cf86b.zip
FreeBSD-src-b137080f19736ee33fede2e88bb54438604cf86b.tar.gz
Merge from head@274682
Diffstat (limited to 'libexec')
-rw-r--r--libexec/Makefile2
-rw-r--r--libexec/Makefile.amd645
-rw-r--r--libexec/Makefile.i3865
-rw-r--r--libexec/Makefile.pc984
-rw-r--r--libexec/atf/atf-check/Makefile5
-rw-r--r--libexec/atf/atf-sh/Makefile8
-rw-r--r--libexec/atf/atf-sh/tests/Makefile3
-rw-r--r--libexec/getty/main.c2
-rw-r--r--libexec/hyperv/Makefile10
-rw-r--r--libexec/mail.local/Makefile2
-rw-r--r--libexec/rshd/rshd.c2
-rw-r--r--libexec/rtld-elf/Makefile8
-rw-r--r--libexec/rtld-elf/amd64/reloc.c351
-rw-r--r--libexec/rtld-elf/arm/reloc.c4
-rw-r--r--libexec/rtld-elf/i386/reloc.c264
-rw-r--r--libexec/rtld-elf/libmap.c4
-rw-r--r--libexec/rtld-elf/mips/reloc.c4
-rw-r--r--libexec/rtld-elf/powerpc/reloc.c4
-rw-r--r--libexec/rtld-elf/powerpc64/reloc.c4
-rw-r--r--libexec/rtld-elf/rtld.c18
-rw-r--r--libexec/rtld-elf/rtld.h3
-rw-r--r--libexec/rtld-elf/sparc64/reloc.c4
-rw-r--r--libexec/rtld-elf/tests/Makefile4
-rw-r--r--libexec/rtld-elf/tests/ld_library_pathfds.c23
-rw-r--r--libexec/rtld-elf/tests/libpythagoras/Makefile4
-rw-r--r--libexec/rtld-elf/tests/target/Makefile7
-rwxr-xr-xlibexec/save-entropy/save-entropy.sh2
-rw-r--r--libexec/smrsh/Makefile2
-rw-r--r--libexec/telnetd/Makefile3
29 files changed, 384 insertions, 377 deletions
diff --git a/libexec/Makefile b/libexec/Makefile
index 8a32694..7d1c1f8 100644
--- a/libexec/Makefile
+++ b/libexec/Makefile
@@ -90,4 +90,6 @@ _atf= atf
_tests= tests
.endif
+.include <bsd.arch.inc.mk>
+
.include <bsd.subdir.mk>
diff --git a/libexec/Makefile.amd64 b/libexec/Makefile.amd64
new file mode 100644
index 0000000..1092a29
--- /dev/null
+++ b/libexec/Makefile.amd64
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+.if ${MK_HYPERV} != "no"
+SUBDIR+= hyperv
+.endif
diff --git a/libexec/Makefile.i386 b/libexec/Makefile.i386
new file mode 100644
index 0000000..1092a29
--- /dev/null
+++ b/libexec/Makefile.i386
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+.if ${MK_HYPERV} != "no"
+SUBDIR+= hyperv
+.endif
diff --git a/libexec/Makefile.pc98 b/libexec/Makefile.pc98
new file mode 100644
index 0000000..a755298
--- /dev/null
+++ b/libexec/Makefile.pc98
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+# Because i386 adds extra stuff we don't need or want for PC98 we need
+# an empty file so it doesn't get added.
diff --git a/libexec/atf/atf-check/Makefile b/libexec/atf/atf-check/Makefile
index fa7fabe..2a9851e 100644
--- a/libexec/atf/atf-check/Makefile
+++ b/libexec/atf/atf-check/Makefile
@@ -36,11 +36,10 @@ SRCS= atf-check.cpp
MAN= atf-check.1
CFLAGS+= -I${ATF}
+CFLAGS+= -DATF_SHELL='"/bin/sh"'
-LDFLAGS+= -L${.OBJDIR}/../../../lib/atf/libatf-c++
-LDFLAGS+= -L${.OBJDIR}/../../../lib/atf/libatf-c
DPADD+= ${LIBATF_CXX} ${LIBATF_C}
-LDADD+= -latf-c++ -latf-c
+LDADD+= ${LDATF_CXX} ${LDATF_C}
USEPRIVATELIB= atf-c++ atf-c
.if ${MK_TESTS} != "no"
diff --git a/libexec/atf/atf-sh/Makefile b/libexec/atf/atf-sh/Makefile
index 3f461fd..4e14643 100644
--- a/libexec/atf/atf-sh/Makefile
+++ b/libexec/atf/atf-sh/Makefile
@@ -33,13 +33,17 @@ ATF= ${.CURDIR:H:H:H}/contrib/atf
PROG_CXX= atf-sh
SRCS= atf-sh.cpp
-MAN= atf-sh.1 atf-sh-api.3
+MAN= atf-sh.1 atf-sh.3
+MLINKS+= atf-sh.3 atf-sh-api.3 # Backwards compatibility.
CFLAGS+= -DHAVE_CONFIG_H
+CFLAGS+= -DATF_LIBEXECDIR='"${LIBEXECDIR}"'
+CFLAGS+= -DATF_PKGDATADIR='"${SHAREDIR}/atf"'
+CFLAGS+= -DATF_SHELL='"/bin/sh"'
CFLAGS+= -I${ATF}
DPADD+= ${LIBATF_C} ${LIBATF_CXX}
-LDADD+= -latf-c++ -latf-c
+LDADD+= ${LDATF_C} ${LDATF_CXX}
USEPRIVATELIB= atf-c++ atf-c
FILESGROUPS= SUBR
diff --git a/libexec/atf/atf-sh/tests/Makefile b/libexec/atf/atf-sh/tests/Makefile
index e71b6b5..3360b97 100644
--- a/libexec/atf/atf-sh/tests/Makefile
+++ b/libexec/atf/atf-sh/tests/Makefile
@@ -16,8 +16,7 @@ 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'
+ -e 's,__ATF_SH__,/usr/libexec/atf-sh,g'
SCRIPTS+= misc_helpers
SCRIPTSDIR_misc_helpers=${TESTSDIR}
diff --git a/libexec/getty/main.c b/libexec/getty/main.c
index c9d2093..94ecb07 100644
--- a/libexec/getty/main.c
+++ b/libexec/getty/main.c
@@ -187,7 +187,7 @@ main(int argc, char *argv[])
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
- openlog("getty", LOG_ODELAY|LOG_CONS|LOG_PID, LOG_AUTH);
+ openlog("getty", LOG_CONS|LOG_PID, LOG_AUTH);
gethostname(hostname, sizeof(hostname) - 1);
hostname[sizeof(hostname) - 1] = '\0';
if (hostname[0] == '\0')
diff --git a/libexec/hyperv/Makefile b/libexec/hyperv/Makefile
new file mode 100644
index 0000000..37abdf5
--- /dev/null
+++ b/libexec/hyperv/Makefile
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR}/../../contrib/hyperv/tools/scripts
+
+BINDIR= /usr/libexec/hyperv
+
+SCRIPTS= hv_set_ifconfig hv_get_dns_info hv_get_dhcp_info
+NO_OBJ=
+
+.include <bsd.prog.mk>
diff --git a/libexec/mail.local/Makefile b/libexec/mail.local/Makefile
index dff4238..3e59609 100644
--- a/libexec/mail.local/Makefile
+++ b/libexec/mail.local/Makefile
@@ -9,8 +9,6 @@ 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/rshd/rshd.c b/libexec/rshd/rshd.c
index 7cdacae..b315040 100644
--- a/libexec/rshd/rshd.c
+++ b/libexec/rshd/rshd.c
@@ -127,7 +127,7 @@ main(int argc, char *argv[])
int ch, on = 1;
struct sockaddr_storage from;
- openlog("rshd", LOG_PID | LOG_ODELAY, LOG_DAEMON);
+ openlog("rshd", LOG_PID, LOG_DAEMON);
opterr = 0;
while ((ch = getopt(argc, argv, OPTIONS)) != -1)
diff --git a/libexec/rtld-elf/Makefile b/libexec/rtld-elf/Makefile
index 48e86f7..cc30132 100644
--- a/libexec/rtld-elf/Makefile
+++ b/libexec/rtld-elf/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+# Use the following command to build local debug version of dynamic
+# linker:
+# make DEBUG_FLAGS=-g DEBUG=-DDEBUG MK_TESTS=no all
+
.include <src.opts.mk>
MK_SSP= no
@@ -42,7 +46,7 @@ LDFLAGS+= -shared -Wl,-Bsymbolic
DPADD= ${LIBC_PIC}
LDADD= -lc_pic
-.if ${MACHINE_CPUARCH} == "arm" && ${MK_ARM_EABI} != "no"
+.if ${MACHINE_CPUARCH} == "arm"
# Some of the required math functions (div & mod) are implemented in
# libcompiler_rt on ARM. The library also needs to be placed first to be
# correctly linked. As some of the functions are used before we have
@@ -78,8 +82,6 @@ beforeinstall:
.PATH: ${.CURDIR}/${RTLD_ARCH}
-NO_PIE= yes
-
.if ${MK_TESTS} != "no"
SUBDIR+= tests
.endif
diff --git a/libexec/rtld-elf/amd64/reloc.c b/libexec/rtld-elf/amd64/reloc.c
index 7b002b2..35f33cc 100644
--- a/libexec/rtld-elf/amd64/reloc.c
+++ b/libexec/rtld-elf/amd64/reloc.c
@@ -125,213 +125,188 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags,
const Elf_Rela *relalim;
const Elf_Rela *rela;
SymCache *cache;
- int r = -1;
+ const Elf_Sym *def;
+ const Obj_Entry *defobj;
+ Elf_Addr *where, symval;
+ Elf32_Addr *where32;
+ int r;
+ r = -1;
/*
* The dynamic loader may be called from a thread, we have
* limited amounts of stack available so we cannot use alloca().
*/
if (obj != obj_rtld) {
- cache = calloc(obj->dynsymcount, sizeof(SymCache));
- /* No need to check for NULL here */
+ cache = calloc(obj->dynsymcount, sizeof(SymCache));
+ /* No need to check for NULL here */
} else
- cache = NULL;
+ cache = NULL;
- relalim = (const Elf_Rela *) ((caddr_t) obj->rela + obj->relasize);
+ relalim = (const Elf_Rela *)((caddr_t)obj->rela + obj->relasize);
for (rela = obj->rela; rela < relalim; rela++) {
- Elf_Addr *where = (Elf_Addr *) (obj->relocbase + rela->r_offset);
- Elf32_Addr *where32 = (Elf32_Addr *)where;
-
- switch (ELF_R_TYPE(rela->r_info)) {
-
- case R_X86_64_NONE:
- break;
-
- case R_X86_64_64:
- {
- 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)
- goto done;
-
- *where = (Elf_Addr) (defobj->relocbase + def->st_value + rela->r_addend);
- }
- break;
-
- case R_X86_64_PC32:
- /*
- * I don't think the dynamic linker should ever see this
- * type of relocation. But the binutils-2.6 tools sometimes
- * generate it.
- */
- {
- 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)
- goto done;
-
- *where32 = (Elf32_Addr) (unsigned long) (defobj->relocbase +
- def->st_value + rela->r_addend - (Elf_Addr) where);
- }
- break;
- /* missing: R_X86_64_GOT32 R_X86_64_PLT32 */
-
- case R_X86_64_COPY:
/*
- * These are deferred until all other relocations have
- * been done. All we do here is make sure that the COPY
- * relocation is not in a shared library. They are allowed
- * only in executable files.
+ * First, resolve symbol for relocations which
+ * reference symbols.
*/
- if (!obj->mainprog) {
- _rtld_error("%s: Unexpected R_X86_64_COPY relocation"
- " in shared library", obj->path);
- goto done;
- }
- break;
-
- case R_X86_64_GLOB_DAT:
- {
- 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)
- goto done;
-
- *where = (Elf_Addr) (defobj->relocbase + def->st_value);
- }
- break;
-
- case R_X86_64_TPOFF64:
- {
- 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)
- goto done;
-
- /*
- * 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);
- goto done;
+ switch (ELF_R_TYPE(rela->r_info)) {
+ case R_X86_64_64:
+ case R_X86_64_PC32:
+ case R_X86_64_GLOB_DAT:
+ case R_X86_64_TPOFF64:
+ case R_X86_64_TPOFF32:
+ case R_X86_64_DTPMOD64:
+ case R_X86_64_DTPOFF64:
+ case R_X86_64_DTPOFF32:
+ def = find_symdef(ELF_R_SYM(rela->r_info), obj,
+ &defobj, flags, cache, lockstate);
+ if (def == NULL)
+ goto done;
+ /*
+ * If symbol is IFUNC, only perform relocation
+ * when caller allowed it by passing
+ * SYMLOOK_IFUNC flag. Skip the relocations
+ * otherwise.
+ *
+ * Also error out in case IFUNC relocations
+ * are specified for TLS, which cannot be
+ * usefully interpreted.
+ */
+ if (ELF_ST_TYPE(def->st_info) == STT_GNU_IFUNC) {
+ switch (ELF_R_TYPE(rela->r_info)) {
+ case R_X86_64_64:
+ case R_X86_64_PC32:
+ case R_X86_64_GLOB_DAT:
+ if ((flags & SYMLOOK_IFUNC) == 0) {
+ obj->non_plt_gnu_ifunc = true;
+ continue;
+ }
+ symval = (Elf_Addr)rtld_resolve_ifunc(
+ defobj, def);
+ break;
+ case R_X86_64_TPOFF64:
+ case R_X86_64_TPOFF32:
+ case R_X86_64_DTPMOD64:
+ case R_X86_64_DTPOFF64:
+ case R_X86_64_DTPOFF32:
+ _rtld_error("%s: IFUNC for TLS reloc",
+ obj->path);
+ goto done;
+ }
+ } else {
+ if ((flags & SYMLOOK_IFUNC) != 0)
+ continue;
+ symval = (Elf_Addr)defobj->relocbase +
+ def->st_value;
}
- }
-
- *where = (Elf_Addr) (def->st_value - defobj->tlsoffset +
- rela->r_addend);
+ break;
+ default:
+ if ((flags & SYMLOOK_IFUNC) != 0)
+ continue;
+ break;
}
- break;
-
- case R_X86_64_TPOFF32:
- {
- 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)
- goto done;
-
- /*
- * 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);
- goto done;
+ where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
+ where32 = (Elf32_Addr *)where;
+
+ switch (ELF_R_TYPE(rela->r_info)) {
+ case R_X86_64_NONE:
+ break;
+ case R_X86_64_64:
+ *where = symval + rela->r_addend;
+ break;
+ case R_X86_64_PC32:
+ /*
+ * I don't think the dynamic linker should
+ * ever see this type of relocation. But the
+ * binutils-2.6 tools sometimes generate it.
+ */
+ *where32 = (Elf32_Addr)(unsigned long)(symval +
+ rela->r_addend - (Elf_Addr)where);
+ break;
+ /* missing: R_X86_64_GOT32 R_X86_64_PLT32 */
+ case R_X86_64_COPY:
+ /*
+ * These are deferred until all other relocations have
+ * been done. All we do here is make sure that the COPY
+ * relocation is not in a shared library. They are allowed
+ * only in executable files.
+ */
+ if (!obj->mainprog) {
+ _rtld_error("%s: Unexpected R_X86_64_COPY "
+ "relocation in shared library", obj->path);
+ goto done;
}
- }
-
- *where32 = (Elf32_Addr) (def->st_value -
- defobj->tlsoffset +
- rela->r_addend);
- }
- break;
-
- case R_X86_64_DTPMOD64:
- {
- 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)
- goto done;
-
- *where += (Elf_Addr) defobj->tlsindex;
- }
- break;
-
- case R_X86_64_DTPOFF64:
- {
- 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)
- goto done;
-
- *where += (Elf_Addr) (def->st_value + rela->r_addend);
- }
- break;
-
- case R_X86_64_DTPOFF32:
- {
- 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)
+ break;
+ case R_X86_64_GLOB_DAT:
+ *where = symval;
+ break;
+ case R_X86_64_TPOFF64:
+ /*
+ * 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);
+ goto done;
+ }
+ }
+ *where = (Elf_Addr)(def->st_value - defobj->tlsoffset +
+ rela->r_addend);
+ break;
+ case R_X86_64_TPOFF32:
+ /*
+ * 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);
+ goto done;
+ }
+ }
+ *where32 = (Elf32_Addr)(def->st_value -
+ defobj->tlsoffset + rela->r_addend);
+ break;
+ case R_X86_64_DTPMOD64:
+ *where += (Elf_Addr)defobj->tlsindex;
+ break;
+ case R_X86_64_DTPOFF64:
+ *where += (Elf_Addr)(def->st_value + rela->r_addend);
+ break;
+ case R_X86_64_DTPOFF32:
+ *where32 += (Elf32_Addr)(def->st_value +
+ rela->r_addend);
+ break;
+ case R_X86_64_RELATIVE:
+ *where = (Elf_Addr)(obj->relocbase + rela->r_addend);
+ break;
+ /*
+ * missing:
+ * R_X86_64_GOTPCREL, R_X86_64_32, R_X86_64_32S, R_X86_64_16,
+ * R_X86_64_PC16, R_X86_64_8, R_X86_64_PC8
+ */
+ default:
+ _rtld_error("%s: Unsupported relocation type %u"
+ " in non-PLT relocations\n", obj->path,
+ (unsigned int)ELF_R_TYPE(rela->r_info));
goto done;
-
- *where32 += (Elf32_Addr) (def->st_value + rela->r_addend);
}
- break;
-
- case R_X86_64_RELATIVE:
- *where = (Elf_Addr)(obj->relocbase + rela->r_addend);
- break;
-
- /* missing: R_X86_64_GOTPCREL, R_X86_64_32, R_X86_64_32S, R_X86_64_16, R_X86_64_PC16, R_X86_64_8, R_X86_64_PC8 */
-
- default:
- _rtld_error("%s: Unsupported relocation type %u"
- " in non-PLT relocations\n", obj->path,
- (unsigned int)ELF_R_TYPE(rela->r_info));
- goto done;
- }
}
r = 0;
done:
- if (cache != NULL)
- free(cache);
+ free(cache);
return (r);
}
diff --git a/libexec/rtld-elf/arm/reloc.c b/libexec/rtld-elf/arm/reloc.c
index 715cb7e..9cbdc0e 100644
--- a/libexec/rtld-elf/arm/reloc.c
+++ b/libexec/rtld-elf/arm/reloc.c
@@ -324,6 +324,10 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags,
/* The relocation for the dynamic loader has already been done. */
if (obj == obj_rtld)
return (0);
+ if ((flags & SYMLOOK_IFUNC) != 0)
+ /* XXX not implemented */
+ return (0);
+
/*
* The dynamic loader may be called from a thread, we have
* limited amounts of stack available so we cannot use alloca().
diff --git a/libexec/rtld-elf/i386/reloc.c b/libexec/rtld-elf/i386/reloc.c
index 58073db..c1e0a39 100644
--- a/libexec/rtld-elf/i386/reloc.c
+++ b/libexec/rtld-elf/i386/reloc.c
@@ -126,168 +126,144 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags,
const Elf_Rel *rellim;
const Elf_Rel *rel;
SymCache *cache;
- int r = -1;
+ const Elf_Sym *def;
+ const Obj_Entry *defobj;
+ Elf_Addr *where, symval, add;
+ int r;
+ r = -1;
/*
* The dynamic loader may be called from a thread, we have
* limited amounts of stack available so we cannot use alloca().
*/
if (obj != obj_rtld) {
- cache = calloc(obj->dynsymcount, sizeof(SymCache));
- /* No need to check for NULL here */
+ cache = calloc(obj->dynsymcount, sizeof(SymCache));
+ /* No need to check for NULL here */
} else
- cache = NULL;
+ cache = NULL;
- rellim = (const Elf_Rel *) ((caddr_t) obj->rel + obj->relsize);
+ rellim = (const Elf_Rel *)((caddr_t) obj->rel + obj->relsize);
for (rel = obj->rel; rel < rellim; rel++) {
- Elf_Addr *where = (Elf_Addr *) (obj->relocbase + rel->r_offset);
-
- switch (ELF_R_TYPE(rel->r_info)) {
-
- case R_386_NONE:
- break;
-
- case R_386_32:
- {
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
- flags, cache, lockstate);
- if (def == NULL)
- goto done;
-
- *where += (Elf_Addr) (defobj->relocbase + def->st_value);
- }
- break;
-
- case R_386_PC32:
- /*
- * I don't think the dynamic linker should ever see this
- * type of relocation. But the binutils-2.6 tools sometimes
- * generate it.
- */
- {
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
- flags, cache, lockstate);
- if (def == NULL)
- goto done;
-
- *where +=
- (Elf_Addr) (defobj->relocbase + def->st_value) -
- (Elf_Addr) where;
- }
- break;
-
- case R_386_COPY:
- /*
- * These are deferred until all other relocations have
- * been done. All we do here is make sure that the COPY
- * relocation is not in a shared library. They are allowed
- * only in executable files.
- */
- if (!obj->mainprog) {
- _rtld_error("%s: Unexpected R_386_COPY relocation"
- " in shared library", obj->path);
- goto done;
- }
- break;
-
- case R_386_GLOB_DAT:
- {
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
- flags, cache, lockstate);
- if (def == NULL)
- goto done;
-
- *where = (Elf_Addr) (defobj->relocbase + def->st_value);
+ switch (ELF_R_TYPE(rel->r_info)) {
+ case R_386_32:
+ case R_386_PC32:
+ case R_386_GLOB_DAT:
+ case R_386_TLS_TPOFF:
+ case R_386_TLS_TPOFF32:
+ case R_386_TLS_DTPMOD32:
+ case R_386_TLS_DTPOFF32:
+ def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
+ flags, cache, lockstate);
+ if (def == NULL)
+ goto done;
+ if (ELF_ST_TYPE(def->st_info) == STT_GNU_IFUNC) {
+ switch (ELF_R_TYPE(rel->r_info)) {
+ case R_386_32:
+ case R_386_PC32:
+ case R_386_GLOB_DAT:
+ if ((flags & SYMLOOK_IFUNC) == 0) {
+ obj->non_plt_gnu_ifunc = true;
+ continue;
+ }
+ symval = (Elf_Addr)rtld_resolve_ifunc(
+ defobj, def);
+ break;
+ case R_386_TLS_TPOFF:
+ case R_386_TLS_TPOFF32:
+ case R_386_TLS_DTPMOD32:
+ case R_386_TLS_DTPOFF32:
+ _rtld_error("%s: IFUNC for TLS reloc",
+ obj->path);
+ goto done;
+ }
+ } else {
+ if ((flags & SYMLOOK_IFUNC) != 0)
+ continue;
+ symval = (Elf_Addr)defobj->relocbase +
+ def->st_value;
+ }
+ break;
+ default:
+ if ((flags & SYMLOOK_IFUNC) != 0)
+ continue;
+ break;
}
- break;
-
- case R_386_RELATIVE:
- *where += (Elf_Addr) obj->relocbase;
- break;
-
- case R_386_TLS_TPOFF:
- case R_386_TLS_TPOFF32:
- {
- const Elf_Sym *def;
- const Obj_Entry *defobj;
- Elf_Addr add;
-
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
- flags, cache, lockstate);
- if (def == NULL)
- goto done;
-
+ where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
+
+ switch (ELF_R_TYPE(rel->r_info)) {
+ case R_386_NONE:
+ break;
+ case R_386_32:
+ *where += symval;
+ break;
+ case R_386_PC32:
/*
- * 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.
+ * I don't think the dynamic linker should ever
+ * see this type of relocation. But the
+ * binutils-2.6 tools sometimes generate it.
*/
- if (!defobj->tls_done) {
- if (!allocate_tls_offset((Obj_Entry*) defobj)) {
- _rtld_error("%s: No space available for static "
- "Thread Local Storage", obj->path);
- goto done;
+ *where += symval - (Elf_Addr)where;
+ break;
+ case R_386_COPY:
+ /*
+ * These are deferred until all other
+ * relocations have been done. All we do here
+ * is make sure that the COPY relocation is
+ * not in a shared library. They are allowed
+ * only in executable files.
+ */
+ if (!obj->mainprog) {
+ _rtld_error("%s: Unexpected R_386_COPY "
+ "relocation in shared library", obj->path);
+ goto done;
}
- }
- add = (Elf_Addr) (def->st_value - defobj->tlsoffset);
- if (ELF_R_TYPE(rel->r_info) == R_386_TLS_TPOFF)
- *where += add;
- else
- *where -= add;
- }
- break;
-
- case R_386_TLS_DTPMOD32:
- {
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
- flags, cache, lockstate);
- if (def == NULL)
- goto done;
-
- *where += (Elf_Addr) defobj->tlsindex;
- }
- break;
-
- case R_386_TLS_DTPOFF32:
- {
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
- flags, cache, lockstate);
- if (def == NULL)
+ break;
+ case R_386_GLOB_DAT:
+ *where = symval;
+ break;
+ case R_386_RELATIVE:
+ *where += (Elf_Addr)obj->relocbase;
+ break;
+ case R_386_TLS_TPOFF:
+ case R_386_TLS_TPOFF32:
+ /*
+ * 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);
+ goto done;
+ }
+ }
+ add = (Elf_Addr)(def->st_value - defobj->tlsoffset);
+ if (ELF_R_TYPE(rel->r_info) == R_386_TLS_TPOFF)
+ *where += add;
+ else
+ *where -= add;
+ break;
+ case R_386_TLS_DTPMOD32:
+ *where += (Elf_Addr)defobj->tlsindex;
+ break;
+ case R_386_TLS_DTPOFF32:
+ *where += (Elf_Addr) def->st_value;
+ break;
+ default:
+ _rtld_error("%s: Unsupported relocation type %d"
+ " in non-PLT relocations\n", obj->path,
+ ELF_R_TYPE(rel->r_info));
goto done;
-
- *where += (Elf_Addr) def->st_value;
}
- break;
-
- default:
- _rtld_error("%s: Unsupported relocation type %d"
- " in non-PLT relocations\n", obj->path,
- ELF_R_TYPE(rel->r_info));
- goto done;
- }
}
r = 0;
done:
- if (cache != NULL)
- free(cache);
+ free(cache);
return (r);
}
diff --git a/libexec/rtld-elf/libmap.c b/libexec/rtld-elf/libmap.c
index 8b5faf8..691ad52 100644
--- a/libexec/rtld-elf/libmap.c
+++ b/libexec/rtld-elf/libmap.c
@@ -216,14 +216,14 @@ lmc_parse(char *lm_p, size_t lm_len)
p = NULL;
while (cnt < lm_len) {
i = 0;
- while (lm_p[cnt] != '\n' && cnt < lm_len &&
+ while (cnt < lm_len && lm_p[cnt] != '\n' &&
i < sizeof(line) - 1) {
line[i] = lm_p[cnt];
cnt++;
i++;
}
line[i] = '\0';
- while (lm_p[cnt] != '\n' && cnt < lm_len)
+ while (cnt < lm_len && lm_p[cnt] != '\n')
cnt++;
/* skip over nl */
cnt++;
diff --git a/libexec/rtld-elf/mips/reloc.c b/libexec/rtld-elf/mips/reloc.c
index 24e56ce..4e750d7 100644
--- a/libexec/rtld-elf/mips/reloc.c
+++ b/libexec/rtld-elf/mips/reloc.c
@@ -275,6 +275,10 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags,
if (obj == obj_rtld)
return (0);
+ if ((flags & SYMLOOK_IFUNC) != 0)
+ /* XXX not implemented */
+ return (0);
+
#ifdef SUPPORT_OLD_BROKEN_LD
broken = 0;
sym = obj->symtab;
diff --git a/libexec/rtld-elf/powerpc/reloc.c b/libexec/rtld-elf/powerpc/reloc.c
index 838cfe6..89e5536 100644
--- a/libexec/rtld-elf/powerpc/reloc.c
+++ b/libexec/rtld-elf/powerpc/reloc.c
@@ -294,6 +294,10 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags,
SymCache *cache;
int r = -1;
+ if ((flags & SYMLOOK_IFUNC) != 0)
+ /* XXX not implemented */
+ return (0);
+
/*
* The dynamic loader may be called from a thread, we have
* limited amounts of stack available so we cannot use alloca().
diff --git a/libexec/rtld-elf/powerpc64/reloc.c b/libexec/rtld-elf/powerpc64/reloc.c
index fb5325f..65db28f 100644
--- a/libexec/rtld-elf/powerpc64/reloc.c
+++ b/libexec/rtld-elf/powerpc64/reloc.c
@@ -290,6 +290,10 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags,
int bytes = obj->dynsymcount * sizeof(SymCache);
int r = -1;
+ if ((flags & SYMLOOK_IFUNC) != 0)
+ /* XXX not implemented */
+ return (0);
+
/*
* The dynamic loader may be called from a thread, we have
* limited amounts of stack available so we cannot use alloca().
diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index 03c92d0..cc7afda 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -2546,7 +2546,7 @@ relocate_object(Obj_Entry *obj, bool bind_now, Obj_Entry *rtldobj,
}
}
- /* Process the non-PLT relocations. */
+ /* Process the non-PLT non-IFUNC relocations. */
if (reloc_non_plt(obj, rtldobj, flags, lockstate))
return (-1);
@@ -2559,7 +2559,6 @@ relocate_object(Obj_Entry *obj, bool bind_now, Obj_Entry *rtldobj,
}
}
-
/* Set the special PLT or GOT entries. */
init_pltgot(obj);
@@ -2571,6 +2570,16 @@ relocate_object(Obj_Entry *obj, bool bind_now, Obj_Entry *rtldobj,
if (reloc_jmpslots(obj, flags, lockstate) == -1)
return (-1);
+ /*
+ * Process the non-PLT IFUNC relocations. The relocations are
+ * processed in two phases, because IFUNC resolvers may
+ * reference other symbols, which must be readily processed
+ * before resolvers are called.
+ */
+ if (obj->non_plt_gnu_ifunc &&
+ reloc_non_plt(obj, rtldobj, flags | SYMLOOK_IFUNC, lockstate))
+ return (-1);
+
if (obj->relro_size > 0) {
if (mprotect(obj->relro_page, obj->relro_size,
PROT_READ) == -1) {
@@ -2784,7 +2793,7 @@ search_library_pathfds(const char *name, const char *path, int *fdp)
size_t len;
int dirfd, fd;
- dbg("%s('%s', '%s', fdp)\n", __func__, name, path);
+ dbg("%s('%s', '%s', fdp)", __func__, name, path);
/* Don't load from user-specified libdirs into setuid binaries. */
if (!trust)
@@ -3368,8 +3377,7 @@ rtld_fill_dl_phdr_info(const Obj_Entry *obj, struct dl_phdr_info *phdr_info)
{
phdr_info->dlpi_addr = (Elf_Addr)obj->relocbase;
- phdr_info->dlpi_name = STAILQ_FIRST(&obj->names) ?
- STAILQ_FIRST(&obj->names)->name : obj->path;
+ phdr_info->dlpi_name = obj->path;
phdr_info->dlpi_phdr = obj->phdr;
phdr_info->dlpi_phnum = obj->phsize / sizeof(obj->phdr[0]);
phdr_info->dlpi_tls_modid = obj->tlsindex;
diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h
index cbeff66..ace229f 100644
--- a/libexec/rtld-elf/rtld.h
+++ b/libexec/rtld-elf/rtld.h
@@ -271,6 +271,7 @@ typedef struct Struct_Obj_Entry {
bool filtees_loaded : 1; /* Filtees loaded */
bool irelative : 1; /* Object has R_MACHDEP_IRELATIVE relocs */
bool gnu_ifunc : 1; /* Object has references to STT_GNU_IFUNC */
+ bool non_plt_gnu_ifunc : 1; /* Object has non-plt IFUNC references */
bool crt_no_init : 1; /* Object' crt does not call _init/_fini */
bool valid_hash_sysv : 1; /* A valid System V hash hash tag is available */
bool valid_hash_gnu : 1; /* A valid GNU hash tag is available */
@@ -293,6 +294,8 @@ typedef struct Struct_Obj_Entry {
#define SYMLOOK_DLSYM 0x02 /* Return newest versioned symbol. Used by
dlsym. */
#define SYMLOOK_EARLY 0x04 /* Symlook is done during initialization. */
+#define SYMLOOK_IFUNC 0x08 /* Allow IFUNC processing in
+ reloc_non_plt(). */
/* Flags for load_object(). */
#define RTLD_LO_NOLOAD 0x01 /* dlopen() specified RTLD_NOLOAD. */
diff --git a/libexec/rtld-elf/sparc64/reloc.c b/libexec/rtld-elf/sparc64/reloc.c
index 21fae5c..738a847 100644
--- a/libexec/rtld-elf/sparc64/reloc.c
+++ b/libexec/rtld-elf/sparc64/reloc.c
@@ -300,6 +300,10 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags,
SymCache *cache;
int r = -1;
+ if ((flags & SYMLOOK_IFUNC) != 0)
+ /* XXX not implemented */
+ return (0);
+
/*
* The dynamic loader may be called from a thread, we have
* limited amounts of stack available so we cannot use alloca().
diff --git a/libexec/rtld-elf/tests/Makefile b/libexec/rtld-elf/tests/Makefile
index 5e57f60..f384218 100644
--- a/libexec/rtld-elf/tests/Makefile
+++ b/libexec/rtld-elf/tests/Makefile
@@ -5,10 +5,6 @@
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
index 274b5e8..1100894 100644
--- a/libexec/rtld-elf/tests/ld_library_pathfds.c
+++ b/libexec/rtld-elf/tests/ld_library_pathfds.c
@@ -38,7 +38,7 @@ struct descriptors {
int usr;
};
-static void setup(struct descriptors *);
+static void setup(struct descriptors *, const atf_tc_t *);
static void expect_success(int binary, char *pathfds);
static void expect_missing_library(int binary, char *pathfds);
@@ -53,7 +53,7 @@ ATF_TC_BODY(missing_library, tc)
{
struct descriptors files;
- setup(&files);
+ setup(&files, tc);
expect_missing_library(files.binary, NULL);
}
@@ -64,7 +64,7 @@ ATF_TC_BODY(wrong_library_directories, tc)
struct descriptors files;
char *pathfds;
- setup(&files);
+ setup(&files, tc);
ATF_REQUIRE(
asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=%d", files.etc) > 0);
@@ -78,8 +78,8 @@ ATF_TC_BODY(bad_library_directories, tc)
struct descriptors files;
char *pathfds;
- setup(&files);
- ATF_REQUIRE(asprintf(&pathfds, "::", files.etc) > 0);
+ setup(&files, tc);
+ ATF_REQUIRE(asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=::") > 0);
expect_missing_library(files.binary, pathfds);
}
@@ -91,7 +91,7 @@ ATF_TC_BODY(single_library_directory, tc)
struct descriptors files;
char *pathfds;
- setup(&files);
+ setup(&files, tc);
ATF_REQUIRE(
asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=%d", files.testdir) > 0);
@@ -105,7 +105,7 @@ ATF_TC_BODY(first_library_directory, tc)
struct descriptors files;
char *pathfds;
- setup(&files);
+ setup(&files, tc);
ATF_REQUIRE(
asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=%d:%d",
files.testdir, files.etc) > 0);
@@ -120,7 +120,7 @@ ATF_TC_BODY(middle_library_directory, tc)
struct descriptors files;
char *pathfds;
- setup(&files);
+ setup(&files, tc);
ATF_REQUIRE(
asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=%d:%d:%d",
files.root, files.testdir, files.usr) > 0);
@@ -135,7 +135,7 @@ ATF_TC_BODY(last_library_directory, tc)
struct descriptors files;
char *pathfds;
- setup(&files);
+ setup(&files, tc);
ATF_REQUIRE(
asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=%d:%d",
files.root, files.testdir) > 0);
@@ -161,10 +161,11 @@ ATF_TP_ADD_TCS(tp)
static void
-setup(struct descriptors *dp)
+setup(struct descriptors *dp, const atf_tc_t *tc)
{
- ATF_REQUIRE((dp->testdir = opendir(TESTSDIR)) >= 0);
+ dp->testdir = opendir(atf_tc_get_config_var(tc, "srcdir"));
+ ATF_REQUIRE(dp->testdir >= 0);
ATF_REQUIRE(
(dp->binary = openat(dp->testdir, "target", O_RDONLY)) >= 0);
diff --git a/libexec/rtld-elf/tests/libpythagoras/Makefile b/libexec/rtld-elf/tests/libpythagoras/Makefile
index 09b67c9..618612f 100644
--- a/libexec/rtld-elf/tests/libpythagoras/Makefile
+++ b/libexec/rtld-elf/tests/libpythagoras/Makefile
@@ -5,8 +5,8 @@
LIB= pythagoras
SHLIB_MAJOR= 0
-LIBDIR= ${TESTSBASE}${TESTSDIR}/libexec/rtld-elf
-SHLIBDIR= ${TESTSBASE}${TESTSDIR}/libexec/rtld-elf
+LIBDIR= ${TESTSBASE}/libexec/rtld-elf
+SHLIBDIR= ${TESTSBASE}/libexec/rtld-elf
SRCS= pythagoras.c
diff --git a/libexec/rtld-elf/tests/target/Makefile b/libexec/rtld-elf/tests/target/Makefile
index 0ae8c1d..d5305f9 100644
--- a/libexec/rtld-elf/tests/target/Makefile
+++ b/libexec/rtld-elf/tests/target/Makefile
@@ -3,10 +3,13 @@
.include <bsd.own.mk>
PROG= target
-BINDIR= ${TESTSBASE}${TESTSDIR}/libexec/rtld-elf
+BINDIR= ${TESTSBASE}/libexec/rtld-elf
CFLAGS+= -I${.CURDIR}/../libpythagoras
-LDADD= -L${.OBJDIR}/../libpythagoras -lpythagoras
+
+LDFLAGS+= -L${.OBJDIR}/../libpythagoras
+DPADD+= ${.OBJDIR}/../libpythagoras/libpythagoras.a
+LDADD= -lpythagoras
MAN=
diff --git a/libexec/save-entropy/save-entropy.sh b/libexec/save-entropy/save-entropy.sh
index 880a988..06319d5 100755
--- a/libexec/save-entropy/save-entropy.sh
+++ b/libexec/save-entropy/save-entropy.sh
@@ -53,7 +53,7 @@ case ${entropy_dir} in
;;
esac
-entropy_save_sz=${entropy_save_sz:-2048}
+entropy_save_sz=${entropy_save_sz:-4096}
entropy_save_num=${entropy_save_num:-8}
if [ ! -d "${entropy_dir}" ]; then
diff --git a/libexec/smrsh/Makefile b/libexec/smrsh/Makefile
index 9f0bfd4..ae86155 100644
--- a/libexec/smrsh/Makefile
+++ b/libexec/smrsh/Makefile
@@ -9,8 +9,6 @@ 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 f80bf5c..07de197 100644
--- a/libexec/telnetd/Makefile
+++ b/libexec/telnetd/Makefile
@@ -20,13 +20,12 @@ WFORMAT?= 0
CFLAGS+= -DLINEMODE -DUSE_TERMIO -DDIAGNOSTICS -DOLD_ENVIRON \
-DENV_HACK -DSTREAMSPTY
-NO_PIE= yes
-
.if ${MK_INET6_SUPPORT} != "no"
CFLAGS+= -DINET6
.endif
CFLAGS+= -I${TELNETDIR}
+CFLAGS+= -I${TELNETDIR}/telnet
LIBTELNET= ${.OBJDIR}/../../lib/libtelnet/libtelnet.a
OpenPOWER on IntegriCloud