1 /* Load the given section: NULL on error. */
2 static void *PERBIT(load_section
)(ElfPERBIT(Ehdr
) *hdr
,
4 unsigned long *secsize
,
7 return PERBIT(get_section
)(hdr
, 0, secname
, secsize
, conv
);
10 static void PERBIT(load_symbols
)(struct module
*module
)
12 struct PERBIT(kernel_symbol
) *ksyms
;
14 unsigned long i
, size
;
16 /* New-style: strings are in this section. */
17 ksymstrings
= PERBIT(load_section
)(module
->data
, "__ksymtab_strings",
22 /* Skip any zero padding. */
23 while (!ksymstrings
[i
])
26 add_symbol(ksymstrings
+i
, module
);
27 i
+= strlen(ksymstrings
+i
);
30 ksymstrings
= PERBIT(load_section
)(module
->data
,
31 "__ksymtab_strings_gpl",
34 /* Skip any zero padding. */
35 while (!ksymstrings
[i
])
38 add_symbol(ksymstrings
+i
, module
);
39 i
+= strlen(ksymstrings
+i
);
45 ksyms
= PERBIT(load_section
)(module
->data
, "__ksymtab", &size
,
47 for (i
= 0; i
< size
/ sizeof(struct PERBIT(kernel_symbol
)); i
++)
48 add_symbol(ksyms
[i
].name
, module
);
49 ksyms
= PERBIT(load_section
)(module
->data
, "__gpl_ksymtab", &size
,
51 for (i
= 0; i
< size
/ sizeof(struct PERBIT(kernel_symbol
)); i
++)
52 add_symbol(ksyms
[i
].name
, module
);
55 static char *PERBIT(get_aliases
)(struct module
*module
, unsigned long *size
)
57 return PERBIT(load_section
)(module
->data
, ".modalias", size
,
61 static char *PERBIT(get_modinfo
)(struct module
*module
, unsigned long *size
)
63 return PERBIT(load_section
)(module
->data
, ".modinfo", size
,
68 #define STT_REGISTER 13 /* Global register reserved to app. */
71 /* Calculate the dependencies for this module */
72 static void PERBIT(calculate_deps
)(struct module
*module
)
79 int handle_register_symbols
;
81 strings
= PERBIT(load_section
)(module
->data
, ".strtab", &size
,
83 syms
= PERBIT(load_section
)(module
->data
, ".symtab", &size
,
89 if (!strings
|| !syms
) {
90 warn("Couldn't find symtab and strtab in module %s\n",
96 handle_register_symbols
= 0;
97 if (END(hdr
->e_machine
, module
->conv
) == EM_SPARC
||
98 END(hdr
->e_machine
, module
->conv
) == EM_SPARCV9
)
99 handle_register_symbols
= 1;
101 for (i
= 1; i
< size
/ sizeof(syms
[0]); i
++) {
102 if (END(syms
[i
].st_shndx
, module
->conv
) == SHN_UNDEF
) {
103 /* Look for symbol */
105 struct module
*owner
;
108 name
= strings
+ END(syms
[i
].st_name
, module
->conv
);
110 /* Not really undefined: sparc gcc 3.3 creates
111 U references when you have global asm
112 variables, to avoid anyone else misusing
114 if (handle_register_symbols
115 && (ELFPERBIT(ST_TYPE
)(END(syms
[i
].st_info
,
120 weak
= (ELFPERBIT(ST_BIND
)(END(syms
[i
].st_info
,
123 owner
= find_symbol(name
, module
->pathname
, weak
);
125 info("%s needs \"%s\": %s\n",
126 module
->pathname
, name
,
128 add_dep(module
, owner
);
134 static void *PERBIT(deref_sym
)(ElfPERBIT(Ehdr
) *hdr
,
135 ElfPERBIT(Shdr
) *sechdrs
,
137 unsigned int *secsize
,
140 /* In BSS? Happens for empty device tables on
141 * recent GCC versions. */
142 if (END(sechdrs
[END(sym
->st_shndx
, conv
)].sh_type
,conv
) == SHT_NOBITS
)
146 *secsize
= END(sym
->st_size
, conv
);
148 + END(sechdrs
[END(sym
->st_shndx
, conv
)].sh_offset
, conv
)
149 + END(sym
->st_value
, conv
);
152 /* FIXME: Check size, unless we end up using aliases anyway --RR */
153 static void PERBIT(fetch_tables
)(struct module
*module
)
158 ElfPERBIT(Ehdr
) *hdr
;
159 ElfPERBIT(Sym
) *syms
;
160 ElfPERBIT(Shdr
) *sechdrs
;
164 sechdrs
= (void *)hdr
+ END(hdr
->e_shoff
, module
->conv
);
165 strings
= PERBIT(load_section
)(hdr
, ".strtab", &size
, module
->conv
);
166 syms
= PERBIT(load_section
)(hdr
, ".symtab", &size
, module
->conv
);
168 /* Don't warn again: we already have above */
169 if (!strings
|| !syms
)
172 module
->pci_table
= NULL
;
173 module
->usb_table
= NULL
;
174 module
->ccw_table
= NULL
;
175 module
->ieee1394_table
= NULL
;
176 module
->pnp_table
= NULL
;
177 module
->pnp_card_table
= NULL
;
178 module
->input_table
= NULL
;
179 module
->serio_table
= NULL
;
180 module
->of_table
= NULL
;
182 for (i
= 0; i
< size
/ sizeof(syms
[0]); i
++) {
183 char *name
= strings
+ END(syms
[i
].st_name
, module
->conv
);
185 if (!module
->pci_table
&& streq(name
, "__mod_pci_device_table")) {
186 module
->pci_size
= PERBIT(PCI_DEVICE_SIZE
);
187 module
->pci_table
= PERBIT(deref_sym
)(hdr
, sechdrs
, &syms
[i
],
190 else if (!module
->usb_table
&& streq(name
, "__mod_usb_device_table")) {
191 module
->usb_size
= PERBIT(USB_DEVICE_SIZE
);
192 module
->usb_table
= PERBIT(deref_sym
)(hdr
, sechdrs
, &syms
[i
],
195 else if (!module
->ccw_table
&& streq(name
, "__mod_ccw_device_table")) {
196 module
->ccw_size
= PERBIT(CCW_DEVICE_SIZE
);
197 module
->ccw_table
= PERBIT(deref_sym
)(hdr
, sechdrs
, &syms
[i
],
200 else if (!module
->ieee1394_table
&& streq(name
, "__mod_ieee1394_device_table")) {
201 module
->ieee1394_size
= PERBIT(IEEE1394_DEVICE_SIZE
);
202 module
->ieee1394_table
= PERBIT(deref_sym
)(hdr
, sechdrs
, &syms
[i
],
205 else if (!module
->pnp_table
&& streq(name
, "__mod_pnp_device_table")) {
206 module
->pnp_size
= PERBIT(PNP_DEVICE_SIZE
);
207 module
->pnp_table
= PERBIT(deref_sym
)(hdr
, sechdrs
, &syms
[i
],
210 else if (!module
->pnp_card_table
&& streq(name
, "__mod_pnp_card_device_table")) {
211 module
->pnp_card_size
= PERBIT(PNP_CARD_DEVICE_SIZE
);
212 module
->pnp_card_table
= PERBIT(deref_sym
)(hdr
, sechdrs
, &syms
[i
],
214 module
->pnp_card_offset
= PERBIT(PNP_CARD_DEVICE_OFFSET
);
216 else if (!module
->input_table
&& streq(name
, "__mod_input_device_table")) {
217 module
->input_size
= PERBIT(INPUT_DEVICE_SIZE
);
218 module
->input_table
= PERBIT(deref_sym
)(hdr
, sechdrs
, &syms
[i
],
219 &module
->input_table_size
,
222 else if (!module
->serio_table
&& streq(name
, "__mod_serio_device_table")) {
223 module
->serio_size
= PERBIT(SERIO_DEVICE_SIZE
);
224 module
->serio_table
= PERBIT(deref_sym
)(hdr
, sechdrs
, &syms
[i
],
227 else if (!module
->of_table
&& streq(name
, "__mod_of_device_table")) {
228 module
->of_size
= PERBIT(OF_DEVICE_SIZE
);
229 module
->of_table
= PERBIT(deref_sym
)(hdr
, sechdrs
, &syms
[i
],
235 struct module_ops
PERBIT(mod_ops
) = {
236 .load_symbols
= PERBIT(load_symbols
),
237 .calculate_deps
= PERBIT(calculate_deps
),
238 .fetch_tables
= PERBIT(fetch_tables
),
239 .get_aliases
= PERBIT(get_aliases
),
240 .get_modinfo
= PERBIT(get_modinfo
),