[syslinux:elflink] core: Shrink core/ldlinux. sys to be under 64K bytes

syslinux-bot for Matt Fleming matt.fleming at intel.com
Mon Mar 26 15:36:04 PDT 2012


Commit-ID:  a0ff1769893dc47028694ee51824bf681672876c
Gitweb:     http://www.syslinux.org/commit/a0ff1769893dc47028694ee51824bf681672876c
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Tue, 20 Mar 2012 16:27:17 +0000
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Fri, 23 Mar 2012 16:34:41 +0000

core: Shrink core/ldlinux.sys to be under 64K bytes

It would seem that running from a btrfs file system has been broken
for some time. The reason is that core/ldlinux.sys has grown
substantially, resulting in it weighing in at a whopping 88K bytes and
no longer fitting within the first 64K segment of a btrfs file system.

This huge size stems from the fact that the core links with
libcom32min.a because it requires various symbols contained within
that archive but it includes and exports *all* the symbols from
libcom32min.a. The reasoning behind this design decision is that when
a module is loaded any undefined symbols that are defined in
libcom32min.a can be resolved at runtime by the core, without the
module also needing to statically link against libcom32min.a.
Unfortunately doing this has increased the size of the core beyond
acceptable limits, such that booting from a btrfs file system no
longer works.

This commit links ldlinux.c32 against libcom32min.a so that now
ldlinux.c32 exports all the symbols contained within the
archive. Since we will always load ldlinux.c32 before any other
modules, any undefined symbols will now be resolved by ldlinux.c32
instead of the core. ldlinux.c32 isn't subject to same size
constraints as the core, e.g. fitting within 64K.

Here are the sizes in bytes before and after this commit,

Before:
        33806   com32/elflink/ldlinux/ldlinux.c32
        87749   core/ldlinux.sys

After:
        393871  com32/elflink/ldlinux/ldlinux.c32
        45516   core/ldlinux.sys

Signed-off-by: Matt Fleming <matt.fleming at intel.com>

---
 com32/Makefile                 |    4 +-
 com32/elflink/ldlinux/Makefile |    3 +-
 com32/lib/Makefile             |   68 +++++++++++++++++++++++-----------------
 core/Makefile                  |    2 +-
 4 files changed, 44 insertions(+), 33 deletions(-)

diff --git a/com32/Makefile b/com32/Makefile
index debfe47..6ed2632 100644
--- a/com32/Makefile
+++ b/com32/Makefile
@@ -1,4 +1,4 @@
-SUBDIRS = elflink/ldlinux libupload tools lib gpllib libutil modules mboot menu samples \
-	  elflink rosh cmenu hdt gfxboot sysdump lua/src
+SUBDIRS = libupload tools lib elflink/ldlinux gpllib libutil modules mboot \
+	  menu samples elflink rosh cmenu hdt gfxboot sysdump lua/src
 all tidy dist clean spotless install:
 	set -e; for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
diff --git a/com32/elflink/ldlinux/Makefile b/com32/elflink/ldlinux/Makefile
index 5927e50..9960277 100644
--- a/com32/elflink/ldlinux/Makefile
+++ b/com32/elflink/ldlinux/Makefile
@@ -15,13 +15,14 @@ MAKEDIR = $(topdir)/mk
 include $(MAKEDIR)/elf.mk
 
 CFLAGS += -I$(topdir)/core/elflink -I$(topdir)/core/include
+LIBS = --whole-archive $(com32)/lib/libcom32min.a
 
 all: ldlinux.c32 ldlinux_lnx.a
 
 ldlinux.c32 : ldlinux.o cli.o readconfig.o refstr.o colors.o getadv.o \
 		adv.o ipappend.o execute.o kernel.o get_key.o \
 		advwrite.o setadv.o eprintf.o
-	$(LD) $(LDFLAGS) -o $@ $^
+	$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
 
 LNXLIBOBJS = get_key.lo
 ldlinux_lnx.a: $(LNXLIBOBJS)
