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
376376 required */
377377 #define SHF_GROUP (1 << 9) /* Section is member of a group. */
378378 #define SHF_TLS (1 << 10) /* Section hold thread-local data. */
379+#define SHF_COMPRESSED (1 << 11) /* Section with compressed data. */
379380 #define SHF_MASKOS 0x0ff00000 /* OS-specific. */
380381 #define SHF_MASKPROC 0xf0000000 /* Processor-specific */
381382 #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
21942194 {
21952195 ElfW(Ehdr) ehdr;
21962196 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;
21982198 unsigned char *strsec, *strtab;
21992199 int *old_to_new_syms;
22002200 char *sh_name, *name;
@@ -2232,6 +2232,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 31 unmodified lines
22322232 symtab = NULL;
22332233 strtab = NULL;
22342234 nb_syms = 0;
2235+ seencompressed = 0;
22352236 for(i = 1; i < ehdr.e_shnum; i++) {
22362237 sh = &shdr[i];
22372238 if (sh->sh_type == SHT_SYMTAB) {
@@ -2249,6 +2250,8 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 11 unmodified lines
22492250 sh = &shdr[sh->sh_link];
22502251 strtab = load_data(fd, file_offset + sh->sh_offset, sh->sh_size);
22512252 }
2253+ if (sh->sh_flags & SHF_COMPRESSED)
2254+ seencompressed = 1;
22522255 }
22532256
22542257 /* 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
22722275 strcmp(sh_name, ".stabstr")
22732276 )
22742277 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;
22752284 if (sh->sh_addralign < 1)
22762285 sh->sh_addralign = 1;
22772286 /* 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