diff options
| author | Richard M. Stallman | 1995-10-15 01:07:44 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-10-15 01:07:44 +0000 |
| commit | 49bb98339439768d96564ad29f70adbc14ad2115 (patch) | |
| tree | b34804bd61fca27741e895b85fa4ab35874b3d75 /src | |
| parent | f5abdb044bc3b2f11e948af96d005ed74eca2a4f (diff) | |
| download | emacs-49bb98339439768d96564ad29f70adbc14ad2115.tar.gz emacs-49bb98339439768d96564ad29f70adbc14ad2115.zip | |
(find_section): New function.
(unexec): Use it. Also simplify previous changes.
Diffstat (limited to 'src')
| -rw-r--r-- | src/unexsgi.c | 104 |
1 files changed, 50 insertions, 54 deletions
diff --git a/src/unexsgi.c b/src/unexsgi.c index 41df908d5a4..073819afdd5 100644 --- a/src/unexsgi.c +++ b/src/unexsgi.c | |||
| @@ -458,6 +458,44 @@ round_up (x, y) | |||
| 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 | * |
| @@ -526,51 +564,20 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) | |||
| 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; |
| @@ -713,16 +720,9 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) | |||
| 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. */ |
| 717 | { | 724 | if (n == old_bss_index) |
| 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 | { | 725 | { |
| 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); |
| @@ -753,13 +753,9 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) | |||
| 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. */ |