Thu Jun 8 02:50:26 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>

* elf/rtld.c [! NDEBUG] (__assert_perror_fail): New function.

	* hurd/hurdstartup.c (_hurd_startup): Fancier kludge to guess phdr
 	and user entry point addresses.

	* elf/dl-load.c (open_path): Don't do strlen on DIRPATH if it's null.
	(_dl_map_object): DT_RPATH value is relative to DT_STRTAB value.

	* Makerules (install-lib.so): Don't include libc.so.
	[$(build-shared)=yes] (install): Depend on the installed libc.so file.
	[$(build-shared)=yes] (install-no-libc.a): Make this, rather than
	install, depend on the installed $(install-lib.so) files.
	[$(build-shared)=yes] (install-lib.so): Append libc.so after that rule.

	* sysdeps/mach/hurd/dl-sysdep.c (_dl_sysdep_start): Add kludge to
 	allocate high addresses to avoid random mappings appearing there.
	(mmap): Comment out mask; always pass zero.

Tue Jun  6 13:34:53 1995  Roland McGrath  <roland@churchy.gnu.ai.mit.edu>

	* sysdeps/i386/dl-machine.h (ELF_MACHINE_USER_ADDRESS_MASK): New macro.
	* sysdeps/mach/hurd/dl-sysdep.c (mmap): Use it as mask in vm_map call.

	* elf/dl-error.c (_dl_catch_error): Clear *ERRSTRING and *OBJNAME
 	when successful.

	* sysdeps/mach/hurd/dl-sysdep.c (threadvars): New static variable.
	(__hurd_threadvar_max, __hurd_threadvar_stack_offset): Define these
	variables, using the `threadvars' buffer.

	* elf/dl-reloc.c: Don't dereference L->l_prev when it's null.
	* sysdeps/i386/dl-runtime.c: Likewise.

	* elf/rtld.c (dl_main): Add missing NULL terminating argument in
 	_dl_sysdep_fatal call.
	(__assert_fail): Likewise.

	* locale/Makefile (localedef-modules): Renamed ctype to
 	locale-ctype so as not to conflict with the object file for
 	ctype/ctype.c in the build directory.

	* sysdeps/i386/dl-machine.h (elf_machine_rel): If MAP->l_type is
 	lt_interpreter, first undo relocation done during bootstrapping.
This commit is contained in:
Roland McGrath 1995-06-08 09:00:23 +00:00
parent 75598ca67e
commit 5bf62f2d3a
13 changed files with 169 additions and 56 deletions

View File

@ -1,3 +1,46 @@
Thu Jun 8 02:50:26 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
* elf/rtld.c [! NDEBUG] (__assert_perror_fail): New function.
* hurd/hurdstartup.c (_hurd_startup): Fancier kludge to guess phdr
and user entry point addresses.
* elf/dl-load.c (open_path): Don't do strlen on DIRPATH if it's null.
(_dl_map_object): DT_RPATH value is relative to DT_STRTAB value.
* Makerules (install-lib.so): Don't include libc.so.
[$(build-shared)=yes] (install): Depend on the installed libc.so file.
[$(build-shared)=yes] (install-no-libc.a): Make this, rather than
install, depend on the installed $(install-lib.so) files.
[$(build-shared)=yes] (install-lib.so): Append libc.so after that rule.
* sysdeps/mach/hurd/dl-sysdep.c (_dl_sysdep_start): Add kludge to
allocate high addresses to avoid random mappings appearing there.
(mmap): Comment out mask; always pass zero.
Tue Jun 6 13:34:53 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
* sysdeps/i386/dl-machine.h (ELF_MACHINE_USER_ADDRESS_MASK): New macro.
* sysdeps/mach/hurd/dl-sysdep.c (mmap): Use it as mask in vm_map call.
* elf/dl-error.c (_dl_catch_error): Clear *ERRSTRING and *OBJNAME
when successful.
* sysdeps/mach/hurd/dl-sysdep.c (threadvars): New static variable.
(__hurd_threadvar_max, __hurd_threadvar_stack_offset): Define these
variables, using the `threadvars' buffer.
* elf/dl-reloc.c: Don't dereference L->l_prev when it's null.
* sysdeps/i386/dl-runtime.c: Likewise.
* elf/rtld.c (dl_main): Add missing NULL terminating argument in
_dl_sysdep_fatal call.
(__assert_fail): Likewise.
* locale/Makefile (localedef-modules): Renamed ctype to
locale-ctype so as not to conflict with the object file for
ctype/ctype.c in the build directory.
Mon Jun 5 04:02:26 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
* elf/elf.h (ELFMAG): Use \177 instead of \x7f. It seems GCC
@ -15,6 +58,8 @@ Thu Jun 1 12:17:52 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
* elf/rtld.c: Initialize RTLD_MAP.l_type.
* elf/dl-reloc.c (_dl_relocate_object): Clear LAZY if relocating
the dynamic linker itself.
* sysdeps/i386/dl-machine.h (elf_machine_rel): If MAP->l_type is
lt_interpreter, first undo relocation done during bootstrapping.
Tue May 30 15:52:32 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>

