Skip to content

Commit dd2a3ac

Browse files
Andreas Bießmannrustyrussell
authored andcommitted
mod/file2alias: make modpost compile on darwin again
commit e49ce14 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 <[email protected]> CC: Rusty Russell <[email protected]> CC: Greg Kroah-Hartman <[email protected]> CC: Jochen Friedrich <[email protected]> CC: Samuel Ortiz <[email protected]> CC: "K. Y. Srinivasan" <[email protected]> Signed-off-by: Rusty Russell <[email protected]> Tested-by: Bernhard Walle <[email protected]>
1 parent 203738e commit dd2a3ac

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

scripts/mod/file2alias.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,37 @@ struct devtable {
4646
void *function;
4747
};
4848

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+
71+
struct devtable **__start___devtable, **__stop___devtable;
72+
#else
73+
#define INIT_SECTION(name) /* no-op for ELF */
74+
#define SECTION(name) __attribute__((section(#name)))
75+
4976
/* We construct a table of pointers in an ELF section (pointers generally
5077
* go unpadded by gcc). ld creates boundary syms for us. */
5178
extern struct devtable *__start___devtable[], *__stop___devtable[];
52-
#define ___cat(a,b) a ## b
53-
#define __cat(a,b) ___cat(a,b)
79+
#endif /* __MACH__ */
5480

5581
#if __GNUC__ == 3 && __GNUC_MINOR__ < 3
5682
# define __used __attribute__((__unused__))
@@ -65,8 +91,8 @@ extern struct devtable *__start___devtable[], *__stop___devtable[];
6591
(type *)NULL, \
6692
(char *)NULL)), \
6793
sizeof(type), (function) }; \
68-
static struct devtable *__attribute__((section("__devtable"))) \
69-
__used __cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__)
94+
static struct devtable *SECTION(__devtable) __used \
95+
__cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__)
7096

7197
#define ADD(str, sep, cond, field) \
7298
do { \
@@ -1080,6 +1106,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
10801106
do_pnp_card_entries(symval, sym->st_size, mod);
10811107
else {
10821108
struct devtable **p;
1109+
INIT_SECTION(__devtable);
10831110

10841111
for (p = __start___devtable; p < __stop___devtable; p++) {
10851112
if (sym_is(name, namelen, (*p)->device_id)) {

0 commit comments

Comments
 (0)