Skip to contentSkip to conversation

fix weak symbol handling

MODULES Richard Henderson 2 participants 8 messages Jan 13, 2003 – Jan 15, 2003

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

I discovered this while working on oprofile for Alpha. I thought I'd avoid a whole series of nested ifdefs by marking some symbols weak, and so let them go undefined and resolve to null. Except that we don't handle that in the new module loader.

Fixed thus.

I also correct a misconception in simplify_symbol. It is pointless to lookup an undefined symbol in the module in which it is undefined.

Pull from

	bk://are.twiddle.net/mod-2.5

or apply the following patch.

r~

You can import this changeset into BK by piping this whole message to:
'| bk receive [path to repository]' or apply the patch as usual.

===================================================================

[email protected], 2003-01-13 09:47:35-08:00, [email protected]
[MODULES] Centralize undefined symbol checks; handle undef weak.

 arch/alpha/kernel/module.c   |   11 +----
 arch/arm/kernel/module.c     |    5 --
 arch/i386/kernel/module.c    |    8 +---
 arch/ppc/kernel/module.c     |    8 +---
 arch/s390/kernel/module.c    |   10 +----
 arch/s390x/kernel/module.c   |    8 +---
 arch/sparc/kernel/module.c   |   10 +----
 arch/sparc64/kernel/module.c |   10 +----
 arch/v850/kernel/module.c    |   13 +------
 arch/x86_64/kernel/module.c  |    8 +---
 include/linux/elf.h          |   11 +++--
 include/linux/moduleloader.h |    8 ----
 kernel/module.c              |   79 +++++++++++++++++--------------------------
 13 files changed, 62 insertions, 127 deletions
arch/alpha/kernel/module.c +3 -8
diff -Nru a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
@@ -190,15 +190,10 @@
 		/* This is where to make the change.  */
 		location = base + rela[i].r_offset;
 
-		/* This is the symbol it is referring to.  */
+		/* This is the symbol it is referring to.  Note that all
+		   unresolved symbols have been resolved.  */
 		sym = symtab + r_sym;
-		value = sym->st_value;
-		if (!value) {
-			printk(KERN_ERR "module %s: Unknown symbol %s\n",
-			       me->name, strtab + sym->st_name);
-			return -ENOENT;
-		}
-		value += rela[i].r_addend;
+		value = sym->st_value + rela[i].r_addend;
 
 		switch (r_type) {
 		case R_ALPHA_NONE:
arch/arm/kernel/module.c +0 -5
diff -Nru a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
@@ -98,11 +98,6 @@
 		}
 
 		sym = ((Elf32_Sym *)symsec->sh_addr) + offset;
