All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] 2.5.52: compilation fixes for alpha
@ 2002-12-19 22:01 Hannes Reinecke
  2002-12-20  7:44 ` Jochen Friedrich
  0 siblings, 1 reply; 4+ messages in thread
From: Hannes Reinecke @ 2002-12-19 22:01 UTC (permalink / raw
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 860 bytes --]

Hi all,

attached are some compilation fixes needed to get the alpha port up and 
running. Note: These fixes are on top of patch-2.5.52-bk3 in the 
2.5/testing directory, which contain some neccessary fixes regarding 
exception handling.

Note that this is gross hackery. I'm reasonably sure that the patch to 
vmlinux.lds is correct (+/- alignment); the modules stuff is just copied 
straight from Rusty Russels patch (THX !).

Anyway: It works for me (tm), which is more than I could have said from 
the previous 51 kernels of the 2.5 series.
I would be _very_ glad if someone in the know (rth ? davem ? Ivan K.?) 
could have a look at it, make the appropriate corrections and forward it 
in the appropriate channels, just to make sure the next kernels will 
actually _run_ on an alpha.

Cheers,

Hannes
P.S.: Please CC to me directly, I'm not on this list.

[-- Attachment #2: bk3-alpha.patch --]
[-- Type: text/plain, Size: 5336 bytes --]

--- arch/alpha/kernel/Makefile.orig	Thu Dec 19 17:44:23 2002
+++ arch/alpha/kernel/Makefile	Thu Dec 19 17:44:30 2002
@@ -26,6 +26,7 @@
 obj-$(CONFIG_SMP)    += smp.o
 obj-$(CONFIG_PCI)    += pci.o pci_iommu.o
 obj-$(CONFIG_SRM_ENV)	+= srm_env.o
+obj-$(CONFIG_MODULES)	+= module.o
 
 ifdef CONFIG_ALPHA_GENERIC
 
--- arch/alpha/vmlinux.lds.S.orig	Thu Dec 19 17:55:58 2002
+++ arch/alpha/vmlinux.lds.S	Thu Dec 19 17:57:35 2002
@@ -55,6 +55,12 @@
 	__setup_end = .;
   }
 
+  __param ALIGN(16): {
+	__start___param = .;
+	*(__param); 
+	__stop___param = .;
+  }
+
   .initcall.init ALIGN(8): {
 	__initcall_start = .;
 	*(.initcall1.init) 
--- include/asm-alpha/module.h.orig	Thu Dec 19 13:26:01 2002
+++ include/asm-alpha/module.h	Thu Dec 19 13:34:11 2002
@@ -1,6 +1,11 @@
 #ifndef _ASM_ALPHA_MODULE_H
 #define _ASM_ALPHA_MODULE_H
 
-/* Module rewrite still in progress.  */
+struct mod_arch_specific
+{
+};
 
+#define Elf_Shdr Elf64_Shdr
+#define Elf_Sym Elf64_Sym
+#define Elf_Ehdr Elf64_Ehdr
 #endif /* _ASM_ALPHA_MODULE_H */
--- /dev/null	Tue Oct 22 14:39:45 2002
+++ arch/alpha/kernel/module.c	Thu Dec 19 17:48:41 2002
@@ -0,0 +1,135 @@
+/* Kernel module help for Alpha.
+   Copyright (C) 2002  Richard Henderson.
+
+   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
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation, Inc.,
+   59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  */
+
+#include <linux/moduleloader.h>
+#include <linux/elf.h>
+#include <linux/vmalloc.h>
+#include <linux/fs.h>
+#include <linux/string.h>
+#include <linux/kernel.h>
+
+#if 0
+#define DEBUGP printk
+#else
+#define DEBUGP(fmt , ...)
+#endif
+
+void *module_alloc(unsigned long size)
+{
+       if (size == 0)
+               return NULL;
+       return vmalloc(size);
+}
+
+/* Free memory returned from module_alloc */
+void module_free(struct module *mod, void *module_region)
+{
+        vfree(module_region);
+	/* FIXME: If module_region == mod->init_region, trim exception
+           table entries. */
+}
+
+/* We don't need anything special. */
+long module_core_size(const Elf64_Ehdr *hdr,
+		      const Elf64_Shdr *sechdrs,
+		      const char *secstrings,
+		      struct module *module)
+{
+	return module->core_size;
+}
+
+long module_init_size(const Elf64_Ehdr *hdr,
+		      const Elf64_Shdr *sechdrs,
+		      const char *secstrings,
+		      struct module *module)
+{
+	return module->init_size;
+}
+
+int apply_relocate(Elf64_Shdr *sechdrs,
+		   const char *strtab,
+		   unsigned int symindex,
+		   unsigned int relsec,
+		   struct module *me)
+{
+       return -ENOEXEC;
+}
+
+int apply_relocate_add(Elf64_Shdr *sechdrs,
+		       const char *strtab,
+		       unsigned int symindex,
+		       unsigned int relsec,
+		       struct module *me)
+{
+	Elf64_Rela *rela = (void *)sechdrs[relsec].sh_offset;
+	Elf64_Sym *sym;
+	char *location;
+	unsigned long i;
+
+	for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rela); i++) {
+                unsigned long r_type = ELF64_R_TYPE(rela[i].r_info);
+                unsigned long value = 0;
+
+		/* This is where to make the change */
+		location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_offset
+			+ rela[i].r_offset;
+
+                if (r_type == R_ALPHA_RELATIVE) {
+                        /* Binutils before 2.12 or so are borken.  We should
+                           have the RELATIVE offset as the addend of the 
+                           relocation.  If it's not present, fall back to the
+                           value at the relocation address.  */
+                        u64 addend = rela[i].r_addend;
+                        if (addend == 0)
+                                addend = *(u64 *)location;
+
+                        *(u64 *)location = (u64)me->module_core + addend;
+                        continue;
+                }
+
+                /* This is the symbol it is referring to.  */
+		sym = (Elf64_Sym *)sechdrs[symindex].sh_offset
+		    + ELF64_R_SYM(rela[i].r_info);
+		if (!sym->st_value) {
+			printk(KERN_WARNING "%s: Unknown symbol %s\n",
+			       me->name, strtab + sym->st_name);
+			return -ENOENT;
+		}
+                value += rela[i].r_addend;
+
+                switch (r_type) {
+                case R_ALPHA_GLOB_DAT:
+                case R_ALPHA_JMP_SLOT:
+                case R_ALPHA_REFQUAD:
+                        *(u64 *)location = value;
+                        break;
+                default:
+                        printk(KERN_ERR "module %s: Unknown relocation: %lu\n",
+                               me->name, r_type);
+                        return -ENOEXEC;
+                }
+        }
+
+        return 0;
+}
+
+int module_finalize(const Elf_Ehdr *hdr,
+		    const Elf_Shdr *sechdrs,
+		    struct module *me)
+{
+       return 0;
+}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] 2.5.52: compilation fixes for alpha
  2002-12-19 22:01 [PATCH] 2.5.52: compilation fixes for alpha Hannes Reinecke
@ 2002-12-20  7:44 ` Jochen Friedrich
  2002-12-20 14:45   ` Hannes Reinecke
  0 siblings, 1 reply; 4+ messages in thread
From: Jochen Friedrich @ 2002-12-20  7:44 UTC (permalink / raw
  To: Hannes Reinecke; +Cc: Linux Kernel

Hi Hannes,

> attached are some compilation fixes needed to get the alpha port up and
> running. Note: These fixes are on top of patch-2.5.52-bk3 in the
> 2.5/testing directory, which contain some neccessary fixes regarding
> exception handling.

Is there an additional patch missing?

arch/alpha/mm/extable.c: In function `search_exception_table':
arch/alpha/mm/extable.c:48: `module_list' undeclared (first use in this
function)

This is -bk3 from v2.5/snapshots +your patch (-bk4 +your patch fails to
compile with the same message).

It looks like i386 replaced the loop through module_list by a walk through
extables which is not yet in alpha code.

Thanks,
--jochen


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] 2.5.52: compilation fixes for alpha
  2002-12-20  7:44 ` Jochen Friedrich
