svn commit: trunk/busybox/modutils

vapier at busybox.net vapier at busybox.net
Sun Oct 2 07:02:17 UTC 2005


Author: vapier
Date: 2005-10-02 00:02:16 -0700 (Sun, 02 Oct 2005)
New Revision: 11725

Log:
remove all Elf32 hardcodes to make sure the elf handling is 64bit clean

Modified:
   trunk/busybox/modutils/insmod.c


Changeset:
Modified: trunk/busybox/modutils/insmod.c
===================================================================
--- trunk/busybox/modutils/insmod.c	2005-10-02 06:44:39 UTC (rev 11724)
+++ trunk/busybox/modutils/insmod.c	2005-10-02 07:02:16 UTC (rev 11725)
@@ -528,6 +528,12 @@
 # define ELF64_ST_INFO(bind, type)       (((bind) << 4) + ((type) & 0xf))
 #endif
 
+#define ELF_ST_BIND(info) ELFW(ST_BIND)(info)
+#define ELF_ST_TYPE(info) ELFW(ST_TYPE)(info)
+#define ELF_ST_INFO(bind, type) ELFW(ST_INFO)(bind, type)
+#define ELF_R_TYPE(val) ELFW(R_TYPE)(val)
+#define ELF_R_SYM(val) ELFW(R_SYM)(val)
+
 struct obj_string_patch;
 struct obj_symbol_patch;
 
@@ -726,8 +732,8 @@
 struct mips_hi16
 {
 	struct mips_hi16 *next;
-	Elf32_Addr *addr;
-	Elf32_Addr value;
+	ElfW(Addr) *addr;
+	ElfW(Addr) value;
 };
 #endif
 
@@ -859,7 +865,7 @@
 #endif
 #endif
 
