patches/glibc/2.2.3/glibc-2.2.3-mips-base-addr-got.patch
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Feb 24 11:00:05 2007 +0000 (2007-02-24)
changeset 1 eeea35fbf182
permissions -rw-r--r--
Add the full crosstool-NG sources to the new repository of its own.
You might just say: 'Yeah! crosstool-NG's got its own repo!".
Unfortunately, that's because the previous repo got damaged beyond repair and I had no backup.
That means I'm putting backups in place in the afternoon.
That also means we've lost history... :-(
     1 From http://www.ltc.com/~brad/mips/glibc-2.2.3-mips-base-addr-got.diff
     2 
     3 Hopefully fixes the error:
     4 
     5 /opt/crosstool/mipsel-unknown-linux-gnu/gcc-3.2.3-glibc-2.2.3/lib/gcc-lib/mipsel-unknown-linux-gnu/3.2.3/../../../../mipsel-unknown-linux-gnu/bin/ld: target elf32-littlemips not found
     6 collect2: ld returned 1 exit status
     7 make[2]: *** [/home/dank/downloads/crosstool-0.24/build/mipsel-unknown-linux-gnu/gcc-3.2.3-glibc-2.2.3/build-glibc/elf/ld.so] Error 1
     8 
     9 
    10 diff -urNbB glibc-2.2.3/sysdeps/mips/dl-machine.h glibc-2.2.3-mips/sysdeps/mips/dl-machine.h
    11 --- glibc-2.2.3/sysdeps/mips/dl-machine.h	Mon Mar 26 23:53:28 2001
    12 +++ glibc-2.2.3-mips/sysdeps/mips/dl-machine.h	Sun Aug 12 11:08:17 2001
    13 @@ -61,23 +61,6 @@
    14     in l_info array.  */
    15  #define DT_MIPS(x) (DT_MIPS_##x - DT_LOPROC + DT_NUM)
    16  
    17 -/*
    18 - * MIPS libraries are usually linked to a non-zero base address.  We
    19 - * subtract the base address from the address where we map the object
    20 - * to.  This results in more efficient address space usage.
    21 - *
    22 - * FIXME: By the time when MAP_BASE_ADDR is called we don't have the
    23 - * DYNAMIC section read.  Until this is fixed make the assumption that
    24 - * libraries have their base address at 0x5ffe0000.  This needs to be
    25 - * fixed before we can safely get rid of this MIPSism.
    26 - */
    27 -#if 0
    28 -#define MAP_BASE_ADDR(l) ((l)->l_info[DT_MIPS(BASE_ADDRESS)] ? \
    29 -			  (l)->l_info[DT_MIPS(BASE_ADDRESS)]->d_un.d_ptr : 0)
    30 -#else
    31 -#define MAP_BASE_ADDR(l) 0x5ffe0000
    32 -#endif
    33 -
    34  /* If there is a DT_MIPS_RLD_MAP entry in the dynamic section, fill it in
    35     with the run-time address of the r_debug structure  */
    36  #define ELF_MACHINE_DEBUG_SETUP(l,r) \
    37 @@ -557,51 +540,30 @@
    38    /* Do nothing.  */
    39  }
    40  
    41 +#ifndef RTLD_BOOTSTRAP
    42  /* Relocate GOT. */
    43  static inline void
    44  elf_machine_got_rel (struct link_map *map, int lazy)
    45  {
    46    ElfW(Addr) *got;
    47    ElfW(Sym) *sym;
    48 +  const ElfW(Half) *vernum;
    49    int i, n, symidx;
    50 -  /*  This function is loaded in dl-reloc as a nested function and can
    51 -      therefore access the variables scope and strtab from
    52 -      _dl_relocate_object.  */
    53 -#ifdef RTLD_BOOTSTRAP
    54 -# define RESOLVE_GOTSYM(sym,sym_index) 0
    55 -#else
    56 -# define RESOLVE_GOTSYM(sym,sym_index)					  \
    57 +
    58 +#define RESOLVE_GOTSYM(sym,vernum,sym_index)				  \
    59      ({									  \
    60        const ElfW(Sym) *ref = sym;					  \
    61 +      const struct r_found_version *version				  \
    62 +        = vernum ? &map->l_versions [vernum [sym_index]] : NULL;	  \
    63        ElfW(Addr) value;							  \
    64 -									  \
    65 -      switch (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL)		  \
    66 -	{								  \
    67 -	default:							  \
    68 -	  {								  \
    69 -	    const ElfW(Half) *vernum =					  \
    70 -	      (const void *) D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]);  \
    71 -	    ElfW(Half) ndx = vernum[sym_index];				  \
    72 -	    const struct r_found_version *version = &l->l_versions[ndx];  \
    73 -									  \
    74 -	    if (version->hash != 0)					  \
    75 -	      {								  \
    76 -		value = _dl_lookup_versioned_symbol(strtab + sym->st_name,\
    77 -						    map,		  \
    78 -						    &ref, scope, version, \
    79 -						    R_MIPS_REL32, 0);	  \
    80 -		break;							  \
    81 -	      }								  \
    82 -	    /* Fall through.  */					  \
    83 -	  }								  \
    84 -	case 0:								  \
    85 -	  value = _dl_lookup_symbol (strtab + sym->st_name, map, &ref,	  \
    86 -				     scope, R_MIPS_REL32, 0);		  \
    87 -	}								  \
    88 -									  \
    89 +      value = RESOLVE (&ref, version, R_MIPS_REL32);			  \
    90        (ref)? value + ref->st_value: 0;					  \
    91      })
    92 -#endif /* RTLD_BOOTSTRAP */
    93 +
    94 +  if (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL)
    95 +    vernum = (const void *) D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]);
    96 +  else
    97 +    vernum = NULL;
    98  
    99    got = (ElfW(Addr) *) D_PTR (map, l_info[DT_PLTGOT]);
   100  
   101 @@ -639,10 +601,10 @@
   102  	      && sym->st_value && lazy)
   103  	    *got = sym->st_value + map->l_addr;
   104  	  else
   105 -	    *got = RESOLVE_GOTSYM (sym, symidx);
   106 +	    *got = RESOLVE_GOTSYM (sym, vernum, symidx);
   107  	}
   108        else if (sym->st_shndx == SHN_COMMON)
   109 -	*got = RESOLVE_GOTSYM (sym, symidx);
   110 +	*got = RESOLVE_GOTSYM (sym, vernum, symidx);
   111        else if (ELFW(ST_TYPE) (sym->st_info) == STT_FUNC
   112  	       && *got != sym->st_value
   113  	       && lazy)
   114 @@ -653,7 +615,7 @@
   115  	    *got += map->l_addr;
   116  	}
   117        else
   118 -	*got = RESOLVE_GOTSYM (sym, symidx);
   119 +	*got = RESOLVE_GOTSYM (sym, vernum, symidx);
   120  
   121        ++got;
   122        ++sym;
   123 @@ -661,9 +623,8 @@
   124      }
   125  
   126  #undef RESOLVE_GOTSYM
   127 -
   128 -  return;
   129  }
   130 +#endif
   131  
   132  /* Set up the loaded object described by L so its stub function
   133     will jump to the on-demand fixup code __dl_runtime_resolve.  */
   134 diff -urNbB glibc-2.2.3/sysdeps/mips/mips64/rtld-parms glibc-2.2.3-mips/sysdeps/mips/mips64/rtld-parms
   135 --- glibc-2.2.3/sysdeps/mips/mips64/rtld-parms	Sat Jul 12 18:26:11 1997
   136 +++ glibc-2.2.3-mips/sysdeps/mips/mips64/rtld-parms	Wed Dec 31 19:00:00 1969
   137 @@ -1,3 +0,0 @@
   138 -ifndef rtld-wordsize
   139 -rtld-wordsize = 64
   140 -endif
   141 diff -urNbB glibc-2.2.3/sysdeps/mips/mipsel/rtld-parms glibc-2.2.3-mips/sysdeps/mips/mipsel/rtld-parms
   142 --- glibc-2.2.3/sysdeps/mips/mipsel/rtld-parms	Sat Jul 12 18:26:15 1997
   143 +++ glibc-2.2.3-mips/sysdeps/mips/mipsel/rtld-parms	Wed Dec 31 19:00:00 1969
   144 @@ -1,3 +0,0 @@
   145 -ifndef rtld-oformat
   146 -rtld-oformat = elf32-littlemips
   147 -endif
   148 diff -urNbB glibc-2.2.3/sysdeps/mips/rtld-ldscript.in glibc-2.2.3-mips/sysdeps/mips/rtld-ldscript.in
   149 --- glibc-2.2.3/sysdeps/mips/rtld-ldscript.in	Sat Jul 12 18:23:14 1997
   150 +++ glibc-2.2.3-mips/sysdeps/mips/rtld-ldscript.in	Wed Dec 31 19:00:00 1969
   151 @@ -1,106 +0,0 @@
   152 -OUTPUT_FORMAT("@@rtld-oformat@@")
   153 -OUTPUT_ARCH(@@rtld-arch@@)
   154 -ENTRY(@@rtld-entry@@)
   155 -SECTIONS
   156 -{
   157 -  /* Read-only sections, merged into text segment: */
   158 -  . = @@rtld-base@@;
   159 -  .reginfo       : { *(.reginfo) }
   160 -  .dynamic       : { *(.dynamic) }
   161 -  .dynstr        : { *(.dynstr)		}
   162 -  .dynsym        : { *(.dynsym)		}
   163 -  .hash          : { *(.hash)		}
   164 -  .rel.text      : { *(.rel.text)		}
   165 -  .rela.text     : { *(.rela.text) 	}
   166 -  .rel.data      : { *(.rel.data)		}
   167 -  .rela.data     : { *(.rela.data) 	}
   168 -  .rel.rodata    : { *(.rel.rodata) 	}
   169 -  .rela.rodata   : { *(.rela.rodata) 	}
   170 -  .rel.got       : { *(.rel.got)		}
   171 -  .rela.got      : { *(.rela.got)		}
   172 -  .rel.ctors     : { *(.rel.ctors)	}
   173 -  .rela.ctors    : { *(.rela.ctors)	}
   174 -  .rel.dtors     : { *(.rel.dtors)	}
   175 -  .rela.dtors    : { *(.rela.dtors)	}
   176 -  .rel.init      : { *(.rel.init)	}
   177 -  .rela.init     : { *(.rela.init)	}
   178 -  .rel.fini      : { *(.rel.fini)	}
   179 -  .rela.fini     : { *(.rela.fini)	}
   180 -  .rel.bss       : { *(.rel.bss)		}
   181 -  .rela.bss      : { *(.rela.bss)		}
   182 -  .rel.plt       : { *(.rel.plt)		}
   183 -  .rela.plt      : { *(.rela.plt)		}
   184 -  .rodata    : { *(.rodata)  }
   185 -  .rodata1   : { *(.rodata1) }
   186 -  .init          : { *(.init)	} =0
   187 -  .text      :
   188 -  {
   189 -    *(.text)
   190 -    *(.stub)
   191 -    /* .gnu.warning sections are handled specially by elf32.em.  */
   192 -    *(.gnu.warning)
   193 -  } =0
   194 -  .fini      : { *(.fini)    } =0
   195 -  /* Adjust the address for the data segment.  We want to adjust up to
   196 -     the same address within the page on the next page up.  It would
   197 -     be more correct to do this:
   198 -       . = 0x10000000;
   199 -     The current expression does not correctly handle the case of a
   200 -     text segment ending precisely at the end of a page; it causes the
   201 -     data segment to skip a page.  The above expression does not have
   202 -     this problem, but it will currently (2/95) cause BFD to allocate
   203 -     a single segment, combining both text and data, for this case.
   204 -     This will prevent the text segment from being shared among
   205 -     multiple executions of the program; I think that is more
   206 -     important than losing a page of the virtual address space (note
   207 -     that no actual memory is lost; the page which is skipped can not
   208 -     be referenced).  */
   209 -  . += 0x10000;
   210 -  .data    :
   211 -  {
   212 -    *(.data)
   213 -    CONSTRUCTORS
   214 -  }
   215 -  .data1   : { *(.data1) }
   216 -  .ctors         : { *(.ctors)   }
   217 -  .dtors         : { *(.dtors)   }
   218 -  _gp = ALIGN(16) + 0x7ff0;
   219 -  .got           :
   220 -  {
   221 -    *(.got.plt) *(.got)
   222 -   }
   223 -  /* We want the small data sections together, so single-instruction offsets
   224 -     can access them all, and initialized data all before uninitialized, so
   225 -     we can shorten the on-disk segment size.  */
   226 -  .sdata     : { *(.sdata) }
   227 -  .lit8 : { *(.lit8) }
   228 -  .lit4 : { *(.lit4) }
   229 -  .sbss      : { *(.sbss) *(.scommon) }
   230 -  .bss       :
   231 -  {
   232 -   *(.dynbss)
   233 -   *(.bss)
   234 -   *(COMMON)
   235 -  }
   236 -  /* The normal linker scripts created by the binutils doesn't have the
   237 -     symbols end and _end which breaks ld.so's dl-minimal.c.  */
   238 -  _end = . ;
   239 -  PROVIDE (end = .);
   240 -  /* These are needed for ELF backends which have not yet been
   241 -     converted to the new style linker.  */
   242 -  .stab 0 : { *(.stab) }
   243 -  .stabstr 0 : { *(.stabstr) }
   244 -  /* DWARF debug sections.
   245 -     Symbols in the .debug DWARF section are relative to the beginning of the
   246 -     section so we begin .debug at 0.  It's not clear yet what needs to happen
   247 -     for the others.   */
   248 -  .debug          0 : { *(.debug) }
   249 -  .debug_srcinfo  0 : { *(.debug_srcinfo) }
   250 -  .debug_aranges  0 : { *(.debug_aranges) }
   251 -  .debug_pubnames 0 : { *(.debug_pubnames) }
   252 -  .debug_sfnames  0 : { *(.debug_sfnames) }
   253 -  .line           0 : { *(.line) }
   254 -  /* These must appear regardless of  .  */
   255 -  .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }
   256 -  .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }
   257 -}
   258 diff -urNbB glibc-2.2.3/sysdeps/mips/rtld-parms glibc-2.2.3-mips/sysdeps/mips/rtld-parms
   259 --- glibc-2.2.3/sysdeps/mips/rtld-parms	Mon Jul 21 19:04:07 1997
   260 +++ glibc-2.2.3-mips/sysdeps/mips/rtld-parms	Wed Dec 31 19:00:00 1969
   261 @@ -1,15 +0,0 @@
   262 -ifndef rtld-wordsize
   263 -rtld-wordsize = 32
   264 -endif
   265 -ifndef rtld-oformat
   266 -rtld-oformat = elf$(rtld-wordsize)-bigmips
   267 -endif
   268 -ifndef rtld-arch
   269 -rtld-arch = mips
   270 -endif
   271 -ifndef rtld-entry
   272 -rtld-entry = __start
   273 -endif
   274 -ifndef rtld-base
   275 -rtld-base = 0x0fb60000 + SIZEOF_HEADERS
   276 -endif