浏览代码

Scrub up use of ELF_USES_RELOCA and eliminte some unsightly ifdefs

Eric Andersen 21 年之前
父节点
当前提交
8391a52315
共有 6 个文件被更改,包括 87 次插入93 次删除
  1. 9 0
      ldso/include/dl-elf.h
  2. 9 0
      ldso/include/ld_elf.h
  3. 15 0
      ldso/include/ldso.h
  4. 26 42
      ldso/ldso/dl-elf.c
  5. 2 9
      ldso/ldso/ldso.c
  6. 26 42
      ldso/ldso/readelflib1.c

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

@@ -77,11 +77,20 @@ extern int _dl_linux_resolve(void);
  */
 #ifdef ELF_USES_RELOCA
 # define ELF_RELOC	ElfW(Rela)
+# define DT_RELOC_TABLE_ADDR	DT_RELA
+# define DT_RELOC_TABLE_SIZE	DT_RELASZ
+# define UNSUPPORTED_RELOC_TYPE	DT_REL
+# define UNSUPPORTED_RELOC_STR	"REL"
 #else
 # define ELF_RELOC	ElfW(Rel)
+# define DT_RELOC_TABLE_ADDR	DT_REL
+# define DT_RELOC_TABLE_SIZE	DT_RELSZ
+# define UNSUPPORTED_RELOC_TYPE	DT_RELA
+# define UNSUPPORTED_RELOC_STR	"RELA"
 #endif
 
 
+
 /* Convert between the Linux flags for page protections and the
    ones specified in the ELF standard. */
 #define LXFLAGS(X) ( (((X) & PF_R) ? PROT_READ : 0) | \

+ 9 - 0
ldso/include/ld_elf.h

@@ -77,11 +77,20 @@ extern int _dl_linux_resolve(void);
  */
 #ifdef ELF_USES_RELOCA
 # define ELF_RELOC	ElfW(Rela)
+# define DT_RELOC_TABLE_ADDR	DT_RELA
+# define DT_RELOC_TABLE_SIZE	DT_RELASZ
+# define UNSUPPORTED_RELOC_TYPE	DT_REL
+# define UNSUPPORTED_RELOC_STR	"REL"
 #else
 # define ELF_RELOC	ElfW(Rel)
+# define DT_RELOC_TABLE_ADDR	DT_REL
+# define DT_RELOC_TABLE_SIZE	DT_RELSZ
+# define UNSUPPORTED_RELOC_TYPE	DT_RELA
+# define UNSUPPORTED_RELOC_STR	"RELA"
 #endif
 
 
+
 /* Convert between the Linux flags for page protections and the
    ones specified in the ELF standard. */
 #define LXFLAGS(X) ( (((X) & PF_R) ? PROT_READ : 0) | \

+ 15 - 0
ldso/include/ldso.h

@@ -15,3 +15,18 @@
 #  define PAGE_SHIFT		12
 #  define PAGE_SIZE		(1UL << PAGE_SHIFT)
 #endif
+
+/* Prepare for the case that `__builtin_expect' is not available.  */
+#if __GNUC__ == 2 && __GNUC_MINOR__ < 96
+#define __builtin_expect(x, expected_value) (x)
+#endif
+#ifndef likely
+# define likely(x)	__builtin_expect((!!(x)),1)
+#endif
+#ifndef unlikely
+# define unlikely(x)	__builtin_expect((!!(x)),0)
+#endif
+#ifndef __LINUX_COMPILER_H
+#define __LINUX_COMPILER_H
+#endif
+

+ 26 - 42
ldso/ldso/dl-elf.c

@@ -874,74 +874,58 @@ int _dl_fixup(struct dyn_elf *rpnt, int flag)
 	tpnt = rpnt->dyn;
 
 #if defined (__SUPPORT_LD_DEBUG__)
