diff options
| author | Alan Modra | 2015-11-08 09:28:59 -0800 |
|---|---|---|
| committer | Paul Eggert | 2015-11-08 10:00:59 -0800 |
| commit | 47c6e3035b8182c6436de4673473de7824ad59f1 (patch) | |
| tree | 55e31b91d0e3ab301a1db8bc37c201dc309694a6 /src | |
| parent | 856f4eaba8a76953e0bbcfc7ebb0ca4f2e3cf351 (diff) | |
| download | emacs-47c6e3035b8182c6436de4673473de7824ad59f1.tar.gz emacs-47c6e3035b8182c6436de4673473de7824ad59f1.zip | |
ELF unexec: Merge Alpha and MIPS COFF debug handling
* unexelf.c (unexec): Merge Alpha and MIPS COFF debug handling.
Don't find .mdebug section index, find the section in the loop.
Allow for unlikely possibility that .mdebug is located at sh_offset
before bss segment, by calculating move from difference in
sh_offset rather than just assuming new_data2_size. Simplify
cbLineOffset handling.
Diffstat (limited to 'src')
| -rw-r--r-- | src/unexelf.c | 96 |
1 files changed, 29 insertions, 67 deletions
diff --git a/src/unexelf.c b/src/unexelf.c index d6c66488cc7..0065491b453 100644 --- a/src/unexelf.c +++ b/src/unexelf.c | |||
| @@ -660,9 +660,6 @@ unexec (const char *new_name, const char *old_name) | |||
| 660 | ptrdiff_t n, nn; | 660 | ptrdiff_t n, nn; |
| 661 | ptrdiff_t old_bss_index, old_sbss_index, old_plt_index; | 661 | ptrdiff_t old_bss_index, old_sbss_index, old_plt_index; |
| 662 | ptrdiff_t old_data_index, new_data2_index; | 662 | ptrdiff_t old_data_index, new_data2_index; |
| 663 | #if defined _SYSTYPE_SYSV || defined __sgi | ||
| 664 | ptrdiff_t old_mdebug_index; | ||
| 665 | #endif | ||
| 666 | struct stat stat_buf; | 663 | struct stat stat_buf; |
| 667 | off_t old_file_size; | 664 | off_t old_file_size; |
| 668 | 665 | ||
| @@ -706,13 +703,6 @@ unexec (const char *new_name, const char *old_name) | |||
| 706 | old_section_names = (char *) old_base | 703 | old_section_names = (char *) old_base |
| 707 | + OLD_SECTION_H (old_file_h->e_shstrndx).sh_offset; | 704 | + OLD_SECTION_H (old_file_h->e_shstrndx).sh_offset; |
| 708 | 705 | ||
| 709 | /* Find the mdebug section, if any. */ | ||
| 710 | |||
| 711 | #if defined _SYSTYPE_SYSV || defined __sgi | ||
| 712 | old_mdebug_index = find_section (".mdebug", old_section_names, | ||
| 713 | old_name, old_file_h, old_section_h, 1); | ||
| 714 | #endif | ||
| 715 | |||
| 716 | /* Find the old .bss section. Figure out parameters of the new | 706 | /* Find the old .bss section. Figure out parameters of the new |
| 717 | data2 and bss sections. */ | 707 | data2 and bss sections. */ |
| 718 | 708 | ||
| @@ -1055,51 +1045,31 @@ temacs: | |||
| 1055 | 1045 | ||
| 1056 | memcpy (new_shdr->sh_offset + new_base, src, new_shdr->sh_size); | 1046 | memcpy (new_shdr->sh_offset + new_base, src, new_shdr->sh_size); |
| 1057 | 1047 | ||
| 1058 | #if defined __alpha__ && !defined __OpenBSD__ | 1048 | #if (defined __alpha__ && !defined __OpenBSD__) || defined _SYSTYPE_SYSV |
| 1059 | /* Update Alpha COFF symbol table: */ | 1049 | /* Update Alpha and MIPS COFF debug symbol table. */ |
| 1060 | if (strcmp (old_section_names + old_shdr->sh_name, ".mdebug") == 0) | 1050 | if (strcmp (old_section_names + new_shdr->sh_name, ".mdebug") == 0 |
| 1061 | { | 1051 | && new_shdr->sh_offset - old_shdr->sh_offset != 0 |
| 1062 | pHDRR symhdr = (pHDRR) (new_shdr->sh_offset + new_base); | 1052 | #if defined _SYSTYPE_SYSV |
| 1063 | 1053 | && new_shdr->sh_type == SHT_MIPS_DEBUG | |
| 1064 | symhdr->cbLineOffset += new_data2_size; | 1054 | #endif |
| 1065 | symhdr->cbDnOffset += new_data2_size; | 1055 | ) |
| 1066 | symhdr->cbPdOffset += new_data2_size; | ||
| 1067 | symhdr->cbSymOffset += new_data2_size; | ||
| 1068 | symhdr->cbOptOffset += new_data2_size; | ||
| 1069 | symhdr->cbAuxOffset += new_data2_size; | ||
| 1070 | symhdr->cbSsOffset += new_data2_size; | ||
| 1071 | symhdr->cbSsExtOffset += new_data2_size; | ||
| 1072 | symhdr->cbFdOffset += new_data2_size; | ||
| 1073 | symhdr->cbRfdOffset += new_data2_size; | ||
| 1074 | symhdr->cbExtOffset += new_data2_size; | ||
| 1075 | } | ||
| 1076 | #endif /* __alpha__ && !__OpenBSD__ */ | ||
| 1077 | |||
| 1078 | #if defined (_SYSTYPE_SYSV) | ||
| 1079 | if (new_shdr->sh_type == SHT_MIPS_DEBUG | ||
| 1080 | && old_mdebug_index != -1) | ||
| 1081 | { | 1056 | { |
| 1082 | ptrdiff_t new_offset = new_shdr->sh_offset; | 1057 | ptrdiff_t diff = new_shdr->sh_offset - old_shdr->sh_offset; |
| 1083 | ptrdiff_t old_offset = OLD_SECTION_H (old_mdebug_index).sh_offset; | ||
| 1084 | ptrdiff_t diff = new_offset - old_offset; | ||
| 1085 | HDRR *phdr = (HDRR *) (new_shdr->sh_offset + new_base); | 1058 | HDRR *phdr = (HDRR *) (new_shdr->sh_offset + new_base); |
| 1086 | 1059 | ||
| 1087 | if (diff) | 1060 | phdr->cbLineOffset += diff; |
| 1088 | { | 1061 | phdr->cbDnOffset += diff; |
| 1089 | phdr->cbLineOffset += diff; | 1062 | phdr->cbPdOffset += diff; |
| 1090 | phdr->cbDnOffset += diff; | 1063 | phdr->cbSymOffset += diff; |
| 1091 | phdr->cbPdOffset += diff; | 1064 | phdr->cbOptOffset += diff; |
| 1092 | phdr->cbSymOffset += diff; | 1065 | phdr->cbAuxOffset += diff; |
| 1093 | phdr->cbOptOffset += diff; | 1066 | phdr->cbSsOffset += diff; |
| 1094 | phdr->cbAuxOffset += diff; | 1067 | phdr->cbSsExtOffset += diff; |
| 1095 | phdr->cbSsOffset += diff; | 1068 | phdr->cbFdOffset += diff; |
| 1096 | phdr->cbSsExtOffset += diff; | 1069 | phdr->cbRfdOffset += diff; |
| 1097 | phdr->cbFdOffset += diff; | 1070 | phdr->cbExtOffset += diff; |
| 1098 | phdr->cbRfdOffset += diff; | ||
| 1099 | phdr->cbExtOffset += diff; | ||
| 1100 | } | ||
| 1101 | } | 1071 | } |
| 1102 | #endif /* _SYSTYPE_SYSV */ | 1072 | #endif /* __alpha__ || _SYSTYPE_SYSV */ |
| 1103 | 1073 | ||
| 1104 | #if __sgi | 1074 | #if __sgi |
| 1105 | /* Adjust the HDRR offsets in .mdebug and copy the | 1075 | /* Adjust the HDRR offsets in .mdebug and copy the |
| @@ -1110,7 +1080,8 @@ temacs: | |||
| 1110 | the ld bug that gets the line table in a hole in the | 1080 | the ld bug that gets the line table in a hole in the |
| 1111 | elf file rather than in the .mdebug section proper. | 1081 | elf file rather than in the .mdebug section proper. |
| 1112 | David Anderson. davea@sgi.com Jan 16,1994. */ | 1082 | David Anderson. davea@sgi.com Jan 16,1994. */ |
| 1113 | if (n == old_mdebug_index) | 1083 | if (strcmp (old_section_names + new_shdr->sh_name, ".mdebug") == 0 |
| 1084 | && new_shdr->sh_offset - old_shdr->sh_offset != 0) | ||
| 1114 | { | 1085 | { |
| 1115 | #define MDEBUGADJUST(__ct,__fileaddr) \ | 1086 | #define MDEBUGADJUST(__ct,__fileaddr) \ |
| 1116 | if (n_phdrr->__ct > 0) \ | 1087 | if (n_phdrr->__ct > 0) \ |
| @@ -1120,7 +1091,7 @@ temacs: | |||
| 1120 | 1091 | ||
| 1121 | HDRR *o_phdrr = (HDRR *) ((byte *) old_base + old_shdr->sh_offset); | 1092 | HDRR *o_phdrr = (HDRR *) ((byte *) old_base + old_shdr->sh_offset); |
| 1122 | HDRR *n_phdrr = (HDRR *) ((byte *) new_base + new_shdr->sh_offset); | 1093 | HDRR *n_phdrr = (HDRR *) ((byte *) new_base + new_shdr->sh_offset); |
| 1123 | unsigned movement = new_data2_size; | 1094 | ptrdiff_t movement = new_shdr->sh_offset - old_shdr->sh_offset; |
| 1124 | 1095 | ||
| 1125 | MDEBUGADJUST (idnMax, cbDnOffset); | 1096 | MDEBUGADJUST (idnMax, cbDnOffset); |
| 1126 | MDEBUGADJUST (ipdMax, cbPdOffset); | 1097 | MDEBUGADJUST (ipdMax, cbPdOffset); |
| @@ -1136,22 +1107,13 @@ temacs: | |||
| 1136 | requires special handling. */ | 1107 | requires special handling. */ |
| 1137 | if (n_phdrr->cbLine > 0) | 1108 | if (n_phdrr->cbLine > 0) |
| 1138 | { | 1109 | { |
| 1110 | n_phdrr->cbLineOffset += movement; | ||
| 1111 | |||
| 1139 | if (o_phdrr->cbLineOffset > (old_shdr->sh_offset | 1112 | if (o_phdrr->cbLineOffset > (old_shdr->sh_offset |
| 1140 | + old_shdr->sh_size)) | 1113 | + old_shdr->sh_size)) |
| 1141 | { | 1114 | /* If not covered by section, it hasn't yet been copied. */ |
| 1142 | /* line data is in a hole in elf. do special copy and adjust | 1115 | memcpy (n_phdrr->cbLineOffset + new_base, |
| 1143 | for this ld mistake. | 1116 | o_phdrr->cbLineOffset + old_base, n_phdrr->cbLine); |
| 1144 | */ | ||
| 1145 | n_phdrr->cbLineOffset += movement; | ||
| 1146 | |||
| 1147 | memcpy (n_phdrr->cbLineOffset + new_base, | ||
| 1148 | o_phdrr->cbLineOffset + old_base, n_phdrr->cbLine); | ||
| 1149 | } | ||
| 1150 | else | ||
| 1151 | { | ||
| 1152 | /* somehow line data is in .mdebug as it is supposed to be. */ | ||
| 1153 | MDEBUGADJUST (cbLine, cbLineOffset); | ||
| 1154 | } | ||
| 1155 | } | 1117 | } |
| 1156 | } | 1118 | } |
| 1157 | #endif /* __sgi */ | 1119 | #endif /* __sgi */ |