Browse Source

create generic ELF_* macros to hide 32/64 bit differences

Mike Frysinger 20 years ago
parent
commit
59cc1e9342
3 changed files with 24 additions and 4 deletions
  1. 20 0
      ldso/include/dl-elf.h
  2. 2 2
      ldso/ldso/dl-hash.c
  3. 2 2
      ldso/ldso/dl-startup.c

+ 20 - 0
ldso/include/dl-elf.h

@@ -35,6 +35,26 @@ extern int _dl_linux_resolve(void);
 extern int _dl_fixup(struct dyn_elf *rpnt, int flag);
 extern void _dl_protect_relro (struct elf_resolve *l);
 
+/*
+ * Bitsize related settings for things ElfW()
+ * does not handle already
+ */
+#if __WORDSIZE == 64
+# define ELF_ST_BIND(val) ELF64_ST_TYPE(val)
+# define ELF_ST_TYPE(val) ELF64_ST_TYPE(val)
+# define ELF_R_SYM(i)     ELF64_R_SYM(i)
+# ifndef ELF_CLASS
+#  define ELF_CLASS ELFCLASS64
+# endif
+#else
+# define ELF_ST_BIND(val) ELF32_ST_TYPE(val)
+# define ELF_ST_TYPE(val) ELF32_ST_TYPE(val)
+# define ELF_R_SYM(i)     ELF32_R_SYM(i)
+# ifndef ELF_CLASS
+#  define ELF_CLASS ELFCLASS32
+# endif
+#endif
+
 /*
  * Datatype of a relocation on this platform
  */

+ 2 - 2
ldso/ldso/dl-hash.c

@@ -190,10 +190,10 @@ char *_dl_find_hash(const char *name, struct dyn_elf *rpnt, struct elf_resolve *
 				continue;
 			if (sym->st_value == 0)
 				continue;
-			if (ELF32_ST_TYPE(sym->st_info) > STT_FUNC)
+			if (ELF_ST_TYPE(sym->st_info) > STT_FUNC)
 				continue;
 
-			switch (ELF32_ST_BIND(sym->st_info)) {
+			switch (ELF_ST_BIND(sym->st_info)) {
 			case STB_WEAK:
 #if 0
 /* Perhaps we should support old style weak symbol handling

+ 2 - 2
ldso/ldso/dl-startup.c

@@ -164,7 +164,7 @@ static void * __attribute_used__ _dl_start(unsigned long args)
 	header = (ElfW(Ehdr) *) auxvt[AT_BASE].a_un.a_ptr;
 
 	/* Check the ELF header to make sure everything looks ok.  */
-	if (!header || header->e_ident[EI_CLASS] != ELFCLASS32 ||
+	if (!header || header->e_ident[EI_CLASS] != ELF_CLASS ||
 			header->e_ident[EI_VERSION] != EV_CURRENT
 			/* Do not use an inline _dl_strncmp here or some arches
 			* will blow chunks, i.e. those that need to relocate all
@@ -255,7 +255,7 @@ static void * __attribute_used__ _dl_start(unsigned long args)
 			rpnt = (ELF_RELOC *) (rel_addr + load_addr);
 			for (i = 0; i < rel_size; i += sizeof(ELF_RELOC), rpnt++) {
 				reloc_addr = (unsigned long *) (load_addr + (unsigned long) rpnt->r_offset);
-				symtab_index = ELF32_R_SYM(rpnt->r_info);
+				symtab_index = ELF_R_SYM(rpnt->r_info);
 				symbol_addr = 0;
 				sym = NULL;
 				if (symtab_index) {