elf: remove long-since-obsolete shallow module machinery
authorH. Peter Anvin <hpa@linux.intel.com>
Fri, 18 Jan 2013 00:52:20 +0000 (16:52 -0800)
committerH. Peter Anvin <hpa@linux.intel.com>
Fri, 18 Jan 2013 00:52:20 +0000 (16:52 -0800)
Meant to handle symbols exported from the core, but we just
pregenerate the dynamic section instead.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
com32/include/sys/exec.h
com32/include/sys/module.h
com32/lib/Makefile
com32/lib/sys/module/exec.c
com32/lib/sys/module/shallow_module.c [deleted file]
core/elflink/load_env32.c

index ac05c27..f4559d1 100644 (file)
 extern int spawn_load(const char *name, int argc, char **argv);
 
 /**
- * exec_init - Initialize the dynamic execution environment.
- *
- * Among others, it initializes the module subsystem and loads the root
- * module into memory. You should note the difference between the module
- * management API, and the execution API:
- *  - the module system is a static one - it only manages the data structures
- *  and their relationship. It does not describe the way modules are executed,
- *  when and how they are loaded/unloaded, etc. It acts as a service layer for
- *  the execution API.
- *  - the execution environment is the dynamic part of the SYSLINUX dynamic
- *  module API - it implements the behavior of the modules: it
- *  triggers the execution of initialization and termination functions for
- *  libraries, executes the modules marked as executable, handles dynamic
- *  memory cleanup, etc. In other words, at this layer the code and data
- *  loaded by the lower module layer gets to be executed by the CPU,
- *  thus becoming part of the SYSLINUX environment.
- */
-extern int exec_init(void);
-
-
-/**
  * spawnv - Executes a program in the current environment.
  * @name:      the name of the program to spawn, including the extension
  *                     (e.g. 'hello.c32')
index ea11a88..a18561a 100644 (file)
@@ -246,18 +246,6 @@ extern int module_load(struct elf_module *module);
 
 
 /**
- * module_load_shallow - loads a shallow ELF module into memory.
- * @module:    the module descriptor returned by module_alloc.
- *
- * The function reads the module file, checks whether the file has a valid
- * structure, then loads into memory the module metadata. The metadata currently
- * contains a symbol table that describes code & data allocated by other means.
- * Its current use is to describe the root COM32 module to the rest of the
- * module subsystem.
- */
-extern int module_load_shallow(struct elf_module *module, Elf32_Addr base_addr);
-
-/**
  * module_unload - unloads the module from the system.
  * @module: the module descriptor structure.
  *
index dd1ef7c..d979ab4 100644 (file)
@@ -86,7 +86,7 @@ LIBENTRY_OBJS = \
 
 LIBMODULE_OBJS = \
        sys/module/common.o sys/module/elf_module.o             \
-       sys/module/shallow_module.o     sys/module/elfutils.o   \
+       sys/module/elfutils.o                                   \
        sys/module/exec.o
 
 LIBGCC_OBJS = \
index ac9ca79..2b3a4c0 100644 (file)
 
 #define DBG_PRINT(fmt, args...) dprintf("[EXEC] " fmt, ##args)
 
-static struct elf_module    *mod_root = NULL;
 struct elf_module *__syslinux_current = NULL;
 
-int exec_init(void)
-{
-       int res;
-
-       res = modules_init();
-       if (res != 0)
-               return res;
-
-       // Load the root module
-       mod_root = module_alloc(EXEC_ROOT_NAME);
-
-       if (mod_root == NULL)
-               return -1;
-
-       res = module_load_shallow(mod_root, 0);
-       if (res != 0) {
-               mod_root = NULL;
-               return res;
-       }
-
-       return 0;
-}
-
 int get_module_type(struct elf_module *module)
 {
        if(module->main_func) return EXEC_MODULE;
diff --git a/com32/lib/sys/module/shallow_module.c b/com32/lib/sys/module/shallow_module.c
deleted file mode 100644 (file)
index 8a88e40..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * shallow_module.c
- *
- *  Created on: Aug 11, 2008
- *      Author: Stefan Bucur <stefanb@zytor.com>
- */
-
-
-#include <string.h>
-#include <sys/module.h>
-
-#include "common.h"
-#include "elfutils.h"
-
-
-static int check_header_shallow(Elf32_Ehdr *elf_hdr) {
-       int res;
-
-       res = check_header_common(elf_hdr);
-
-       if (res != 0)
-               return res;
-
-       if (elf_hdr->e_shoff == 0x00000000) {
-               DBG_PRINT("SHT missing\n");
-               return -1;
-       }
-
-       return 0;
-}
-
-static int load_shallow_sections(struct elf_module *module, Elf32_Ehdr *elf_hdr) {
-       int i;
-       int res = 0;
-       char *sht = NULL;
-       char *buffer = NULL;
-       Elf32_Shdr *crt_sht;
-       Elf32_Off buff_offset;
-
-       Elf32_Off min_offset = 0xFFFFFFFF;
-       Elf32_Off max_offset = 0x00000000;
-       Elf32_Word max_align = 0x1;
-
-       Elf32_Off sym_offset = 0xFFFFFFFF;
-       Elf32_Off str_offset = 0xFFFFFFFF;
-
-
-       char *sh_strtable;
-
-       // We buffer the data up to the SHT
-       buff_offset = module->u.l._cr_offset;
-
-       buffer = malloc(elf_hdr->e_shoff - buff_offset);
-       // Get to the SHT
-       image_read(buffer, elf_hdr->e_shoff - buff_offset, module);
-
-       // Load the SHT
-       sht = malloc(elf_hdr->e_shnum * elf_hdr->e_shentsize);
-       image_read(sht, elf_hdr->e_shnum * elf_hdr->e_shentsize, module);
-
-       // Get the string table of the section names
-       crt_sht = (Elf32_Shdr*)(sht + elf_hdr->e_shstrndx * elf_hdr->e_shentsize);
-       sh_strtable = (char*)(buffer + (crt_sht->sh_offset - buff_offset));
-
-       for (i = 0; i < elf_hdr->e_shnum; i++) {
-               crt_sht = (Elf32_Shdr*)(sht + i*elf_hdr->e_shentsize);
-
-               if (strcmp(".symtab", sh_strtable + crt_sht->sh_name) == 0) {
-                       // We found the symbol table
-                       min_offset = MIN(min_offset, crt_sht->sh_offset);
-                       max_offset = MAX(max_offset, crt_sht->sh_offset + crt_sht->sh_size);
-                       max_align = MAX(max_align, crt_sht->sh_addralign);
-
-                       sym_offset = crt_sht->sh_offset;
-
-                       module->syment_size = crt_sht->sh_entsize;
-                       module->symtable_size = crt_sht->sh_size / crt_sht->sh_entsize;
-               }
-               if (strcmp(".strtab", sh_strtable + crt_sht->sh_name) == 0) {
-                       // We found the string table
-                       min_offset = MIN(min_offset, crt_sht->sh_offset);
-                       max_offset = MAX(max_offset, crt_sht->sh_offset + crt_sht->sh_size);
-                       max_align = MAX(max_align, crt_sht->sh_addralign);
-
-                       str_offset = crt_sht->sh_offset;
-
-                       module->strtable_size = crt_sht->sh_size;
-               }
-       }
-
-       if (elf_malloc(&module->module_addr, max_align,
-                       max_offset - min_offset) != 0) {
-               DBG_PRINT("Could not allocate sections\n");
-               goto out;
-       }
-
-       // Copy the data
-       image_seek(min_offset, module);
-       image_read(module->module_addr, max_offset - min_offset, module);
-
-       // Setup module information
-       module->module_size = max_offset - min_offset;
-       module->str_table = (char *)module->module_addr + (str_offset - min_offset);
-       module->sym_table = (char *)module->module_addr + (sym_offset - min_offset);
-
-out:
-       // Release the SHT
-       if (sht != NULL)
-               free(sht);
-
-       // Release the buffer
-       if (buffer != NULL)
-               free(buffer);
-
-       return res;
-}
-
-
-int module_load_shallow(struct elf_module *module, Elf32_Addr base_addr) {
-       int res;
-       Elf32_Ehdr elf_hdr;
-
-       // Do not allow duplicate modules
-       if (module_find(module->name) != NULL) {
-               DBG_PRINT("Module already loaded.\n");
-               return -1;
-       }
-
-       res = image_load(module);
-
-       if (res < 0)
-               return res;
-
-       module->shallow = 1;
-
-       CHECKED(res, image_read(&elf_hdr, sizeof(Elf32_Ehdr), module), error);
-
-       // Checking the header signature and members
-       CHECKED(res, check_header_shallow(&elf_hdr), error);
-
-       CHECKED(res, load_shallow_sections(module, &elf_hdr), error);
-       module->base_addr = base_addr;
-
-       // Check the symbols for duplicates / missing definitions
-       CHECKED(res, check_symbols(module), error);
-
-       // Add the module at the beginning of the module list
-       list_add(&module->list, &modules_head);
-
-       // The file image is no longer needed
-       image_unload(module);
-
-       DBG_PRINT("SHALLOW MODULE %s LOADED SUCCESSFULLY\n", module->name);
-
-       return 0;
-
-error:
-       image_unload(module);
-
-       return res;
-}
index 7c0afac..7a6b08f 100644 (file)
@@ -50,10 +50,10 @@ struct elf_module core_module = {
 };
 
 /*
-       Initializes the module subsystem by taking the core module ( shallow module ) and placing
-       it on top of the modules_head_list. Since the core module is initialized when declared
-       we technically don't need the exec_init() and module_load_shallow() procedures
-*/
+ * Initializes the module subsystem by taking the core module
+ * (preinitialized shallow module) and placing it on top of the
+ * modules_head_list.
+ */
 void init_module_subsystem(struct elf_module *module)
 {
     list_add(&module->list, &modules_head);