Skip to content

Commit 7f2084f

Browse files
author
Al Viro
committed
[kbuild] handle exports in lib-y objects reliably
Collect the symbols exported by anything that goes into lib.a and add an empty object (lib-exports.o) with explicit undefs for each of those to obj-y. That allows to relax the rules regarding the use of exports in lib-* objects - right now an object with export can be in lib-* only if we are guaranteed that there always will be users in built-in parts of the tree, otherwise it needs to be in obj-*. As the result, we have an unholy mix of lib- and obj- in lib/Makefile and (especially) in arch/*/lib/Makefile. Moreover, a change in generic part of the kernel can lead to mysteriously missing exports on some configs. With this change we don't have to worry about that anymore. One side effect is that built-in.o now pulls everything with exports from the corresponding lib.a (if such exists). That's exactly what we want for linking vmlinux and fortunately it's almost the only thing built-in.o is used in. arch/ia64/hp/sim/boot/bootloader is the only exception and it's easy to get rid of now - just turn everything in arch/ia64/lib into lib-* and don't bother with arch/ia64/lib/built-in.o anymore. [AV: stylistic fix from Michal folded in] Acked-by: Michal Marek <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 29b4817 commit 7f2084f

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

arch/ia64/hp/sim/boot/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ $(obj)/vmlinux.bin: vmlinux FORCE
3333
LDFLAGS_bootloader = -static -T
3434

3535
$(obj)/bootloader: $(src)/bootloader.lds $(obj)/bootloader.o $(obj)/boot_head.o $(obj)/fw-emu.o \
36-
lib/lib.a arch/ia64/lib/built-in.o arch/ia64/lib/lib.a FORCE
36+
lib/lib.a arch/ia64/lib/lib.a FORCE
3737
$(call if_changed,ld)

arch/ia64/lib/Makefile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
# Makefile for ia64-specific library routines..
33
#
44

5-
obj-y := io.o
6-
7-
lib-y := __divsi3.o __udivsi3.o __modsi3.o __umodsi3.o \
5+
lib-y := io.o __divsi3.o __udivsi3.o __modsi3.o __umodsi3.o \
86
__divdi3.o __udivdi3.o __moddi3.o __umoddi3.o \
97
checksum.o clear_page.o csum_partial_copy.o \
108
clear_user.o strncpy_from_user.o strlen_user.o strnlen_user.o \
119
flush.o ip_fast_csum.o do_csum.o \
1210
memset.o strlen.o xor.o
1311

14-
obj-$(CONFIG_ITANIUM) += copy_page.o copy_user.o memcpy.o
15-
obj-$(CONFIG_MCKINLEY) += copy_page_mck.o memcpy_mck.o
12+
lib-$(CONFIG_ITANIUM) += copy_page.o copy_user.o memcpy.o
13+
lib-$(CONFIG_MCKINLEY) += copy_page_mck.o memcpy_mck.o
1614
lib-$(CONFIG_PERFMON) += carta_random.o
1715

1816
AFLAGS___divdi3.o =

scripts/Makefile.build

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ endif
8181

8282
ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),)
8383
lib-target := $(obj)/lib.a
84+
obj-y += $(obj)/lib-ksyms.o
8485
endif
8586

8687
ifneq ($(strip $(obj-y) $(obj-m) $(obj-) $(subdir-m) $(lib-target)),)
@@ -395,6 +396,25 @@ $(lib-target): $(lib-y) FORCE
395396
$(call if_changed,link_l_target)
396397

397398
targets += $(lib-target)
399+
400+
dummy-object = $(obj)/.lib_exports.o
401+
ksyms-lds = $(dot-target).lds
402+
ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX
403+
ref_prefix = EXTERN(_
404+
else
405+
ref_prefix = EXTERN(
406+
endif
407+
408+
quiet_cmd_export_list = EXPORTS $@
409+
cmd_export_list = $(OBJDUMP) -h $< | \
410+
sed -ne '/___ksymtab/{s/.*+/$(ref_prefix)/;s/ .*/)/;p}' >$(ksyms-lds);\
411+
rm -f $(dummy-object);\
412+
$(AR) rcs$(KBUILD_ARFLAGS) $(dummy-object);\
413+
$(LD) $(ld_flags) -r -o $@ -T $(ksyms-lds) $(dummy-object);\
414+
rm $(dummy-object) $(ksyms-lds)
415+
416+
$(obj)/lib-ksyms.o: $(lib-target) FORCE
417+
$(call if_changed,export_list)
398418
endif
399419

400420
#

0 commit comments

Comments
 (0)