History

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

bellard committed 24 years ago

Commit 18e40e11 parent 519ec301 file · +46 −37Browse files

Unified · Split

tcc.c+46−37
@@ -7031,7 +7031,7 @@ static void tcc_add_runtime(TCCState *s1) · 7030 unmodified lines
70317031 ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE),
70327032 s->sh_num, buf);
70337033 }
7034− next_sec:
7034+ next_sec: ;
70357035 }
70367036 }
70377037
@@ -7236,11 +7236,20 @@ int tcc_output_file(TCCState *s1, const char *filename) · 198 unmodified lines
72367236 break;
72377237 }
72387238
7239− /* allocate strings for section names */
7239+ /* allocate strings for section names and decide if an unallocated
7240+ section should be output */
7241+ /* NOTE: the strsec section comes last, so its size is also
7242+ correct ! */
72407243 for(i = 1; i < nb_sections; i++) {
72417244 s = sections[i];
72427245 s->sh_name = put_elf_str(strsec, s->name);
7243− s->sh_size = s->data_offset;
7246+ /* we output all sections if debug or object file */
7247+ if (do_debug ||
7248+ file_type == TCC_OUTPUT_OBJ ||
7249+ (s->sh_flags & SHF_ALLOC) ||
7250+ i == (nb_sections - 1)) {
7251+ s->sh_size = s->data_offset;
7252+ }
72447253 }
72457254
72467255 /* allocate program segment headers */
@@ -7531,7 +7540,7 @@ int tcc_output_file(TCCState *s1, const char *filename) · 284 unmodified lines
75317540 fputc(0, f);
75327541 offset++;
75337542 }
7534− size = s->data_offset;
7543+ size = s->sh_size;
75357544 fwrite(s->data, 1, size, f);
75367545 offset += size;
75377546 }
@@ -8456,6 +8465,31 @@ int tcc_set_output_type(TCCState *s, int output_type) · 918 unmodified lines
84568465 {
84578466 s->output_type = output_type;
84588467
8468+ /* if bound checking, then add corresponding sections */
8469+#ifdef CONFIG_TCC_BCHECK
8470+ if (do_bounds_check) {
8471+ /* define symbol */
8472+ tcc_define_symbol(s, "__BOUNDS_CHECKING_ON", NULL);
8473+ /* create bounds sections */
8474+ bounds_section = new_section(".bounds",
8475+ SHT_PROGBITS, SHF_ALLOC);
8476+ lbounds_section = new_section(".lbounds",
8477+ SHT_PROGBITS, SHF_ALLOC);
8478+ }
8479+#endif
8480+
8481+ /* add debug sections */
8482+ if (do_debug) {
8483+ /* stab symbols */
8484+ stab_section = new_section(".stab", SHT_PROGBITS, 0);
8485+ stab_section->sh_entsize = sizeof(Stab_Sym);
8486+ stabstr_section = new_section(".stabstr", SHT_STRTAB, 0);
8487+ put_elf_str(stabstr_section, "");
8488+ stab_section->link = stabstr_section;
8489+ /* put first entry */
8490+ put_stabs("", 0, 0, 0, 0);
8491+ }
8492+
84598493 /* add libc crt1/crti objects */
84608494 if (output_type == TCC_OUTPUT_EXE ||
84618495 output_type == TCC_OUTPUT_DLL) {
@@ -8553,41 +8587,16 @@ int main(int argc, char **argv) · 91 unmodified lines
85538587 dynarray_add((void ***)&libraries, &nb_libraries, r + 2);
85548588 } else if (!strcmp(r + 1, "bench")) {
85558589 do_bench = 1;
8590+ } else
85568591 #ifdef CONFIG_TCC_BCHECK
8557− } else if (r[1] == 'b') {
8558− if (!do_bounds_check) {
8559− do_bounds_check = 1;
8560− /* define symbol */
8561− tcc_define_symbol(s, "__BOUNDS_CHECKING_ON", NULL);
8562− /* create bounds sections */
8563− bounds_section = new_section(".bounds",
8564− SHT_PROGBITS, SHF_ALLOC);
8565− lbounds_section = new_section(".lbounds",
8566− SHT_PROGBITS, SHF_ALLOC);
8567− /* debug is implied */
8568− goto debug_opt;
8569− }
8570−#endif
8571− } else if (r[1] == 'g') {
8572−#ifdef CONFIG_TCC_BCHECK
8573− debug_opt:
8574−#endif
8575− if (!do_debug) {
8576− do_debug = 1;
8577−
8578− /* stab symbols */
8579− stab_section = new_section(".stab", SHT_PROGBITS, 0);
8580− stab_section->sh_entsize = sizeof(Stab_Sym);
8581− stabstr_section = new_section(".stabstr", SHT_STRTAB, 0);
8582− put_elf_str(stabstr_section, "");
8583− stab_section->link = stabstr_section;
8584− /* put first entry */
8585− put_stabs("", 0, 0, 0, 0);
8586− }
8592+ if (r[1] == 'b') {
8593+ do_bounds_check = 1;
8594+ do_debug = 1;
85878595 } else
8588− /* the following options are only for testing, so not
8589− documented */
8590− if (r[1] == 'c') {
8596+#endif
8597+ if (r[1] == 'g') {
8598+ do_debug = 1;
8599+ } else if (r[1] == 'c') {
85918600 multiple_files = 1;
85928601 output_type = TCC_OUTPUT_OBJ;
85938602 } else if (!strcmp(r + 1, "static")) {

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