add stripping if not debug mode - moved debug and bound check init

This commit is contained in:
bellard 2002-07-27 15:38:21 +00:00
parent 519ec30bcf
commit 18e40e1a25

85
tcc.c
View File

@ -7031,7 +7031,7 @@ static void tcc_add_runtime(TCCState *s1)
ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE),
s->sh_num, buf);
}
next_sec:
next_sec: ;
}
}
@ -7236,11 +7236,20 @@ int tcc_output_file(TCCState *s1, const char *filename)
break;
}
/* allocate strings for section names */
/* allocate strings for section names and decide if an unallocated
section should be output */
/* NOTE: the strsec section comes last, so its size is also
correct ! */
for(i = 1; i < nb_sections; i++) {
s = sections[i];
s->sh_name = put_elf_str(strsec, s->name);
s->sh_size = s->data_offset;
/* we output all sections if debug or object file */
if (do_debug ||
file_type == TCC_OUTPUT_OBJ ||
(s->sh_flags & SHF_ALLOC) ||
i == (nb_sections - 1)) {
s->sh_size = s->data_offset;
}
}
/* allocate program segment headers */
@ -7531,7 +7540,7 @@ int tcc_output_file(TCCState *s1, const char *filename)
fputc(0, f);
offset++;
}
size = s->data_offset;
size = s->sh_size;
fwrite(s->data, 1, size, f);
offset += size;
}
@ -8456,6 +8465,31 @@ int tcc_set_output_type(TCCState *s, int output_type)
{
s->output_type = output_type;
/* if bound checking, then add corresponding sections */
#ifdef CONFIG_TCC_BCHECK
if (do_bounds_check) {
/* define symbol */
tcc_define_symbol(s, "__BOUNDS_CHECKING_ON", NULL);
/* create bounds sections */
bounds_section = new_section(".bounds",
SHT_PROGBITS, SHF_ALLOC);
lbounds_section = new_section(".lbounds",
SHT_PROGBITS, SHF_ALLOC);
}
#endif
/* add debug sections */
if (do_debug) {
/* stab symbols */
stab_section = new_section(".stab", SHT_PROGBITS, 0);
stab_section->sh_entsize = sizeof(Stab_Sym);
stabstr_section = new_section(".stabstr", SHT_STRTAB, 0);
put_elf_str(stabstr_section, "");
stab_section->link = stabstr_section;
/* put first entry */
put_stabs("", 0, 0, 0, 0);
}
/* add libc crt1/crti objects */
if (output_type == TCC_OUTPUT_EXE ||
output_type == TCC_OUTPUT_DLL) {
@ -8553,41 +8587,16 @@ int main(int argc, char **argv)
dynarray_add((void ***)&libraries, &nb_libraries, r + 2);
} else if (!strcmp(r + 1, "bench")) {
do_bench = 1;
#ifdef CONFIG_TCC_BCHECK
} else if (r[1] == 'b') {
if (!do_bounds_check) {
do_bounds_check = 1;
/* define symbol */
tcc_define_symbol(s, "__BOUNDS_CHECKING_ON", NULL);
/* create bounds sections */
bounds_section = new_section(".bounds",
SHT_PROGBITS, SHF_ALLOC);
lbounds_section = new_section(".lbounds",
SHT_PROGBITS, SHF_ALLOC);
/* debug is implied */
goto debug_opt;
}
#endif
} else if (r[1] == 'g') {
#ifdef CONFIG_TCC_BCHECK
debug_opt:
#endif
if (!do_debug) {
do_debug = 1;
/* stab symbols */
stab_section = new_section(".stab", SHT_PROGBITS, 0);
stab_section->sh_entsize = sizeof(Stab_Sym);
stabstr_section = new_section(".stabstr", SHT_STRTAB, 0);
put_elf_str(stabstr_section, "");
stab_section->link = stabstr_section;
/* put first entry */
put_stabs("", 0, 0, 0, 0);
}
} else
/* the following options are only for testing, so not
documented */
if (r[1] == 'c') {
#ifdef CONFIG_TCC_BCHECK
if (r[1] == 'b') {
do_bounds_check = 1;
do_debug = 1;
} else
#endif
if (r[1] == 'g') {
do_debug = 1;
} else if (r[1] == 'c') {
multiple_files = 1;
output_type = TCC_OUTPUT_OBJ;
} else if (!strcmp(r + 1, "static")) {