aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraglitke <aglitke@aglitke.localdomain>2006-08-29 13:49:21 -0500
committeraglitke <aglitke@aglitke.localdomain>2006-08-29 13:49:21 -0500
commitf70a04643203ba49f157a7a6189a6159b1501c2b (patch)
tree34d50ff5e394ca6903ca9f912b585ce48305f024
parentc5086d13801ca0b1b104882dc614fa58dbd62904 (diff)
downloadlibhugetlbfs-f70a04643203ba49f157a7a6189a6159b1501c2b.tar.gz
elflink: Disable segment remapping when libhugetlbfs is preloadeddev-20060829-1
One of our testers has been hitting the following problem: When running an application linked against a libhugetlbfs-provided linker script, LD_PRELOAD=libhugetlbfs.so is accidentally set. The library incorrectly tries to perform remapping, which results in an application segfault. We must add extra checking to handle this case since our normal method of disabling segment remapping won't work in this scenario. This patch checks for "libhugetlbfs" in the LD_PRELOAD environment variable. If found, remapping is disabled and the user is warned. With the addition of an additional environment check, I felt it was time to move them into a separate function. Signed-off-by: Adam Litke <agl@us.ibm.com> Acked-by: Nishanth Aravamudan <nacc@us.ibm.com>
-rw-r--r--elflink.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/elflink.c b/elflink.c
index 3df207d..37bd6e7 100644
--- a/elflink.c
+++ b/elflink.c
@@ -496,24 +496,22 @@ static int maybe_prepare(int fd_state, struct seg_info *seg)
return ret;
}
-static void __attribute__ ((constructor)) setup_elflink(void)
+static int check_env(void)
{
- extern Elf_Ehdr __executable_start __attribute__((weak));
- ehdr = &__executable_start;
char *env;
- int ret, i;
env = getenv("HUGETLB_ELFMAP");
if (env && (strcasecmp(env, "no") == 0)) {
DEBUG("HUGETLB_ELFMAP=%s, not attempting to remap program "
"segments\n", env);
- return;
+ return -1;
}
- if (! ehdr) {
- DEBUG("Couldn't locate __executable_start, "
- "not attempting to remap segments\n");
- return;
+ env = getenv("LD_PRELOAD");
+ if (env && strstr(env, "libhugetlbfs")) {
+ ERROR("LD_PRELOAD is incompatible with segment remapping\n");
+ ERROR("Segment remapping has been DISABLED\n");
+ return -1;
}
env = getenv("HUGETLB_MINIMAL_COPY");
@@ -529,6 +527,24 @@ static void __attribute__ ((constructor)) setup_elflink(void)
__debug = 1;
}
+ return 0;
+}
+
+static void __attribute__ ((constructor)) setup_elflink(void)
+{
+ extern Elf_Ehdr __executable_start __attribute__((weak));
+ ehdr = &__executable_start;
+ int ret, i;
+
+ if (! ehdr) {
+ DEBUG("Couldn't locate __executable_start, "
+ "not attempting to remap segments\n");
+ return;
+ }
+
+ if (check_env())
+ return;
+
parse_phdrs(ehdr);
if (htlb_num_segs == 0) {