The ABI wrapper from r775 made the SHARED definitions obsolete. They're not that readable anyway, so kill them and use standard definitions instead.
Introduce EXPORT_SYMBOL for shared symbols. EXPORT_SYMBOL tells the compiler to use the standard calling conventions for a given symbol and not to optimize it away. Benefits: - We can later use gcc -combine -fwhole-program without problems. - It's a correctness fix for some optimizations. - We could check for duplicated exported functions at link time. - We could check whether exported functions are linked into initram or stage2 by accident. - We could generate usage statistics and possibly optimize away unused shared functions. - Through the above points, significant side reductions of 10-40%
Build and boot tested on qemu. Build tested on all targets.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: corebootv3-remove_SHARED/include/console.h =================================================================== --- corebootv3-remove_SHARED/include/console.h (Revision 775) +++ corebootv3-remove_SHARED/include/console.h (Arbeitskopie) @@ -71,10 +71,13 @@ #endif };
-SHARED_WITH_ATTRIBUTES(printk, int, __attribute__((format (printf, 2, 3))), - int msg_level, const char *fmt, ...); -SHARED(banner, void, int msg_level, const char *msg); -SHARED(dump_mem_range, void, int msg_level, unsigned char *buf, int size); -SHARED(die, void, const char *msg); +int printk(int msg_level, const char *fmt, ...) __attribute__((format (printf, 2, 3))); +EXPORT_SYMBOL(printk); +void banner(int msg_level, const char *msg); +EXPORT_SYMBOL(banner); +void dump_mem_range(int msg_level, unsigned char *buf, int size); +EXPORT_SYMBOL(dump_mem_range); +void die(const char *msg); +EXPORT_SYMBOL(die);
#endif /* CONSOLE_H */ Index: corebootv3-remove_SHARED/include/mc146818rtc.h =================================================================== --- corebootv3-remove_SHARED/include/mc146818rtc.h (Revision 775) +++ corebootv3-remove_SHARED/include/mc146818rtc.h (Arbeitskopie) @@ -122,7 +122,8 @@ #else #include <shared.h>
-SHARED(get_option, int, void *dest, char *name); +int get_option(void *dest, char *name); +EXPORT_SYMBOL(get_option); #endif void rtc_init(int invalid); int last_boot_normal(void); Index: corebootv3-remove_SHARED/include/string.h =================================================================== --- corebootv3-remove_SHARED/include/string.h (Revision 775) +++ corebootv3-remove_SHARED/include/string.h (Arbeitskopie) @@ -31,10 +31,14 @@ int strncmp(const char *s1, const char *s2, int maxlen);
/* lib/mem.c */ -SHARED(memcpy, void *, void *dest, const void *src, size_t len); -SHARED(memmove, void *, void *dest, const void *src, size_t len); -SHARED(memset, void *, void *s, int c, size_t len); -SHARED(memcmp, int , const void *s1, const void *s2, size_t len); +void * memcpy(void *dest, const void *src, size_t len); +EXPORT_SYMBOL(memcpy); +void * memmove(void *dest, const void *src, size_t len); +EXPORT_SYMBOL(memmove); +void * memset(void *s, int c, size_t len); +EXPORT_SYMBOL(memset); +int memcmp(const void *s1, const void *s2, size_t len); +EXPORT_SYMBOL(memcmp);
/* console/vsprintf.c */ int sprintf(char *buf, const char *fmt, ...); Index: corebootv3-remove_SHARED/include/shared.h =================================================================== --- corebootv3-remove_SHARED/include/shared.h (Revision 775) +++ corebootv3-remove_SHARED/include/shared.h (Arbeitskopie) @@ -1,8 +1,7 @@ /* * This file is part of the coreboot project * - * Copyright(C) 2007 coresystems GmbH - * Written by Stefan Reinauer stepan@coresystems.de + * Copyright(C) 2008 Carl-Daniel Hailfinger * * 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 @@ -22,41 +21,6 @@ #ifndef SHARED_H #define SHARED_H
-#define FUNC(func, ret, attr, args...) \ - ret func(args) attr -#define EXTERN(func, ret, attr, args...) +#define EXPORT_SYMBOL(sym) extern typeof(sym) sym __attribute__((externally_visible,used))
-/** - * Use the SHARED macro to create a universally usable function - * prototype. This will create a function prototype in stage 0 and - * a function prototype plus a function pointer for all code compiled - * with _SHARED defined (required for XIP code) - * - * @func function name - * @ret return value - * @args function arguments - */ - -#define SHARED(func,ret,args...) \ - FUNC(func,ret,,##args); \ - EXTERN(func,ret,,##args) - - -/** - * Use the SHARED_WITH_ATTRIBUTES macro to create a universally usable function - * prototype for a function using GCC attributes. - * This macro works identically to SHARED(), but it adds a GCC attribute to the - * function. So far we use this to have printk parameters tested with a - * "format" attribute. - * - * @func function name - * @ret return value - * @attr function attributes - * @args function arguments - */ - -#define SHARED_WITH_ATTRIBUTES(func,ret,attr,args...) \ - FUNC(func,ret,attr,##args); \ - EXTERN(func,ret,attr,##args) - #endif /* SHARED_H */ Index: corebootv3-remove_SHARED/include/device/pci_ops.h =================================================================== --- corebootv3-remove_SHARED/include/device/pci_ops.h (Revision 775) +++ corebootv3-remove_SHARED/include/device/pci_ops.h (Arbeitskopie) @@ -30,13 +30,21 @@ void pci_write_config16(struct device * dev, unsigned where, u16 val); void pci_write_config32(struct device * dev, unsigned where, u32 val);
-SHARED(pci_conf1_read_config8, u8, u32 bdf, int where); -SHARED(pci_conf1_read_config16, u16, u32 bdf, int where); -SHARED(pci_conf1_read_config32, u32, u32 bdf, int where); -SHARED(pci_conf1_write_config8, void , u32 bdf, int where, u8 value); -SHARED(pci_conf1_write_config16, void, u32 bdf, int where, u16 value); -SHARED(pci_conf1_write_config32, void, u32 bdf, int where, u32 value); -SHARED(pci_conf1_find_on_bus, int, u16 bus, u16 vid, u16 did, u32 *busdevfn); -SHARED(pci_conf1_find_device, int, u16 vid, u16 did, u32 * dev); +u8 pci_conf1_read_config8(u32 bdf, int where); +EXPORT_SYMBOL(pci_conf1_read_config8); +u16 pci_conf1_read_config16(u32 bdf, int where); +EXPORT_SYMBOL(pci_conf1_read_config16); +u32 pci_conf1_read_config32(u32 bdf, int where); +EXPORT_SYMBOL(pci_conf1_read_config32); +void pci_conf1_write_config8(u32 bdf, int where, u8 value); +EXPORT_SYMBOL(pci_conf1_write_config8); +void pci_conf1_write_config16(u32 bdf, int where, u16 value); +EXPORT_SYMBOL(pci_conf1_write_config16); +void pci_conf1_write_config32(u32 bdf, int where, u32 value); +EXPORT_SYMBOL(pci_conf1_write_config32); +int pci_conf1_find_on_bus(u16 bus, u16 vid, u16 did, u32 *busdevfn); +EXPORT_SYMBOL(pci_conf1_find_on_bus); +int pci_conf1_find_device(u16 vid, u16 did, u32 * dev); +EXPORT_SYMBOL(pci_conf1_find_device);
#endif /* DEVICE_PCI_OPS_H */ Index: corebootv3-remove_SHARED/include/lar.h =================================================================== --- corebootv3-remove_SHARED/include/lar.h (Revision 775) +++ corebootv3-remove_SHARED/include/lar.h (Arbeitskopie) @@ -94,14 +94,23 @@
/* Prototypes. */ /* architecture-defined */ -SHARED(init_archive, void, struct mem_file *); +void init_archive(struct mem_file *); +EXPORT_SYMBOL(init_archive); /* architecture-independent */ -SHARED(find_file, int, const struct mem_file *archive, const char *filename, struct mem_file *result); -SHARED(copy_file, int, const struct mem_file *archive, const char *filename, void *where); -SHARED(run_file, int, const struct mem_file *archive, const char *filename, void *where); -SHARED(execute_in_place, int, const struct mem_file *archive, const char *filename); -SHARED(run_address, int, void *f); -SHARED(load_file, void *, const struct mem_file *archive, const char *filename); -SHARED(load_file_segments, void *, const struct mem_file *archive, const char *filename); -SHARED(process_file, int, const struct mem_file *archive, void *where); +int find_file(const struct mem_file *archive, const char *filename, struct mem_file *result); +EXPORT_SYMBOL(find_file); +int copy_file(const struct mem_file *archive, const char *filename, void *where); +EXPORT_SYMBOL(copy_file); +int run_file(const struct mem_file *archive, const char *filename, void *where); +EXPORT_SYMBOL(run_file); +int execute_in_place(const struct mem_file *archive, const char *filename); +EXPORT_SYMBOL(execute_in_place); +int run_address(void *f); +EXPORT_SYMBOL(run_address); +void * load_file(const struct mem_file *archive, const char *filename); +EXPORT_SYMBOL(load_file); +void * load_file_segments(const struct mem_file *archive, const char *filename); +EXPORT_SYMBOL(load_file_segments); +int process_file(const struct mem_file *archive, void *where); +EXPORT_SYMBOL(process_file); #endif /* LAR_H */ Index: corebootv3-remove_SHARED/include/post_code.h =================================================================== --- corebootv3-remove_SHARED/include/post_code.h (Revision 775) +++ corebootv3-remove_SHARED/include/post_code.h (Arbeitskopie) @@ -24,7 +24,8 @@ #include <types.h> #include <shared.h>
-SHARED(post_code, void, u8 value); +void post_code(u8 value); +EXPORT_SYMBOL(post_code);
/* This is a collection of existing POST values used by post_code(). * port80_post() and Geode specific codes are not (yet?) listed here. Index: corebootv3-remove_SHARED/include/arch/x86/cpu.h =================================================================== --- corebootv3-remove_SHARED/include/arch/x86/cpu.h (Revision 775) +++ corebootv3-remove_SHARED/include/arch/x86/cpu.h (Arbeitskopie) @@ -201,8 +201,10 @@ __asm__ __volatile__("hlt" : : : "memory"); }
-SHARED(bottom_of_stack, void *, void); -SHARED(global_vars, struct global_vars *, void); +void * bottom_of_stack(void); +EXPORT_SYMBOL(bottom_of_stack); +struct global_vars * global_vars(void); +EXPORT_SYMBOL(global_vars);
#ifdef CONFIG_CONSOLE_BUFFER #define PRINTK_BUF_SIZE_CAR (CONFIG_CARSIZE / 2) @@ -251,9 +253,11 @@ }; };
-SHARED(setup_resource_map_x_offset, void, const struct rmap *rm, u32 max, +void setup_resource_map_x_offset(const struct rmap *rm, u32 max, u32 offset_dev, u32 offset_pciio, u32 offset_io); -SHARED(setup_resource_map, void, const struct rmap *rm, u32 max); +EXPORT_SYMBOL(setup_resource_map_x_offset); +void setup_resource_map(const struct rmap *rm, u32 max); +EXPORT_SYMBOL(setup_resource_map);
#endif /* ARCH_X86_CPU_H */ Index: corebootv3-remove_SHARED/arch/x86/Makefile =================================================================== --- corebootv3-remove_SHARED/arch/x86/Makefile (Revision 775) +++ corebootv3-remove_SHARED/arch/x86/Makefile (Arbeitskopie) @@ -268,7 +268,7 @@
$(obj)/coreboot.initram $(obj)/coreboot.initram.map: $(obj)/stage0.init $(obj)/stage0-prefixed.o $(INITRAM_SRC) $(Q)printf " CC $(subst $(shell pwd)/,,$(@)) (XIP)\n" - $(Q)$(CC) $(INITCFLAGS) -D_SHARED -fPIE -c -combine $(INITRAM_SRC) -o $(obj)/coreboot.initram_partiallylinked.o + $(Q)$(CC) $(INITCFLAGS) -fPIE -c -combine $(INITRAM_SRC) -o $(obj)/coreboot.initram_partiallylinked.o $(Q)printf " WRAP $(subst $(shell pwd)/,,$(@)) (PIC->non-PIC)\n" $(Q)$(NM) --undefined-only $(obj)/coreboot.initram_partiallylinked.o |\ grep -v _GLOBAL_OFFSET_TABLE_ | grep " U " | sed "s/^ *U //" |\