History

elf: Ignore SHF_COMPRESSED sections

some newer systems have debug sections compressed by default, which includes those in the crt[1in].o startup files. These can't simply be concatenated like all others (which leads to invalid section contents ultimately making gdb fail) but need special handling. Instead of that special handling (decompressing, which in turn requires linking against zlib) let's just ignore such sections, even though that means to also ignore all other debug sections from that particular input file. Our own generated files of course don't have the problem.

Michael Matz committed 9 years ago

Commit 600018c1 parent ff998902 files · +11 −1Browse files

Unified · Split

2 files
  1. elf.h +1 −0
  2. tccelf.c +10 −1
elf.h+1−0
@@ -376,6 +376,7 @@ typedef struct · 375 unmodified lines
376 required */376 required */
377#define SHF_GROUP (1 << 9) /* Section is member of a group. */377#define SHF_GROUP (1 << 9) /* Section is member of a group. */
378#define SHF_TLS (1 << 10) /* Section hold thread-local data. */378#define SHF_TLS (1 << 10) /* Section hold thread-local data. */
379#define SHF_COMPRESSED (1 << 11) /* Section with compressed data. */
379#define SHF_MASKOS 0x0ff00000 /* OS-specific. */380#define SHF_MASKOS 0x0ff00000 /* OS-specific. */
380#define SHF_MASKPROC 0xf0000000 /* Processor-specific */381#define SHF_MASKPROC 0xf0000000 /* Processor-specific */
381#define SHF_ORDERED (1 << 30) /* Special ordering requirement382#define SHF_ORDERED (1 << 30) /* Special ordering requirement
tccelf.c+10−1
@@ -2194,7 +2194,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 2193 unmodified lines
2194{2194{
2195 ElfW(Ehdr) ehdr;2195 ElfW(Ehdr) ehdr;
2196 ElfW(Shdr) *shdr, *sh;2196 ElfW(Shdr) *shdr, *sh;
2197 int size, i, j, offset, offseti, nb_syms, sym_index, ret;2197 int size, i, j, offset, offseti, nb_syms, sym_index, ret, seencompressed;
2198 unsigned char *strsec, *strtab;2198 unsigned char *strsec, *strtab;
2199 int *old_to_new_syms;2199 int *old_to_new_syms;
2200 char *sh_name, *name;2200 char *sh_name, *name;
@@ -2232,6 +2232,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 31 unmodified lines
2232 symtab = NULL;2232 symtab = NULL;
2233 strtab = NULL;2233 strtab = NULL;
2234 nb_syms = 0;2234 nb_syms = 0;
2235 seencompressed = 0;
2235 for(i = 1; i < ehdr.e_shnum; i++) {2236 for(i = 1; i < ehdr.e_shnum; i++) {
2236 sh = &shdr[i];2237 sh = &shdr[i];
2237 if (sh->sh_type == SHT_SYMTAB) {2238 if (sh->sh_type == SHT_SYMTAB) {
@@ -2249,6 +2250,8 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 11 unmodified lines
2249 sh = &shdr[sh->sh_link];2250 sh = &shdr[sh->sh_link];
2250 strtab = load_data(fd, file_offset + sh->sh_offset, sh->sh_size);2251 strtab = load_data(fd, file_offset + sh->sh_offset, sh->sh_size);
2251 }2252 }
2253 if (sh->sh_flags & SHF_COMPRESSED)
2254 seencompressed = 1;
2252 }2255 }
2253 2256
2254 /* now examine each section and try to merge its content with the2257 /* now examine each section and try to merge its content with the
@@ -2272,6 +2275,12 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 17 unmodified lines
2272 strcmp(sh_name, ".stabstr")2275 strcmp(sh_name, ".stabstr")
2273 )2276 )
2274 continue;2277 continue;
2278 if (seencompressed
2279 && (!strncmp(sh_name, ".debug_", sizeof(".debug_")-1)
2280 || (sh->sh_type == SHT_RELX
2281 && !strncmp((char*)strsec + shdr[sh->sh_info].sh_name,
2282 ".debug_", sizeof(".debug_")-1))))
2283 continue;
2275 if (sh->sh_addralign < 1)2284 if (sh->sh_addralign < 1)
2276 sh->sh_addralign = 1;2285 sh->sh_addralign = 1;
2277 /* find corresponding section, if any */2286 /* find corresponding section, if any */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t