-	switch (ELF32_R_TYPE(rel->r_info)) {
+	switch (ELF_R_TYPE(rel->r_info)) {
 
 #if defined(__arm__)
 		case R_ARM_NONE:
@@ -921,7 +927,7 @@
 				ip = (unsigned long *)(ifile->plt->contents + pe->offset);
 				ip[0] = 0x0d105810; /* basr 1,0; lg 1,10(1); br 1 */
 				ip[1] = 0x100607f1;
-				if (ELF32_R_TYPE(rel->r_info) == R_390_PLT16DBL)
+				if (ELF_R_TYPE(rel->r_info) == R_390_PLT16DBL)
 					ip[2] = v - 2;
 				else
 					ip[2] = v;
@@ -930,9 +936,9 @@
 
 			/* Insert relative distance to target.  */
 			v = plt + pe->offset - dot;
-			if (ELF32_R_TYPE(rel->r_info) == R_390_PLT32)
+			if (ELF_R_TYPE(rel->r_info) == R_390_PLT32)
 				*(unsigned int *) loc = (unsigned int) v;
-			else if (ELF32_R_TYPE(rel->r_info) == R_390_PLT16DBL)
+			else if (ELF_R_TYPE(rel->r_info) == R_390_PLT16DBL)
 				*(unsigned short *) loc = (unsigned short) ((v + 2) >> 1);
 			break;
 
@@ -958,13 +964,13 @@
 			if (!isym->gotent.inited)
 			{
 				isym->gotent.inited = 1;
-				*(Elf32_Addr *)(ifile->got->contents + isym->gotent.offset) = v;
+				*(ElfW(Addr) *)(ifile->got->contents + isym->gotent.offset) = v;
 			}
-			if (ELF32_R_TYPE(rel->r_info) == R_390_GOT12)
+			if (ELF_R_TYPE(rel->r_info) == R_390_GOT12)
 				*(unsigned short *) loc |= (*(unsigned short *) loc + isym->gotent.offset) & 0xfff;
-			else if (ELF32_R_TYPE(rel->r_info) == R_390_GOT16)
+			else if (ELF_R_TYPE(rel->r_info) == R_390_GOT16)
 				*(unsigned short *) loc += isym->gotent.offset;
-			else if (ELF32_R_TYPE(rel->r_info) == R_390_GOT32)
+			else if (ELF_R_TYPE(rel->r_info) == R_390_GOT32)
 				*(unsigned int *) loc += isym->gotent.offset;
 			break;
 
@@ -1106,8 +1112,8 @@
 
 		case R_68K_PC8:
 			v -= dot;
-			if ((Elf32_Sword)v > 0x7f ||
-					(Elf32_Sword)v < -(Elf32_Sword)0x80) {
+			if ((ElfW(Sword))v > 0x7f ||
+					(ElfW(Sword))v < -(ElfW(Sword))0x80) {
 				ret = obj_reloc_overflow;
 			}
 			*(char *)loc = v;
@@ -1115,8 +1121,8 @@
 
 		case R_68K_PC16:
 			v -= dot;
-			if ((Elf32_Sword)v > 0x7fff ||
-					(Elf32_Sword)v < -(Elf32_Sword)0x8000) {
+			if ((ElfW(Sword))v > 0x7fff ||
+					(ElfW(Sword))v < -(ElfW(Sword))0x8000) {
 				ret = obj_reloc_overflow;
 			}
 			*(short *)loc = v;
@@ -1182,7 +1188,7 @@
 		case R_MIPS_LO16:
 			{
 				unsigned long insnlo = *loc;
-				Elf32_Addr val, vallo;
+				ElfW(Addr) val, vallo;
 
 				/* Sign extend the addend we extract from the lo insn.  */
 				vallo = ((insnlo & 0xffff) ^ 0x8000) - 0x8000;
@@ -1300,9 +1306,9 @@
 		case R_SH_IMM_MEDLOW16:
 		case R_SH_IMM_LOW16:
 			{
-				Elf32_Addr word;
+				ElfW(Addr) word;
 
-				if (ELF32_R_TYPE(rel->r_info) == R_SH_IMM_MEDLOW16)
+				if (ELF_R_TYPE(rel->r_info) == R_SH_IMM_MEDLOW16)
 					v >>= 16;
 
 				/*
@@ -1324,13 +1330,13 @@
 		case R_SH_IMM_MEDLOW16_PCREL:
 		case R_SH_IMM_LOW16_PCREL:
 			{
-				Elf32_Addr word;
+				ElfW(Addr) word;
 
 				word = *loc & ~0x3fffc00;
 
 				v -= dot;
 
-				if (ELF32_R_TYPE(rel->r_info) == R_SH_IMM_MEDLOW16_PCREL)
+				if (ELF_R_TYPE(rel->r_info) == R_SH_IMM_MEDLOW16_PCREL)
 					v >>= 16;
 
 				word |= (v & 0xffff) << 10;
@@ -1343,7 +1349,7 @@
 #endif /* __sh__ */
 
 		default:
-			printf("Warning: unhandled reloc %d\n",(int)ELF32_R_TYPE(rel->r_info));
+			printf("Warning: unhandled reloc %d\n",(int)ELF_R_TYPE(rel->r_info));
 			ret = obj_reloc_unhandled;
 			break;
 
@@ -1391,16 +1397,16 @@
 			break;
 	        case R_H8_PCREL16:
 			v -= dot + 2;
-			if ((Elf32_Sword)v > 0x7fff || 
-			    (Elf32_Sword)v < -(Elf32_Sword)0x8000)
+			if ((ElfW(Sword))v > 0x7fff || 
+			    (ElfW(Sword))v < -(ElfW(Sword))0x8000)
 				ret = obj_reloc_overflow;
 			else 
 				*(unsigned short *)loc = v;
 			break;
 	        case R_H8_PCREL8:
 			v -= dot + 1;
-			if ((Elf32_Sword)v > 0x7f || 
-			    (Elf32_Sword)v < -(Elf32_Sword)0x80)
+			if ((ElfW(Sword))v > 0x7f || 
+			    (ElfW(Sword))v < -(ElfW(Sword))0x80)
 				ret = obj_reloc_overflow;
 			else 
 				*(unsigned char *)loc = v;
@@ -1453,7 +1459,7 @@
 #if defined (__arm__) || defined (__powerpc__)
 			if ((int)v < -0x02000000 || (int)v >= 0x02000000)
 #elif defined (__v850e__)
-				if ((Elf32_Sword)v > 0x1fffff || (Elf32_Sword)v < (Elf32_Sword)-0x200000)
+				if ((ElfW(Sword))v > 0x1fffff || (ElfW(Sword))v < (ElfW(Sword))-0x200000)
 #endif
 					/* go via the plt */
 					v = plt + pe->offset - dot;
@@ -1610,7 +1616,7 @@
 		strtab = (const char *) strsec->contents;
 
 		for (; rel < relend; ++rel) {
-			extsym = &symtab[ELF32_R_SYM(rel->r_info)];
+			extsym = &symtab[ELF_R_SYM(rel->r_info)];
 
 #if defined(CONFIG_USE_GOT_ENTRIES)
 			got_allocate = 0;
@@ -1619,7 +1625,7 @@
 			plt_allocate = 0;
 #endif
 
-			switch (ELF32_R_TYPE(rel->r_info)) {
+			switch (ELF_R_TYPE(rel->r_info)) {
 #if defined(__arm__)
 				case R_ARM_PC24:
 				case R_ARM_PLT32:
@@ -1818,15 +1824,15 @@
 {
 	struct obj_symbol *sym;
 	unsigned long hash = f->symbol_hash(name) % HASH_BUCKETS;
-	int n_type = ELFW(ST_TYPE) (info);
-	int n_binding = ELFW(ST_BIND) (info);
+	int n_type = ELF_ST_TYPE(info);
+	int n_binding = ELF_ST_BIND(info);
 
 	for (sym = f->symtab[hash]; sym; sym = sym->next)
 		if (f->symbol_cmp(sym->name, name) == 0) {
 			int o_secidx = sym->secidx;
 			int o_info = sym->info;
-			int o_type = ELFW(ST_TYPE) (o_info);
-			int o_binding = ELFW(ST_BIND) (o_info);
+			int o_type = ELF_ST_TYPE(o_info);
+			int o_binding = ELF_ST_BIND(o_info);
 
 			/* A redefinition!  Is it legal?  */
 
@@ -1887,7 +1893,7 @@
 	f->symtab[hash] = sym;
 	sym->ksymidx = -1;
 
-	if (ELFW(ST_BIND)(info) == STB_LOCAL && symidx != -1) {
+	if (ELF_ST_BIND(info) == STB_LOCAL && symidx != -1) {
 		if (symidx >= f->local_symtab_size)
 			bb_error_msg("local symbol %s with index %ld exceeds local_symtab_size %ld",
 					name, (long) symidx, (long) f->local_symtab_size);
@@ -2101,14 +2107,14 @@
 #endif /* SYMBOL_PREFIX */
 
 		sym = obj_find_symbol(f, name);
-		if (sym && !(ELFW(ST_BIND) (sym->info) == STB_LOCAL)) {
+		if (sym && !(ELF_ST_BIND(sym->info) == STB_LOCAL)) {
 #ifdef SYMBOL_PREFIX
 			/* Put NAME_BUF into more permanent storage.  */
 			name = xmalloc (name_size);
 			strcpy (name, name_buf);
 #endif
 			sym = obj_add_symbol(f, name, -1,
-					ELFW(ST_INFO) (STB_GLOBAL,
+					ELF_ST_INFO(STB_GLOBAL,
 						STT_NOTYPE),
 					idx, s->value, 0);
 			/* Did our symbol just get installed?  If so, mark the
@@ -2569,7 +2575,7 @@
 	memset(sec->contents, 0, sizeof(struct new_module));
 
 	obj_add_symbol(f, SPFX "__this_module", -1,
-			ELFW(ST_INFO) (STB_LOCAL, STT_OBJECT), sec->idx, 0,
+			ELF_ST_INFO(STB_LOCAL, STT_OBJECT), sec->idx, 0,
 			sizeof(struct new_module));
 
 	obj_string_patch(f, sec->idx, offsetof(struct new_module, name),
@@ -2658,7 +2664,7 @@
 		for (nsyms = i = 0; i < HASH_BUCKETS; ++i) {
 			struct obj_symbol *sym;
 			for (sym = f->symtab[i]; sym; sym = sym->next)
-				if (ELFW(ST_BIND) (sym->info) != STB_LOCAL
+				if (ELF_ST_BIND(sym->info) != STB_LOCAL
 						&& sym->secidx <= SHN_HIRESERVE
 						&& (sym->secidx >= SHN_LORESERVE
 							|| loaded[sym->secidx])) {
@@ -2815,7 +2821,7 @@
 		struct obj_symbol *sym;
 		for (sym = f->symtab[i]; sym; sym = sym->next)
 			if (sym->secidx == SHN_UNDEF) {
-				if (ELFW(ST_BIND) (sym->info) == STB_WEAK) {
+				if (ELF_ST_BIND(sym->info) == STB_WEAK) {
 					sym->secidx = SHN_ABS;
 					sym->value = 0;
 				} else {
@@ -3001,12 +3007,12 @@
 
 			/* Attempt to find a value to use for this relocation.  */
 
-			symndx = ELFW(R_SYM) (rel->r_info);
+			symndx = ELF_R_SYM(rel->r_info);
 			if (symndx) {
 				/* Note we've already checked for undefined symbols.  */
 
 				extsym = &symtab[symndx];
-				if (ELFW(ST_BIND) (extsym->st_info) == STB_LOCAL) {
+				if (ELF_ST_BIND(extsym->st_info) == STB_LOCAL) {
 					/* Local symbols we look up in the local table to be sure
 					   we get the one that is really intended.  */
 					intsym = f->local_symtab[symndx];
@@ -3027,7 +3033,7 @@
 #if defined(__alpha__) && defined(AXP_BROKEN_GAS)
 			/* Work around a nasty GAS bug, that is fixed as of 2.7.0.9.  */
 			if (!extsym || !extsym->st_name ||
-					ELFW(ST_BIND) (extsym->st_info) != STB_LOCAL)
+					ELF_ST_BIND(extsym->st_info) != STB_LOCAL)
 #endif
 				value += rel->r_addend;
 #endif
@@ -3049,11 +3055,11 @@
 bad_reloc:
 					if (extsym) {
 						bb_error_msg("%s of type %ld for %s", errmsg,
-								(long) ELFW(R_TYPE) (rel->r_info),
+								(long) ELF_R_TYPE(rel->r_info),
 								strtab + extsym->st_name);
 					} else {
 						bb_error_msg("%s of type %ld", errmsg,
-								(long) ELFW(R_TYPE) (rel->r_info));
+								(long) ELF_R_TYPE(rel->r_info));
 					}
 					ret = 0;
 					break;
@@ -3373,7 +3379,7 @@
 	for (p = specials; *p; ++p)
 		if ((sym = obj_find_symbol(f, *p)) != NULL)
 			sym->info =
-				ELFW(ST_INFO) (STB_LOCAL, ELFW(ST_TYPE) (sym->info));
+				ELF_ST_INFO(STB_LOCAL, ELF_ST_TYPE(sym->info));
 }
 
 
@@ -3577,7 +3583,7 @@
 				(int)(2*sizeof(statbuf.st_mtime)), statbuf.st_mtime,
 				version);
 		sym = obj_add_symbol(f, name, -1,
-				ELFW(ST_INFO) (STB_GLOBAL, STT_NOTYPE),
+				ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE),
 				sec->idx, sec->header.sh_addr, 0);
 		if (use_ksymtab)
 			new_add_ksymtab(f, sym);
@@ -3595,7 +3601,7 @@
 		name = xmalloc(l);
 		snprintf(name, l, "%s%s_P%s",
 				symprefix, m_name, f->persist);
-		sym = obj_add_symbol(f, name, -1, ELFW(ST_INFO) (STB_GLOBAL, STT_NOTYPE),
+		sym = obj_add_symbol(f, name, -1, ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE),
 				sec->idx, sec->header.sh_addr, 0);
 		if (use_ksymtab)
 			new_add_ksymtab(f, sym);
@@ -3617,7 +3623,7 @@
 			snprintf(name, l, "%s%s_S%s_L%ld",
 					symprefix, m_name, sec->name,
 					(long)sec->header.sh_size);
-			sym = obj_add_symbol(f, name, -1, ELFW(ST_INFO) (STB_GLOBAL, STT_NOTYPE),
+			sym = obj_add_symbol(f, name, -1, ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE),
 					sec->idx, sec->header.sh_addr, 0);
 			if (use_ksymtab)
 				new_add_ksymtab(f, sym);
@@ -3707,7 +3713,7 @@
 			value = sym->value + sec->header.sh_addr;
 		}
 
-		if (ELFW(ST_BIND) (sym->info) == STB_LOCAL)
+		if (ELF_ST_BIND(sym->info) == STB_LOCAL)
 			type = tolower(type);
 
 		printf("%0*lx %c %s\n", (int) (2 * sizeof(void *)), value,




More information about the busybox-cvs mailing list