-	if(_dl_debug) _dl_dprintf(_dl_debug_file,"\nrelocation processing: %s", tpnt->libname);	
-#endif    
-	
-	if (tpnt->dynamic_info[DT_REL]) {
-#ifdef ELF_USES_RELOCA
-#if defined (__SUPPORT_LD_DEBUG__)
-		if(_dl_debug) _dl_dprintf(2, "%s: can't handle REL relocation records\n", _dl_progname);
-#endif    
-		goof++;
-		return goof;
-#else
-		if (tpnt->init_flag & RELOCS_DONE)
-			return goof;
-		tpnt->init_flag |= RELOCS_DONE;
-		goof += _dl_parse_relocation_information(tpnt, 
-				tpnt->dynamic_info[DT_REL], 
-				tpnt->dynamic_info[DT_RELSZ], 0);
+	if(_dl_debug) _dl_dprintf(_dl_debug_file,"\nrelocation processing: %s", tpnt->libname);
 #endif
-	}
-	if (tpnt->dynamic_info[DT_RELA]) {
-#ifndef ELF_USES_RELOCA
+
+	if (unlikely(tpnt->dynamic_info[UNSUPPORTED_RELOC_TYPE])) {
 #if defined (__SUPPORT_LD_DEBUG__)
-		if(_dl_debug) _dl_dprintf(2, "%s: can't handle RELA relocation records\n", _dl_progname);
-#endif    
+		if(_dl_debug) {
+			_dl_dprintf(2, "%s: can't handle %s relocation records\n",
+					_dl_progname, UNSUPPORTED_RELOC_STR);
+		}
+#endif
 		goof++;
 		return goof;
-#else
+	}
+
+	if (tpnt->dynamic_info[DT_RELOC_TABLE_ADDR]) {
 		if (tpnt->init_flag & RELOCS_DONE)
 			return goof;
 		tpnt->init_flag |= RELOCS_DONE;
-		goof += _dl_parse_relocation_information(tpnt, 
-				tpnt->dynamic_info[DT_RELA], 
-				tpnt->dynamic_info[DT_RELASZ], 0);
-#endif
+		goof += _dl_parse_relocation_information(tpnt,
+				tpnt->dynamic_info[DT_RELOC_TABLE_ADDR],
+				tpnt->dynamic_info[DT_RELOC_TABLE_SIZE], 0);
 	}
+
 	if (tpnt->dynamic_info[DT_JMPREL]) {
 		if (tpnt->init_flag & JMP_RELOCS_DONE)
 			return goof;
 		tpnt->init_flag |= JMP_RELOCS_DONE;
 		if (flag & RTLD_LAZY) {
-			_dl_parse_lazy_relocation_information(tpnt, 
-					tpnt->dynamic_info[DT_JMPREL], 
+			_dl_parse_lazy_relocation_information(tpnt,
+					tpnt->dynamic_info[DT_JMPREL],
 					tpnt->dynamic_info [DT_PLTRELSZ], 0);
 		} else {
-			goof += _dl_parse_relocation_information(tpnt, 
-					tpnt->dynamic_info[DT_JMPREL], 
+			goof += _dl_parse_relocation_information(tpnt,
+					tpnt->dynamic_info[DT_JMPREL],
 					tpnt->dynamic_info[DT_PLTRELSZ], 0);
 		}
 	}
+
 	if (tpnt->init_flag & COPY_RELOCS_DONE)
 		return goof;
 	tpnt->init_flag |= COPY_RELOCS_DONE;
-#ifdef ELF_USES_RELOCA
-	goof += _dl_parse_copy_information(rpnt, 
-		tpnt->dynamic_info[DT_RELA], tpnt->dynamic_info[DT_RELASZ], 0);
-
-#else
-	goof += _dl_parse_copy_information(rpnt, tpnt->dynamic_info[DT_REL], 
-		tpnt->dynamic_info[DT_RELSZ], 0);
-
-#endif
+	goof += _dl_parse_copy_information(rpnt,
+		tpnt->dynamic_info[DT_RELOC_TABLE_ADDR],
+		tpnt->dynamic_info[DT_RELOC_TABLE_SIZE], 0);
 
 #if defined (__SUPPORT_LD_DEBUG__)
 	if(_dl_debug) {
-		_dl_dprintf(_dl_debug_file,"\nrelocation processing: %s", tpnt->libname);     
+		_dl_dprintf(_dl_debug_file,"\nrelocation processing: %s", tpnt->libname);
 		_dl_dprintf(_dl_debug_file,"; finished\n\n");
 	}
-#endif    
+#endif
+
 	return goof;
 }
 

+ 2 - 9
ldso/ldso/ldso.c

@@ -565,17 +565,10 @@ LD_BOOT(unsigned long args)
 		unsigned long rel_addr, rel_size;
 
 
-#ifdef ELF_USES_RELOCA
 		rel_addr = (indx ? tpnt->dynamic_info[DT_JMPREL] : tpnt->
-			 dynamic_info[DT_RELA]);
+			 dynamic_info[DT_RELOC_TABLE_ADDR]);
 		rel_size = (indx ? tpnt->dynamic_info[DT_PLTRELSZ] : tpnt->
-			 dynamic_info[DT_RELASZ]);
-#else
-		rel_addr = (indx ? tpnt->dynamic_info[DT_JMPREL] : tpnt->
-			 dynamic_info[DT_REL]);
-		rel_size = (indx ? tpnt->dynamic_info[DT_PLTRELSZ] : tpnt->
-			 dynamic_info[DT_RELSZ]);
-#endif
+			 dynamic_info[DT_RELOC_TABLE_SIZE]);
 
 		if (!rel_addr)
 			continue;

+ 26 - 42
ldso/ldso/readelflib1.c

