build shared versions of libraries

building defaults to off until clang is updated.

current clang does not handle -shared, necessary to change the ld
invocation to build shared libraries properly. a new clang should be
installed and MKPIC defaults to no unless the newer clang is detected.

changes:

	. mainly small imports of a Makefile or two and small fixes
	  (turning things back on that were turned off in Makefiles)
	. e.g.: dynamic librefuse now depends on dynamic
	  libpuffs, so libpuffs has to be built dynamically too
	  and a make dependency barrier is needed in lib/Makefile
	. all library objects now have a PIC (for .so) and non-PIC
	  version, so everything is built twice.
	. generate PIC versions of the compat (un-RENAMEd) jump files,
	  include function type annotation in generated assembly
	. build progs with -static by default for now
	. also build ld.elf_so
	. also import NetBSD ldd
This commit is contained in:
Ben Gras
2012-03-31 02:28:03 +02:00
parent 53002f6f6c
commit 4b999f1962
49 changed files with 1051 additions and 53 deletions

View File

@@ -3,6 +3,6 @@
.include <bsd.own.mk>
# NetBSD imports
SUBDIR= makewhatis
SUBDIR= makewhatis ld.elf_so
.include <bsd.subdir.mk>

View File

@@ -5,6 +5,12 @@
WARNS?=4
# This executable needs to be linked dynamically
MINIXDYNAMIC=yes
# And the minix gcc currently references /libexec/ld-elf.so.1
SYMLINKS+= ${SHLINKINSTALLDIR}/${PROG} /libexec/ld-elf.so.1
# This needs to be before bsd.init.mk
.if defined(BSD_MK_COMPAT_FILE)
.include <${BSD_MK_COMPAT_FILE}>
@@ -75,7 +81,7 @@ SRCS+= stack_protector.c
.PATH.c: ${NETBSDSRCDIR}/lib/libc/stdlib
SRCS+= exit.c
errlist_concat.h: ${NETBSDSRCDIR}/lib/libc/gen/errlist.awk ${NETBSDSRCDIR}/sys/sys/errno.h
errlist_concat.h: ${NETBSDSRCDIR}/lib/libc/gen/errlist.awk ${NETBSDSRCDIR}/include/sys/errno.h
${TOOL_AWK} -v concat=1 -f ${.ALLSRC} > ${.TARGET}.tmp && \
mv -f ${.TARGET}.tmp ${.TARGET}
@@ -93,8 +99,8 @@ CPPFLAGS+= -DCOMBRELOC
#CPPFLAGS+= -DDEBUG
#CPPFLAGS+= -DRTLD_DEBUG
#CPPFLAGS+= -DRTLD_DEBUG_RELOC
#DBG= -g
DBG= -O3 -fomit-frame-pointer
DBG= -g
#DBG= -O3 -fomit-frame-pointer
.if ${SHLIBDIR} != ${LIBDIR}
CPPFLAGS+= -DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"

View File

@@ -62,15 +62,20 @@ static const struct {
ADD(PLATFORM) /* uname -p */
};
#ifndef __minix
static int mib[3][2] = {
{ CTL_KERN, KERN_OSTYPE },
{ CTL_KERN, KERN_OSRELEASE },
{ CTL_HW, HW_MACHINE_ARCH },
};
#endif
static size_t
expand(char *buf, const char *execname, int what, size_t bl)
{
#ifdef __minix
return 0;
#else
const char *p, *ep;
char *bp = buf;
size_t len;
@@ -106,6 +111,7 @@ expand(char *buf, const char *execname, int what, size_t bl)
*bp++ = *p++, bl--;
return bp - buf;
#endif
}

View File

