Patch for Makefile to improve linkability of the kernel

Arjan van de Ven (arjan@stack.nl)
Mon, 14 Dec 1998 11:05:03 +0100 (CET)


Hi Linus,

The following patch solves several uggly problems with the linking-order in
the toplevel-Makefile. Please include it into the mainstream kernels.

--- linux-2.1.131/Makefile Sun Dec 13 07:20:35 1998
+++ linux/Makefile Sun Dec 13 07:21:34 1998
@@ -196,10 +196,12 @@
vmlinux: $(CONFIGURATION) init/main.o init/version.o linuxsubdirs
$(LD) $(LINKFLAGS) $(HEAD) init/main.o init/version.o \
$(CORE_FILES) \
+ --start-group \
$(FILESYSTEMS) \
$(NETWORKS) \
$(DRIVERS) \
$(LIBS) \
+ --end-group \
-o vmlinux
$(NM) vmlinux | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aU] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map

Description of the problem
--------------------------
Several of the Linux-kernel .a files have dependencies among them. The "ld"
program (in normal operation) only links the symbols in an .a file that
where previously unresolved. This is a problem when a symbol is needed in an
.a file that is linked _after_ the current file. (For example, drivers/net/net.a
is linked before drivers/cdrom/cdrom.a, cdrom.a uses auto_irq from it but
drivers/net/net.a does not provide it if it is not used before).

The solution
------------
One way of solving this kind a stuff is to modify the linking order. This is
uggly and even circular dependencies might exist. the "--start-group ....
--end-group" aproach seems like a clean, tool-based solution:

[taken from "info ld"]

--start-group ARCHIVES --end-group'
The ARCHIVES should be a list of archive files. They may be
either explicit file names, or -l' options.

The specified archives are searched repeatedly until no new
undefined references are created. Normally, an archive is
searched only once in the order that it is specified on the
command line. If a symbol in that archive is needed to resolve an
undefined symbol referred to by an object in an archive that
appears later on the command line, the linker would not be able to
resolve that reference. By grouping the archives, they all be
searched repeatedly until all possible references are resolved.

Using this option has a significant performance cost. It is best
to use it only when there are unavoidable circular references
between two or more archives.

[end quote]

About the performance-cost
--------------------------
Michael Elizabeth (he deserves the credit for this patch) solved the problem
and also did some timing on it. On a very slow machine (a kernel compile
took more than 2 hours), the linking-time increased by 5% (was about 7
seconds!). I think this is negliable.

Greetings,
Arjan van de Ven

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/