aboutsummaryrefslogtreecommitdiffstats
path: root/com32/elflink
diff options
context:
space:
mode:
Diffstat (limited to 'com32/elflink')
-rw-r--r--com32/elflink/elf_module.c6
-rw-r--r--com32/elflink/elf_module.h8
-rw-r--r--com32/elflink/modules/Makefile100
-rw-r--r--com32/elflink/modules/hello.c29
4 files changed, 136 insertions, 7 deletions
diff --git a/com32/elflink/elf_module.c b/com32/elflink/elf_module.c
index 758a0631..fbd596e4 100644
--- a/com32/elflink/elf_module.c
+++ b/com32/elflink/elf_module.c
@@ -133,12 +133,12 @@ static int image_seek(Elf32_Off offset, struct elf_module *module) {
// Initialization of the module subsystem
-int modules_init() {
+int modules_init(void) {
return 0;
}
// Termination of the module subsystem
-void modules_term() {
+void modules_term(void) {
}
@@ -770,7 +770,7 @@ static int check_symbols(struct elf_module *module) {
if (strong_count > 0 && ELF32_ST_BIND(ref_sym->st_info) == STB_GLOBAL) {
// It's not an error - at relocation, the most recent symbol
// will be considered
- DBG_PRINT("Symbol %s is defined more than once\n", crt_name);
+ DBG_PRINT("Info: Symbol %s is defined more than once\n", crt_name);
}
}
}
diff --git a/com32/elflink/elf_module.h b/com32/elflink/elf_module.h
index b93dc0df..cdc2254f 100644
--- a/com32/elflink/elf_module.h
+++ b/com32/elflink/elf_module.h
@@ -16,8 +16,8 @@
#define MODULE_ELF_MACHINE EM_386
-typedef int (*module_init_func)();
-typedef void (*module_exit_func)();
+typedef int (*module_init_func)(void);
+typedef void (*module_exit_func)(void);
// Structure encapsulating a module loaded in memory
struct elf_module {
@@ -62,9 +62,9 @@ struct module_dep {
};
// Initialization of the module subsystem
-extern int modules_init();
+extern int modules_init(void);
// Termination of the module subsystem
-extern void modules_term();
+extern void modules_term(void);
// Allocates the structure for a new module
extern struct elf_module *module_alloc(const char *name);
diff --git a/com32/elflink/modules/Makefile b/com32/elflink/modules/Makefile
new file mode 100644
index 00000000..35958cf6
--- /dev/null
+++ b/com32/elflink/modules/Makefile
@@ -0,0 +1,100 @@
+## -----------------------------------------------------------------------
+##
+## Copyright 2001-2008 H. Peter Anvin - All Rights Reserved
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, Inc., 53 Temple Place Ste 330,
+## Boston MA 02111-1307, USA; either version 2 of the License, or
+## (at your option) any later version; incorporated herein by reference.
+##
+## -----------------------------------------------------------------------
+
+##
+## COM32 standard modules
+##
+
+TMPFILE = $(shell mktemp /tmp/gcc_ok.XXXXXX)
+CC = gcc
+
+gcc_ok = $(shell tmpf=$(TMPFILE); if $(CC) $(1) -c -x c /dev/null -o $$tmpf 2>/dev/null; \
+ then echo $(1); else echo $(2); fi; rm -f $$tmpf)
+
+M32 := $(call gcc_ok,-m32,) $(call gcc_ok,-fno-stack-protector,)
+
+LD = ld -m elf_i386
+AR = ar
+NASM = nasm
+NASMOPT = -O9999
+RANLIB = ranlib
+CFLAGS = $(M32) -mregparm=3 -DREGPARM=3 -W -Wall -march=i386 -Os \
+ -fomit-frame-pointer -D__COM32__ \
+ -nostdinc -iwithprefix include \
+ -I../../libutil/include -I../../include \
+ -Wp,-MT,$@,-MD,$(dir $@).$(notdir $@).d
+LNXCFLAGS = -W -Wall -O -g -I../libutil/include
+LNXSFLAGS = -g
+LNXLDFLAGS = -g
+SFLAGS = -D__COM32__ -march=i386
+LDFLAGS = -shared -T ../../lib/elf32.ld
+OBJCOPY = objcopy
+PPMTOLSS16 = ../ppmtolss16
+LIBGCC := $(shell $(CC) --print-libgcc)
+LIBS = $(LIBGCC)
+
+.SUFFIXES: .lss .c .o .dyn
+
+BINDIR = /usr/bin
+LIBDIR = /usr/lib
+DATADIR = /usr/share
+AUXDIR = $(DATADIR)/syslinux
+INCDIR = /usr/include
+COM32DIR = $(AUXDIR)/com32
+
+MODULES = hello.dyn
+
+TESTFILES =
+
+all: $(MODULES) $(TESTFILES)
+
+.PRECIOUS: %.o
+%.o: %.S
+ $(CC) $(SFLAGS) -c -o $@ $<
+
+.PRECIOUS: %.o
+%.o: %.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+.PRECIOUS: %.dyn
+%.dyn: %.o $(LIBS)
+ $(LD) $(LDFLAGS) -o $@ $^
+
+.PRECIOUS: %.lo
+%.lo: %.S
+ $(CC) $(LNXSFLAGS) -c -o $@ $<
+
+.PRECIOUS: %.lo
+%.lo: %.c
+ $(CC) $(LNXCFLAGS) -c -o $@ $<
+
+.PRECIOUS: %.lnx
+%.lnx: %.lo $(LNXLIBS)
+ $(CC) $(LNXLDFLAGS) -o $@ $^
+
+hello.dyn : hello.o $(LIBS)
+ $(LD) $(LDFLAGS) -o $@ $^
+
+tidy dist:
+ rm -f *.o *.lo *.a *.lst .*.d
+
+clean: tidy
+ rm -f *.lss *.lnx *.com *.dyn
+
+spotless: clean
+ rm -f *~ \#*
+
+install: all
+ mkdir -m 755 -p $(INSTALLROOT)$(AUXDIR)
+ install -m 644 $(MODULES) $(INSTALLROOT)$(AUXDIR)
+
+-include .*.d
diff --git a/com32/elflink/modules/hello.c b/com32/elflink/modules/hello.c
new file mode 100644
index 00000000..f396c794
--- /dev/null
+++ b/com32/elflink/modules/hello.c
@@ -0,0 +1,29 @@
+/*
+ * The first prototype of an ELF module, inspired from the Linux kernel
+ * module system.
+ */
+
+#include <stdio.h>
+
+typedef int (*module_init_t)(void);
+typedef void (*module_exit_t)(void);
+
+#define __used __attribute__((used))
+
+#define MODULE_INIT(fn) static module_init_t __module_init \
+ __used __attribute__((section(".ctors_module"))) = fn
+
+#define MODULE_EXIT(fn) static module_exit_t __module_exit \
+ __used __attribute__((section(".dtors_module"))) = fn
+
+static int hello_init(void) {
+ printf("Hello, world, from 0x%08X!\n", (unsigned int)&hello_init);
+ return 0;
+}
+
+static void hello_exit(void) {
+ printf("Good bye, cruel world!\n");
+}
+
+MODULE_INIT(hello_init);
+MODULE_EXIT(hello_exit);