aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/mod/file2alias.c
diff options
context:
space:
mode:
authorAndreas Bießmann <andreas@biessmann.de>2012-02-24 02:23:53 -0500
committerRusty Russell <rusty@rustcorp.com.au>2012-02-26 18:59:31 -0500
commitdd2a3acaecd7abb2d43b09a823cf2e4c967fa2ac (patch)
treedf29f8479dedda8939f680998aa857e4ebd1d176 /scripts/mod/file2alias.c
parent203738e548cefc3fc3c2f73a9063176c9f3583d5 (diff)
mod/file2alias: make modpost compile on darwin again
commit e49ce14150c64b29a8dd211df785576fa19a9858 breaks cross compiling the linux kernel on darwin hosts. This fix introduce some minimal glue to adopt linker section handling for darwin hosts. Signed-off-by: Andreas Bießmann <andreas@biessmann.de> CC: Rusty Russell <rusty@rustcorp.com.au> CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org> CC: Jochen Friedrich <jochen@scram.de> CC: Samuel Ortiz <sameo@linux.intel.com> CC: "K. Y. Srinivasan" <kys@microsoft.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Tested-by: Bernhard Walle <bernhard@bwalle.de>
Diffstat (limited to 'scripts/mod/file2alias.c')
-rw-r--r--scripts/mod/file2alias.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index d0de2a2c3a2d..b89efe6e4c85 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -46,11 +46,37 @@ struct devtable {
46 void *function; 46 void *function;
47}; 47};
48 48
49#define ___cat(a,b) a ## b
50#define __cat(a,b) ___cat(a,b)
51
52/* we need some special handling for this host tool running eventually on
53 * Darwin. The Mach-O section handling is a bit different than ELF section
54 * handling. The differnces in detail are:
55 * a) we have segments which have sections
56 * b) we need a API call to get the respective section symbols */
57#if defined(__MACH__)
58#include <mach-o/getsect.h>
59
60#define INIT_SECTION(name) do { \
61 unsigned long name ## _len; \
62 char *__cat(pstart_,name) = getsectdata("__TEXT", \
63 #name, &__cat(name,_len)); \
64 char *__cat(pstop_,name) = __cat(pstart_,name) + \
65 __cat(name, _len); \
66 __cat(__start_,name) = (void *)__cat(pstart_,name); \
67 __cat(__stop_,name) = (void *)__cat(pstop_,name); \
68 } while (0)
69#define SECTION(name) __attribute__((section("__TEXT, " #name)))
70
71struct devtable **__start___devtable, **__stop___devtable;
72#else
73#define INIT_SECTION(name) /* no-op for ELF */
74#define SECTION(name) __attribute__((section(#name)))
75
49/* We construct a table of pointers in an ELF section (pointers generally 76/* We construct a table of pointers in an ELF section (pointers generally
50 * go unpadded by gcc). ld creates boundary syms for us. */ 77 * go unpadded by gcc). ld creates boundary syms for us. */
51extern struct devtable *__start___devtable[], *__stop___devtable[]; 78extern struct devtable *__start___devtable[], *__stop___devtable[];
52#define ___cat(a,b) a ## b 79#endif /* __MACH__ */
53#define __cat(a,b) ___cat(a,b)
54 80
55#if __GNUC__ == 3 && __GNUC_MINOR__ < 3 81#if __GNUC__ == 3 && __GNUC_MINOR__ < 3
56# define __used __attribute__((__unused__)) 82# define __used __attribute__((__unused__))
@@ -65,8 +91,8 @@ extern struct devtable *__start___devtable[], *__stop___devtable[];
65 (type *)NULL, \ 91 (type *)NULL, \
66 (char *)NULL)), \ 92 (char *)NULL)), \
67 sizeof(type), (function) }; \ 93 sizeof(type), (function) }; \
68 static struct devtable *__attribute__((section("__devtable"))) \ 94 static struct devtable *SECTION(__devtable) __used \
69 __used __cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__) 95 __cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__)
70 96
71#define ADD(str, sep, cond, field) \ 97#define ADD(str, sep, cond, field) \
72do { \ 98do { \
@@ -1080,6 +1106,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
1080 do_pnp_card_entries(symval, sym->st_size, mod); 1106 do_pnp_card_entries(symval, sym->st_size, mod);
1081 else { 1107 else {
1082 struct devtable **p; 1108 struct devtable **p;
1109 INIT_SECTION(__devtable);
1083 1110
1084 for (p = __start___devtable; p < __stop___devtable; p++) { 1111 for (p = __start___devtable; p < __stop___devtable; p++) {
1085 if (sym_is(name, namelen, (*p)->device_id)) { 1112 if (sym_is(name, namelen, (*p)->device_id)) {