Mercurial > emacs
comparison src/=unexsgi.c @ 13223:b0717b54e8b6
(find_section): New function.
(unexec): Use it. Also simplify previous changes.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 15 Oct 1995 01:07:44 +0000 |
parents | 93a5a82b3b75 |
children | 77efc3b74f0d |
comparison
equal
deleted
inserted
replaced
13222:93a5a82b3b75 | 13223:b0717b54e8b6 |
---|---|
456 if (rem == 0) | 456 if (rem == 0) |
457 return x; | 457 return x; |
458 return x - rem + y; | 458 return x - rem + y; |
459 } | 459 } |
460 | 460 |
461 /* Return the index of the section named NAME. | |
462 SECTION_NAMES, FILE_NAME and FILE_H give information | |
463 about the file we are looking in. | |
464 | |
465 If we don't find the section NAME, that is a fatal error | |
466 if NOERROR is 0; we return -1 if NOERROR is nonzero. */ | |
467 | |
468 static int | |
469 find_section (name, section_names, file_name, file_h, noerror) | |
470 char *name; | |
471 char *section_names; | |
472 char *file_name; | |
473 Elf32_Ehdr file_h; | |
474 int noerror; | |
475 { | |
476 int idx; | |
477 | |
478 for (idx = 1; idx < file_h->e_shnum; idx++) | |
479 { | |
480 #ifdef DEBUG | |
481 fprintf (stderr, "Looking for %s - found %s\n", name, | |
482 section_names + OLD_SECTION_H (idx).sh_name); | |
483 #endif | |
484 if (!strcmp (section_names + OLD_SECTION_H (idx).sh_name, | |
485 name)) | |
486 break; | |
487 } | |
488 if (idx == file_h->e_shnum) | |
489 { | |
490 if (noerror) | |
491 return -1; | |
492 else | |
493 fatal ("Can't find .bss in %s.\n", file_name, 0); | |
494 } | |
495 | |
496 return idx; | |
497 } | |
498 | |
461 /* **************************************************************** | 499 /* **************************************************************** |
462 * unexec | 500 * unexec |
463 * | 501 * |
464 * driving logic. | 502 * driving logic. |
465 * | 503 * |
524 old_section_h = (Elf32_Shdr *) ((byte *) old_base + old_file_h->e_shoff); | 562 old_section_h = (Elf32_Shdr *) ((byte *) old_base + old_file_h->e_shoff); |
525 old_section_names | 563 old_section_names |
526 = (char *) old_base + OLD_SECTION_H (old_file_h->e_shstrndx).sh_offset; | 564 = (char *) old_base + OLD_SECTION_H (old_file_h->e_shstrndx).sh_offset; |
527 | 565 |
528 /* Find the mdebug section, if any. */ | 566 /* Find the mdebug section, if any. */ |
529 for (old_mdebug_index = 1; old_mdebug_index < old_file_h->e_shnum; old_mdebug_index++) | 567 |
530 { | 568 old_mdebug_index = find_section (".mdebug", old_section_names, |
531 #ifdef DEBUG | 569 old_name, old_file_h, 1); |
532 fprintf (stderr, "Looking for .mdebug - found %s\n", | |
533 old_section_names + OLD_SECTION_H(old_mdebug_index).sh_name); | |
534 #endif | |
535 if (!strcmp (old_section_names + OLD_SECTION_H(old_mdebug_index).sh_name, | |
536 ".mdebug")) | |
537 break; | |
538 } | |
539 if (old_mdebug_index == old_file_h->e_shnum) | |
540 old_mdebug_index = -1; /* just means no such section was present */ | |
541 | 570 |
542 /* Find the old .bss section. */ | 571 /* Find the old .bss section. */ |
543 | 572 |
544 for (old_bss_index = 1; old_bss_index < old_file_h->e_shnum; old_bss_index++) | 573 old_bss_index = find_section (".bss", old_section_names, |
545 { | 574 old_name, old_file_h, 0); |
546 #ifdef DEBUG | |
547 fprintf (stderr, "Looking for .bss - found %s\n", | |
548 old_section_names + OLD_SECTION_H(old_bss_index).sh_name); | |
549 #endif | |
550 if (!strcmp (old_section_names + OLD_SECTION_H(old_bss_index).sh_name, | |
551 ".bss")) | |
552 break; | |
553 } | |
554 if (old_bss_index == old_file_h->e_shnum) | |
555 fatal ("Can't find .bss in %s.\n", old_name, 0); | |
556 | 575 |
557 /* Find the old .data section. Figure out parameters of | 576 /* Find the old .data section. Figure out parameters of |
558 the new data2 and bss sections. */ | 577 the new data2 and bss sections. */ |
559 | 578 |
560 for (old_data_index = 1; | 579 old_data_index = find_section (".data", old_section_names, |
561 old_data_index < old_file_h->e_shnum; | 580 old_name, old_file_h, 0); |
562 old_data_index++) | |
563 { | |
564 #ifdef DEBUG | |
565 fprintf (stderr, "Looking for .data - found %s\n", | |
566 old_section_names + OLD_SECTION_H(old_data_index).sh_name); | |
567 #endif | |
568 if (!strcmp (old_section_names + OLD_SECTION_H(old_data_index).sh_name, | |
569 ".data")) | |
570 break; | |
571 } | |
572 if (old_data_index == old_file_h->e_shnum) | |
573 fatal ("Can't find .data in %s.\n", old_name, 0); | |
574 | 581 |
575 old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr; | 582 old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr; |
576 old_bss_size = OLD_SECTION_H (old_bss_index).sh_size; | 583 old_bss_size = OLD_SECTION_H (old_bss_index).sh_size; |
577 #if defined(emacs) || !defined(DEBUG) | 584 #if defined(emacs) || !defined(DEBUG) |
578 bss_end = (unsigned int) sbrk (0); | 585 bss_end = (unsigned int) sbrk (0); |
711 before the new bss section. */ | 718 before the new bss section. */ |
712 for (n = 1, nn = 1; n < old_file_h->e_shnum; n++, nn++) | 719 for (n = 1, nn = 1; n < old_file_h->e_shnum; n++, nn++) |
713 { | 720 { |
714 caddr_t src; | 721 caddr_t src; |
715 | 722 |
716 if (n < old_bss_index) | 723 /* If it is bss section, insert the new data2 section before it. */ |
724 if (n == old_bss_index) | |
717 { | 725 { |
718 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (n), | |
719 old_file_h->e_shentsize); | |
720 | |
721 } | |
722 else if (n == old_bss_index) | |
723 { | |
724 | |
725 /* If it is bss section, insert the new data2 section before it. */ | |
726 /* Steal the data section header for this data2 section. */ | 726 /* Steal the data section header for this data2 section. */ |
727 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (old_data_index), | 727 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (old_data_index), |
728 new_file_h->e_shentsize); | 728 new_file_h->e_shentsize); |
729 | 729 |
730 NEW_SECTION_H (nn).sh_addr = new_data2_addr; | 730 NEW_SECTION_H (nn).sh_addr = new_data2_addr; |
751 section address alignment followed the old bss section, so | 751 section address alignment followed the old bss section, so |
752 this section will be placed in exactly the same place. */ | 752 this section will be placed in exactly the same place. */ |
753 NEW_SECTION_H (nn).sh_addralign = OLD_SECTION_H (nn).sh_addralign; | 753 NEW_SECTION_H (nn).sh_addralign = OLD_SECTION_H (nn).sh_addralign; |
754 NEW_SECTION_H (nn).sh_size = 0; | 754 NEW_SECTION_H (nn).sh_size = 0; |
755 } | 755 } |
756 else /* n > old_bss_index */ | 756 else |
757 { | 757 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (n), |
758 | 758 old_file_h->e_shentsize); |
759 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (n), | |
760 old_file_h->e_shentsize); | |
761 | |
762 } | |
763 | 759 |
764 /* Any section that was original placed AFTER the bss | 760 /* Any section that was original placed AFTER the bss |
765 section must now be adjusted by NEW_OFFSETS_SHIFT. */ | 761 section must now be adjusted by NEW_OFFSETS_SHIFT. */ |
766 | 762 |
767 if (NEW_SECTION_H (nn).sh_offset >= new_data2_offset) | 763 if (NEW_SECTION_H (nn).sh_offset >= new_data2_offset) |