Commit dfe2cbd1 authored by Rusty Russell's avatar Rusty Russell Committed by Linus Torvalds

[PATCH] Modules 1/3: remove common section handling

As RTH pointed out, we use -fno-common for the kernel (otherwise we'd
have to sort out the small symbols anyway).

So the common section allocation in the module code is pointless.
parent d434727a
...@@ -840,37 +840,10 @@ static int handle_section(const char *name, ...@@ -840,37 +840,10 @@ static int handle_section(const char *name,
return ret; return ret;
} }
/* Figure out total size desired for the common vars */
static unsigned long read_commons(void *start, Elf_Shdr *sechdr)
{
unsigned long size, i, max_align;
Elf_Sym *sym;
size = max_align = 0;
for (sym = start + sechdr->sh_offset, i = 0;
i < sechdr->sh_size / sizeof(Elf_Sym);
i++) {
if (sym[i].st_shndx == SHN_COMMON) {
/* Value encodes alignment. */
if (sym[i].st_value > max_align)
max_align = sym[i].st_value;
/* Pad to required alignment */
size = ALIGN(size, sym[i].st_value) + sym[i].st_size;
}
}
/* Now, add in max alignment requirement (with align
attribute, this could be large), so we know we have space
whatever the start alignment is */
return size + max_align;
}
/* Change all symbols so that sh_value encodes the pointer directly. */ /* Change all symbols so that sh_value encodes the pointer directly. */
static void simplify_symbols(Elf_Shdr *sechdrs, static int simplify_symbols(Elf_Shdr *sechdrs,
unsigned int symindex, unsigned int symindex,
unsigned int strindex, unsigned int strindex,
void *common,
struct module *mod) struct module *mod)
{ {
unsigned int i; unsigned int i;
...@@ -884,13 +857,10 @@ static void simplify_symbols(Elf_Shdr *sechdrs, ...@@ -884,13 +857,10 @@ static void simplify_symbols(Elf_Shdr *sechdrs,
i++) { i++) {
switch (sym[i].st_shndx) { switch (sym[i].st_shndx) {
case SHN_COMMON: case SHN_COMMON:
/* Value encodes alignment. */ /* We compiled with -fno-common. These are not
common = (void *)ALIGN((unsigned long)common, supposed to happen. */
sym[i].st_value); DEBUGP("Common symbol: %s\n", strtab + sym[i].st_name);
/* Change it to encode pointer */ return -ENOEXEC;
sym[i].st_value = (unsigned long)common;
common += sym[i].st_size;
break;
case SHN_ABS: case SHN_ABS:
/* Don't need to do anything */ /* Don't need to do anything */
...@@ -928,15 +898,16 @@ static void simplify_symbols(Elf_Shdr *sechdrs, ...@@ -928,15 +898,16 @@ static void simplify_symbols(Elf_Shdr *sechdrs,
&ksg); &ksg);
} }
} }
return 0;
} }
/* Get the total allocation size of the init and non-init sections */ /* Get the total allocation size of the init and non-init sections */
static struct sizes get_sizes(const Elf_Ehdr *hdr, static struct sizes get_sizes(const Elf_Ehdr *hdr,
const Elf_Shdr *sechdrs, const Elf_Shdr *sechdrs,
const char *secstrings, const char *secstrings)
unsigned long common_length)
{ {
struct sizes ret = { 0, common_length }; struct sizes ret = { 0, 0 };
unsigned i; unsigned i;
/* Everything marked ALLOC (this includes the exported /* Everything marked ALLOC (this includes the exported
...@@ -971,7 +942,6 @@ static struct module *load_module(void *umod, ...@@ -971,7 +942,6 @@ static struct module *load_module(void *umod,
unsigned int i, symindex, exportindex, strindex, setupindex, exindex, unsigned int i, symindex, exportindex, strindex, setupindex, exindex,
modindex, obsparmindex; modindex, obsparmindex;
long arglen; long arglen;
unsigned long common_length;
struct sizes sizes, used; struct sizes sizes, used;
struct module *mod; struct module *mod;
long err = 0; long err = 0;
...@@ -1089,9 +1059,8 @@ static struct module *load_module(void *umod, ...@@ -1089,9 +1059,8 @@ static struct module *load_module(void *umod,
mod->state = MODULE_STATE_COMING; mod->state = MODULE_STATE_COMING;
/* How much space will we need? (Common area in first) */ /* How much space will we need? */
common_length = read_commons(hdr, &sechdrs[symindex]); sizes = get_sizes(hdr, sechdrs, secstrings);
sizes = get_sizes(hdr, sechdrs, secstrings, common_length);
/* Set these up, and allow archs to manipulate them. */ /* Set these up, and allow archs to manipulate them. */
mod->core_size = sizes.core_size; mod->core_size = sizes.core_size;
...@@ -1127,7 +1096,7 @@ static struct module *load_module(void *umod, ...@@ -1127,7 +1096,7 @@ static struct module *load_module(void *umod,
/* Transfer each section which requires ALLOC, and set sh_offset /* Transfer each section which requires ALLOC, and set sh_offset
fields to absolute addresses. */ fields to absolute addresses. */
used.core_size = common_length; used.core_size = 0;
used.init_size = 0; used.init_size = 0;
for (i = 1; i < hdr->e_shnum; i++) { for (i = 1; i < hdr->e_shnum; i++) {
if (sechdrs[i].sh_flags & SHF_ALLOC) { if (sechdrs[i].sh_flags & SHF_ALLOC) {
...@@ -1151,7 +1120,9 @@ static struct module *load_module(void *umod, ...@@ -1151,7 +1120,9 @@ static struct module *load_module(void *umod,
module_unload_init(mod); module_unload_init(mod);
/* Fix up syms, so that st_value is a pointer to location. */ /* Fix up syms, so that st_value is a pointer to location. */
simplify_symbols(sechdrs, symindex, strindex, mod->module_core, mod); err = simplify_symbols(sechdrs, symindex, strindex, mod);
if (err < 0)
goto cleanup;
/* Set up EXPORTed symbols */ /* Set up EXPORTed symbols */
if (exportindex) { if (exportindex) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment