Changeset 609 for branches/GNU/src/binutils/bfd/elfcode.h
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/elfcode.h
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* ELF executable support for BFD. 2 2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 3 2001 Free Software Foundation, Inc.3 2001, 2002 Free Software Foundation, Inc. 4 4 5 5 Written by Fred Fish @ Cygnus Support, from information published … … 67 67 #include "bfd.h" 68 68 #include "sysdep.h" 69 #include "libiberty.h" 69 70 #include "bfdlink.h" 70 71 #include "libbfd.h" … … 123 124 #define elf_link_create_dynamic_sections \ 124 125 NAME(bfd_elf,link_create_dynamic_sections) 126 #define elf_bfd_discard_info NAME(bfd_elf,discard_info) 127 #define elf_reloc_symbol_deleted_p NAME(_bfd_elf,reloc_symbol_deleted_p) 125 128 #define elf_link_record_dynamic_symbol _bfd_elf_link_record_dynamic_symbol 126 129 #define elf_bfd_final_link NAME(bfd_elf,bfd_final_link) … … 168 171 #define section_from_elf_index bfd_section_from_elf_index 169 172 170 static b oolean elf_slurp_reloc_table_from_section173 static bfd_boolean elf_slurp_reloc_table_from_section 171 174 PARAMS ((bfd *, asection *, Elf_Internal_Shdr *, bfd_size_type, 172 arelent *, asymbol **, b oolean));173 174 static b oolean elf_file_p PARAMS ((Elf_External_Ehdr *));175 arelent *, asymbol **, bfd_boolean)); 176 177 static bfd_boolean elf_file_p PARAMS ((Elf_External_Ehdr *)); 175 178 176 179 #ifdef DEBUG … … 186 189 can be handled by explicitly specifying 32 bits or "the long type". */ 187 190 #if ARCH_SIZE == 64 188 #define put_word bfd_h_put_64189 #define put_signed_word bfd_h_put_signed_64190 #define get_word bfd_h_get_64191 #define get_signed_word bfd_h_get_signed_64191 #define H_PUT_WORD H_PUT_64 192 #define H_PUT_SIGNED_WORD H_PUT_S64 193 #define H_GET_WORD H_GET_64 194 #define H_GET_SIGNED_WORD H_GET_S64 192 195 #endif 193 196 #if ARCH_SIZE == 32 194 #define put_word bfd_h_put_32195 #define put_signed_word bfd_h_put_signed_32196 #define get_word bfd_h_get_32197 #define get_signed_word bfd_h_get_signed_32197 #define H_PUT_WORD H_PUT_32 198 #define H_PUT_SIGNED_WORD H_PUT_S32 199 #define H_GET_WORD H_GET_32 200 #define H_GET_SIGNED_WORD H_GET_S32 198 201 #endif 199 202 … … 202 205 203 206 void 204 elf_swap_symbol_in (abfd, src, dst) 205 bfd *abfd; 206 const Elf_External_Sym *src; 207 elf_swap_symbol_in (abfd, psrc, pshn, dst) 208 bfd *abfd; 209 const PTR psrc; 210 const PTR pshn; 207 211 Elf_Internal_Sym *dst; 208 212 { 213 const Elf_External_Sym *src = (const Elf_External_Sym *) psrc; 214 const Elf_External_Sym_Shndx *shndx = (const Elf_External_Sym_Shndx *) pshn; 209 215 int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma; 210 216 211 dst->st_name = bfd_h_get_32 (abfd, (bfd_byte *)src->st_name);217 dst->st_name = H_GET_32 (abfd, src->st_name); 212 218 if (signed_vma) 213 dst->st_value = get_signed_word (abfd, (bfd_byte *)src->st_value);219 dst->st_value = H_GET_SIGNED_WORD (abfd, src->st_value); 214 220 else 215 dst->st_value = get_word (abfd, (bfd_byte *) src->st_value); 216 dst->st_size = get_word (abfd, (bfd_byte *) src->st_size); 217 dst->st_info = bfd_h_get_8 (abfd, (bfd_byte *) src->st_info); 218 dst->st_other = bfd_h_get_8 (abfd, (bfd_byte *) src->st_other); 219 dst->st_shndx = bfd_h_get_16 (abfd, (bfd_byte *) src->st_shndx); 221 dst->st_value = H_GET_WORD (abfd, src->st_value); 222 dst->st_size = H_GET_WORD (abfd, src->st_size); 223 dst->st_info = H_GET_8 (abfd, src->st_info); 224 dst->st_other = H_GET_8 (abfd, src->st_other); 225 dst->st_shndx = H_GET_16 (abfd, src->st_shndx); 226 if (dst->st_shndx == SHN_XINDEX) 227 { 228 if (shndx == NULL) 229 abort (); 230 dst->st_shndx = H_GET_32 (abfd, shndx->est_shndx); 231 } 220 232 } 221 233 … … 224 236 225 237 void 226 elf_swap_symbol_out (abfd, src, cdst )238 elf_swap_symbol_out (abfd, src, cdst, shndx) 227 239 bfd *abfd; 228 240 const Elf_Internal_Sym *src; 229 241 PTR cdst; 230 { 242 PTR shndx; 243 { 244 unsigned int tmp; 231 245 Elf_External_Sym *dst = (Elf_External_Sym *) cdst; 232 bfd_h_put_32 (abfd, src->st_name, dst->st_name); 233 put_word (abfd, src->st_value, dst->st_value); 234 put_word (abfd, src->st_size, dst->st_size); 235 bfd_h_put_8 (abfd, src->st_info, dst->st_info); 236 bfd_h_put_8 (abfd, src->st_other, dst->st_other); 237 bfd_h_put_16 (abfd, src->st_shndx, dst->st_shndx); 246 H_PUT_32 (abfd, src->st_name, dst->st_name); 247 H_PUT_WORD (abfd, src->st_value, dst->st_value); 248 H_PUT_WORD (abfd, src->st_size, dst->st_size); 249 H_PUT_8 (abfd, src->st_info, dst->st_info); 250 H_PUT_8 (abfd, src->st_other, dst->st_other); 251 tmp = src->st_shndx; 252 if (tmp > SHN_HIRESERVE) 253 { 254 if (shndx == NULL) 255 abort (); 256 H_PUT_32 (abfd, tmp, shndx); 257 tmp = SHN_XINDEX; 258 } 259 H_PUT_16 (abfd, tmp, dst->st_shndx); 238 260 } 239 261 … … 249 271 int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma; 250 272 memcpy (dst->e_ident, src->e_ident, EI_NIDENT); 251 dst->e_type = bfd_h_get_16 (abfd, (bfd_byte *)src->e_type);252 dst->e_machine = bfd_h_get_16 (abfd, (bfd_byte *)src->e_machine);253 dst->e_version = bfd_h_get_32 (abfd, (bfd_byte *)src->e_version);273 dst->e_type = H_GET_16 (abfd, src->e_type); 274 dst->e_machine = H_GET_16 (abfd, src->e_machine); 275 dst->e_version = H_GET_32 (abfd, src->e_version); 254 276 if (signed_vma) 255 dst->e_entry = get_signed_word (abfd, (bfd_byte *)src->e_entry);277 dst->e_entry = H_GET_SIGNED_WORD (abfd, src->e_entry); 256 278 else 257 dst->e_entry = get_word (abfd, (bfd_byte *)src->e_entry);258 dst->e_phoff = get_word (abfd, (bfd_byte *)src->e_phoff);259 dst->e_shoff = get_word (abfd, (bfd_byte *)src->e_shoff);260 dst->e_flags = bfd_h_get_32 (abfd, (bfd_byte *)src->e_flags);261 dst->e_ehsize = bfd_h_get_16 (abfd, (bfd_byte *)src->e_ehsize);262 dst->e_phentsize = bfd_h_get_16 (abfd, (bfd_byte *)src->e_phentsize);263 dst->e_phnum = bfd_h_get_16 (abfd, (bfd_byte *)src->e_phnum);264 dst->e_shentsize = bfd_h_get_16 (abfd, (bfd_byte *)src->e_shentsize);265 dst->e_shnum = bfd_h_get_16 (abfd, (bfd_byte *)src->e_shnum);266 dst->e_shstrndx = bfd_h_get_16 (abfd, (bfd_byte *)src->e_shstrndx);279 dst->e_entry = H_GET_WORD (abfd, src->e_entry); 280 dst->e_phoff = H_GET_WORD (abfd, src->e_phoff); 281 dst->e_shoff = H_GET_WORD (abfd, src->e_shoff); 282 dst->e_flags = H_GET_32 (abfd, src->e_flags); 283 dst->e_ehsize = H_GET_16 (abfd, src->e_ehsize); 284 dst->e_phentsize = H_GET_16 (abfd, src->e_phentsize); 285 dst->e_phnum = H_GET_16 (abfd, src->e_phnum); 286 dst->e_shentsize = H_GET_16 (abfd, src->e_shentsize); 287 dst->e_shnum = H_GET_16 (abfd, src->e_shnum); 288 dst->e_shstrndx = H_GET_16 (abfd, src->e_shstrndx); 267 289 } 268 290 … … 276 298 Elf_External_Ehdr *dst; 277 299 { 300 unsigned int tmp; 278 301 int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma; 279 302 memcpy (dst->e_ident, src->e_ident, EI_NIDENT); 280 303 /* note that all elements of dst are *arrays of unsigned char* already... */ 281 bfd_h_put_16 (abfd, src->e_type, dst->e_type);282 bfd_h_put_16 (abfd, src->e_machine, dst->e_machine);283 bfd_h_put_32 (abfd, src->e_version, dst->e_version);304 H_PUT_16 (abfd, src->e_type, dst->e_type); 305 H_PUT_16 (abfd, src->e_machine, dst->e_machine); 306 H_PUT_32 (abfd, src->e_version, dst->e_version); 284 307 if (signed_vma) 285 put_signed_word(abfd, src->e_entry, dst->e_entry);308 H_PUT_SIGNED_WORD (abfd, src->e_entry, dst->e_entry); 286 309 else 287 put_word (abfd, src->e_entry, dst->e_entry); 288 put_word (abfd, src->e_phoff, dst->e_phoff); 289 put_word (abfd, src->e_shoff, dst->e_shoff); 290 bfd_h_put_32 (abfd, src->e_flags, dst->e_flags); 291 bfd_h_put_16 (abfd, src->e_ehsize, dst->e_ehsize); 292 bfd_h_put_16 (abfd, src->e_phentsize, dst->e_phentsize); 293 bfd_h_put_16 (abfd, src->e_phnum, dst->e_phnum); 294 bfd_h_put_16 (abfd, src->e_shentsize, dst->e_shentsize); 295 bfd_h_put_16 (abfd, src->e_shnum, dst->e_shnum); 296 bfd_h_put_16 (abfd, src->e_shstrndx, dst->e_shstrndx); 310 H_PUT_WORD (abfd, src->e_entry, dst->e_entry); 311 H_PUT_WORD (abfd, src->e_phoff, dst->e_phoff); 312 H_PUT_WORD (abfd, src->e_shoff, dst->e_shoff); 313 H_PUT_32 (abfd, src->e_flags, dst->e_flags); 314 H_PUT_16 (abfd, src->e_ehsize, dst->e_ehsize); 315 H_PUT_16 (abfd, src->e_phentsize, dst->e_phentsize); 316 H_PUT_16 (abfd, src->e_phnum, dst->e_phnum); 317 H_PUT_16 (abfd, src->e_shentsize, dst->e_shentsize); 318 tmp = src->e_shnum; 319 if (tmp >= SHN_LORESERVE) 320 tmp = SHN_UNDEF; 321 H_PUT_16 (abfd, tmp, dst->e_shnum); 322 tmp = src->e_shstrndx; 323 if (tmp >= SHN_LORESERVE) 324 tmp = SHN_XINDEX; 325 H_PUT_16 (abfd, tmp, dst->e_shstrndx); 297 326 } 298 327 … … 308 337 int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma; 309 338 310 dst->sh_name = bfd_h_get_32 (abfd, (bfd_byte *)src->sh_name);311 dst->sh_type = bfd_h_get_32 (abfd, (bfd_byte *)src->sh_type);312 dst->sh_flags = get_word (abfd, (bfd_byte *)src->sh_flags);339 dst->sh_name = H_GET_32 (abfd, src->sh_name); 340 dst->sh_type = H_GET_32 (abfd, src->sh_type); 341 dst->sh_flags = H_GET_WORD (abfd, src->sh_flags); 313 342 if (signed_vma) 314 dst->sh_addr = get_signed_word (abfd, (bfd_byte *)src->sh_addr);343 dst->sh_addr = H_GET_SIGNED_WORD (abfd, src->sh_addr); 315 344 else 316 dst->sh_addr = get_word (abfd, (bfd_byte *)src->sh_addr);317 dst->sh_offset = get_word (abfd, (bfd_byte *)src->sh_offset);318 dst->sh_size = get_word (abfd, (bfd_byte *)src->sh_size);319 dst->sh_link = bfd_h_get_32 (abfd, (bfd_byte *)src->sh_link);320 dst->sh_info = bfd_h_get_32 (abfd, (bfd_byte *)src->sh_info);321 dst->sh_addralign = get_word (abfd, (bfd_byte *)src->sh_addralign);322 dst->sh_entsize = get_word (abfd, (bfd_byte *)src->sh_entsize);345 dst->sh_addr = H_GET_WORD (abfd, src->sh_addr); 346 dst->sh_offset = H_GET_WORD (abfd, src->sh_offset); 347 dst->sh_size = H_GET_WORD (abfd, src->sh_size); 348 dst->sh_link = H_GET_32 (abfd, src->sh_link); 349 dst->sh_info = H_GET_32 (abfd, src->sh_info); 350 dst->sh_addralign = H_GET_WORD (abfd, src->sh_addralign); 351 dst->sh_entsize = H_GET_WORD (abfd, src->sh_entsize); 323 352 dst->bfd_section = NULL; 324 353 dst->contents = NULL; … … 335 364 { 336 365 /* note that all elements of dst are *arrays of unsigned char* already... */ 337 bfd_h_put_32 (abfd, src->sh_name, dst->sh_name);338 bfd_h_put_32 (abfd, src->sh_type, dst->sh_type);339 put_word(abfd, src->sh_flags, dst->sh_flags);340 put_word(abfd, src->sh_addr, dst->sh_addr);341 put_word(abfd, src->sh_offset, dst->sh_offset);342 put_word(abfd, src->sh_size, dst->sh_size);343 bfd_h_put_32 (abfd, src->sh_link, dst->sh_link);344 bfd_h_put_32 (abfd, src->sh_info, dst->sh_info);345 put_word(abfd, src->sh_addralign, dst->sh_addralign);346 put_word(abfd, src->sh_entsize, dst->sh_entsize);366 H_PUT_32 (abfd, src->sh_name, dst->sh_name); 367 H_PUT_32 (abfd, src->sh_type, dst->sh_type); 368 H_PUT_WORD (abfd, src->sh_flags, dst->sh_flags); 369 H_PUT_WORD (abfd, src->sh_addr, dst->sh_addr); 370 H_PUT_WORD (abfd, src->sh_offset, dst->sh_offset); 371 H_PUT_WORD (abfd, src->sh_size, dst->sh_size); 372 H_PUT_32 (abfd, src->sh_link, dst->sh_link); 373 H_PUT_32 (abfd, src->sh_info, dst->sh_info); 374 H_PUT_WORD (abfd, src->sh_addralign, dst->sh_addralign); 375 H_PUT_WORD (abfd, src->sh_entsize, dst->sh_entsize); 347 376 } 348 377 … … 358 387 int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma; 359 388 360 dst->p_type = bfd_h_get_32 (abfd, (bfd_byte *)src->p_type);361 dst->p_flags = bfd_h_get_32 (abfd, (bfd_byte *)src->p_flags);362 dst->p_offset = get_word (abfd, (bfd_byte *)src->p_offset);389 dst->p_type = H_GET_32 (abfd, src->p_type); 390 dst->p_flags = H_GET_32 (abfd, src->p_flags); 391 dst->p_offset = H_GET_WORD (abfd, src->p_offset); 363 392 if (signed_vma) 364 393 { 365 dst->p_vaddr = get_signed_word (abfd, (bfd_byte *)src->p_vaddr);366 dst->p_paddr = get_signed_word (abfd, (bfd_byte *)src->p_paddr);394 dst->p_vaddr = H_GET_SIGNED_WORD (abfd, src->p_vaddr); 395 dst->p_paddr = H_GET_SIGNED_WORD (abfd, src->p_paddr); 367 396 } 368 397 else 369 398 { 370 dst->p_vaddr = get_word (abfd, (bfd_byte *)src->p_vaddr);371 dst->p_paddr = get_word (abfd, (bfd_byte *)src->p_paddr);372 } 373 dst->p_filesz = get_word (abfd, (bfd_byte *)src->p_filesz);374 dst->p_memsz = get_word (abfd, (bfd_byte *)src->p_memsz);375 dst->p_align = get_word (abfd, (bfd_byte *)src->p_align);399 dst->p_vaddr = H_GET_WORD (abfd, src->p_vaddr); 400 dst->p_paddr = H_GET_WORD (abfd, src->p_paddr); 401 } 402 dst->p_filesz = H_GET_WORD (abfd, src->p_filesz); 403 dst->p_memsz = H_GET_WORD (abfd, src->p_memsz); 404 dst->p_align = H_GET_WORD (abfd, src->p_align); 376 405 } 377 406 … … 383 412 { 384 413 /* note that all elements of dst are *arrays of unsigned char* already... */ 385 bfd_h_put_32 (abfd, src->p_type, dst->p_type);386 put_word(abfd, src->p_offset, dst->p_offset);387 put_word(abfd, src->p_vaddr, dst->p_vaddr);388 put_word(abfd, src->p_paddr, dst->p_paddr);389 put_word(abfd, src->p_filesz, dst->p_filesz);390 put_word(abfd, src->p_memsz, dst->p_memsz);391 bfd_h_put_32 (abfd, src->p_flags, dst->p_flags);392 put_word(abfd, src->p_align, dst->p_align);414 H_PUT_32 (abfd, src->p_type, dst->p_type); 415 H_PUT_WORD (abfd, src->p_offset, dst->p_offset); 416 H_PUT_WORD (abfd, src->p_vaddr, dst->p_vaddr); 417 H_PUT_WORD (abfd, src->p_paddr, dst->p_paddr); 418 H_PUT_WORD (abfd, src->p_filesz, dst->p_filesz); 419 H_PUT_WORD (abfd, src->p_memsz, dst->p_memsz); 420 H_PUT_32 (abfd, src->p_flags, dst->p_flags); 421 H_PUT_WORD (abfd, src->p_align, dst->p_align); 393 422 } 394 423 395 424 /* Translate an ELF reloc from external format to internal format. */ 396 INLINE void 397 elf_swap_reloc_in (abfd, src, dst) 398 bfd *abfd; 399 const Elf_External_Rel *src; 400 Elf_Internal_Rel *dst; 401 { 402 dst->r_offset = get_word (abfd, (bfd_byte *) src->r_offset); 403 dst->r_info = get_word (abfd, (bfd_byte *) src->r_info); 404 } 405 406 INLINE void 407 elf_swap_reloca_in (abfd, src, dst) 408 bfd *abfd; 409 const Elf_External_Rela *src; 425 void 426 elf_swap_reloc_in (abfd, s, dst) 427 bfd *abfd; 428 const bfd_byte *s; 410 429 Elf_Internal_Rela *dst; 411 430 { 412 dst->r_offset = get_word (abfd, (bfd_byte *) src->r_offset); 413 dst->r_info = get_word (abfd, (bfd_byte *) src->r_info); 414 dst->r_addend = get_signed_word (abfd, (bfd_byte *) src->r_addend); 431 const Elf_External_Rel *src = (const Elf_External_Rel *) s; 432 dst->r_offset = H_GET_WORD (abfd, src->r_offset); 433 dst->r_info = H_GET_WORD (abfd, src->r_info); 434 dst->r_addend = 0; 435 } 436 437 void 438 elf_swap_reloca_in (abfd, s, dst) 439 bfd *abfd; 440 const bfd_byte *s; 441 Elf_Internal_Rela *dst; 442 { 443 const Elf_External_Rela *src = (const Elf_External_Rela *) s; 444 dst->r_offset = H_GET_WORD (abfd, src->r_offset); 445 dst->r_info = H_GET_WORD (abfd, src->r_info); 446 dst->r_addend = H_GET_SIGNED_WORD (abfd, src->r_addend); 415 447 } 416 448 417 449 /* Translate an ELF reloc from internal format to external format. */ 418 INLINE void 419 elf_swap_reloc_out (abfd, src, dst) 420 bfd *abfd; 421 const Elf_Internal_Rel *src; 422 Elf_External_Rel *dst; 423 { 424 put_word (abfd, src->r_offset, dst->r_offset); 425 put_word (abfd, src->r_info, dst->r_info); 426 } 427 428 INLINE void 429 elf_swap_reloca_out (abfd, src, dst) 450 void 451 elf_swap_reloc_out (abfd, src, d) 430 452 bfd *abfd; 431 453 const Elf_Internal_Rela *src; 432 Elf_External_Rela *dst; 433 { 434 put_word (abfd, src->r_offset, dst->r_offset); 435 put_word (abfd, src->r_info, dst->r_info); 436 put_signed_word (abfd, src->r_addend, dst->r_addend); 454 bfd_byte *d; 455 { 456 Elf_External_Rel *dst = (Elf_External_Rel *) d; 457 H_PUT_WORD (abfd, src->r_offset, dst->r_offset); 458 H_PUT_WORD (abfd, src->r_info, dst->r_info); 459 } 460 461 void 462 elf_swap_reloca_out (abfd, src, d) 463 bfd *abfd; 464 const Elf_Internal_Rela *src; 465 bfd_byte *d; 466 { 467 Elf_External_Rela *dst = (Elf_External_Rela *) d; 468 H_PUT_WORD (abfd, src->r_offset, dst->r_offset); 469 H_PUT_WORD (abfd, src->r_info, dst->r_info); 470 H_PUT_SIGNED_WORD (abfd, src->r_addend, dst->r_addend); 437 471 } 438 472 … … 445 479 const Elf_External_Dyn *src = (const Elf_External_Dyn *) p; 446 480 447 dst->d_tag = get_word(abfd, src->d_tag);448 dst->d_un.d_val = get_word(abfd, src->d_un.d_val);481 dst->d_tag = H_GET_WORD (abfd, src->d_tag); 482 dst->d_un.d_val = H_GET_WORD (abfd, src->d_un.d_val); 449 483 } 450 484 … … 457 491 Elf_External_Dyn *dst = (Elf_External_Dyn *) p; 458 492 459 put_word(abfd, src->d_tag, dst->d_tag);460 put_word(abfd, src->d_un.d_val, dst->d_un.d_val);493 H_PUT_WORD (abfd, src->d_tag, dst->d_tag); 494 H_PUT_WORD (abfd, src->d_un.d_val, dst->d_un.d_val); 461 495 } 462 496 … … 469 503 the magic number. */ 470 504 471 static INLINE b oolean505 static INLINE bfd_boolean 472 506 elf_file_p (x_ehdrp) 473 507 Elf_External_Ehdr *x_ehdrp; … … 494 528 Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form */ 495 529 Elf_External_Shdr x_shdr; /* Section header table entry, external form */ 496 Elf_Internal_Shdr *i_shdrp = NULL; /* Section header table, internal form */ 530 Elf_Internal_Shdr i_shdr; 531 Elf_Internal_Shdr *i_shdrp; /* Section header table, internal form */ 497 532 unsigned int shindex; 498 533 char *shstrtab; /* Internal copy of section header stringtab */ 499 534 struct elf_backend_data *ebd; 500 struct elf_obj_tdata *preserved_tdata = elf_tdata (abfd); 501 struct sec *preserved_sections = abfd->sections; 502 unsigned int preserved_section_count = abfd->section_count; 503 enum bfd_architecture previous_arch = bfd_get_arch (abfd); 504 unsigned long previous_mach = bfd_get_mach (abfd); 505 struct elf_obj_tdata *new_tdata = NULL; 535 struct bfd_preserve preserve; 506 536 asection *s; 507 508 /* Clear section information, since there might be a recognized bfd that 509 we now check if we can replace, and we don't want to append to it. */ 510 abfd->sections = NULL; 511 abfd->section_count = 0; 537 bfd_size_type amt; 538 539 preserve.marker = NULL; 512 540 513 541 /* Read in the ELF header in external format. */ 514 542 515 if (bfd_read ((PTR) & x_ehdr, sizeof (x_ehdr), 1, abfd) != sizeof (x_ehdr)) 543 if (bfd_bread ((PTR) & x_ehdr, (bfd_size_type) sizeof (x_ehdr), abfd) 544 != sizeof (x_ehdr)) 516 545 { 517 546 if (bfd_get_error () != bfd_error_system_call) … … 527 556 file). */ 528 557 529 if ( (elf_file_p (&x_ehdr) == false) ||530 (x_ehdr.e_ident[EI_VERSION] != EV_CURRENT) ||531 (x_ehdr.e_ident[EI_CLASS] != ELFCLASS))558 if (! elf_file_p (&x_ehdr) 559 || x_ehdr.e_ident[EI_VERSION] != EV_CURRENT 560 || x_ehdr.e_ident[EI_CLASS] != ELFCLASS) 532 561 goto got_wrong_format_error; 533 562 … … 551 580 the tdata pointer in the bfd. */ 552 581 553 new_tdata = ((struct elf_obj_tdata *)554 bfd_zalloc (abfd, sizeof (struct elf_obj_tdata)));555 if ( new_tdata== NULL)582 amt = sizeof (struct elf_obj_tdata); 583 preserve.marker = bfd_zalloc (abfd, amt); 584 if (preserve.marker == NULL) 556 585 goto got_no_match; 557 elf_tdata (abfd) = new_tdata; 586 if (!bfd_preserve_save (abfd, &preserve)) 587 goto got_no_match; 588 589 elf_tdata (abfd) = preserve.marker; 558 590 559 591 /* Now that we know the byte order, swap in the rest of the header */ … … 568 600 goto got_wrong_format_error; 569 601 570 /* If there is no section header table, we're hosed. */ 571 if (i_ehdrp->e_shoff == 0) 602 /* If this is a relocatable file and there is no section header 603 table, then we're hosed. */ 604 if (i_ehdrp->e_shoff == 0 && i_ehdrp->e_type == ET_REL) 572 605 goto got_wrong_format_error; 573 606 574 607 /* As a simple sanity check, verify that the what BFD thinks is the 575 608 size of each section header table entry actually matches the size 576 recorded in the file. */ 577 if (i_ehdrp->e_shentsize != sizeof (x_shdr)) 609 recorded in the file, but only if there are any sections. */ 610 if (i_ehdrp->e_shentsize != sizeof (x_shdr) && i_ehdrp->e_shnum != 0) 611 goto got_wrong_format_error; 612 613 /* Further sanity check. */ 614 if (i_ehdrp->e_shoff == 0 && i_ehdrp->e_shnum != 0) 578 615 goto got_wrong_format_error; 579 616 … … 583 620 BFD format expects. */ 584 621 if (ebd->elf_machine_code != i_ehdrp->e_machine 585 && (ebd->elf_machine_alt1 == 0 || i_ehdrp->e_machine != ebd->elf_machine_alt1) 586 && (ebd->elf_machine_alt2 == 0 || i_ehdrp->e_machine != ebd->elf_machine_alt2)) 622 && (ebd->elf_machine_alt1 == 0 623 || i_ehdrp->e_machine != ebd->elf_machine_alt1) 624 && (ebd->elf_machine_alt2 == 0 625 || i_ehdrp->e_machine != ebd->elf_machine_alt2)) 587 626 { 588 627 const bfd_target * const *target_ptr; … … 631 670 bfd_set_start_address (abfd, i_ehdrp->e_entry); 632 671 672 if (i_ehdrp->e_shoff != 0) 673 { 674 /* Seek to the section header table in the file. */ 675 if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_shoff, SEEK_SET) != 0) 676 goto got_no_match; 677 678 /* Read the first section header at index 0, and convert to internal 679 form. */ 680 if (bfd_bread ((PTR) & x_shdr, (bfd_size_type) sizeof x_shdr, abfd) 681 != sizeof (x_shdr)) 682 goto got_no_match; 683 elf_swap_shdr_in (abfd, &x_shdr, &i_shdr); 684 685 /* If the section count is zero, the actual count is in the first 686 section header. */ 687 if (i_ehdrp->e_shnum == SHN_UNDEF) 688 i_ehdrp->e_shnum = i_shdr.sh_size; 689 690 /* And similarly for the string table index. */ 691 if (i_ehdrp->e_shstrndx == SHN_XINDEX) 692 i_ehdrp->e_shstrndx = i_shdr.sh_link; 693 } 694 633 695 /* Allocate space for a copy of the section header table in 634 internal form, seek to the section header table in the file, 635 read it in, and convert it to internal form. */ 636 i_shdrp = ((Elf_Internal_Shdr *) 637 bfd_alloc (abfd, sizeof (*i_shdrp) * i_ehdrp->e_shnum)); 638 elf_elfsections (abfd) = ((Elf_Internal_Shdr **) 639 bfd_alloc (abfd, 640 sizeof (i_shdrp) * i_ehdrp->e_shnum)); 641 if (!i_shdrp || !elf_elfsections (abfd)) 642 goto got_no_match; 643 if (bfd_seek (abfd, i_ehdrp->e_shoff, SEEK_SET) != 0) 644 goto got_no_match; 645 for (shindex = 0; shindex < i_ehdrp->e_shnum; shindex++) 646 { 647 if (bfd_read ((PTR) & x_shdr, sizeof x_shdr, 1, abfd) != sizeof (x_shdr)) 696 internal form. */ 697 if (i_ehdrp->e_shnum != 0) 698 { 699 Elf_Internal_Shdr *shdrp; 700 unsigned int num_sec; 701 702 amt = sizeof (*i_shdrp) * i_ehdrp->e_shnum; 703 i_shdrp = (Elf_Internal_Shdr *) bfd_alloc (abfd, amt); 704 if (!i_shdrp) 648 705 goto got_no_match; 649 elf_swap_shdr_in (abfd, &x_shdr, i_shdrp + shindex); 650 elf_elfsections (abfd)[shindex] = i_shdrp + shindex; 651 652 /* If the section is loaded, but not page aligned, clear 653 D_PAGED. */ 654 if ((i_shdrp[shindex].sh_flags & SHF_ALLOC) != 0 655 && i_shdrp[shindex].sh_type != SHT_NOBITS 656 && (((i_shdrp[shindex].sh_addr - i_shdrp[shindex].sh_offset) 657 % ebd->maxpagesize) 658 != 0)) 659 abfd->flags &= ~D_PAGED; 660 } 661 if (i_ehdrp->e_shstrndx) 706 num_sec = i_ehdrp->e_shnum; 707 if (num_sec > SHN_LORESERVE) 708 num_sec += SHN_HIRESERVE + 1 - SHN_LORESERVE; 709 elf_numsections (abfd) = num_sec; 710 amt = sizeof (i_shdrp) * num_sec; 711 elf_elfsections (abfd) = (Elf_Internal_Shdr **) bfd_alloc (abfd, amt); 712 if (!elf_elfsections (abfd)) 713 goto got_no_match; 714 715 memcpy (i_shdrp, &i_shdr, sizeof (*i_shdrp)); 716 shdrp = i_shdrp; 717 shindex = 0; 718 if (num_sec > SHN_LORESERVE) 719 { 720 for ( ; shindex < SHN_LORESERVE; shindex++) 721 elf_elfsections (abfd)[shindex] = shdrp++; 722 for ( ; shindex < SHN_HIRESERVE + 1; shindex++) 723 elf_elfsections (abfd)[shindex] = i_shdrp; 724 } 725 for ( ; shindex < num_sec; shindex++) 726 elf_elfsections (abfd)[shindex] = shdrp++; 727 728 /* Read in the rest of the section header table and convert it 729 to internal form. */ 730 for (shindex = 1; shindex < i_ehdrp->e_shnum; shindex++) 731 { 732 if (bfd_bread ((PTR) & x_shdr, (bfd_size_type) sizeof x_shdr, abfd) 733 != sizeof (x_shdr)) 734 goto got_no_match; 735 elf_swap_shdr_in (abfd, &x_shdr, i_shdrp + shindex); 736 737 /* If the section is loaded, but not page aligned, clear 738 D_PAGED. */ 739 if (i_shdrp[shindex].sh_size != 0 740 && (i_shdrp[shindex].sh_flags & SHF_ALLOC) != 0 741 && i_shdrp[shindex].sh_type != SHT_NOBITS 742 && (((i_shdrp[shindex].sh_addr - i_shdrp[shindex].sh_offset) 743 % ebd->maxpagesize) 744 != 0)) 745 abfd->flags &= ~D_PAGED; 746 } 747 } 748 749 if (i_ehdrp->e_shstrndx && i_ehdrp->e_shoff) 662 750 { 663 751 if (! bfd_section_from_shdr (abfd, i_ehdrp->e_shstrndx)) … … 673 761 unsigned int i; 674 762 675 elf_tdata (abfd)->phdr = ((Elf_Internal_Phdr *) 676 bfd_alloc (abfd, 677 (i_ehdrp->e_phnum 678 * sizeof (Elf_Internal_Phdr)))); 763 amt = i_ehdrp->e_phnum * sizeof (Elf_Internal_Phdr); 764 elf_tdata (abfd)->phdr = (Elf_Internal_Phdr *) bfd_alloc (abfd, amt); 679 765 if (elf_tdata (abfd)->phdr == NULL) 680 766 goto got_no_match; 681 if (bfd_seek (abfd, i_ehdrp->e_phoff, SEEK_SET) != 0)767 if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_phoff, SEEK_SET) != 0) 682 768 goto got_no_match; 683 769 i_phdr = elf_tdata (abfd)->phdr; … … 686 772 Elf_External_Phdr x_phdr; 687 773 688 if (bfd_ read ((PTR) &x_phdr, sizeof x_phdr, 1, abfd)774 if (bfd_bread ((PTR) &x_phdr, (bfd_size_type) sizeof x_phdr, abfd) 689 775 != sizeof x_phdr) 690 776 goto got_no_match; … … 699 785 used to find all of the ELF section names.) */ 700 786 701 shstrtab = bfd_elf_get_str_section (abfd, i_ehdrp->e_shstrndx); 702 if (!shstrtab) 703 goto got_no_match; 704 705 /* Once all of the section headers have been read and converted, we 706 can start processing them. Note that the first section header is 707 a dummy placeholder entry, so we ignore it. */ 708 709 for (shindex = 1; shindex < i_ehdrp->e_shnum; shindex++) 710 { 711 if (! bfd_section_from_shdr (abfd, shindex)) 787 if (i_ehdrp->e_shstrndx != 0 && i_ehdrp->e_shoff) 788 { 789 unsigned int num_sec; 790 791 shstrtab = bfd_elf_get_str_section (abfd, i_ehdrp->e_shstrndx); 792 if (!shstrtab) 712 793 goto got_no_match; 794 795 /* Once all of the section headers have been read and converted, we 796 can start processing them. Note that the first section header is 797 a dummy placeholder entry, so we ignore it. */ 798 num_sec = elf_numsections (abfd); 799 for (shindex = 1; shindex < num_sec; shindex++) 800 { 801 if (! bfd_section_from_shdr (abfd, shindex)) 802 goto got_no_match; 803 if (shindex == SHN_LORESERVE - 1) 804 shindex += SHN_HIRESERVE + 1 - SHN_LORESERVE; 805 } 713 806 } 714 807 … … 717 810 if (ebd->elf_backend_object_p) 718 811 { 719 if ( (*ebd->elf_backend_object_p) (abfd) == false)812 if (! (*ebd->elf_backend_object_p) (abfd)) 720 813 goto got_wrong_format_error; 721 814 } … … 740 833 } 741 834 742 return (abfd->xvec); 835 bfd_preserve_finish (abfd, &preserve); 836 return abfd->xvec; 743 837 744 838 got_wrong_format_error: … … 752 846 whole bfd here and restoring it would be even worse; the first thing 753 847 you notice is that the cached bfd file position gets out of sync. */ 754 bfd_default_set_arch_mach (abfd, previous_arch, previous_mach);755 848 bfd_set_error (bfd_error_wrong_format); 849 756 850 got_no_match: 757 if (new_tdata != NULL 758 && new_tdata->elf_sect_ptr != NULL) 759 bfd_release (abfd, new_tdata->elf_sect_ptr); 760 if (i_shdrp != NULL) 761 bfd_release (abfd, i_shdrp); 762 if (new_tdata != NULL) 763 bfd_release (abfd, new_tdata); 764 elf_tdata (abfd) = preserved_tdata; 765 abfd->sections = preserved_sections; 766 abfd->section_count = preserved_section_count; 767 return (NULL); 851 if (preserve.marker != NULL) 852 bfd_preserve_restore (abfd, &preserve); 853 return NULL; 768 854 } 769 855 … … 779 865 PTR data; 780 866 { 781 b oolean *failedp = (boolean *) data;867 bfd_boolean *failedp = (bfd_boolean *) data; 782 868 Elf_Internal_Shdr *rela_hdr; 783 Elf_External_Rela *outbound_relocas; 784 Elf_External_Rel *outbound_relocs; 869 bfd_vma addr_offset; 870 void (*swap_out) PARAMS ((bfd *, const Elf_Internal_Rela *, bfd_byte *)); 871 size_t extsize; 872 bfd_byte *dst_rela; 785 873 unsigned int idx; 786 int use_rela_p; 787 asymbol *last_sym = 0; 788 int last_sym_idx = 0; 874 asymbol *last_sym; 875 int last_sym_idx; 789 876 790 877 /* If we have already failed, don't do anything. */ … … 808 895 if (rela_hdr->contents == NULL) 809 896 { 810 *failedp = true;897 *failedp = TRUE; 811 898 return; 812 899 } … … 814 901 /* Figure out whether the relocations are RELA or REL relocations. */ 815 902 if (rela_hdr->sh_type == SHT_RELA) 816 use_rela_p = true; 903 { 904 swap_out = elf_swap_reloca_out; 905 extsize = sizeof (Elf_External_Rela); 906 } 817 907 else if (rela_hdr->sh_type == SHT_REL) 818 use_rela_p = false; 908 { 909 swap_out = elf_swap_reloc_out; 910 extsize = sizeof (Elf_External_Rel); 911 } 819 912 else 820 913 /* Every relocation section should be either an SHT_RELA or an … … 822 915 abort (); 823 916 917 /* The address of an ELF reloc is section relative for an object 918 file, and absolute for an executable file or shared library. 919 The address of a BFD reloc is always section relative. */ 920 addr_offset = 0; 921 if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0) 922 addr_offset = sec->vma; 923 824 924 /* orelocation has the data, reloc_count has the count... */ 825 if (use_rela_p) 826 { 827 outbound_relocas = (Elf_External_Rela *) rela_hdr->contents; 828 829 for (idx = 0; idx < sec->reloc_count; idx++) 925 last_sym = 0; 926 last_sym_idx = 0; 927 dst_rela = rela_hdr->contents; 928 929 for (idx = 0; idx < sec->reloc_count; idx++, dst_rela += extsize) 930 { 931 Elf_Internal_Rela src_rela; 932 arelent *ptr; 933 asymbol *sym; 934 int n; 935 936 ptr = sec->orelocation[idx]; 937 sym = *ptr->sym_ptr_ptr; 938 if (sym == last_sym) 939 n = last_sym_idx; 940 else if (bfd_is_abs_section (sym->section) && sym->value == 0) 941 n = STN_UNDEF; 942 else 830 943 { 831 Elf_Internal_Rela dst_rela; 832 Elf_External_Rela *src_rela; 833 arelent *ptr; 834 asymbol *sym; 835 int n; 836 837 ptr = sec->orelocation[idx]; 838 src_rela = outbound_relocas + idx; 839 840 /* The address of an ELF reloc is section relative for an object 841 file, and absolute for an executable file or shared library. 842 The address of a BFD reloc is always section relative. */ 843 if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0) 844 dst_rela.r_offset = ptr->address; 845 else 846 dst_rela.r_offset = ptr->address + sec->vma; 847 848 sym = *ptr->sym_ptr_ptr; 849 if (sym == last_sym) 850 n = last_sym_idx; 851 else if (bfd_is_abs_section (sym->section) && sym->value == 0) 852 n = STN_UNDEF; 853 else 944 last_sym = sym; 945 n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym); 946 if (n < 0) 854 947 { 855 last_sym = sym; 856 n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym); 857 if (n < 0) 858 { 859 *failedp = true; 860 return; 861 } 862 last_sym_idx = n; 863 } 864 865 if ((*ptr->sym_ptr_ptr)->the_bfd != NULL 866 && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec 867 && ! _bfd_elf_validate_reloc (abfd, ptr)) 868 { 869 *failedp = true; 948 *failedp = TRUE; 870 949 return; 871 950 } 872 873 dst_rela.r_info = ELF_R_INFO (n, ptr->howto->type); 874 875 dst_rela.r_addend = ptr->addend; 876 elf_swap_reloca_out (abfd, &dst_rela, src_rela); 951 last_sym_idx = n; 877 952 } 878 } 879 else 880 /* REL relocations */ 881 { 882 outbound_relocs = (Elf_External_Rel *) rela_hdr->contents; 883 884 for (idx = 0; idx < sec->reloc_count; idx++) 953 954 if ((*ptr->sym_ptr_ptr)->the_bfd != NULL 955 && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec 956 && ! _bfd_elf_validate_reloc (abfd, ptr)) 885 957 { 886 Elf_Internal_Rel dst_rel; 887 Elf_External_Rel *src_rel; 888 arelent *ptr; 889 int n; 890 asymbol *sym; 891 892 ptr = sec->orelocation[idx]; 893 sym = *ptr->sym_ptr_ptr; 894 src_rel = outbound_relocs + idx; 895 896 /* The address of an ELF reloc is section relative for an object 897 file, and absolute for an executable file or shared library. 898 The address of a BFD reloc is always section relative. */ 899 if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0) 900 dst_rel.r_offset = ptr->address; 901 else 902 dst_rel.r_offset = ptr->address + sec->vma; 903 904 if (sym == last_sym) 905 n = last_sym_idx; 906 else if (bfd_is_abs_section (sym->section) && sym->value == 0) 907 n = STN_UNDEF; 908 else 909 { 910 last_sym = sym; 911 n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym); 912 if (n < 0) 913 { 914 *failedp = true; 915 return; 916 } 917 last_sym_idx = n; 918 } 919 920 if ((*ptr->sym_ptr_ptr)->the_bfd != NULL 921 && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec 922 && ! _bfd_elf_validate_reloc (abfd, ptr)) 923 { 924 *failedp = true; 925 return; 926 } 927 928 dst_rel.r_info = ELF_R_INFO (n, ptr->howto->type); 929 930 elf_swap_reloc_out (abfd, &dst_rel, src_rel); 958 *failedp = TRUE; 959 return; 931 960 } 961 962 src_rela.r_offset = ptr->address + addr_offset; 963 src_rela.r_info = ELF_R_INFO (n, ptr->howto->type); 964 src_rela.r_addend = ptr->addend; 965 (*swap_out) (abfd, &src_rela, dst_rela); 932 966 } 933 967 } … … 939 973 bfd *abfd; 940 974 const Elf_Internal_Phdr *phdr; 941 int count;975 unsigned int count; 942 976 { 943 977 while (count--) … … 945 979 Elf_External_Phdr extphdr; 946 980 elf_swap_phdr_out (abfd, phdr, &extphdr); 947 if (bfd_ write (&extphdr, sizeof (Elf_External_Phdr), 1, abfd)948 981 if (bfd_bwrite (&extphdr, (bfd_size_type) sizeof (Elf_External_Phdr), 982 abfd) != sizeof (Elf_External_Phdr)) 949 983 return -1; 950 984 phdr++; … … 955 989 /* Write out the section headers and the ELF file header. */ 956 990 957 b oolean991 bfd_boolean 958 992 elf_write_shdrs_and_ehdr (abfd) 959 993 bfd *abfd; … … 964 998 Elf_Internal_Shdr **i_shdrp; /* Section header table, internal form */ 965 999 unsigned int count; 1000 bfd_size_type amt; 966 1001 967 1002 i_ehdrp = elf_elfheader (abfd); … … 974 1009 #endif 975 1010 elf_swap_ehdr_out (abfd, i_ehdrp, &x_ehdr); 1011 amt = sizeof (x_ehdr); 976 1012 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0 977 || (bfd_write ((PTR) & x_ehdr, sizeof (x_ehdr), 1, abfd) 978 != sizeof (x_ehdr))) 979 return false; 1013 || bfd_bwrite ((PTR) & x_ehdr, amt, abfd) != amt) 1014 return FALSE; 1015 1016 /* Some fields in the first section header handle overflow of ehdr 1017 fields. */ 1018 if (i_ehdrp->e_shnum >= SHN_LORESERVE) 1019 i_shdrp[0]->sh_size = i_ehdrp->e_shnum; 1020 if (i_ehdrp->e_shstrndx >= SHN_LORESERVE) 1021 i_shdrp[0]->sh_link = i_ehdrp->e_shstrndx; 980 1022 981 1023 /* at this point we've concocted all the ELF sections... */ 982 x_shdrp = (Elf_External_Shdr *) 983 bfd_alloc (abfd, sizeof (*x_shdrp) * (i_ehdrp->e_shnum)); 1024 amt = i_ehdrp->e_shnum; 1025 amt *= sizeof (*x_shdrp); 1026 x_shdrp = (Elf_External_Shdr *) bfd_alloc (abfd, amt); 984 1027 if (!x_shdrp) 985 return false;986 987 for (count = 0; count < i_ehdrp->e_shnum; count++)1028 return FALSE; 1029 1030 for (count = 0; count < i_ehdrp->e_shnum; i_shdrp++, count++) 988 1031 { 989 1032 #if DEBUG & 2 990 elf_debug_section (count, i_shdrp[count]);1033 elf_debug_section (count, *i_shdrp); 991 1034 #endif 992 elf_swap_shdr_out (abfd, i_shdrp[count], x_shdrp + count); 1035 elf_swap_shdr_out (abfd, *i_shdrp, x_shdrp + count); 1036 1037 if (count == SHN_LORESERVE - 1) 1038 i_shdrp += SHN_HIRESERVE + 1 - SHN_LORESERVE; 993 1039 } 994 1040 if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_shoff, SEEK_SET) != 0 995 || (bfd_write ((PTR) x_shdrp, sizeof (*x_shdrp), i_ehdrp->e_shnum, abfd) 996 != sizeof (*x_shdrp) * i_ehdrp->e_shnum)) 997 return false; 1041 || bfd_bwrite ((PTR) x_shdrp, amt, abfd) != amt) 1042 return FALSE; 998 1043 999 1044 /* need to dump the string table too... */ 1000 1045 1001 return true;1046 return TRUE; 1002 1047 } 1003 1048 … … 1006 1051 bfd *abfd; 1007 1052 asymbol **symptrs; /* Buffer for generated bfd symbols */ 1008 b oolean dynamic;1053 bfd_boolean dynamic; 1009 1054 { 1010 1055 Elf_Internal_Shdr *hdr; … … 1013 1058 elf_symbol_type *sym; /* Pointer to current bfd symbol */ 1014 1059 elf_symbol_type *symbase; /* Buffer for generated bfd symbols */ 1015 Elf_Internal_Sym i_sym; 1016 Elf_External_Sym *x_symp = NULL; 1017 Elf_External_Versym *x_versymp = NULL; 1060 Elf_Internal_Sym *isym; 1061 Elf_Internal_Sym *isymend; 1062 Elf_Internal_Sym *isymbuf = NULL; 1063 Elf_External_Versym *xver; 1064 Elf_External_Versym *xverbuf = NULL; 1065 struct elf_backend_data *ebd; 1066 bfd_size_type amt; 1018 1067 1019 1068 /* Read each raw ELF symbol, converting from external ELF form to … … 1049 1098 } 1050 1099 1051 if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) == -1) 1052 return -1; 1053 1100 ebd = get_elf_backend_data (abfd); 1054 1101 symcount = hdr->sh_size / sizeof (Elf_External_Sym); 1055 1056 1102 if (symcount == 0) 1057 1103 sym = symbase = NULL; 1058 1104 else 1059 1105 { 1060 unsigned long i;1061 1062 if ( bfd_seek (abfd, hdr->sh_offset, SEEK_SET) == -1)1106 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, symcount, 0, 1107 NULL, NULL, NULL); 1108 if (isymbuf == NULL) 1063 1109 return -1; 1064 1110 1065 symbase = ((elf_symbol_type *) 1066 bfd_zalloc (abfd, symcount * sizeof (elf_symbol_type))); 1111 amt = symcount; 1112 amt *= sizeof (elf_symbol_type); 1113 symbase = (elf_symbol_type *) bfd_zalloc (abfd, amt); 1067 1114 if (symbase == (elf_symbol_type *) NULL) 1068 return -1;1069 sym = symbase;1070 1071 /* Temporarily allocate room for the raw ELF symbols. */1072 x_symp = ((Elf_External_Sym *)1073 bfd_malloc (symcount * sizeof (Elf_External_Sym)));1074 if (x_symp == NULL && symcount != 0)1075 1115 goto error_return; 1076 1116 1077 if (bfd_read ((PTR) x_symp, sizeof (Elf_External_Sym), symcount, abfd)1078 != symcount * sizeof (Elf_External_Sym))1079 goto error_return;1080 1081 1117 /* Read the raw ELF version symbol information. */ 1082 1083 1118 if (verhdr != NULL 1084 1119 && verhdr->sh_size / sizeof (Elf_External_Versym) != symcount) … … 1100 1135 goto error_return; 1101 1136 1102 x _versymp= (Elf_External_Versym *) bfd_malloc (verhdr->sh_size);1103 if (x _versymp== NULL && verhdr->sh_size != 0)1137 xverbuf = (Elf_External_Versym *) bfd_malloc (verhdr->sh_size); 1138 if (xverbuf == NULL && verhdr->sh_size != 0) 1104 1139 goto error_return; 1105 1140 1106 if (bfd_ read ((PTR) x_versymp, 1, verhdr->sh_size, abfd)1141 if (bfd_bread ((PTR) xverbuf, verhdr->sh_size, abfd) 1107 1142 != verhdr->sh_size) 1108 1143 goto error_return; … … 1110 1145 1111 1146 /* Skip first symbol, which is a null dummy. */ 1112 for (i = 1; i < symcount; i++) 1147 xver = xverbuf; 1148 if (xver != NULL) 1149 ++xver; 1150 isymend = isymbuf + symcount; 1151 for (isym = isymbuf + 1, sym = symbase; isym < isymend; isym++, sym++) 1113 1152 { 1114 elf_swap_symbol_in (abfd, x_symp + i, &i_sym); 1115 memcpy (&sym->internal_elf_sym, &i_sym, sizeof (Elf_Internal_Sym)); 1116 #ifdef ELF_KEEP_EXTSYM 1117 memcpy (&sym->native_elf_sym, x_symp + i, sizeof (Elf_External_Sym)); 1118 #endif 1153 memcpy (&sym->internal_elf_sym, isym, sizeof (Elf_Internal_Sym)); 1119 1154 sym->symbol.the_bfd = abfd; 1120 1155 1121 1156 sym->symbol.name = bfd_elf_string_from_elf_section (abfd, 1122 1157 hdr->sh_link, 1123 i_sym.st_name); 1124 1125 sym->symbol.value = i_sym.st_value; 1126 1127 if (i_sym.st_shndx > 0 && i_sym.st_shndx < SHN_LORESERVE) 1158 isym->st_name); 1159 1160 sym->symbol.value = isym->st_value; 1161 1162 if (isym->st_shndx == SHN_UNDEF) 1163 { 1164 sym->symbol.section = bfd_und_section_ptr; 1165 } 1166 else if (isym->st_shndx < SHN_LORESERVE 1167 || isym->st_shndx > SHN_HIRESERVE) 1128 1168 { 1129 1169 sym->symbol.section = section_from_elf_index (abfd, 1130 i _sym.st_shndx);1170 isym->st_shndx); 1131 1171 if (sym->symbol.section == NULL) 1132 1172 { … … 1137 1177 } 1138 1178 } 1139 else if (i _sym.st_shndx == SHN_ABS)1179 else if (isym->st_shndx == SHN_ABS) 1140 1180 { 1141 1181 sym->symbol.section = bfd_abs_section_ptr; 1142 1182 } 1143 else if (i _sym.st_shndx == SHN_COMMON)1183 else if (isym->st_shndx == SHN_COMMON) 1144 1184 { 1145 1185 sym->symbol.section = bfd_com_section_ptr; … … 1148 1188 size in the value field, and doesn't care (at the 1149 1189 moment) about the alignment. */ 1150 sym->symbol.value = i_sym.st_size; 1151 } 1152 else if (i_sym.st_shndx == SHN_UNDEF) 1153 { 1154 sym->symbol.section = bfd_und_section_ptr; 1190 sym->symbol.value = isym->st_size; 1155 1191 } 1156 1192 else … … 1162 1198 sym->symbol.value -= sym->symbol.section->vma; 1163 1199 1164 switch (ELF_ST_BIND (i _sym.st_info))1200 switch (ELF_ST_BIND (isym->st_info)) 1165 1201 { 1166 1202 case STB_LOCAL: … … 1168 1204 break; 1169 1205 case STB_GLOBAL: 1170 if (i_sym.st_shndx != SHN_UNDEF 1171 && i_sym.st_shndx != SHN_COMMON) 1206 if (isym->st_shndx != SHN_UNDEF && isym->st_shndx != SHN_COMMON) 1172 1207 sym->symbol.flags |= BSF_GLOBAL; 1173 1208 break; … … 1177 1212 } 1178 1213 1179 switch (ELF_ST_TYPE (i _sym.st_info))1214 switch (ELF_ST_TYPE (isym->st_info)) 1180 1215 { 1181 1216 case STT_SECTION: … … 1196 1231 sym->symbol.flags |= BSF_DYNAMIC; 1197 1232 1198 if (x _versymp!= NULL)1233 if (xver != NULL) 1199 1234 { 1200 1235 Elf_Internal_Versym iversym; 1201 1236 1202 _bfd_elf_swap_versym_in (abfd, x _versymp + i, &iversym);1237 _bfd_elf_swap_versym_in (abfd, xver, &iversym); 1203 1238 sym->version = iversym.vs_vers; 1239 xver++; 1204 1240 } 1205 1241 1206 1242 /* Do some backend-specific processing on this symbol. */ 1207 { 1208 struct elf_backend_data *ebd = get_elf_backend_data (abfd); 1209 if (ebd->elf_backend_symbol_processing) 1210 (*ebd->elf_backend_symbol_processing) (abfd, &sym->symbol); 1211 } 1212 1213 sym++; 1243 if (ebd->elf_backend_symbol_processing) 1244 (*ebd->elf_backend_symbol_processing) (abfd, &sym->symbol); 1214 1245 } 1215 1246 } 1216 1247 1217 1248 /* Do some backend-specific processing on this symbol table. */ 1218 { 1219 struct elf_backend_data *ebd = get_elf_backend_data (abfd); 1220 if (ebd->elf_backend_symbol_table_processing) 1221 (*ebd->elf_backend_symbol_table_processing) (abfd, symbase, symcount); 1222 } 1249 if (ebd->elf_backend_symbol_table_processing) 1250 (*ebd->elf_backend_symbol_table_processing) (abfd, symbase, symcount); 1223 1251 1224 1252 /* We rely on the zalloc to clear out the final symbol entry. */ … … 1240 1268 } 1241 1269 1242 if (x _versymp!= NULL)1243 free (x _versymp);1244 if ( x_symp != NULL)1245 free ( x_symp);1270 if (xverbuf != NULL) 1271 free (xverbuf); 1272 if (isymbuf != NULL && hdr->contents != (unsigned char *) isymbuf) 1273 free (isymbuf); 1246 1274 return symcount; 1275 1247 1276 error_return: 1248 if (x _versymp!= NULL)1249 free (x _versymp);1250 if ( x_symp != NULL)1251 free ( x_symp);1277 if (xverbuf != NULL) 1278 free (xverbuf); 1279 if (isymbuf != NULL && hdr->contents != (unsigned char *) isymbuf) 1280 free (isymbuf); 1252 1281 return -1; 1253 1282 } … … 1256 1285 them. */ 1257 1286 1258 static b oolean1287 static bfd_boolean 1259 1288 elf_slurp_reloc_table_from_section (abfd, asect, rel_hdr, reloc_count, 1260 1289 relents, symbols, dynamic) … … 1265 1294 arelent *relents; 1266 1295 asymbol **symbols; 1267 b oolean dynamic;1296 bfd_boolean dynamic; 1268 1297 { 1269 1298 struct elf_backend_data * const ebd = get_elf_backend_data (abfd); … … 1273 1302 unsigned int i; 1274 1303 int entsize; 1275 1276 allocated = (PTR) bfd_malloc ((size_t) rel_hdr->sh_size); 1304 unsigned int symcount; 1305 1306 allocated = (PTR) bfd_malloc (rel_hdr->sh_size); 1277 1307 if (allocated == NULL) 1278 1308 goto error_return; 1279 1309 1280 1310 if (bfd_seek (abfd, rel_hdr->sh_offset, SEEK_SET) != 0 1281 || (bfd_ read (allocated, 1, rel_hdr->sh_size, abfd)1311 || (bfd_bread (allocated, rel_hdr->sh_size, abfd) 1282 1312 != rel_hdr->sh_size)) 1283 1313 goto error_return; … … 1289 1319 || entsize == sizeof (Elf_External_Rela)); 1290 1320 1321 if (dynamic) 1322 symcount = bfd_get_dynamic_symcount (abfd); 1323 else 1324 symcount = bfd_get_symcount (abfd); 1325 1291 1326 for (i = 0, relent = relents; 1292 1327 i < reloc_count; … … 1294 1329 { 1295 1330 Elf_Internal_Rela rela; 1296 Elf_Internal_Rel rel;1297 1331 1298 1332 if (entsize == sizeof (Elf_External_Rela)) 1299 elf_swap_reloca_in (abfd, (Elf_External_Rela *)native_relocs, &rela);1333 elf_swap_reloca_in (abfd, native_relocs, &rela); 1300 1334 else 1301 { 1302 elf_swap_reloc_in (abfd, (Elf_External_Rel *) native_relocs, &rel); 1303 rela.r_offset = rel.r_offset; 1304 rela.r_info = rel.r_info; 1305 rela.r_addend = 0; 1306 } 1335 elf_swap_reloc_in (abfd, native_relocs, &rela); 1307 1336 1308 1337 /* The address of an ELF reloc is section relative for an object … … 1317 1346 if (ELF_R_SYM (rela.r_info) == 0) 1318 1347 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; 1348 else if (ELF_R_SYM (rela.r_info) > symcount) 1349 { 1350 (*_bfd_error_handler) 1351 (_("%s(%s): relocation %d has invalid symbol index %ld"), 1352 abfd->filename, asect->name, i, ELF_R_SYM (rela.r_info)); 1353 relent->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr; 1354 } 1319 1355 else 1320 1356 { … … 1333 1369 relent->addend = rela.r_addend; 1334 1370 1335 if (entsize == sizeof (Elf_External_Rela)) 1371 if ((entsize == sizeof (Elf_External_Rela) 1372 && ebd->elf_info_to_howto != NULL) 1373 || ebd->elf_info_to_howto_rel == NULL) 1336 1374 (*ebd->elf_info_to_howto) (abfd, relent, &rela); 1337 1375 else 1338 (*ebd->elf_info_to_howto_rel) (abfd, relent, &rel );1376 (*ebd->elf_info_to_howto_rel) (abfd, relent, &rela); 1339 1377 } 1340 1378 … … 1342 1380 free (allocated); 1343 1381 1344 return true;1382 return TRUE; 1345 1383 1346 1384 error_return: 1347 1385 if (allocated != NULL) 1348 1386 free (allocated); 1349 return false;1387 return FALSE; 1350 1388 } 1351 1389 1352 1390 /* Read in and swap the external relocs. */ 1353 1391 1354 b oolean1392 bfd_boolean 1355 1393 elf_slurp_reloc_table (abfd, asect, symbols, dynamic) 1356 1394 bfd *abfd; 1357 1395 asection *asect; 1358 1396 asymbol **symbols; 1359 b oolean dynamic;1397 bfd_boolean dynamic; 1360 1398 { 1361 1399 struct bfd_elf_section_data * const d = elf_section_data (asect); … … 1365 1403 bfd_size_type reloc_count2; 1366 1404 arelent *relents; 1405 bfd_size_type amt; 1367 1406 1368 1407 if (asect->relocation != NULL) 1369 return true;1408 return TRUE; 1370 1409 1371 1410 if (! dynamic) … … 1373 1412 if ((asect->flags & SEC_RELOC) == 0 1374 1413 || asect->reloc_count == 0) 1375 return true;1414 return TRUE; 1376 1415 1377 1416 rel_hdr = &d->rel_hdr; … … 1392 1431 in elf.c does not update the RELOC_COUNT. */ 1393 1432 if (asect->_raw_size == 0) 1394 return true;1433 return TRUE; 1395 1434 1396 1435 rel_hdr = &d->this_hdr; … … 1400 1439 } 1401 1440 1402 relents = ((arelent *) 1403 bfd_alloc (abfd, 1404 (reloc_count + reloc_count2) * sizeof (arelent))); 1441 amt = (reloc_count + reloc_count2) * sizeof (arelent); 1442 relents = (arelent *) bfd_alloc (abfd, amt); 1405 1443 if (relents == NULL) 1406 return false;1444 return FALSE; 1407 1445 1408 1446 if (!elf_slurp_reloc_table_from_section (abfd, asect, … … 1410 1448 relents, 1411 1449 symbols, dynamic)) 1412 return false;1450 return FALSE; 1413 1451 1414 1452 if (rel_hdr2 … … 1417 1455 relents + reloc_count, 1418 1456 symbols, dynamic)) 1419 return false;1457 return FALSE; 1420 1458 1421 1459 asect->relocation = relents; 1422 return true;1460 return TRUE; 1423 1461 } 1424 1462 … … 1560 1598 elf_write_shdrs_and_ehdr, 1561 1599 elf_write_relocs, 1600 elf_swap_symbol_in, 1562 1601 elf_swap_symbol_out, 1563 1602 elf_slurp_reloc_table, … … 1565 1604 elf_swap_dyn_in, 1566 1605 elf_swap_dyn_out, 1567 NULL,1568 NULL,1569 NULL,1570 NULL1606 elf_swap_reloc_in, 1607 elf_swap_reloc_out, 1608 elf_swap_reloca_in, 1609 elf_swap_reloca_out 1571 1610 }; -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.