Unified · Split
| @@ -466,6 +466,9 @@ struct TCCState { · 465 unmodified lines | ||
| 466 | 466 | Section **sections; |
| 467 | 467 | int nb_sections; /* number of sections, including first dummy section */ |
| 468 | 468 | |
| 469 | + Section **priv_sections; | |
| 470 | + int nb_priv_sections; /* number of private sections */ | |
| 471 | + | |
| 469 | 472 | /* got handling */ |
| 470 | 473 | Section *got; |
| 471 | 474 | Section *plt; |
| @@ -1294,22 +1297,19 @@ Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags) · 822 unmodified lines | ||
| 1294 | 1297 | break; |
| 1295 | 1298 | } |
| 1296 | 1299 | |
| 1297 | − /* only add section if not private */ | |
| 1298 | − if (!(sh_flags & SHF_PRIVATE)) { | |
| 1300 | + if (sh_flags & SHF_PRIVATE) { | |
| 1301 | + dynarray_add((void ***)&s1->priv_sections, &s1->nb_priv_sections, sec); | |
| 1302 | + } else { | |
| 1299 | 1303 | sec->sh_num = s1->nb_sections; |
| 1300 | 1304 | dynarray_add((void ***)&s1->sections, &s1->nb_sections, sec); |
| 1301 | 1305 | } |
| 1306 | + | |
| 1302 | 1307 | return sec; |
| 1303 | 1308 | } |
| 1304 | 1309 | |
| 1305 | 1310 | static void free_section(Section *s) |
| 1306 | 1311 | { |
| 1307 | − if (s->link && (s->link->sh_flags & SHF_PRIVATE)) | |
| 1308 | − free_section(s->link); | |
| 1309 | − if (s->hash && (s->hash->sh_flags & SHF_PRIVATE)) | |
| 1310 | − s->hash->link = NULL, free_section(s->hash); | |
| 1311 | 1312 | tcc_free(s->data); |
| 1312 | − tcc_free(s); | |
| 1313 | 1313 | } |
| 1314 | 1314 | |
| 1315 | 1315 | /* realloc section and set its content to zero */ |
| @@ -10506,15 +10506,16 @@ void tcc_delete(TCCState *s1) · 9190 unmodified lines | ||
| 10506 | 10506 | tcc_cleanup(); |
| 10507 | 10507 | |
| 10508 | 10508 | /* free all sections */ |
| 10509 | − free_section(s1->dynsymtab_section); | |
| 10510 | − | |
| 10511 | 10509 | for(i = 1; i < s1->nb_sections; i++) |
| 10512 | 10510 | free_section(s1->sections[i]); |
| 10513 | − tcc_free(s1->sections); | |
| 10514 | − | |
| 10511 | + dynarray_reset(&s1->sections, &s1->nb_sections); | |
| 10512 | + | |
| 10513 | + for(i = 0; i < s1->nb_priv_sections; i++) | |
| 10514 | + free_section(s1->priv_sections[i]); | |
| 10515 | + dynarray_reset(&s1->priv_sections, &s1->nb_priv_sections); | |
| 10516 | + | |
| 10515 | 10517 | /* free any loaded DLLs */ |
| 10516 | − for ( i = 0; i < s1->nb_loaded_dlls; i++) | |
| 10517 | − { | |
| 10518 | + for ( i = 0; i < s1->nb_loaded_dlls; i++) { | |
| 10518 | 10519 | DLLReference *ref = s1->loaded_dlls[i]; |
| 10519 | 10520 | if ( ref->handle ) |
| 10520 | 10521 | dlclose(ref->handle); |