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 <[EMAIL PROTECTED]> diff -purN libhugetlbfs-20060828/elflink.c libhugetlbfs-ldpreload/elflink.c --- libhugetlbfs-20060828/elflink.c 2006-08-28 08:02:18.000000000 -0700 +++ libhugetlbfs-ldpreload/elflink.c 2006-08-29 11:18:41.000000000 -0700 @@ -496,24 +496,22 @@ static int maybe_prepare(int fd_state, s 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) __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) { -- Adam Litke - (agl at us.ibm.com) IBM Linux Technology Center ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel