Re: kbuild: LDFLAGS_MODULE unusable for external module builds (2.6.23-rc2)

From: Henry Nestler
Date: Thu Sep 27 2007 - 04:20:30 EST

Hello Sam,

Henry Nestler wrote:
Sam Ravnborg wrote:
What macro should set for linker parameters of foo.o ? I'm not shure.
Have you read:

If your example requires the LDFALGS_$@ I wil introduce it - for now
it has not been required (except for vdso support where it was hacked).

I will check EXTRA_LDFLAGS compatibilities with older kernel versions. Than I come back with results. Currently I no need LDFLAGS_$@.

Ok, EXTRA_LDFLAGS is good. I use it now.

To explain, a full example: function2 to function4 will be locate in
alternated directories A, B and than A again. Without --start-group,
function4 would be missing. That's why we need it.

cat >>>
rm -rf /tmp/test; mkdir /tmp/test; cd /tmp/test
mkdir A B

cat >Makefile <<EOF
obj-y := A/ B/
obj-m := module.o
module-objs := file1.o A/lib.a B/lib.a
EXTRA_LDFLAGS := --start-group # Solve circular references in archives

cat >A/Makefile <<EOF
lib-m := file2.o file4.o

cat >B/Makefile <<EOF
lib-m := file3.o

cat >file1.c <<EOF
#include <linux/module.h>
#include <linux/init.h>
void function2(void);
int init_module(void) {function2(); return 0;}
void cleanup_module(void) {return;}

cat >A/file2.c <<EOF
void function3(void);
void function2(void) {function3();}

cat >B/file3.c <<EOF
void function4(void);
void function3(void) {function4();}

cat >A/file4.c <<EOF
#include <linux/module.h>
void function4(void) {printk("done\n");}

make V=1 -C $HOME/kernel/linux-2.6.git2-smp-repg M=$PWD | grep " ld "
<<< end <<<

Output is:
ld -m elf_i386 -m elf_i386 --start-group -r -o /tmp/test/built-in.o
/tmp/test/A/built-in.o /tmp/test/B/built-in.o
ld -m elf_i386 -m elf_i386 --start-group -r -o /tmp/test/module.o
/tmp/test/file1.o /tmp/test/A/lib.a /tmp/test/B/lib.a
ld -m elf_i386 -r -m elf_i386 -o /tmp/test/module.ko
/tmp/test/module.o /tmp/test/module.mod.o

Currently can not put lib.a into EXTRA_LDFLAGS, because "--start-group
... lib.a --end-group" would bring the lib.a before the object list,
with more problems. The other is the path, that this needs. Example:

cat >Makefile <<EOF
obj-y := A/ B/
obj-m := module.o
module-objs := file1.o
EXTRA_LDFLAGS := --start-group \$(KBUILD_EXTMOD)/A/lib.a
\$(KBUILD_EXTMOD)/B/lib.a --end-group

Result from the make and grep ld:
ld -m elf_i386 -m elf_i386 --start-group /tmp/test/A/lib.a
/tmp/test/B/lib.a --end-group -r -o /tmp/test/module.o /tmp/test/file1.o
WARNING: "function2" [/tmp/test/module.ko] undefined!

Idea for future:
An 'APPEND_LDFLAGS' would be nice to append flags behind the last .o
object. Than can be close the group with --end-group.

Exactly linker call would be with grouping only archives, and the group
block behind the last object, for example:
ld -m elf_i386 -r -o module.o file1.o --start-group A/lib.a B/lib.a

But remember: We can very good live with EXTRA_LDFLAGS, it's usable in
all 2.6 kernels.

Many thanks.


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at