summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2021-01-08 09:04:49 +0100
committerMark Wielaard <mark@klomp.org>2021-01-28 14:23:28 +0100
commite29965f401896a3652394df8e28cc14979fedc91 (patch)
tree44703d7a01898f519e89dffa32dde77c8fc0682f
parentstrip: Pull update_section_size() into file scope (diff)
downloadelfutils-e29965f401896a3652394df8e28cc14979fedc91.tar.gz
elfutils-e29965f401896a3652394df8e28cc14979fedc91.tar.bz2
elfutils-e29965f401896a3652394df8e28cc14979fedc91.tar.xz
strip: Remove no_symtab_updates() function
The no_symtab_updates() function was being called at the beginning of all case labels in this switch, so we can just call it once before the switch. Then it only has one call-site, so inline this short function there. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
-rw-r--r--src/ChangeLog6
-rw-r--r--src/strip.c74
2 files changed, 35 insertions, 45 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index d1d9a8bf..4fc54ce7 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,11 @@
12021-01-08 Timm Bäder <tbaeder@redhat.com> 12021-01-08 Timm Bäder <tbaeder@redhat.com>
2 2
3 * strip.c (handle_elf): Remove no_symtab_updates function and
4 calls inside the switch statement. Add checks and (possibly)
5 continue, before switch statement is called.
6
72021-01-08 Timm Bäder <tbaeder@redhat.com>
8
3 * strip.c (handle_elf): Move inlined update_section_size function 9 * strip.c (handle_elf): Move inlined update_section_size function
4 to... 10 to...
5 (update_section_size): ...here. New static function that takes as 11 (update_section_size): ...here. New static function that takes as
diff --git a/src/strip.c b/src/strip.c
index e608dc5e..7a5d4e4c 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -2175,49 +2175,43 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
2175 /* Find all relocation sections which use this symbol table. */ 2175 /* Find all relocation sections which use this symbol table. */
2176 for (cnt = 1; cnt <= shdridx; ++cnt) 2176 for (cnt = 1; cnt <= shdridx; ++cnt)
2177 { 2177 {
2178 if (shdr_info[cnt].idx == 0 && debug_fname == NULL) 2178 struct shdr_info *info = &shdr_info[cnt];
2179 if (info->idx == 0 && debug_fname == NULL)
2179 /* Ignore sections which are discarded. When we are saving a 2180 /* Ignore sections which are discarded. When we are saving a
2180 relocation section in a separate debug file, we must fix up 2181 relocation section in a separate debug file, we must fix up
2181 the symbol table references. */ 2182 the symbol table references. */
2182 continue; 2183 continue;
2183 2184
2184 const Elf32_Word symtabidx = shdr_info[cnt].old_sh_link; 2185 const Elf32_Word symtabidx = info->old_sh_link;
2185 elf_assert (symtabidx < shnum + 2); 2186 elf_assert (symtabidx < shnum + 2);
2186 const Elf32_Word *const newsymidx = shdr_info[symtabidx].newsymidx; 2187 const Elf32_Word *const newsymidx = shdr_info[symtabidx].newsymidx;
2187 switch (shdr_info[cnt].shdr.sh_type)
2188 {
2189 inline bool no_symtab_updates (void)
2190 {
2191 /* If the symbol table hasn't changed, do not do anything. */
2192 if (shdr_info[symtabidx].newsymidx == NULL)
2193 return true;
2194
2195 /* If the symbol table is not discarded, but additionally
2196 duplicated in the separate debug file and this section
2197 is discarded, don't adjust anything. */
2198 return (shdr_info[cnt].idx == 0
2199 && shdr_info[symtabidx].debug_data != NULL);
2200 }
2201 2188
2189 /* If the symbol table hasn't changed, do not do anything. */
2190 if (newsymidx == NULL)
2191 continue;
2192
2193 /* If the symbol table is not discarded, but additionally
2194 duplicated in the separate debug file and this section
2195 is discarded, don't adjust anything. */
2196 if (info->idx == 0 && shdr_info[symtabidx].debug_data != NULL)
2197 continue;
2198
2199 switch (info->shdr.sh_type)
2200 {
2202 case SHT_REL: 2201 case SHT_REL:
2203 case SHT_RELA: 2202 case SHT_RELA:
2204 if (no_symtab_updates ()) 2203 scn = (info->idx == 0
2205 break; 2204 ? elf_getscn (debugelf, cnt)
2206 2205 : elf_getscn (newelf, info->idx));
2207 Elf_Data *d = elf_getdata (shdr_info[cnt].idx == 0 2206 Elf_Data *d = elf_getdata (scn, NULL);
2208 ? elf_getscn (debugelf, cnt)
2209 : elf_getscn (newelf,
2210 shdr_info[cnt].idx),
2211 NULL);
2212 elf_assert (d != NULL && d->d_buf != NULL 2207 elf_assert (d != NULL && d->d_buf != NULL
2213 && shdr_info[cnt].shdr.sh_entsize != 0); 2208 && info->shdr.sh_entsize != 0);
2214 size_t nrels = (shdr_info[cnt].shdr.sh_size 2209 size_t nrels = (info->shdr.sh_size / info->shdr.sh_entsize);
2215 / shdr_info[cnt].shdr.sh_entsize);
2216 2210
2217 size_t symsize = gelf_fsize (elf, ELF_T_SYM, 1, EV_CURRENT); 2211 size_t symsize = gelf_fsize (elf, ELF_T_SYM, 1, EV_CURRENT);
2218 const Elf32_Word symidxn = (shdr_info[symtabidx].data->d_size 2212 const Elf32_Word symidxn = (shdr_info[symtabidx].data->d_size
2219 / symsize); 2213 / symsize);
2220 if (shdr_info[cnt].shdr.sh_type == SHT_REL) 2214 if (info->shdr.sh_type == SHT_REL)
2221 for (size_t relidx = 0; relidx < nrels; ++relidx) 2215 for (size_t relidx = 0; relidx < nrels; ++relidx)
2222 { 2216 {
2223 GElf_Rel rel_mem; 2217 GElf_Rel rel_mem;
@@ -2258,15 +2252,12 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
2258 break; 2252 break;
2259 2253
2260 case SHT_HASH: 2254 case SHT_HASH:
2261 if (no_symtab_updates ())
2262 break;
2263
2264 /* We have to recompute the hash table. */ 2255 /* We have to recompute the hash table. */
2265 2256
2266 elf_assert (shdr_info[cnt].idx > 0); 2257 elf_assert (info->idx > 0);
2267 2258
2268 /* The hash section in the new file. */ 2259 /* The hash section in the new file. */
2269 scn = elf_getscn (newelf, shdr_info[cnt].idx); 2260 scn = elf_getscn (newelf, info->idx);
2270 2261
2271 /* The symbol table data. */ 2262 /* The symbol table data. */
2272 Elf_Data *symd = elf_getdata (elf_getscn (newelf, 2263 Elf_Data *symd = elf_getdata (elf_getscn (newelf,
@@ -2278,7 +2269,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
2278 Elf_Data *hashd = elf_getdata (scn, NULL); 2269 Elf_Data *hashd = elf_getdata (scn, NULL);
2279 elf_assert (hashd != NULL && hashd->d_buf != NULL); 2270 elf_assert (hashd != NULL && hashd->d_buf != NULL);
2280 2271
2281 if (shdr_info[cnt].shdr.sh_entsize == sizeof (Elf32_Word)) 2272 if (info->shdr.sh_entsize == sizeof (Elf32_Word))
2282 { 2273 {
2283 /* Sane arches first. */ 2274 /* Sane arches first. */
2284 elf_assert (hashd->d_size >= 2 * sizeof (Elf32_Word)); 2275 elf_assert (hashd->d_size >= 2 * sizeof (Elf32_Word));
@@ -2339,8 +2330,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
2339 else 2330 else
2340 { 2331 {
2341 /* Alpha and S390 64-bit use 64-bit SHT_HASH entries. */ 2332 /* Alpha and S390 64-bit use 64-bit SHT_HASH entries. */
2342 elf_assert (shdr_info[cnt].shdr.sh_entsize 2333 elf_assert (info->shdr.sh_entsize == sizeof (Elf64_Xword));
2343 == sizeof (Elf64_Xword));
2344 2334
2345 Elf64_Xword *bucket = (Elf64_Xword *) hashd->d_buf; 2335 Elf64_Xword *bucket = (Elf64_Xword *) hashd->d_buf;
2346 2336
@@ -2402,13 +2392,10 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
2402 2392
2403 case SHT_GNU_versym: 2393 case SHT_GNU_versym:
2404 /* If the symbol table changed we have to adjust the entries. */ 2394 /* If the symbol table changed we have to adjust the entries. */
2405 if (no_symtab_updates ()) 2395 elf_assert (info->idx > 0);
2406 break;
2407
2408 elf_assert (shdr_info[cnt].idx > 0);
2409 2396
2410 /* The symbol version section in the new file. */ 2397 /* The symbol version section in the new file. */
2411 scn = elf_getscn (newelf, shdr_info[cnt].idx); 2398 scn = elf_getscn (newelf, info->idx);
2412 2399
2413 /* The symbol table data. */ 2400 /* The symbol table data. */
2414 symd = elf_getdata (elf_getscn (newelf, shdr_info[symtabidx].idx), 2401 symd = elf_getdata (elf_getscn (newelf, shdr_info[symtabidx].idx),
@@ -2444,12 +2431,9 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
2444 break; 2431 break;
2445 2432
2446 case SHT_GROUP: 2433 case SHT_GROUP:
2447 if (no_symtab_updates ())
2448 break;
2449
2450 /* Yes, the symbol table changed. 2434 /* Yes, the symbol table changed.
2451 Update the section header of the section group. */ 2435 Update the section header of the section group. */
2452 scn = elf_getscn (newelf, shdr_info[cnt].idx); 2436 scn = elf_getscn (newelf, info->idx);
2453 GElf_Shdr shdr_mem; 2437 GElf_Shdr shdr_mem;
2454 GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); 2438 GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
2455 elf_assert (shdr != NULL); 2439 elf_assert (shdr != NULL);