-		if (!sym->st_value) {
-			printk(KERN_WARNING "%s: unknown symbol %s\n",
-				module->name, strtab + sym->st_name);
-			return -ENOENT;
-		}
 
 		if (rel->r_offset < 0 || rel->r_offset > dstsec->sh_size - sizeof(u32)) {
 			printk(KERN_ERR "%s: out of bounds relocation, "
arch/i386/kernel/module.c +2 -6
diff -Nru a/arch/i386/kernel/module.c b/arch/i386/kernel/module.c
@@ -70,14 +70,10 @@
 		/* This is where to make the change */
 		location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
 			+ rel[i].r_offset;
-		/* This is the symbol it is referring to */
+		/* This is the symbol it is referring to.  Note that all
+		   undefined symbols have been resolved.  */
 		sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
 			+ ELF32_R_SYM(rel[i].r_info);
-		if (!sym->st_value) {
-			printk(KERN_WARNING "%s: Unknown symbol %s\n",
-			       me->name, strtab + sym->st_name);
-			return -ENOENT;
-		}
 
 		switch (ELF32_R_TYPE(rel[i].r_info)) {
 		case R_386_32:
arch/ppc/kernel/module.c +2 -6
diff -Nru a/arch/ppc/kernel/module.c b/arch/ppc/kernel/module.c
@@ -197,14 +197,10 @@
 		/* This is where to make the change */
 		location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
 			+ rela[i].r_offset;
-		/* This is the symbol it is referring to */
+		/* This is the symbol it is referring to.  Note that all
+		   undefined symbols have been resolved.  */
 		sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
 			+ ELF32_R_SYM(rela[i].r_info);
-		if (!sym->st_value) {
-			printk(KERN_WARNING "%s: Unknown symbol %s\n",
-			       module->name, strtab + sym->st_name);
-			return -ENOENT;
-		}
 		/* `Everything is relative'. */
 		value = sym->st_value + rela[i].r_addend;
 
arch/s390/kernel/module.c +3 -7
diff -Nru a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
@@ -1,5 +1,5 @@
 /*
- *  arch/s390x/kernel/module.c - Kernel module help for s390x.
+ *  arch/s390/kernel/module.c - Kernel module help for s390.
  *
  *  S390 version
  *    Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation
@@ -77,14 +77,10 @@
 		/* This is where to make the change */
 		location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
 			+ rel[i].r_offset;
-		/* This is the symbol it is referring to */
+		/* This is the symbol it is referring to.  Note that all
+		   undefined symbols have been resolved.  */
 		sym = (ElfW(Sym) *)sechdrs[symindex].sh_addr
 			+ ELFW(R_SYM)(rel[i].r_info);
-		if (!sym->st_value) {
-			printk(KERN_WARNING "%s: Unknown symbol %s\n",
-			       me->name, strtab + sym->st_name);
-			return -ENOENT;
-		}
 
 		switch (ELF_R_TYPE(rel[i].r_info)) {
 		case R_390_8:		/* Direct 8 bit.   */
arch/s390x/kernel/module.c +2 -6
diff -Nru a/arch/s390x/kernel/module.c b/arch/s390x/kernel/module.c
@@ -78,14 +78,10 @@
 		/* This is where to make the change */
 		location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
 			+ rel[i].r_offset;
-		/* This is the symbol it is referring to */
+		/* This is the symbol it is referring to.  Note that all
+		   undefined symbols have been resolved.  */
 		sym = (ElfW(Sym) *)sechdrs[symindex].sh_addr
 			+ ELFW(R_SYM)(rel[i].r_info);
-		if (!sym->st_value) {
-			printk(KERN_WARNING "%s: Unknown symbol %s\n",
-			       me->name, strtab + sym->st_name);
-			return -ENOENT;
-		}
 
 		switch (ELF_R_TYPE(rel[i].r_info)) {
 		case R_390_8:		/* Direct 8 bit.   */
arch/sparc/kernel/module.c +3 -7
diff -Nru a/arch/sparc/kernel/module.c b/arch/sparc/kernel/module.c
@@ -75,15 +75,11 @@
 		location = (u8 *)sechdrs[sechdrs[relsec].sh_info].sh_addr
 			+ rel[i].r_offset;
 		loc32 = (u32 *) location;
-		/* This is the symbol it is referring to */
+		/* This is the symbol it is referring to.  Note that all
+		   undefined symbols have been resolved.  */
 		sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
 			+ ELF32_R_SYM(rel[i].r_info);
-		if (!(v = sym->st_value)) {
-			printk(KERN_WARNING "%s: Unknown symbol %s\n",
-			       me->name, strtab + sym->st_name);
-			return -ENOENT;
-		}
-		v += rel[i].r_addend;
+		v = sym->st_value + rel[i].r_addend;
 
 		switch (ELF32_R_TYPE(rel[i].r_info)) {
 		case R_SPARC_32:
arch/sparc64/kernel/module.c +3 -7
diff -Nru a/arch/sparc64/kernel/module.c b/arch/sparc64/kernel/module.c
@@ -185,15 +185,11 @@
 
 		BUG_ON(((u64)location >> (u64)32) != (u64)0);
 
-		/* This is the symbol it is referring to */
+		/* This is the symbol it is referring to.  Note that all
+		   undefined symbols have been resolved.  */
 		sym = (Elf64_Sym *)sechdrs[symindex].sh_addr
 			+ ELF64_R_SYM(rel[i].r_info);
-		if (!(v = sym->st_value)) {
-			printk(KERN_WARNING "%s: Unknown symbol %s\n",
-			       me->name, strtab + sym->st_name);
-			return -ENOENT;
-		}
-		v += rel[i].r_addend;
+		v = sym->st_value + rel[i].r_addend;
 
 		switch (ELF64_R_TYPE(rel[i].r_info) & 0xff) {
 		case R_SPARC_64:
arch/v850/kernel/module.c +3 -10
diff -Nru a/arch/v850/kernel/module.c b/arch/v850/kernel/module.c
@@ -184,19 +184,12 @@
 		uint32_t *loc
 			= ((void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
 			   + rela[i].r_offset);
-		/* This is the symbol it is referring to */
+		/* This is the symbol it is referring to.  Note that all
+		   undefined symbols have been resolved.  */
 		Elf32_Sym *sym
 			= ((Elf32_Sym *)sechdrs[symindex].sh_addr
 			   + ELF32_R_SYM (rela[i].r_info));
-		uint32_t val = sym->st_value;
-
-		if (! val) {
-			printk (KERN_WARNING "%s: Unknown symbol %s\n",
-				mod->name, strtab + sym->st_name);
-			return -ENOENT;
-		}
-
-		val += rela[i].r_addend;
+		uint32_t val = sym->st_value + rela[i].r_addend;
 
 		switch (ELF32_R_TYPE (rela[i].r_info)) {
 		case R_V850_32:
arch/x86_64/kernel/module.c +2 -6
diff -Nru a/arch/x86_64/kernel/module.c b/arch/x86_64/kernel/module.c
@@ -53,14 +53,10 @@
 		loc = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
 			+ rel[i].r_offset;
 
-		/* This is the symbol it is referring to */
+		/* This is the symbol it is referring to.  Note that all
+		   undefined symbols have been resolved.  */
 		sym = (Elf64_Sym *)sechdrs[symindex].sh_addr
 			+ ELF64_R_SYM(rel[i].r_info);
-		if (!sym->st_value) {
-			printk(KERN_WARNING "%s: Unknown symbol %s\n",
-			       me->name, strtab + sym->st_name);
-			return -ENOENT;
-		}
 
 	        DEBUGP("type %d st_value %Lx r_addend %Lx loc %Lx\n",
 		       (int)ELF64_R_TYPE(rel[i].r_info), 
include/linux/elf.h +6 -5
diff -Nru a/include/linux/elf.h b/include/linux/elf.h
@@ -156,11 +156,12 @@
 #define STT_SECTION 3
 #define STT_FILE    4
 
-#define ELF32_ST_BIND(x) ((x) >> 4)
-#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
-
-#define ELF64_ST_BIND(x) ((x) >> 4)
-#define ELF64_ST_TYPE(x) (((unsigned int) x) & 0xf)
+#define ELF_ST_BIND(x)		((x) >> 4)
+#define ELF_ST_TYPE(x)		(((unsigned int) x) & 0xf)
+#define ELF32_ST_BIND(x)	ELF_ST_BIND(x)
+#define ELF32_ST_TYPE(x)	ELF_ST_TYPE(x)
+#define ELF64_ST_BIND(x)	ELF_ST_BIND(x)
+#define ELF64_ST_TYPE(x)	ELF_ST_TYPE(x)
 
 /* Symbolic values for the entries in the auxiliary table
    put on the initial stack */
include/linux/moduleloader.h +0 -8
diff -Nru a/include/linux/moduleloader.h b/include/linux/moduleloader.h
@@ -5,14 +5,6 @@
 #include <linux/module.h>
 #include <linux/elf.h>
 
-/* Helper function for arch-specific module loaders */
-unsigned long find_symbol_internal(Elf_Shdr *sechdrs,
-				   unsigned int symindex,
-				   const char *strtab,
-				   const char *name,
-				   struct module *mod,
-				   struct kernel_symbol_group **group);
-
 /* These must be implemented by the specific architecture */
 
 /* Adjust arch-specific sections.  Return 0 on success.  */
kernel/module.c +33 -46

118 lines not on this page · raw message

===================================================================

This BitKeeper patch contains the following changesets:
+
## Wrapped with gzip_uu ##

begin 664 bkpatch854 M'XL(`#(*(SX``]5:_7.;.!K^V?P5VNWL7IS&6$(?0'S)I&UR>YEVTT[:SMY- MM^/!(,>L,7@I\D=?_R]$G;\$7<MTZO:092D%X>O7KTZ-4K/4,?,YD>-M)\
M8#Q#_TRR_+#AI=+,OX1!$$DSECD\OTP2>-X>)"/9AI+MEZ_;HR1H628WX.T[ M+_<'Z%JFV6&#F/3N27X[EH>-R[/?/KYY<6D81T?HU<"+K^1[F:.C(R-/TFLO M"K(3+Q]$26SFJ1=G(YE[II^,BKNBA86Q!?\XL2GFHB",[OP24"(QX@,L,4< MP>;6%,AUMB@FQ"(NQ]@I&+=M;)PB8KJ,(TS;F+0)1=@]9/8AY2WL'&*,H,4G M0[#@+7H%/8>"+6R\1-^V':\,'WWZ_>WIQS=G[S^C5S(&<U'X'XDF<2#[82P# ME-V.>DF$_('TAUD'P0<4_D>?9'>T#1>(TH=AQGOYAXW6H_\,0SL8>,89?X M6BW[V?#V))!FV!NI=GV:M?ISX:7^H)U1%]^TAS*-9:2X,0$O^;K)A!#'(M3A M5H$9M:W"YH[$@HL^@3JN4^W>!ZRJ3J3$9L+B!78MR@%H.AJ>]*,PSDTO'9GP MQ^3&3-(K<S(LC<'3.HNX0QC7'#N$E8PYC+FV)AYC-FNVUN'L,;H(CY*""<* MWR3+;T_4U4_2L7*BZ4U**^.Q7PO-LJA#W()3SECANZS?\WH]1_J6LE?!ZW& MZ"(TBPBJH7>M1R=Q),\,^,P'GH+/3"&FV!UZ"R".66XH"YQ:=$3SV$0[A# MI,\":VW7UAM>1$@LN+"41C)["3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:'^87754-D&()W:K,PJZ%LC56=64;>[ MP+0]_5'T*]0Z4-]J'4>A+^-,=J_&43)L*E-,E#;*/1SP]MY/$RA0(MN#VP&" MZJWCY$LLTV93A50<YM9S!SPHZ$==SN"ML/E".U=)V&]IM3+WZ:^>NSF0U4 MVBOM&(W['E,5R__/*^;IO8I+/1$>H%@EV:H^E*G3J&VD;DE_;PH16MM0%4L_ MX8YJB:-W54O_*?[MA?"*=%"(_HYBN#U_WD3_5;.[JX,*N*FH8NKJUMG%V[-_ MG;WJJ$>]%,91!\IP&Q&FG@BE>V;)0-W?-'J\2;T6W.++3(HD;)%>6CYVAN ML>Q7Q9J.\:<J"/J[5"-E>6XI%'VZH4]!.TOZGM3V$O6M#G<Q=K+\X<<TMA MW$^:,!77/RR^\?9B]=+!C6H,71A/MQ[?79YT?WCQ>7%^<5OZ.=?LD/T,1[& MP*?9R/\E^S/^^<"8#@WXT50MVUC3^&9GI1\N/BCG"Z99/$-QZ@@'5N+P0N^0 AJO*35,5N>6=^*KP\I#P9'?DN[6'>LXW_4TL]:MR+@``
`
end

#1 lore raw

In message <[email protected]> you write:

Quoted 6 lines

I discovered this while working on oprofile for Alpha. I thought I'd avoid a whole series of nested ifdefs by marking some symbols weak, and so let them go undefined and resolve to null. Except that we don't handle that in the new module loader.

Fixed thus.

That part looks OK. The second loop was only there so we placed common symbols first: now we don't do that, your cleanup is a good idea. I'll extract and test that part.

Quoted 3 lines

I also correct a misconception in simplify_symbol. It is pointless to lookup an undefined symbol in the module in which it is undefined.

<sigh>. I don't think so.

PPC64 (not in tree yet):

+ /* REL24 references to (external) .function won't
+ resolve; deal with that below */
+ if (!sym->st_value
+ && ELF64_R_TYPE(rela[i].r_info) != R_PPC_REL24) {
+ printk("%s: Unknown symbol %s (index %u)\n",
+ me->name, strtab + sym->st_name,
+ sym->st_shndx);
+ return -ENOENT;
+ }

That's *why* find_symbol_internal() is not static, and why we don't fail in simplify_symbol() 8(

Hope that clarifies,
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

#3 lore raw
In reply to Richard Henderson

In message <[email protected]> you write:

Quoted 6 lines
kernel/module.c +5 -0
 		case SHN_UNDEF:
+			sym[i].st_value
+			  = resolve_symbol(sechdrs, symindex, strtab,
+					   strtab + sym[i].st_name, mod);
+
+			/* Ok if resolved.  */

kernel/module.c line 864

Quoted 10 lines
kernel/module.c +9 -0
+			if (sym[i].st_value != 0)
+				break;
+			/* Ok if weak.  */
+			if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK)
+				break;
+
+			printk(KERN_WARNING "%s: Unknown symbol %s\n",
+			       mod->name, strtab + sym[i].st_name);
+			ret = -ENOENT;
 			break;

I don't understand this. For a weak symbol, st_shndx won't be SHN_UNDEF. And you don't want to set its value to 0, anyway. I think you want:

	default:
		if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK) {
			unsigned long val = resolve_symbol(...);
			if (val)
				sym[i].st_value = val;
		} else
			...

Or am I missing something?
Rusty.
PS. "s/Fix weak symbol handling/Implement weak symbol handling/" 8) --
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

#5 lore raw
In reply to Richard Henderson

In message <[email protected]> you write:

Quoted 6 lines

I discovered this while working on oprofile for Alpha. I thought I'd avoid a whole series of nested ifdefs by marking some symbols weak, and so let them go undefined and resolve to null. Except that we don't handle that in the new module loader.

Fixed thus.

After that's reverted, here's my implementation. Richard?

Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

Name: Weak Symbol Support
Author: Richard Henderson
Status: Tested on 2.5.58
Depends: Module/revert-rth.patch.gz

D: This is Rusty's cut-down version of Richard's Weak Symbol Support
D: patch.

include/linux/moduleloader.h +3 -6
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .22700-2.5.58-weak.pre/include/linux/moduleloader.h .22700-2.5.58-weak/include/linux/moduleloader.h
@@ -6,12 +6,9 @@
 #include <linux/elf.h>
 
 /* Helper function for arch-specific module loaders */
-unsigned long find_symbol_internal(Elf_Shdr *sechdrs,
-				   unsigned int symindex,
-				   const char *strtab,
-				   const char *name,
-				   struct module *mod,
-				   struct kernel_symbol_group **group);
+unsigned long module_find_symbol(const char *name,
+				 struct module *mod,
+				 struct kernel_symbol_group **group);
 
 /* These must be implemented by the specific architecture */
 
kernel/module.c +28 -39

98 lines not on this page · raw message

include/asm-alpha/module.h +1 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .22700-2.5.58-weak.pre/include/asm-alpha/module.h .22700-2.5.58-weak/include/asm-alpha/module.h
@@ -13,6 +13,7 @@ struct mod_arch_specific
 #define Elf_Dyn Elf64_Dyn
 #define Elf_Rel Elf64_Rel
 #define Elf_Rela Elf64_Rela
+#define ELF_ST_BIND(info) ELF64_ST_BIND(info)
 
 #define ARCH_SHF_SMALL SHF_ALPHA_GPREL
 
include/asm-arm/module.h +1 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .22700-2.5.58-weak.pre/include/asm-arm/module.h .22700-2.5.58-weak/include/asm-arm/module.h
@@ -9,5 +9,6 @@ struct mod_arch_specific
 #define Elf_Shdr	Elf32_Shdr
 #define Elf_Sym		Elf32_Sym
 #define Elf_Ehdr	Elf32_Ehdr
+#define ELF_ST_BIND(info) ELF32_ST_BIND(info)
 
 #endif /* _ASM_ARM_MODULE_H */
include/asm-i386/module.h +1 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .22700-2.5.58-weak.pre/include/asm-i386/module.h .22700-2.5.58-weak/include/asm-i386/module.h
@@ -8,4 +8,5 @@ struct mod_arch_specific
 #define Elf_Shdr Elf32_Shdr
 #define Elf_Sym Elf32_Sym
 #define Elf_Ehdr Elf32_Ehdr
+#define ELF_ST_BIND(info) ELF32_ST_BIND(info)
 #endif /* _ASM_I386_MODULE_H */
include/asm-m68k/module.h +1 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .22700-2.5.58-weak.pre/include/asm-m68k/module.h .22700-2.5.58-weak/include/asm-m68k/module.h
@@ -4,4 +4,5 @@ struct mod_arch_specific { };
 #define Elf_Shdr Elf32_Shdr
 #define Elf_Sym Elf32_Sym
 #define Elf_Ehdr Elf32_Ehdr
+#define ELF_ST_BIND(info) ELF32_ST_BIND(info)
 #endif /* _ASM_M68K_MODULE_H */
include/asm-parisc/module.h +2 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .22700-2.5.58-weak.pre/include/asm-parisc/module.h .22700-2.5.58-weak/include/asm-parisc/module.h
@@ -7,10 +7,12 @@
 #define Elf_Shdr Elf64_Shdr
 #define Elf_Sym Elf64_Sym
 #define Elf_Ehdr Elf64_Ehdr
+#define ELF_ST_BIND(info) ELF64_ST_BIND(info)
 #else
 #define Elf_Shdr Elf32_Shdr
 #define Elf_Sym Elf32_Sym
 #define Elf_Ehdr Elf32_Ehdr
+#define ELF_ST_BIND(info) ELF32_ST_BIND(info)
 #endif
 
 #define module_map(x)		vmalloc(x)
include/asm-ppc/module.h +1 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .22700-2.5.58-weak.pre/include/asm-ppc/module.h .22700-2.5.58-weak/include/asm-ppc/module.h
@@ -25,6 +25,7 @@ struct mod_arch_specific
 #define Elf_Shdr Elf32_Shdr
 #define Elf_Sym Elf32_Sym
 #define Elf_Ehdr Elf32_Ehdr
+#define ELF_ST_BIND(info) ELF32_ST_BIND(info)
 
 /* Make empty sections for module_frob_arch_sections to expand. */
 #ifdef MODULE
include/asm-s390/module.h +1 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .22700-2.5.58-weak.pre/include/asm-s390/module.h .22700-2.5.58-weak/include/asm-s390/module.h
@@ -22,4 +22,5 @@ struct mod_arch_specific
 #define Elf_Sym ElfW(Sym)
 #define Elf_Ehdr ElfW(Ehdr)
 #define ELF_R_TYPE ELFW(R_TYPE)
+#define ELF_ST_BIND(info) ELFW(_ST_BIND)(info)
 #endif /* _ASM_S390_MODULE_H */
include/asm-s390x/module.h +1 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .22700-2.5.58-weak.pre/include/asm-s390x/module.h .22700-2.5.58-weak/include/asm-s390x/module.h
@@ -22,4 +22,5 @@ struct mod_arch_specific
 #define Elf_Sym ElfW(Sym)
 #define Elf_Ehdr ElfW(Ehdr)
 #define ELF_R_TYPE ELFW(R_TYPE)
+#define ELF_ST_BIND(info) ELFW(_ST_BIND)(info)
 #endif /* _ASM_S390_MODULE_H */
include/asm-sparc/module.h +1 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .22700-2.5.58-weak.pre/include/asm-sparc/module.h .22700-2.5.58-weak/include/asm-sparc/module.h
@@ -4,4 +4,5 @@ struct mod_arch_specific { };
 #define Elf_Shdr Elf32_Shdr
 #define Elf_Sym Elf32_Sym
 #define Elf_Ehdr Elf32_Ehdr
+#define ELF_ST_BIND(info) ELF32_ST_BIND(info)
 #endif /* _ASM_SPARC_MODULE_H */
include/asm-sparc64/module.h +1 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .22700-2.5.58-weak.pre/include/asm-sparc64/module.h .22700-2.5.58-weak/include/asm-sparc64/module.h
@@ -4,4 +4,5 @@ struct mod_arch_specific { };
 #define Elf_Shdr Elf64_Shdr
 #define Elf_Sym Elf64_Sym
 #define Elf_Ehdr Elf64_Ehdr
+#define ELF_ST_BIND(info) ELF64_ST_BIND(info)
 #endif /* _ASM_SPARC64_MODULE_H */
include/asm-v850/module.h +1 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .22700-2.5.58-weak.pre/include/asm-v850/module.h .22700-2.5.58-weak/include/asm-v850/module.h
@@ -34,6 +34,7 @@ struct mod_arch_specific
 #define Elf_Shdr Elf32_Shdr
 #define Elf_Sym Elf32_Sym
 #define Elf_Ehdr Elf32_Ehdr
+#define ELF_ST_BIND(info) ELF32_ST_BIND(info)
 
 /* Make empty sections for module_frob_arch_sections to expand. */
 #ifdef MODULE
include/asm-x86_64/module.h +1 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .22700-2.5.58-weak.pre/include/asm-x86_64/module.h .22700-2.5.58-weak/include/asm-x86_64/module.h
@@ -6,5 +6,6 @@ struct mod_arch_specific {}; 
 #define Elf_Shdr Elf64_Shdr
 #define Elf_Sym Elf64_Sym
 #define Elf_Ehdr Elf64_Ehdr
+#define ELF_ST_BIND(info) ELF64_ST_BIND(info)
 
 #endif 
#2 lore raw
In reply to Rusty Russell
Quoted 12 lines · Rusty Russell

PPC64 (not in tree yet):

(quoted diff) +9 -0
+		/* REL24 references to (external) .function won't
+                   resolve; deal with that below */
+		if (!sym->st_value
+		    && ELF64_R_TYPE(rela[i].r_info) != R_PPC_REL24) {
+			printk("%s: Unknown symbol %s (index %u)\n",
+			       me->name, strtab + sym->st_name,
+			       sym->st_shndx);
+			return -ENOENT;
+		}
Quoted 4 lines

That's *why* find_symbol_internal() is not static, and why we don't fail in simplify_symbol() 8(

Hope that clarifies,

Not really. Send me the whole file?

r~

#6 lore raw
In reply to Rusty Russell
Quoted 1 line · Rusty Russell

After that's reverted, here's my implementation. Richard?

Nope. Doesn't handle undef weak. Handling of defined weak I'm not sure is necessary at all; I can't think of any good use for it in the kernel.

r~

#7 lore raw

In message <[email protected]> you write:

Quoted 6 lines · Rusty Russell
Quoted 1 line

After that's reverted, here's my implementation. Richard?

Nope. Doesn't handle undef weak. Handling of defined weak I'm not sure is necessary at all; I can't think of any good use for it in the kernel.

I didn't know about undefined weak symbols. I was thinking:

int nosupport_function(void)

{
	return -ENOSYS;
}

extern int support_function(void)

	__attribute__((alias("nosupport_function"), weak));

....

int init(void)

{
	/* Or you could simply call it... */
	if (support_function == nosupport_function)
		...

Of course, you can use symbol_get and symbol_put, too, but they don't work if !CONFIG_MODULES: I chose to implement that case as simply a reference, so you'll get a link failure: see linux/module.h.

Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.