From ff7a89cdec58567f9e0cd48005ddede6f1f771cd Mon Sep 17 00:00:00 2001 From: Chia-Che Tsai Date: Fri, 5 Dec 2014 09:53:14 -0500 Subject: [PATCH] Fix robust list behavior Reorganize platform-independent code in PAL --- LibOS/shim/src/bookkeep/shim_thread.c | 1 + LibOS/shim/src/sys/shim_exec.c | 2 ++ .../test/apps/python/python.manifest.template | 6 +++- Pal/lib/Makefile | 4 +-- Pal/src/Makefile | 29 ++++++++++--------- Pal/src/db_rtld.c | 4 +-- Pal/src/dl-machine-x86_64.h | 4 +-- Pal/src/host/Linux/db_rtld.c | 2 +- Pal/src/host/Skeleton/db_rtld.c | 2 +- 9 files changed, 32 insertions(+), 22 deletions(-) diff --git a/LibOS/shim/src/bookkeep/shim_thread.c b/LibOS/shim/src/bookkeep/shim_thread.c index be077d74..f7f595b9 100644 --- a/LibOS/shim/src/bookkeep/shim_thread.c +++ b/LibOS/shim/src/bookkeep/shim_thread.c @@ -645,6 +645,7 @@ MIGRATE_FUNC_BODY(thread) new_thread->handle_map = NULL; new_thread->root = NULL; new_thread->cwd = NULL; + new_thread->robust_list = NULL; if (!recursive) new_thread->tcb = NULL; diff --git a/LibOS/shim/src/sys/shim_exec.c b/LibOS/shim/src/sys/shim_exec.c index af033731..75449b8d 100644 --- a/LibOS/shim/src/sys/shim_exec.c +++ b/LibOS/shim/src/sys/shim_exec.c @@ -136,6 +136,8 @@ int shim_do_execve_rtld (struct shim_handle * hdl, const char ** argv, SAVE_PROFILE_INTERVAL(load_new_executable_for_exec); + cur_thread->robust_list = NULL; + debug("execve: start execution\n"); execute_elf_object(cur_thread->exec, new_argc, new_argp, REQUIRED_ELF_AUXV, new_auxp); diff --git a/LibOS/shim/test/apps/python/python.manifest.template b/LibOS/shim/test/apps/python/python.manifest.template index 23e1a5d0..49024d7f 100644 --- a/LibOS/shim/test/apps/python/python.manifest.template +++ b/LibOS/shim/test/apps/python/python.manifest.template @@ -4,7 +4,7 @@ loader.preload = file:$(SHIMPATH) loader.exec = file:/usr/bin/python loader.execname = python loader.env.LD_LIBRARY_PATH = /lib:/lib/x86_64-linux-gnu:/usr/lib:/usr/lib/x86_64-linux-gnu -loader.env.PATH = /usr/bin +loader.env.PATH = /usr/bin:/bin loader.env.USERNAME = loader.env.HOME = loader.env.PWD = @@ -21,6 +21,10 @@ fs.mount.other.lib2.type = chroot fs.mount.other.lib2.path = /lib/x86_64-linux-gnu fs.mount.other.lib2.uri = file:/lib/x86_64-linux-gnu +fs.mount.other.bin.type = chroot +fs.mount.other.bin.path = /bin +fs.mount.other.bin.uri = file:/bin + fs.mount.other.usr.type = chroot fs.mount.other.usr.path = /usr fs.mount.other.usr.uri = file:/usr diff --git a/Pal/lib/Makefile b/Pal/lib/Makefile index 5d66fb02..7e0c7f6b 100644 --- a/Pal/lib/Makefile +++ b/Pal/lib/Makefile @@ -5,12 +5,12 @@ AR = ar rcs CFLAGS = -Wall -fPIC -O2 -std=gnu99 -fgnu89-inline -U_FORTIFY_SOURCE \ -fno-omit-frame-pointer \ - -fno-stack-protector -fno-builtin \ - -I. -I../include + -fno-stack-protector -fno-builtin ARFLAGS = include ../src/host/$(OS)/Makefile.am +CFLAGS += -I. -I../include subdirs = string stdlib network graphene objs = $(foreach dir,$(subdirs),$(patsubst %.c,%.o,$(wildcard $(dir)/*.c))) headers = asm-errlist.h api.h diff --git a/Pal/src/Makefile b/Pal/src/Makefile index 24d2a44b..13edb1a2 100644 --- a/Pal/src/Makefile +++ b/Pal/src/Makefile @@ -8,17 +8,20 @@ LD = ld CFLAGS = -Wall -fPIC -O2 -std=gnu99 -fgnu89-inline -U_FORTIFY_SOURCE \ -fno-omit-frame-pointer \ - -fno-stack-protector -fno-builtin \ - -I. -I../include -Ihost/$(OS) -I../lib + -fno-stack-protector -fno-builtin LDFLAGS = -shared -nostdlib --version-script pal.map -z combreloc -z defs \ -T pal.lds ARFLAGS = -pal_target = libpal.a libpal.so +pal_loader = libpal.so +pal_lib = libpal.a include host/$(OS)/Makefile.am -defs = -DIN_PAL +CFLAGS += -I. -I../include -Ihost/$(OS) -I../lib + +pal_target = $(pal_loader) $(pal_lib) +defs = -DIN_PAL -DSRCDIR="$(PWD)/" objs = $(addprefix db_,streams memory threading semaphore events process \ object main misc ipc exception rtld) slab printf graphene_lib = ../lib/graphene-lib.a @@ -43,14 +46,14 @@ $(host_lib): security: @[ ! -d security/$(OS) ] || make -C security/$(OS) $(debug) -libpal.so: $(addsuffix .o,$(objs)) $(filter %.map %.lds,$(LDFLAGS)) \ - $(host_lib) $(graphene_lib) - @echo [ $@ ] - @$(LD) $(LDFLAGS) -o $@ $(filter-out %.map %.lds,$^) -soname=$@ +$(pal_loader): $(addsuffix .o,$(objs)) $(filter %.map %.lds,$(LDFLAGS)) \ + $(host_lib) $(graphene_lib) + @echo [ libpal.exe ] + $(LD) $(LDFLAGS) -o $@ $(filter-out %.map %.lds,$^) $(LDFLAGS-suffix) -libpal.a: $(addsuffix .o,$(objs)) $(host_lib) $(graphene_lib) +$(pal_lib): $(addsuffix .o,$(objs)) $(host_lib) $(graphene_lib) @echo [ $@ ] - @$(AR) $(ARFLAGS) $@ $^ + $(AR) $(ARFLAGS) $@ $^ $(ARFLAGS-suffix) %.asm: %.c $(headers) $(CC) $(CFLAGS) $(defs) -c $< -o $<.o @@ -59,13 +62,13 @@ libpal.a: $(addsuffix .o,$(objs)) $(host_lib) $(graphene_lib) %.o: %.c $(headers) @echo [ $@ ] - @$(CC) $(CFLAGS) $(defs) -c $< -o $@ + @$(CC) $(CFLAGS) $(defs) -c $< -o $@ $(CFLAGS-suffix) %.e: %.c $(headers) @echo [ $@ ] - @$(CC) $(CFLAGS) $(defs) -E $< -o $@ + @$(CC) $(CFLAGS) $(defs) -E $< -o $@ $(CFLAGS-suffix) clean: - rm -f $(addsuffix .o,$(objs)) $(pal_target) + rm -rf $(addsuffix .o,$(objs)) $(pal_target) @[ ! -d host/$(OS) ] || make -C host/$(OS) clean @[ ! -d security/$(OS) ] || make -C security/$(OS) clean diff --git a/Pal/src/db_rtld.c b/Pal/src/db_rtld.c index 679d3abc..591da1d2 100644 --- a/Pal/src/db_rtld.c +++ b/Pal/src/db_rtld.c @@ -98,9 +98,9 @@ static ElfW(Addr) resolve_map (const char **strtab, ElfW(Sym) ** ref) return 0; } -extern ElfW(Addr) resolve_map_in_rtld (ElfW(Sym) * ref); +extern ElfW(Addr) resolve_rtld (const char * sym_name); -#define RESOLVE_MAP_IN_RTLD(ref) resolve_map_in_rtld(ref) +#define RESOLVE_RTLD(sym_name) resolve_rtld(sym_name) #define RESOLVE_MAP(strtab, ref) resolve_map(strtab, ref) #include "dynamic_link.h" diff --git a/Pal/src/dl-machine-x86_64.h b/Pal/src/dl-machine-x86_64.h index 2b495946..c6938f52 100644 --- a/Pal/src/dl-machine-x86_64.h +++ b/Pal/src/dl-machine-x86_64.h @@ -98,9 +98,9 @@ elf_machine_rela (Elf64_Dyn **l_info, Elf64_Addr l_addr, #else Elf64_Sym *refsym = sym; Elf64_Addr value; - Elf64_Addr sym_map; + Elf64_Addr sym_map = 0; - value = RESOLVE_MAP_IN_RTLD(sym); + value = RESOLVE_RTLD(strtab + sym->st_name); if (value) { /* We can't handle a IRELEATIVE symbol if it's found in RTLD, diff --git a/Pal/src/host/Linux/db_rtld.c b/Pal/src/host/Linux/db_rtld.c index 85f54f30..394c5589 100644 --- a/Pal/src/host/Linux/db_rtld.c +++ b/Pal/src/host/Linux/db_rtld.c @@ -185,7 +185,7 @@ void setup_vdso_map (ElfW(Addr) addr) } #endif -ElfW(Addr) resolve_map_in_rtld (ElfW(Sym) * ref) +ElfW(Addr) resolve_rtld (const char * sym_name) { /* We are not using this, because in Linux we can rely on rtld_map to directly lookup symbols */ diff --git a/Pal/src/host/Skeleton/db_rtld.c b/Pal/src/host/Skeleton/db_rtld.c index 16e2dc64..966a10f0 100644 --- a/Pal/src/host/Skeleton/db_rtld.c +++ b/Pal/src/host/Skeleton/db_rtld.c @@ -39,7 +39,7 @@ #include #include -ElfW(Addr) resolve_map_in_rtld (ElfW(Sym) * ref) +ElfW(Addr) resolve_rtld (const char * sym_name) { /* Not yet implemented */ return 0;