Unified · Split
| @@ -7031,7 +7031,7 @@ static void tcc_add_runtime(TCCState *s1) · 7030 unmodified lines | ||
| 7031 | 7031 | ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), |
| 7032 | 7032 | s->sh_num, buf); |
| 7033 | 7033 | } |
| 7034 | − next_sec: | |
| 7034 | + next_sec: ; | |
| 7035 | 7035 | } |
| 7036 | 7036 | } |
| 7037 | 7037 | |
| @@ -7236,11 +7236,20 @@ int tcc_output_file(TCCState *s1, const char *filename) · 198 unmodified lines | ||
| 7236 | 7236 | break; |
| 7237 | 7237 | } |
| 7238 | 7238 | |
| 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 ! */ | |
| 7240 | 7243 | for(i = 1; i < nb_sections; i++) { |
| 7241 | 7244 | s = sections[i]; |
| 7242 | 7245 | 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 | + } | |
| 7244 | 7253 | } |
| 7245 | 7254 | |
| 7246 | 7255 | /* allocate program segment headers */ |
| @@ -7531,7 +7540,7 @@ int tcc_output_file(TCCState *s1, const char *filename) · 284 unmodified lines | ||
| 7531 | 7540 | fputc(0, f); |
| 7532 | 7541 | offset++; |
| 7533 | 7542 | } |
| 7534 | − size = s->data_offset; | |
| 7543 | + size = s->sh_size; | |
| 7535 | 7544 | fwrite(s->data, 1, size, f); |
| 7536 | 7545 | offset += size; |
| 7537 | 7546 | } |
| @@ -8456,6 +8465,31 @@ int tcc_set_output_type(TCCState *s, int output_type) · 918 unmodified lines | ||
| 8456 | 8465 | { |
| 8457 | 8466 | s->output_type = output_type; |
| 8458 | 8467 | |
| 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 | + | |
| 8459 | 8493 | /* add libc crt1/crti objects */ |
| 8460 | 8494 | if (output_type == TCC_OUTPUT_EXE || |
| 8461 | 8495 | output_type == TCC_OUTPUT_DLL) { |
| @@ -8553,41 +8587,16 @@ int main(int argc, char **argv) · 91 unmodified lines | ||
| 8553 | 8587 | dynarray_add((void ***)&libraries, &nb_libraries, r + 2); |
| 8554 | 8588 | } else if (!strcmp(r + 1, "bench")) { |
| 8555 | 8589 | do_bench = 1; |
| 8590 | + } else | |
| 8556 | 8591 | #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; | |
| 8587 | 8595 | } 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') { | |
| 8591 | 8600 | multiple_files = 1; |
| 8592 | 8601 | output_type = TCC_OUTPUT_OBJ; |
| 8593 | 8602 | } else if (!strcmp(r + 1, "static")) { |