diff --git a/com32/lib/Makefile b/com32/lib/Makefile
index 10fb4de..66cfcbf 100644
--- a/com32/lib/Makefile
+++ b/com32/lib/Makefile
@@ -100,9 +100,9 @@ LIBCONSOLE_OBJS = \
 	sys/openconsole.o sys/line_input.o				\
 	sys/colortable.o sys/screensize.o				\
 	\
-	sys/stdcon_read.o sys/stdcon_write.o sys/rawcon_read.o		\
-	sys/rawcon_write.o sys/err_read.o sys/err_write.o		\
-	sys/null_read.o sys/null_write.o sys/serial_write.o		\
+	sys/stdcon_read.o sys/rawcon_read.o		\
+	sys/rawcon_write.o						\
+	sys/null_write.o sys/serial_write.o		\
 	\
 	sys/xserial_write.o						\
 	\
@@ -114,30 +114,28 @@ LIBCONSOLE_OBJS = \
 
 LIBOTHER_OBJS = \
 	atoi.o atol.o atoll.o calloc.o creat.o		\
-	ctypes.o errno.o fgetc.o fgets.o fopen.o fprintf.o fputc.o	\
-	fclose.o putchar.o setjmp.o				\
-	fputs.o fread2.o fread.o fwrite2.o fwrite.o 			\
+	fgets.o fprintf.o fputc.o	\
+	putchar.o				\
 	getopt.o getopt_long.o						\
-	lrand48.o stack.o memccpy.o memchr.o memcmp.o		\
-	memcpy.o mempcpy.o memmem.o memmove.o memset.o memswap.o	\
-	perror.o printf.o puts.o qsort.o seed48.o snprintf.o	\
-	sprintf.o srand48.o sscanf.o strcasecmp.o strcat.o	\
-	strchr.o strcmp.o strcpy.o strdup.o strerror.o strlen.o		\
+	lrand48.o stack.o memccpy.o memchr.o 		\
+	mempcpy.o memmem.o memmove.o memswap.o	\
+	perror.o qsort.o seed48.o \
+	srand48.o sscanf.o strcasecmp.o strcat.o	\
+	strerror.o		\
 	strnlen.o							\
-	strncat.o strncmp.o strncpy.o strndup.o		\
-	strncasecmp.o							\
-	stpcpy.o stpncpy.o						\
+	strncat.o strndup.o		\
+	stpncpy.o						\
 	strntoimax.o strntoumax.o strrchr.o strsep.o strspn.o strstr.o	\
 	strtoimax.o strtok.o strtol.o strtoll.o strtoul.o strtoull.o	\
-	strtoumax.o vfprintf.o vprintf.o vsnprintf.o vsprintf.o		\
-	asprintf.o vasprintf.o strlcpy.o strlcat.o			\
+	strtoumax.o vprintf.o vsprintf.o		\
+	asprintf.o vasprintf.o			\
 	vsscanf.o							\
 	skipspace.o							\
 	chrreplace.o							\
 	bufprintf.o							\
 	inet.o								\
 	\
-	lmalloc.o lstrdup.o						\
+	lstrdup.o						\
 	\
 	dprintf.o vdprintf.o						\
 	\
@@ -145,16 +143,11 @@ LIBOTHER_OBJS = \
 	\
 	getcwd.o fdopendir.o	\
 	\
-	libgcc/__ashldi3.o libgcc/__udivdi3.o			\
-	libgcc/__negdi2.o libgcc/__ashrdi3.o libgcc/__lshrdi3.o		\
-	libgcc/__muldi3.o libgcc/__udivmoddi4.o libgcc/__umoddi3.o	\
-	libgcc/__divdi3.o libgcc/__moddi3.o				\
-	\
-	sys/openconsole.o sys/line_input.o				\
+	sys/line_input.o				\
 	sys/colortable.o sys/screensize.o				\
 	\
 	sys/stdcon_read.o sys/stdcon_write.o sys/rawcon_read.o		\
