summaryrefslogtreecommitdiffstats
path: root/libexec
diff options
context:
space:
mode:
authorrdivacky <rdivacky@FreeBSD.org>2010-05-18 08:55:23 +0000
committerrdivacky <rdivacky@FreeBSD.org>2010-05-18 08:55:23 +0000
commit7f3f7db3798a4d71f451d4eede04bcd6f9bec96b (patch)
tree7fc7f07db9e35a3b666f265dc0bf57e5ecb0d5ee /libexec
parentfb4f09998080bd2fa70c75879bedb4dfef12a265 (diff)
downloadFreeBSD-src-7f3f7db3798a4d71f451d4eede04bcd6f9bec96b.zip
FreeBSD-src-7f3f7db3798a4d71f451d4eede04bcd6f9bec96b.tar.gz
Only use the cache after the early stage of loading. This is
because calling mmap() etc. may use GOT which is not set up yet. Use calloc() instead of mmap() in cases where this was the case before (sparc64, powerpc, arm). Submitted by: Dimitry Andric (dimitry andric com) Reviewed by: kan Approved by: ed (mentor)
Diffstat (limited to 'libexec')
-rw-r--r--libexec/rtld-elf/amd64/reloc.c11
-rw-r--r--libexec/rtld-elf/arm/reloc.c13
-rw-r--r--libexec/rtld-elf/i386/reloc.c11
-rw-r--r--libexec/rtld-elf/powerpc/reloc.c12
-rw-r--r--libexec/rtld-elf/rtld.c4
-rw-r--r--libexec/rtld-elf/sparc64/reloc.c11
6 files changed, 29 insertions, 33 deletions
diff --git a/libexec/rtld-elf/amd64/reloc.c b/libexec/rtld-elf/amd64/reloc.c
index 8a32adf..9e8c694 100644
--- a/libexec/rtld-elf/amd64/reloc.c
+++ b/libexec/rtld-elf/amd64/reloc.c
@@ -118,15 +118,16 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
const Elf_Rela *relalim;
const Elf_Rela *rela;
SymCache *cache;
- int bytes = obj->nchains * 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)
+ if (obj != obj_rtld) {
+ cache = calloc(obj->nchains, sizeof(SymCache));
+ /* No need to check for NULL here */
+ } else
cache = NULL;
relalim = (const Elf_Rela *) ((caddr_t) obj->rela + obj->relasize);
@@ -322,8 +323,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
}
r = 0;
done:
- if (cache)
- munmap(cache, bytes);
+ if (cache != NULL)
+ free(cache);
return(r);
}
diff --git a/libexec/rtld-elf/arm/reloc.c b/libexec/rtld-elf/arm/reloc.c
index e383892..6ad80fd 100644
--- a/libexec/rtld-elf/arm/reloc.c
+++ b/libexec/rtld-elf/arm/reloc.c
@@ -245,7 +245,6 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
const Elf_Rel *rellim;
const Elf_Rel *rel;
SymCache *cache;
- int bytes = obj->nchains * sizeof(SymCache);
int r = -1;
/* The relocation for the dynamic loader has already been done. */
@@ -255,10 +254,9 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
* 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;
-
+ cache = calloc(obj->nchains, sizeof(SymCache));
+ /* No need to check for NULL here */
+
rellim = (const Elf_Rel *)((caddr_t)obj->rel + obj->relsize);
for (rel = obj->rel; rel < rellim; rel++) {
if (reloc_nonplt_object(obj, rel, cache) < 0)
@@ -266,9 +264,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
}
r = 0;
done:
- if (cache) {
- munmap(cache, bytes);
- }
+ if (cache != NULL)
+ free(cache);
return (r);
}
diff --git a/libexec/rtld-elf/i386/reloc.c b/libexec/rtld-elf/i386/reloc.c
index ec83bff..818d2eb 100644
--- a/libexec/rtld-elf/i386/reloc.c
+++ b/libexec/rtld-elf/i386/reloc.c
@@ -119,15 +119,16 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
const Elf_Rel *rellim;
const Elf_Rel *rel;
SymCache *cache;
- int bytes = obj->nchains * 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)
+ if (obj != obj_rtld) {
+ cache = calloc(obj->nchains, sizeof(SymCache));
+ /* No need to check for NULL here */
+ } else
cache = NULL;
rellim = (const Elf_Rel *) ((caddr_t) obj->rel + obj->relsize);
@@ -273,8 +274,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
}
r = 0;
done:
- if (cache)
- munmap(cache, bytes);
+ if (cache != NULL)
+ free(cache);
return(r);
}
diff --git a/libexec/rtld-elf/powerpc/reloc.c b/libexec/rtld-elf/powerpc/reloc.c
index ccdcd90..c90852f 100644
--- a/libexec/rtld-elf/powerpc/reloc.c
+++ b/libexec/rtld-elf/powerpc/reloc.c
@@ -287,7 +287,6 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
const Elf_Rela *relalim;
const Elf_Rela *rela;
SymCache *cache;
- int bytes = obj->nchains * sizeof(SymCache);
int r = -1;
/*
@@ -295,10 +294,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
* limited amounts of stack available so we cannot use alloca().
*/
if (obj != obj_rtld) {
- cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON,
- -1, 0);
- if (cache == MAP_FAILED)
- cache = NULL;
+ cache = calloc(obj->nchains, sizeof(SymCache));
+ /* No need to check for NULL here */
} else
cache = NULL;
@@ -314,9 +311,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
}
r = 0;
done:
- if (cache) {
- munmap(cache, bytes);
- }
+ if (cache != NULL)
+ free(cache);
return (r);
}
diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index cb1002c..c303483 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -3311,6 +3311,10 @@ allocate_module_tls(int index)
}
p = malloc(obj->tlssize);
+ if (p == NULL) {
+ _rtld_error("Cannot allocate TLS block for index %d", index);
+ die();
+ }
memcpy(p, obj->tlsinit, obj->tlsinitsize);
memset(p + obj->tlsinitsize, 0, obj->tlssize - obj->tlsinitsize);
diff --git a/libexec/rtld-elf/sparc64/reloc.c b/libexec/rtld-elf/sparc64/reloc.c
index 23b73dd..1b8f1fd 100644
--- a/libexec/rtld-elf/sparc64/reloc.c
+++ b/libexec/rtld-elf/sparc64/reloc.c
@@ -254,7 +254,6 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
const Elf_Rela *relalim;
const Elf_Rela *rela;
SymCache *cache;
- int bytes = obj->nchains * sizeof(SymCache);
int r = -1;
/*
@@ -262,10 +261,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
* limited amounts of stack available so we cannot use alloca().
*/
if (obj != obj_rtld) {
- cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON,
- -1, 0);
- if (cache == MAP_FAILED)
- cache = NULL;
+ cache = calloc(obj->nchains, sizeof(SymCache));
+ /* No need to check for NULL here */
} else
cache = NULL;
@@ -276,8 +273,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
}
r = 0;
done:
- if (cache)
- munmap(cache, bytes);
+ if (cache != NULL)
+ free(cache);
return (r);
}
OpenPOWER on IntegriCloud