View File

@ -492,12 +492,15 @@ $(INSTALL_PROGRAM) $< $@.new
mv -f $@.new $@
endef
install-lib.so := libc.so $(filter %.so,$(install-lib:%_pic.a=%.so))
install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
install-lib := $(filter-out %.so,$(install-lib))
ifeq (yes,$(build-shared))
install: $(foreach so,$(install-lib.so),\
install: $(libdir)/libc.so$(libc.so-version)
install-no-libc.a: $(foreach so,$(install-lib.so),\
$(libdir)/$(patsubst $(libprefix)lib%,lib$(libprefix)%,\
$(libprefix)$(so))$($(so)-version))
install-lib.so += libc.so
$(foreach v,$(sort $(foreach so,$(install-lib.so),.so$($(so)-version))),\
$(libdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so
$(do-install-program)

View File

@ -46,6 +46,7 @@ _dl_catch_error (const char **errstring,
if (errcode == 0)
{
(*operate) ();
*errstring = *objname = NULL;
return 0;
}

View File

@ -54,7 +54,7 @@ open_path (const char *name, size_t namelen,
const char *dirpath,
char **realname)
{
char buf[strlen (dirpath) + 1 + namelen];
char *buf;
const char *p;
int fd;
@ -65,6 +65,7 @@ open_path (const char *name, size_t namelen,
return -1;
}
buf = alloca (strlen (dirpath) + 1 + namelen);
do
{
dirpath = p;
@ -166,7 +167,8 @@ _dl_map_object (struct link_map *loader, const char *name,
fd = -1;
if (loader && loader->l_info[DT_RPATH])
trypath ((const char *) (loader->l_addr +
loader->l_info[DT_RPATH]->d_un.d_ptr));
loader->l_info[DT_STRTAB]->d_un.d_ptr +
loader->l_info[DT_RPATH]->d_un.d_val));
if (fd == -1 && ! _dl_secure)
trypath (getenv ("LD_LIBRARY_PATH"));
if (fd == -1)

View File

@ -69,7 +69,8 @@ _dl_relocate_object (struct link_map *l, int lazy)
real_next = l->l_next;
if (l->l_info[DT_SYMBOLIC])
{
l->l_prev->l_next = real_next;
if (l->l_prev)
l->l_prev->l_next = real_next;
l->l_next = _dl_loaded;
scope = l;
}
@ -88,7 +89,8 @@ _dl_relocate_object (struct link_map *l, int lazy)
/* Restore list frobnication done above for DT_SYMBOLIC. */
l->l_next = real_next;
l->l_prev->l_next = l;
if (l->l_prev)
l->l_prev->l_next = l;
}
if (l->l_info[DT_JMPREL] && lazy)

View File

@ -144,8 +144,8 @@ command line to load and run an ELF executable file; this is like executing\n\
that file itself, but always uses this helper program from the file you\n\
specified, instead of the helper program file specified in the executable\n\
file you run. This is mostly of use for maintainers to test new versions\n\
of this helper program; chances are you did not intend to run this program.\n"
);
of this helper program; chances are you did not intend to run this program.\n",
NULL);
rtld_command = 1;
interpreter_name = _dl_argv[0];
@ -289,9 +289,25 @@ __assert_fail (const char *assertion,
_dl_sysdep_fatal ("BUG IN DYNAMIC LINKER ld.so: ",
file, ": ", _itoa (line, buf + sizeof buf - 1, 10, 0),
": ", function ?: "", function ? ": " : "",
"Assertion `", assertion, "' failed!\n");
"Assertion `", assertion, "' failed!\n",
NULL);
}
weak_symbol (__assert_fail)
void
__assert_perror_fail (int errnum,
const char *file, unsigned int line,
const char *function)
{
char buf[64];
buf[sizeof buf - 1] = '\0';
_dl_sysdep_fatal ("BUG IN DYNAMIC LINKER ld.so: ",
file, ": ", _itoa (line, buf + sizeof buf - 1, 10, 0),
": ", function ?: "", function ? ": " : "",
"Unexpected error: ", strerror (errnum), "\n", NULL);
}
weak_symbol (__assert_perror_fail)
#endif

View File

@ -158,33 +158,29 @@ _hurd_startup (void **argptr, void (*main) (int *data))
{
struct hurd_startup_data *d = (void *) &envp[envc + 1];
/* XXX hardcoded until exec_startup changes */
#ifdef PIC
#if 0
const Elf32_Ehdr *ehdr = (const void *) 0x08000000;
vm_address_t phdr = 0x08000000 + ehdr->e_phoff;
vm_size_t phdrsz = ehdr->e_phnum * ehdr->e_phentsize;
vm_address_t user_entry = ehdr->e_entry;
#else
vm_address_t phdr = 0;
vm_size_t phdrsz = 0;
extern void _start();
vm_address_t user_entry = (vm_address_t) &_start;
#endif
#else
vm_address_t phdr = 0;
vm_size_t phdrsz = 0;
vm_address_t user_entry = 0;
#endif
if ((void *) d != argv[0])
{
*d = data;
_hurd_init_dtable = d->dtable;
_hurd_init_dtablesize = d->dtablesize;
d->phdr = phdr;
d->phdrsz = phdrsz;
d->user_entry = user_entry;
/* XXX hardcoded kludge until exec_startup changes */
{
extern void _start();
vm_address_t page = 0;
vm_size_t size = 0;
if (__vm_read (__mach_task_self (),
0x08000000, __vm_page_size, &page, &size) == 0)
{
const Elf32_Ehdr *ehdr = (const void *) 0x08000000;
d->phdr = 0x08000000 + ehdr->e_phoff;
d->phdrsz = ehdr->e_phnum * ehdr->e_phentsize;
d->user_entry = ehdr->e_entry;
__vm_deallocate (__mach_task_self (), page, size);
}
else
d->user_entry = (Elf32_Addr) &_start;
}
}
(*main) (argcptr);

View File

@ -34,7 +34,7 @@ install-bin = localedef locale
extra-objs = $(localedef-modules:=.o) $(locale-modules:=.o) \
$(lib-modules:=.o)
localedef-modules := charmap locfile-lex locfile-parse ctype \
localedef-modules := charmap locfile-lex locfile-parse locale-ctype \
monetary messages collate numeric
locale-modules := ctypedump
lib-modules := error hash xmalloc

View File

@ -66,8 +66,19 @@ char *malloc ();
char *realloc ();
#endif
/* We used to test for `BSTRING' here, but only GCC and Emacs define
`BSTRING', as far as I know, and neither of them use this code. */
/* When used in Emacs's lib-src, we need to get bzero and bcopy somehow.
If nothing else has been done, use the method below. */
#ifdef INHIBIT_STRING_HEADER
#if !(defined (HAVE_BZERO) && defined (HAVE_BCOPY))
#if !defined (bzero) && !defined (bcopy)
#undef INHIBIT_STRING_HEADER
#endif
#endif
#endif
/* This is the normal way of making sure we have a bcopy and a bzero.
This is used in most programs--a few other programs avoid this
by defining INHIBIT_STRING_HEADER. */
#ifndef INHIBIT_STRING_HEADER
#if HAVE_STRING_H || STDC_HEADERS || defined (_LIBC)
#include <string.h>
@ -187,7 +198,7 @@ init_syntax_once ()
#define ISXDIGIT(c) (ISASCII (c) && isxdigit (c))
#ifndef NULL
#define NULL 0
#define NULL (void *)0
#endif
/* We remove any previous definition of `SIGN_EXTEND_CHAR',
@ -2760,7 +2771,7 @@ at_endline_loc_p (p, pend, syntax)
{
const char *next = p;
boolean next_backslash = *next == '\\';
const char *next_next = p + 1 < pend ? p + 1 : NULL;
const char *next_next = p + 1 < pend ? p + 1 : 0;
return
/* Before a subexpression? */

View File

@ -88,10 +88,22 @@ elf_machine_rel (struct link_map *map,
*reloc_addr = sym_value;
break;
case R_386_32:
if (map->l_type == lt_interpreter)
{
/* Undo the relocation done here during bootstrapping. Now we will
relocate it anew, possibly using a binding found in the user
program or a loaded library rather than the dynamic linker's
built-in definitions used while loading those libraries. */
const Elf32_Sym *const dlsymtab
= (void *) (map->l_addr + map->l_info[DT_SYMTAB]->d_un.d_ptr);
*reloc_addr -= (map->l_addr +
dlsymtab[ELF32_R_SYM (reloc->r_info)].st_value);
}
*reloc_addr += sym_value;
break;
case R_386_RELATIVE:
*reloc_addr += map->l_addr;
if (map->l_type != lt_interpreter) /* Already done in dynamic linker. */
*reloc_addr += map->l_addr;
break;
case R_386_PC32:
*reloc_addr = sym_value - (Elf32_Addr) reloc_addr;
@ -142,6 +154,12 @@ elf_machine_runtime_setup (struct link_map *l)
}
/* Mask identifying addresses reserved for the user program,
where the dynamic linker should not map anything. */
#define ELF_MACHINE_USER_ADDRESS_MASK 0xf8000000UL
/* Initial entry point code for the dynamic linker.
The C function `_dl_start' is the real entry point;
its return value is the user program's entry point. */

View File

@ -54,8 +54,9 @@ _dl_runtime_resolve (Elf32_Word reloc_offset)
real_next = l->l_next;
if (l->l_info[DT_SYMBOLIC])
{
l->l_prev->l_next = real_next;
l->l_next = _dl_loaded;
if (l->l_prev)
l->l_prev->l_next = real_next;
scope = l;
}
else
@ -67,7 +68,8 @@ _dl_runtime_resolve (Elf32_Word reloc_offset)
/* Restore list frobnication done above for DT_SYMBOLIC. */
l->l_next = real_next;
l->l_prev->l_next = l;
if (l->l_prev)
l->l_prev->l_next = l;
/* Apply the relocation with that value. */
elf_machine_rel (l, reloc, loadbase, definer);

View File

@ -44,6 +44,36 @@ extern char **_environ;
struct hurd_startup_data *_dl_hurd_data;
unsigned int __hurd_threadvar_max = _HURD_THREADVAR_MAX;
static unsigned long int threadvars[_HURD_THREADVAR_MAX];
unsigned long int __hurd_threadvar_stack_offset
= (unsigned long int) &threadvars;
/* XXX loser kludge for vm_map kernel bug */
static vm_address_t fmha;
static vm_size_t fmhs;
static void unfmh(){
__vm_deallocate(__mach_task_self(),fmha,fmhs);}
static void fmh() {
error_t err;int x;mach_port_t p;
vm_address_t a=0x08000000U,max=VM_MAX_ADDRESS;
while (!(err=__vm_region(__mach_task_self(),&a,&fmhs,&x,&x,&x,&x,&p,&x))){
__mach_port_deallocate(__mach_task_self(),p);
if (a+fmhs>=0x80000000U){
max=a;break;}
fmha=a+=fmhs;}
if (err) assert(err==KERN_NO_SPACE);
fmhs=max-fmha;
err = __vm_map (__mach_task_self (),
&fmha, fmhs, 0, 0, MACH_PORT_NULL, 0, 1,
VM_PROT_NONE, VM_PROT_NONE, VM_INHERIT_COPY);
assert_perror(err);
}
/* XXX loser kludge for vm_map kernel bug */
Elf32_Addr
_dl_sysdep_start (void **start_argptr,
void (*dl_main) (const Elf32_Phdr *phdr, Elf32_Word phent,
@ -62,6 +92,7 @@ _dl_sysdep_start (void **start_argptr,
_dl_secure = _dl_hurd_data->flags & EXEC_SECURE;
unfmh(); /* XXX */
/* Call elf/rtld.c's main program. It will set everything
up and leave us to transfer control to USER_ENTRY. */
(*dl_main) ((const Elf32_Phdr *) _dl_hurd_data->phdr,
@ -85,6 +116,8 @@ _dl_sysdep_start (void **start_argptr,
/* Set up so we can do RPCs. */
__mach_init ();
fmh(); /* XXX */
/* See hurd/hurdstartup.c; this deals with getting information
from the exec server and slicing up the arguments.
Then it will call `go', above. */
@ -92,22 +125,6 @@ _dl_sysdep_start (void **start_argptr,
LOSE;
}
/* This is called when all other dynamic linking is finished, before the
dynamic linker re-relocates itself when ld.so itself appears in a
DT_NEEDED entry. It is called whether of not ld.so is being linked in.
We take this opportunity to deallocate the reply port and task-self send
right user reference we have acquired, since they will not be used again
before the library and user code runs. The C library will acquire its
own ports in its initialization. */
void
_dl_sysdep_prepare_for_ld_reloc (void)
{
__mig_dealloc_reply_port (__mig_get_reply_port ());
__mach_port_deallocate (__mach_task_self (), __mach_task_self ());
}
int
_dl_sysdep_open_zero_fill (void)
@ -415,7 +432,7 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t offset)
mapaddr = (vm_address_t) addr;
errno = __vm_map (__mach_task_self (),
&mapaddr, (vm_size_t) len, (vm_address_t) 0,
&mapaddr, (vm_size_t) len, 0 /*ELF_MACHINE_USER_ADDRESS_MASK*/,
!(flags & MAP_FIXED),
(mach_port_t) fd, (vm_offset_t) offset,
flags & (MAP_COPY|MAP_PRIVATE),