@@ -874,74 +874,58 @@ int _dl_fixup(struct dyn_elf *rpnt, int flag)
 	tpnt = rpnt->dyn;
 
 #if defined (__SUPPORT_LD_DEBUG__)
-	if(_dl_debug) _dl_dprintf(_dl_debug_file,"\nrelocation processing: %s", tpnt->libname);	
-#endif    
-	
-	if (tpnt->dynamic_info[DT_REL]) {
-#ifdef ELF_USES_RELOCA
-#if defined (__SUPPORT_LD_DEBUG__)
-		if(_dl_debug) _dl_dprintf(2, "%s: can't handle REL relocation records\n", _dl_progname);
-#endif    
-		goof++;
-		return goof;
-#else
-		if (tpnt->init_flag & RELOCS_DONE)
-			return goof;
-		tpnt->init_flag |= RELOCS_DONE;
-		goof += _dl_parse_relocation_information(tpnt, 
-				tpnt->dynamic_info[DT_REL], 
-				tpnt->dynamic_info[DT_RELSZ], 0);
+	if(_dl_debug) _dl_dprintf(_dl_debug_file,"\nrelocation processing: %s", tpnt->libname);
 #endif
-	}
-	if (tpnt->dynamic_info[DT_RELA]) {
-#ifndef ELF_USES_RELOCA
+
+	if (unlikely(tpnt->dynamic_info[UNSUPPORTED_RELOC_TYPE])) {
 #if defined (__SUPPORT_LD_DEBUG__)
-		if(_dl_debug) _dl_dprintf(2, "%s: can't handle RELA relocation records\n", _dl_progname);
-#endif    
+		if(_dl_debug) {
+			_dl_dprintf(2, "%s: can't handle %s relocation records\n",
+					_dl_progname, UNSUPPORTED_RELOC_STR);
+		}
+#endif
 		goof++;
 		return goof;
-#else
+	}
+
+	if (tpnt->dynamic_info[DT_RELOC_TABLE_ADDR]) {
 		if (tpnt->init_flag & RELOCS_DONE)
 			return goof;
 		tpnt->init_flag |= RELOCS_DONE;
-		goof += _dl_parse_relocation_information(tpnt, 
-				tpnt->dynamic_info[DT_RELA], 
-				tpnt->dynamic_info[DT_RELASZ], 0);
-#endif
+		goof += _dl_parse_relocation_information(tpnt,
+				tpnt->dynamic_info[DT_RELOC_TABLE_ADDR],
+				tpnt->dynamic_info[DT_RELOC_TABLE_SIZE], 0);
 	}
+
 	if (tpnt->dynamic_info[DT_JMPREL]) {
 		if (tpnt->init_flag & JMP_RELOCS_DONE)
 			return goof;
 		tpnt->init_flag |= JMP_RELOCS_DONE;
 		if (flag & RTLD_LAZY) {
-			_dl_parse_lazy_relocation_information(tpnt, 
-					tpnt->dynamic_info[DT_JMPREL], 
+			_dl_parse_lazy_relocation_information(tpnt,
+					tpnt->dynamic_info[DT_JMPREL],
 					tpnt->dynamic_info [DT_PLTRELSZ], 0);
 		} else {
-			goof += _dl_parse_relocation_information(tpnt, 
-					tpnt->dynamic_info[DT_JMPREL], 
+			goof += _dl_parse_relocation_information(tpnt,
+					tpnt->dynamic_info[DT_JMPREL],
 					tpnt->dynamic_info[DT_PLTRELSZ], 0);
 		}
 	}
+
 	if (tpnt->init_flag & COPY_RELOCS_DONE)
 		return goof;
 	tpnt->init_flag |= COPY_RELOCS_DONE;
-#ifdef ELF_USES_RELOCA
-	goof += _dl_parse_copy_information(rpnt, 
-		tpnt->dynamic_info[DT_RELA], tpnt->dynamic_info[DT_RELASZ], 0);
-
-#else
-	goof += _dl_parse_copy_information(rpnt, tpnt->dynamic_info[DT_REL], 
-		tpnt->dynamic_info[DT_RELSZ], 0);
-
-#endif
+	goof += _dl_parse_copy_information(rpnt,
+		tpnt->dynamic_info[DT_RELOC_TABLE_ADDR],
+		tpnt->dynamic_info[DT_RELOC_TABLE_SIZE], 0);
 
 #if defined (__SUPPORT_LD_DEBUG__)
 	if(_dl_debug) {
-		_dl_dprintf(_dl_debug_file,"\nrelocation processing: %s", tpnt->libname);     
+		_dl_dprintf(_dl_debug_file,"\nrelocation processing: %s", tpnt->libname);
 		_dl_dprintf(_dl_debug_file,"; finished\n\n");
 	}
-#endif    
+#endif
+
 	return goof;
 }