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.
master
Michael Matz 2017-05-06 07:30:44 +02:00
parent ff998900b1
commit 600018ce47
2 changed files with 11 additions and 1 deletions

1
elf.h
View File

@ -376,6 +376,7 @@ typedef struct
required */
#define SHF_GROUP (1 << 9) /* Section is member of a group. */
#define SHF_TLS (1 << 10) /* Section hold thread-local data. */
#define SHF_COMPRESSED (1 << 11) /* Section with compressed data. */
#define SHF_MASKOS 0x0ff00000 /* OS-specific. */
#define SHF_MASKPROC 0xf0000000 /* Processor-specific */
#define SHF_ORDERED (1 << 30) /* Special ordering requirement

View File

@ -2194,7 +2194,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1,
{
ElfW(Ehdr) ehdr;
ElfW(Shdr) *shdr, *sh;
int size, i, j, offset, offseti, nb_syms, sym_index, ret;
int size, i, j, offset, offseti, nb_syms, sym_index, ret, seencompressed;
unsigned char *strsec, *strtab;
int *old_to_new_syms;
char *sh_name, *name;
@ -2232,6 +2232,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1,
symtab = NULL;
strtab = NULL;
nb_syms = 0;
seencompressed = 0;
for(i = 1; i < ehdr.e_shnum; i++) {
sh = &shdr[i];
if (sh->sh_type == SHT_SYMTAB) {
@ -2249,6 +2250,8 @@ ST_FUNC int tcc_load_object_file(TCCState *s1,
sh = &shdr[sh->sh_link];
strtab = load_data(fd, file_offset + sh->sh_offset, sh->sh_size);
}
if (sh->sh_flags & SHF_COMPRESSED)
seencompressed = 1;
}
/* 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,
strcmp(sh_name, ".stabstr")
)
continue;
if (seencompressed
&& (!strncmp(sh_name, ".debug_", sizeof(".debug_")-1)
|| (sh->sh_type == SHT_RELX
&& !strncmp((char*)strsec + shdr[sh->sh_info].sh_name,
".debug_", sizeof(".debug_")-1))))
continue;
if (sh->sh_addralign < 1)
sh->sh_addralign = 1;
/* find corresponding section, if any */