@@ -57,6 +57,10 @@ __RCSID("$NetBSD: load.c,v 1.42 2010/12/24 12:41:43 skrll Exp $");
#include <sys/sysctl.h>
#include <dirent.h>
#ifdef __minix
#define munmap minix_munmap
#endif
#include "debug.h"
#include "rtld.h"
@@ -211,6 +215,9 @@ _rtld_load_by_name(const char *name, Obj_Entry *obj, Needed_Entry **needed,
dbg(("load by name %s %p", name, x));
for (; x; x = x->next) {
#ifdef __minix
continue;
#else
if (strcmp(x->name, name) != 0)
continue;
@@ -274,6 +281,7 @@ _rtld_load_by_name(const char *name, Obj_Entry *obj, Needed_Entry **needed,
}
#endif
}
if (got)

View File

@@ -119,6 +119,7 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb)
int nsegs;
caddr_t mapbase = MAP_FAILED;
size_t mapsize = 0;
size_t bsssize = 0;
int mapflags;
Elf_Off base_offset;
#ifdef MAP_ALIGNED
@@ -367,22 +368,29 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb)
goto bad;
}
bsssize= base_vlimit - data_vlimit;
if(bsssize > 0) {
/* Overlay the bss segment onto the proper region. */
if (mmap(mapbase + data_vlimit - base_vaddr, base_vlimit - data_vlimit,
if (mmap(mapbase + data_vlimit - base_vaddr, bsssize,
data_flags, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0) ==
MAP_FAILED) {
_rtld_error("mmap of bss failed: %s", xstrerror(errno));
_rtld_error("mmap of bss (at 0x%lx, 0x%lx bytes) failed: %s",
mapbase + data_vlimit - base_vaddr, bsssize, xstrerror(errno));
goto bad;
}
}
/* Unmap the gap between the text and data. */
gap_addr = mapbase + round_up(text_vlimit - base_vaddr);
gap_size = data_addr - gap_addr;
#ifndef __minix
if (gap_size != 0 && mprotect(gap_addr, gap_size, PROT_NONE) == -1) {
_rtld_error("mprotect of text -> data gap failed: %s",
xstrerror(errno));
goto bad;
}
#endif
#ifdef RTLD_LOADER
/* Clear any BSS in the last page of the data segment. */

View File

@@ -49,7 +49,9 @@ __RCSID("$NetBSD: paths.c,v 1.40 2009/05/19 20:44:52 christos Exp $");
#include <sys/gmon.h>
#include <sys/socket.h>
#include <sys/mount.h>
#ifndef __minix
#include <sys/mbuf.h>
#endif
#include <sys/resource.h>
#include <machine/cpu.h>
@@ -336,13 +338,17 @@ void
_rtld_process_hints(const char *execname, Search_Path **path_p,
Library_Xform **lib_p, const char *fname)
{
#ifdef __minix
/* Minix doesn't support MAP_SHARED. */
return;
#else
int fd;
char *buf, small[128];
const char *b, *ep, *ptr;
struct stat st;
ssize_t sz;
Search_Path **head_p = path_p;
if ((fd = open(fname, O_RDONLY)) == -1) {
/* Don't complain */
return;
@@ -406,8 +412,10 @@ _rtld_process_hints(const char *execname, Search_Path **path_p,
if (buf != small)
(void)munmap(buf, sz);
#endif
}
#ifndef __minix
/* Basic name -> sysctl MIB translation */
int
_rtld_sysctl(const char *name, void *oldp, size_t *oldlen)
@@ -476,3 +484,4 @@ bad:
xfree(result);
return (-1);
}
#endif

View File

@@ -166,6 +166,7 @@ _rtld_relocate_objects(Obj_Entry *first, bool bind_now)
(long)(obj->pltrellim - obj->pltrel),
(long)(obj->pltrelalim - obj->pltrela)));
#ifndef __minix
if (obj->textrel) {
/*
* There are relocations to the write-protected text
@@ -178,9 +179,13 @@ _rtld_relocate_objects(Obj_Entry *first, bool bind_now)
return -1;
}
}
#endif
dbg(("doing non-PLT relocations"));
if (_rtld_relocate_nonplt_objects(obj) < 0)
ok = 0;
#ifndef __minix
if (obj->textrel) { /* Re-protected the text segment. */
if (mprotect(obj->mapbase, obj->textsize,
PROT_READ | PROT_EXEC) == -1) {
@@ -189,6 +194,8 @@ _rtld_relocate_objects(Obj_Entry *first, bool bind_now)
return -1;
}
}
#endif
dbg(("doing lazy PLT binding"));
if (_rtld_relocate_plt_lazy(obj) < 0)
ok = 0;

View File

@@ -38,6 +38,10 @@
* John Polstra <jdp@polstra.com>.
*/
#ifdef __minix
#define munmap minix_munmap
#endif
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: rtld.c,v 1.137 2010/12/24 12:41:43 skrll Exp $");

View File

@@ -47,7 +47,7 @@
#if defined(_RTLD_SOURCE)
#ifndef RTLD_DEFAULT_LIBRARY_PATH
#define RTLD_DEFAULT_LIBRARY_PATH "/usr/lib"
#define RTLD_DEFAULT_LIBRARY_PATH "/lib:/usr/lib:/libexec"
#endif
#define _PATH_LD_HINTS "/etc/ld.so.conf"

View File

@@ -60,6 +60,10 @@
* SUCH DAMAGE.
*/
#ifdef __minix
#define munmap minix_munmap
#endif
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)malloc.c 5.11 (Berkeley) 2/23/91";*/
#endif /* LIBC_SCCS and not lint */
@@ -409,6 +413,10 @@ mstats(char *s)
}
#endif
/* Minix mmap can do this. */
#ifdef __minix
#define mmap minix_mmap
#endif
static int
morepages(int n)