-	sys/rawcon_write.o sys/err_read.o sys/err_write.o		\
+	sys/rawcon_write.o		\
 	sys/null_read.o sys/null_write.o sys/serial_write.o		\
 	\
 	sys/xserial_write.o						\
@@ -168,16 +161,28 @@ LIBOTHER_OBJS = \
 	pci/writeb.o pci/writew.o pci/writel.o	\
 	\
 	sys/x86_init_fpu.o math/pow.o math/strtod.o			\
-	\
-	syslinux/memscan.o
+
+CORELIBOBJS = \
+	memcpy.o memset.o memcmp.o printf.o strncmp.o vfprintf.o 	\
+	strlen.o vsnprintf.o snprintf.o stpcpy.o strcmp.o strdup.o 	\
+	strcpy.o strncpy.o setjmp.o fopen.o fread.o fread2.o puts.o 	\
+	sprintf.o strlcat.o strchr.o strlcpy.o strncasecmp.o ctypes.o 	\
+	fputs.o fwrite2.o fwrite.o fgetc.o fclose.o errno.o lmalloc.o 	\
+	sys/err_read.o sys/err_write.o sys/null_read.o 			\
+	sys/stdcon_write.o sys/openconsole.o				\
+	syslinux/memscan.o						\
+	libgcc/__ashldi3.o libgcc/__udivdi3.o				\
+	libgcc/__negdi2.o libgcc/__ashrdi3.o libgcc/__lshrdi3.o		\
+	libgcc/__muldi3.o libgcc/__udivmoddi4.o libgcc/__umoddi3.o	\
+	libgcc/__divdi3.o libgcc/__moddi3.o				\
+	$(LIBENTRY_OBJS) \
+	$(LIBMODULE_OBJS)
 
 MINLIBOBJS = \
 	$(LIBOTHER_OBJS) \
-	$(LIBENTRY_OBJS) \
 	$(LIBGCC_OBJS) \
 	$(LIBCONSOLE_OBJS) \
 	$(LIBLOAD_OBJS) \
-	$(LIBMODULE_OBJS) \
 	$(LIBZLIB_OBJS)
 #	$(LIBVESA_OBJS)
 
@@ -204,7 +209,7 @@ AUXDIR   = $(DATADIR)/syslinux
 INCDIR   = /usr/include
 COM32DIR = $(AUXDIR)/com32
 
-all: libcom32.c32 libcom32min.a
+all: libcom32.c32 libcom32min.a libcom32core.a
 
 libcom32.c32 : $(LIBOBJS)
 	rm -f $@
@@ -215,6 +220,11 @@ libcom32min.a : $(MINLIBOBJS)
 	$(AR) cq $@ $^
 	$(RANLIB) $@
 
+libcom32core.a : $(CORELIBOBJS)
+	rm -f $@
+	$(AR) cq $@ $^
+	$(RANLIB) $@
+
 tidy dist clean:
 	rm -f sys/vesa/alphatbl.c
 	find . \( -name \*.o -o -name \*.a -o -name .\*.d -o -name \*.tmp \) -print0 | \
diff --git a/core/Makefile b/core/Makefile
index 5288da6..3898b4d 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -53,7 +53,7 @@ SOBJ	 := $(patsubst %.S,%.o,$(SSRC))
 COBJS	 = $(filter-out rawcon.o plaincon.o,$(COBJ))
 
 LIB	 = libcom32.a
-LIBS	 = $(LIB) --whole-archive $(com32)/lib/libcom32min.a
+LIBS	 = $(LIB) --whole-archive $(com32)/lib/libcom32core.a
 LIBDEP   = $(filter-out -% %start%,$(LIBS))
 LIBOBJS	 = $(COBJS) $(SOBJ)
 


More information about the Syslinux-commits mailing list