[syslinux:elflink] elflink: change the exit.c, remove the exit.S to make process exit working

syslinux-bot for Feng Tang feng.tang at intel.com
Thu Aug 12 21:03:14 PDT 2010


Commit-ID:  71d5d1ba646e676cf1faf394e0d54950e416fe1c
Gitweb:     http://syslinux.zytor.com/commit/71d5d1ba646e676cf1faf394e0d54950e416fe1c
Author:     Feng Tang <feng.tang at intel.com>
AuthorDate: Thu, 17 Jun 2010 17:09:30 +0800
Committer:  Feng Tang <feng.tang at intel.com>
CommitDate: Tue, 20 Jul 2010 11:10:03 +0800

elflink: change the exit.c, remove the exit.S to make process exit working

following elflink branch


---
 com32/lib/MCONFIG                 |    2 +-
 com32/lib/Makefile                |    2 +-
 com32/lib/exit.c                  |   24 +++++++++++++++++++--
 com32/lib/sys/exit.S              |   41 -------------------------------------
 com32/lib/sys/module/elf_module.c |    5 +--
 com32/lib/sys/module/exec.c       |    1 +
 6 files changed, 26 insertions(+), 49 deletions(-)

diff --git a/com32/lib/MCONFIG b/com32/lib/MCONFIG
index 44278bd..c441c9c 100644
--- a/com32/lib/MCONFIG
+++ b/com32/lib/MCONFIG
@@ -38,7 +38,7 @@ OPTFLAGS  = -Os -march=i386 -falign-functions=0 -falign-jumps=0 \
 WARNFLAGS = $(GCCWARN) -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Winline
 
 CFLAGS  = $(OPTFLAGS) $(REQFLAGS) $(WARNFLAGS) $(LIBFLAGS)
-LDFLAGS	= -m elf32_i386
+LDFLAGS	= -m elf32_i386 --hash-style=gnu
 
 .SUFFIXES: .c .o .a .so .lo .i .S .s .ls .ss .lss
 
diff --git a/com32/lib/Makefile b/com32/lib/Makefile
index f53c2c2..2c15b9d 100755
--- a/com32/lib/Makefile
+++ b/com32/lib/Makefile
@@ -68,7 +68,7 @@ DYNENTRY_OBJS = \
 ## CORE OBJECTS, INCLUDED IN THE ROOT COM32 MODULE
 LIBENTRY_OBJS = \
 	sys/intcall.o sys/farcall.o sys/cfarcall.o sys/zeroregs.o	\
-	sys/argv.o sys/exit.o 							\
+	sys/argv.o							\
 	sys/fileinfo.o sys/opendev.o sys/read.o sys/write.o sys/ftell.o \
 	sys/close.o sys/open.o sys/fileread.o sys/fileclose.o		\
 	sys/openmem.o					\
diff --git a/com32/lib/exit.c b/com32/lib/exit.c
index ccd6f1e..cba6cee 100644
--- a/com32/lib/exit.c
+++ b/com32/lib/exit.c
@@ -31,11 +31,29 @@
  * The regular exit
  */
 
+#include <sys/module.h>
 #include <stdlib.h>
-
-extern __noreturn(*__exit_handler) (int);
+#include <unistd.h>
+#include "atexit.h"
 
 __noreturn exit(int rv)
 {
-    __exit_handler(rv);
+	struct atexit *ap;
+
+    for (ap = __syslinux_current->u.x.atexit_list; ap; ap = ap->next) {
+	ap->fctn(rv, ap->arg);	/* This assumes extra args are harmless */
+    }
+
+    _exit(rv);
+}    
+
+__noreturn _Exit(int rv)
+{
+    _exit(rv);
 }
+
+__noreturn _exit(int rv)
+{
+    longjmp(__syslinux_current->u.x.process_exit, rv+1);
+}
+
diff --git a/com32/lib/sys/exit.S b/com32/lib/sys/exit.S
deleted file mode 100644
index 2ab8012..0000000
--- a/com32/lib/sys/exit.S
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Implementation of _exit() for com32 based on c32entry.S
- */
-	.text
-
-	.globl _Exit
-	.type _Exit, @function
-_Exit:
-	/* Just fall through to _exit */
-	.size _Exit, .-_Exit
-
-	.globl _exit
-	.type _exit, @function
-_exit:
-#ifdef REGPARM
-	pushl %eax
-#endif
-
-	/* Run any destructors */
-	movl $__dtors_start, %esi
-2:
-	cmpl $__dtors_end, %esi
-	jae 1f
-	call *(%esi)
-	addl $4,%esi
-	jmp 2b
-
-1:
-#ifdef REGPARM
-	popl %eax
-#else
-	movl 4(%esp),%eax		# Exit code in %eax = return value
-#endif
-	movl (__entry_esp),%esp		# Return stack pointer to entry value
-	ret				# Return to termination address
-	.size _exit, .-_exit
-
-	.data
-__exit_handler:
-	.globl __exit_handler
-	.long _exit
diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c
index 187dfee..26705df 100755
--- a/com32/lib/sys/module/elf_module.c
+++ b/com32/lib/sys/module/elf_module.c
@@ -462,7 +462,7 @@ int module_load(struct elf_module *module) {
 	CHECKED(res, prepare_dynlinking(module), error);
 	//printf("check... 4\n");
 	//
-	dump_elf_module(module);
+	//dump_elf_module(module);
 
 	// Check the symbols for duplicates / missing definitions
 	CHECKED(res, check_symbols(module), error);
@@ -486,13 +486,12 @@ int module_load(struct elf_module *module) {
 	image_unload(module);
 
 	/*
-	*/
 	DBG_PRINT("MODULE %s LOADED SUCCESSFULLY (main@%p, init@%p, exit@%p)\n",
 			module->name,
 			(module->main_func == NULL) ? NULL : *(module->main_func),
 			(module->init_func == NULL) ? NULL : *(module->init_func),
 			(module->exit_func == NULL) ? NULL : *(module->exit_func));
-
+	*/
 	return 0;
 
 error:
diff --git a/com32/lib/sys/module/exec.c b/com32/lib/sys/module/exec.c
index d6942a9..8204ee4 100644
--- a/com32/lib/sys/module/exec.c
+++ b/com32/lib/sys/module/exec.c
@@ -306,6 +306,7 @@ int spawn_load(const char *name,const char **argv)
 		else
 			exit((*module->main_func)(argc, args)); /* Actually run! */
 
+
 		// Clean up the allocation context
 		//__free_tagged(module);
 		// Restore the allocation context



More information about the Syslinux-commits mailing list