@ 2002-12-20 14:45   ` Hannes Reinecke
  2002-12-20 22:54     ` Jochen Friedrich
  0 siblings, 1 reply; 4+ messages in thread
From: Hannes Reinecke @ 2002-12-20 14:45 UTC (permalink / raw
  To: Jochen Friedrich; +Cc: Linux Kernel

[-- Attachment #1: Type: text/plain, Size: 1394 bytes --]

Jochen Friedrich wrote:
> Hi Hannes,
> 
> 
>>attached are some compilation fixes needed to get the alpha port up and
>>running. Note: These fixes are on top of patch-2.5.52-bk3 in the
>>2.5/testing directory, which contain some neccessary fixes regarding
>>exception handling.
> 
> 
> Is there an additional patch missing?
> 
> arch/alpha/mm/extable.c: In function `search_exception_table':
> arch/alpha/mm/extable.c:48: `module_list' undeclared (first use in this
> function)
> 
Shit. I forgot that one (I knew there was something missing).
Try the attached patch instead; it's identical to the previous one, I 
just appended the patch for arch/alpha/mm/extable.c

Let me know whether it works.

Note: Module loading is still likely to be buggered, since it 
appearantly relies on newer modutils (I'm a bit out of touch with 
current events). But at least it compiles and runs, even with modules 
enabled. I see what I can dig out re. modules.

> This is -bk3 from v2.5/snapshots +your patch (-bk4 +your patch fails to
> compile with the same message).
>
Small wonder. Alpha fixes always tend to be a bit uncared-for.

> It looks like i386 replaced the loop through module_list by a walk through
> extables which is not yet in alpha code.
> 
Indeed. Alternatively you can copy the code from i386, which is quite 
generic (and that's what I did anyway).

> Thanks,
Nae bother.

Cheers,

Hannes

[-- Attachment #2: bk3-alpha.patch --]
[-- Type: text/plain, Size: 6449 bytes --]

--- arch/alpha/kernel/Makefile.orig	Thu Dec 19 17:44:23 2002
+++ arch/alpha/kernel/Makefile	Thu Dec 19 17:44:30 2002
@@ -26,6 +26,7 @@
 obj-$(CONFIG_SMP)    += smp.o
 obj-$(CONFIG_PCI)    += pci.o pci_iommu.o
 obj-$(CONFIG_SRM_ENV)	+= srm_env.o
+obj-$(CONFIG_MODULES)	+= module.o
 
 ifdef CONFIG_ALPHA_GENERIC
 
--- arch/alpha/vmlinux.lds.S.orig	Thu Dec 19 17:55:58 2002
+++ arch/alpha/vmlinux.lds.S	Thu Dec 19 17:57:35 2002
@@ -55,6 +55,12 @@
 	__setup_end = .;
   }
 
+  __param ALIGN(16): {
+	__start___param = .;
+	*(__param); 
+	__stop___param = .;
+  }
+
   .initcall.init ALIGN(8): {
 	__initcall_start = .;
 	*(.initcall1.init) 
--- include/asm-alpha/module.h.orig	Thu Dec 19 13:26:01 2002
+++ include/asm-alpha/module.h	Thu Dec 19 13:34:11 2002
@@ -1,6 +1,11 @@
 #ifndef _ASM_ALPHA_MODULE_H
 #define _ASM_ALPHA_MODULE_H
 
-/* Module rewrite still in progress.  */
+struct mod_arch_specific
+{
+};
 
+#define Elf_Shdr Elf64_Shdr
+#define Elf_Sym Elf64_Sym
+#define Elf_Ehdr Elf64_Ehdr
 #endif /* _ASM_ALPHA_MODULE_H */
--- /dev/null	Tue Oct 22 14:39:45 2002
+++ arch/alpha/kernel/module.c	Thu Dec 19 17:48:41 2002
@@ -0,0 +1,135 @@
+/* Kernel module help for Alpha.
+   Copyright (C) 2002  Richard Henderson.
+
+   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
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation, Inc.,
+   59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  */
+
+#include <linux/moduleloader.h>
+#include <linux/elf.h>
+#include <linux/vmalloc.h>
+#include <linux/fs.h>
+#include <linux/string.h>
+#include <linux/kernel.h>
+
+#if 0
+#define DEBUGP printk
+#else
+#define DEBUGP(fmt , ...)
+#endif
+
+void *module_alloc(unsigned long size)
+{
+       if (size == 0)
+               return NULL;
+       return vmalloc(size);
+}
+
+/* Free memory returned from module_alloc */
+void module_free(struct module *mod, void *module_region)
+{
+        vfree(module_region);
+	/* FIXME: If module_region == mod->init_region, trim exception
+           table entries. */
+}
+
+/* We don't need anything special. */
+long module_core_size(const Elf64_Ehdr *hdr,
+		      const Elf64_Shdr *sechdrs,
+		      const char *secstrings,
+		      struct module *module)
+{
+	return module->core_size;
+}
+
+long module_init_size(const Elf64_Ehdr *hdr,
+		      const Elf64_Shdr *sechdrs,
+		      const char *secstrings,
+		      struct module *module)
+{
+	return module->init_size;
+}
+
+int apply_relocate(Elf64_Shdr *sechdrs,
+		   const char *strtab,
+		   unsigned int symindex,
+		   unsigned int relsec,
+		   struct module *me)
+{
+       return -ENOEXEC;
+}
+
+int apply_relocate_add(Elf64_Shdr *sechdrs,
+		       const char *strtab,
+		       unsigned int symindex,
+		       unsigned int relsec,
+		       struct module *me)
+{
+	Elf64_Rela *rela = (void *)sechdrs[relsec].sh_offset;
+	Elf64_Sym *sym;
+	char *location;
+	unsigned long i;
+
+	for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rela); i++) {
+                unsigned long r_type = ELF64_R_TYPE(rela[i].r_info);
+                unsigned long value = 0;
+
+		/* This is where to make the change */
+		location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_offset
+			+ rela[i].r_offset;
+
+                if (r_type == R_ALPHA_RELATIVE) {
+                        /* Binutils before 2.12 or so are borken.  We should
+                           have the RELATIVE offset as the addend of the 
+                           relocation.  If it's not present, fall back to the
+                           value at the relocation address.  */
+                        u64 addend = rela[i].r_addend;
+                        if (addend == 0)
+                                addend = *(u64 *)location;
+
+                        *(u64 *)location = (u64)me->module_core + addend;
+                        continue;
+                }
+
+                /* This is the symbol it is referring to.  */
+		sym = (Elf64_Sym *)sechdrs[symindex].sh_offset
+		    + ELF64_R_SYM(rela[i].r_info);
+		if (!sym->st_value) {
+			printk(KERN_WARNING "%s: Unknown symbol %s\n",
+			       me->name, strtab + sym->st_name);
+			return -ENOENT;
+		}
+                value += rela[i].r_addend;
+
+                switch (r_type) {
+                case R_ALPHA_GLOB_DAT:
+                case R_ALPHA_JMP_SLOT:
+                case R_ALPHA_REFQUAD:
+                        *(u64 *)location = value;
+                        break;
+                default:
+                        printk(KERN_ERR "module %s: Unknown relocation: %lu\n",
+                               me->name, r_type);
+                        return -ENOEXEC;
+                }
+        }
+
+        return 0;
+}
+
+int module_finalize(const Elf_Ehdr *hdr,
+		    const Elf_Shdr *sechdrs,
+		    struct module *me)
+{
+       return 0;
+}
--- arch/alpha/mm/extable.c.orig	Thu Dec 19 13:23:51 2002
+++ arch/alpha/mm/extable.c	Thu Dec 19 13:30:34 2002
@@ -33,23 +33,24 @@
 unsigned
 search_exception_table(unsigned long addr)
 {
-	unsigned ret;
+	unsigned ret = 0;
 
 #ifndef CONFIG_MODULES
 	ret = search_one_table(__start___ex_table, __stop___ex_table-1, addr);
 #else
 	extern spinlock_t modlist_lock;
 	unsigned long flags;
-	/* The kernel is the last "module" -- no need to treat it special. */
-	struct module *mp;
+	struct list_head *i;
 
-	ret = 0;
+	/* The kernel is the last "module" -- no need to treat it special.  */
 	spin_lock_irqsave(&modlist_lock, flags);
-	for (mp = module_list; mp ; mp = mp->next) {
-		if (!mp->ex_table_start || !(mp->flags&(MOD_RUNNING|MOD_INITIALIZING)))
+	list_for_each(i, &extables) {
+		struct exception_table *ex
+			= list_entry(i, struct exception_table, list);
+		if (ex->num_entries == 0)
 			continue;
-		ret = search_one_table(mp->ex_table_start,
-				       mp->ex_table_end - 1, addr);
+		ret = search_one_table(ex->entry,
+				       ex->entry + ex->num_entries - 1, addr);
 		if (ret)
 			break;
 	}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] 2.5.52: compilation fixes for alpha
  2002-12-20 14:45   ` Hannes Reinecke
@ 2002-12-20 22:54     ` Jochen Friedrich
  0 siblings, 0 replies; 4+ messages in thread
From: Jochen Friedrich @ 2002-12-20 22:54 UTC (permalink / raw
  To: Hannes Reinecke; +Cc: Linux Kernel

Hi Hannes,

On Fri, 20 Dec 2002, Hannes Reinecke wrote:

> Shit. I forgot that one (I knew there was something missing).
> Try the attached patch instead; it's identical to the previous one, I
> just appended the patch for arch/alpha/mm/extable.c
>
> Let me know whether it works.

That one compiled OK, now.

> Note: Module loading is still likely to be buggered, since it
> appearantly relies on newer modutils (I'm a bit out of touch with
> current events). But at least it compiles and runs, even with modules
> enabled. I see what I can dig out re. modules.

I currently have module-init-tools 0.9.4 installed, but module loading
complains about an invalid relocation type 6. Using objdump on a module
shows that the module is not linked as a dynamic object file (objdump -R
complains), but still contains static relocation entries (objdump -r is
not empty). On the other hand the arch/alpha/kernel/module.c code looks
almost the same as the 2.5.50 code + rth patch which required dynamic
objects for modules. So either there still is a problem with the Makefiles
or module.c fails to handle all required relocation types for the Alpha
platform.

I have a working 2.5.50 with module-init-tools 0.9.1 + rth patches with
modules working and here objdump -R shows dynamic relocation entries for
the modules and objdump -r is empty.

modprobe tmsisa

module tmsisa: Unknown relocation: 6

objdump -R /lib/modules/2.5.52bk4/kernel/drivers/net/tokenring/tmsisa.ko

/lib/modules/2.5.52bk4/kernel/drivers/net/tokenring/tmsisa.ko:     file
format elf64-alpha

objdump: /lib/modules/2.5.52bk4/kernel/drivers/net/tokenring/tmsisa.ko:
not a dynamic object
objdump: /lib/modules/2.5.52bk4/kernel/drivers/net/tokenring/tmsisa.ko:
Invalid operation

objdump -r /lib/modules/2.5.52bk4/kernel/drivers/net/tokenring/tmsisa.ko

/lib/modules/2.5.52bk4/kernel/drivers/net/tokenring/tmsisa.ko:     file
format elf64-alpha

RELOCATION RECORDS FOR [.text]:
OFFSET           TYPE              VALUE
0000000000000000 GPDISP            .text+0x0000000000000004
000000000000000c ELF_LITERAL       alpha_mv
...
000000000000089c LITUSE            .init.text+0x0000000000000003
000000000000089c HINT              printk
00000000000008a0 GPDISP            .init.text+0x0000000000000004
...

GPDISP seems the one the kernel complains about...

#define R_ALPHA_GPDISP          6       /* Add displacement to GP */

objdump -R /lib/modules/2.5.50/kernel/tmsisa.klm

/lib/modules/2.5.50/kernel/tmsisa.klm:     file format elf64-alpha

DYNAMIC RELOCATION RECORDS
OFFSET           TYPE              VALUE
0000000000012330 RELATIVE          *ABS*+0x0000000000000fe0
0000000000012338 RELATIVE          *ABS*+0x0000000000000ec0
...
0000000000012290 GLOB_DAT          __this_module
00000000000122d0 GLOB_DAT          tms380tr_interrupt
00000000000122e8 GLOB_DAT          ioport_resource
00000000000122f0 GLOB_DAT          alpha_mv
0000000000012288 JMP_SLOT          free_irq
0000000000012298 JMP_SLOT          unregister_trdev
...

Thanks,
--jochen


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-12-20 22:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-12-19 22:01 [PATCH] 2.5.52: compilation fixes for alpha Hannes Reinecke
2002-12-20  7:44 ` Jochen Friedrich
2002-12-20 14:45   ` Hannes Reinecke
2002-12-20 22:54     ` Jochen Friedrich

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.