Browse Source

generalize ELF hash table types not to assume 32-bit entries

alpha and s390x gratuitously use 64-bit entries (wasting 2x space and
cache utilization) despite the values always being 32-bit.

based on patch by Bobby Bingham, with changes suggested by Alexander
Monakov to use the public Elf_Symndx type from link.h (and make it
properly variable by arch) rather than adding new internal
infrastructure for handling the type.
Rich Felker 8 years ago
parent
commit
b418ea1b66
4 changed files with 6 additions and 5 deletions
  1. 1 0
      arch/generic/bits/link.h
  2. 1 2
      include/link.h
  3. 2 2
      ldso/dynlink.c
  4. 2 1
      src/internal/vdso.c

+ 1 - 0
arch/generic/bits/link.h

@@ -0,0 +1 @@
+typedef uint32_t Elf_Symndx;

+ 1 - 2
include/link.h

@@ -16,8 +16,7 @@ extern "C" {
 #define ElfW(type) Elf32_ ## type
 #define ElfW(type) Elf32_ ## type
 #endif
 #endif
 
 
-/* this is the same everywhere except alpha and s390 */
-typedef uint32_t Elf_Symndx;
+#include <bits/link.h>
 
 
 struct dl_phdr_info {
 struct dl_phdr_info {
 	ElfW(Addr) dlpi_addr;
 	ElfW(Addr) dlpi_addr;

+ 2 - 2
ldso/dynlink.c

@@ -54,7 +54,7 @@ struct dso {
 	size_t phentsize;
 	size_t phentsize;
 	int refcnt;
 	int refcnt;
 	Sym *syms;
 	Sym *syms;
-	uint32_t *hashtab;
+	Elf_Symndx *hashtab;
 	uint32_t *ghashtab;
 	uint32_t *ghashtab;
 	int16_t *versym;
 	int16_t *versym;
 	char *strings;
 	char *strings;
@@ -206,7 +206,7 @@ static Sym *sysv_lookup(const char *s, uint32_t h, struct dso *dso)
 {
 {
 	size_t i;
 	size_t i;
 	Sym *syms = dso->syms;
 	Sym *syms = dso->syms;
-	uint32_t *hashtab = dso->hashtab;
+	Elf_Symndx *hashtab = dso->hashtab;
 	char *strings = dso->strings;
 	char *strings = dso->strings;
 	for (i=hashtab[2+h%hashtab[0]]; i; i=hashtab[2+hashtab[0]+i]) {
 	for (i=hashtab[2+h%hashtab[0]]; i; i=hashtab[2+hashtab[0]+i]) {
 		if ((!dso->versym || dso->versym[i] >= 0)
 		if ((!dso->versym || dso->versym[i] >= 0)

+ 2 - 1
src/internal/vdso.c

@@ -1,4 +1,5 @@
 #include <elf.h>
 #include <elf.h>
+#include <link.h>
 #include <limits.h>
 #include <limits.h>
 #include <stdint.h>
 #include <stdint.h>
 #include <string.h>
 #include <string.h>
@@ -57,7 +58,7 @@ void *__vdsosym(const char *vername, const char *name)
 
 
 	char *strings = 0;
 	char *strings = 0;
 	Sym *syms = 0;
 	Sym *syms = 0;
-	uint32_t *hashtab = 0;
+	Elf_Symndx *hashtab = 0;
 	uint16_t *versym = 0;
 	uint16_t *versym = 0;
 	Verdef *verdef = 0;
 	Verdef *verdef = 0;