History

Add debug support to macos

lldb now works with this push. In tccmacho.c add S_ATTR_DEBUG to all debug sections. Add __DWARF section and rearange struct skinfo. In tccdbg.c The first filename in dwarf_line can not be used. Also had to fix structure/union/lexical_block/subroutine to allow empty childs. dwarfdump --verify complained about this.

herman ten brugge committed 3 years ago

Commit 62096261 parent ac0604a2 files · +107 −57Browse files

Unified · Split

2 files
  1. tccdbg.c +71 −33
  2. tccmacho.c +36 −24
tccdbg.c+71−33
@@ -111,12 +111,16 @@ static const struct { · 110 unmodified lines
111#define DWARF_ABBREV_MEMBER 14111#define DWARF_ABBREV_MEMBER 14
112#define DWARF_ABBREV_MEMBER_BF 15112#define DWARF_ABBREV_MEMBER_BF 15
113#define DWARF_ABBREV_STRUCTURE_TYPE 16113#define DWARF_ABBREV_STRUCTURE_TYPE 16
114#define DWARF_ABBREV_UNION_TYPE 17114#define DWARF_ABBREV_STRUCTURE_EMPTY_TYPE 17
115#define DWARF_ABBREV_SUBPROGRAM_EXTERNAL 18115#define DWARF_ABBREV_UNION_TYPE 18
116#define DWARF_ABBREV_SUBPROGRAM_STATIC 19116#define DWARF_ABBREV_UNION_EMPTY_TYPE 19
117#define DWARF_ABBREV_LEXICAL_BLOCK 20117#define DWARF_ABBREV_SUBPROGRAM_EXTERNAL 20
118#define DWARF_ABBREV_SUBROUTINE_TYPE 21118#define DWARF_ABBREV_SUBPROGRAM_STATIC 21
119#define DWARF_ABBREV_FORMAL_PARAMETER2 22119#define DWARF_ABBREV_LEXICAL_BLOCK 22
120#define DWARF_ABBREV_LEXICAL_EMPTY_BLOCK 23
121#define DWARF_ABBREV_SUBROUTINE_TYPE 24
122#define DWARF_ABBREV_SUBROUTINE_EMPTY_TYPE 25
123#define DWARF_ABBREV_FORMAL_PARAMETER2 26
120 124
121/* all entries should have been generated with dwarf_uleb128 except125/* all entries should have been generated with dwarf_uleb128 except
122 has_children. All values are currently below 128 so this currently126 has_children. All values are currently below 128 so this currently
@@ -222,6 +226,12 @@ static const unsigned char dwarf_abbrev_init[] = { · 99 unmodified lines
222 DW_AT_decl_line, DW_FORM_udata,226 DW_AT_decl_line, DW_FORM_udata,
223 DW_AT_sibling, DW_FORM_ref4,227 DW_AT_sibling, DW_FORM_ref4,
224 0, 0,228 0, 0,
229 DWARF_ABBREV_STRUCTURE_EMPTY_TYPE, DW_TAG_structure_type, 0,
230 DW_AT_name, DW_FORM_strp,
231 DW_AT_byte_size, DW_FORM_udata,
232 DW_AT_decl_file, DW_FORM_udata,
233 DW_AT_decl_line, DW_FORM_udata,
234 0, 0,
225 DWARF_ABBREV_UNION_TYPE, DW_TAG_union_type, 1,235 DWARF_ABBREV_UNION_TYPE, DW_TAG_union_type, 1,
226 DW_AT_name, DW_FORM_strp,236 DW_AT_name, DW_FORM_strp,
227 DW_AT_byte_size, DW_FORM_udata,237 DW_AT_byte_size, DW_FORM_udata,
@@ -229,6 +239,12 @@ static const unsigned char dwarf_abbrev_init[] = { · 1 unmodified line
229 DW_AT_decl_line, DW_FORM_udata,239 DW_AT_decl_line, DW_FORM_udata,
230 DW_AT_sibling, DW_FORM_ref4,240 DW_AT_sibling, DW_FORM_ref4,
231 0, 0,241 0, 0,
242 DWARF_ABBREV_UNION_EMPTY_TYPE, DW_TAG_union_type, 0,
243 DW_AT_name, DW_FORM_strp,
244 DW_AT_byte_size, DW_FORM_udata,
245 DW_AT_decl_file, DW_FORM_udata,
246 DW_AT_decl_line, DW_FORM_udata,
247 0, 0,
232 DWARF_ABBREV_SUBPROGRAM_EXTERNAL, DW_TAG_subprogram, 1,248 DWARF_ABBREV_SUBPROGRAM_EXTERNAL, DW_TAG_subprogram, 1,
233 DW_AT_external, DW_FORM_flag,249 DW_AT_external, DW_FORM_flag,
234 DW_AT_name, DW_FORM_strp,250 DW_AT_name, DW_FORM_strp,
@@ -264,12 +280,23 @@ static const unsigned char dwarf_abbrev_init[] = { · 29 unmodified lines
264 DW_AT_high_pc, DW_FORM_data4,280 DW_AT_high_pc, DW_FORM_data4,
265#else281#else
266 DW_AT_high_pc, DW_FORM_data8,282 DW_AT_high_pc, DW_FORM_data8,
283#endif
284 0, 0,
285 DWARF_ABBREV_LEXICAL_EMPTY_BLOCK, DW_TAG_lexical_block, 0,
286 DW_AT_low_pc, DW_FORM_addr,
287#if PTR_SIZE == 4
288 DW_AT_high_pc, DW_FORM_data4,
289#else
290 DW_AT_high_pc, DW_FORM_data8,
267#endif291#endif
268 0, 0,292 0, 0,
269 DWARF_ABBREV_SUBROUTINE_TYPE, DW_TAG_subroutine_type, 1,293 DWARF_ABBREV_SUBROUTINE_TYPE, DW_TAG_subroutine_type, 1,
270 DW_AT_type, DW_FORM_ref4,294 DW_AT_type, DW_FORM_ref4,
271 DW_AT_sibling, DW_FORM_ref4,295 DW_AT_sibling, DW_FORM_ref4,
272 0, 0,296 0, 0,
297 DWARF_ABBREV_SUBROUTINE_EMPTY_TYPE, DW_TAG_subroutine_type, 0,
298 DW_AT_type, DW_FORM_ref4,
299 0, 0,
273 DWARF_ABBREV_FORMAL_PARAMETER2, DW_TAG_formal_parameter, 0,300 DWARF_ABBREV_FORMAL_PARAMETER2, DW_TAG_formal_parameter, 0,
274 DW_AT_type, DW_FORM_ref4,301 DW_AT_type, DW_FORM_ref4,
275 0, 0,302 0, 0,
@@ -546,7 +573,7 @@ static void dwarf_file(TCCState *s1) · 270 unmodified lines
546 573
547 filename = strrchr(file->filename, '/');574 filename = strrchr(file->filename, '/');
548 if (filename == NULL) {575 if (filename == NULL) {
549 for (i = 0; i < dwarf_line.filename_size; i++)576 for (i = 1; i < dwarf_line.filename_size; i++)
550 if (dwarf_line.filename_table[i].dir_entry == 0 &&577 if (dwarf_line.filename_table[i].dir_entry == 0 &&
551 strcmp(dwarf_line.filename_table[i].name,578 strcmp(dwarf_line.filename_table[i].name,
552 file->filename) == 0) {579 file->filename) == 0) {
@@ -789,11 +816,9 @@ ST_FUNC void tcc_debug_start(TCCState *s1) · 236 unmodified lines
789 tcc_malloc(2*sizeof (struct dwarf_filename_struct));816 tcc_malloc(2*sizeof (struct dwarf_filename_struct));
790 dwarf_line.filename_table[0].dir_entry = 0;817 dwarf_line.filename_table[0].dir_entry = 0;
791 if (undo) {818 if (undo) {
792 dwarf_line.filename_table[0].name = tcc_strdup(filename);819 dwarf_line.filename_table[0].name = tcc_strdup(undo + 1);
793 dwarf_line.filename_table[1].dir_entry = 1;820 dwarf_line.filename_table[1].dir_entry = 1;
794 dwarf_line.filename_table[1].name = tcc_strdup(undo + 1);821 dwarf_line.filename_table[1].name = tcc_strdup(undo + 1);
795 *undo = '/';
796 dwarf_line.filename_table[0].name = tcc_strdup(filename);
797 }822 }
798 else {823 else {
799 dwarf_line.filename_table[0].name = tcc_strdup(filename);824 dwarf_line.filename_table[0].name = tcc_strdup(filename);
@@ -849,17 +874,14 @@ ST_FUNC void tcc_debug_end(TCCState *s1) · 49 unmodified lines
849 int pos = dwarf_info_section->data_offset;874 int pos = dwarf_info_section->data_offset;
850 875
851 dwarf_data1(dwarf_info_section,876 dwarf_data1(dwarf_info_section,
852 IS_UNION (t->type.t) ? DWARF_ABBREV_UNION_TYPE877 IS_UNION (t->type.t) ? DWARF_ABBREV_UNION_EMPTY_TYPE
853 : DWARF_ABBREV_STRUCTURE_TYPE);878 : DWARF_ABBREV_STRUCTURE_EMPTY_TYPE);
854 dwarf_strp(dwarf_info_section,879 dwarf_strp(dwarf_info_section,
855 (t->v & ~SYM_STRUCT) >= SYM_FIRST_ANOM880 (t->v & ~SYM_STRUCT) >= SYM_FIRST_ANOM
856 ? "" : get_tok_str(t->v & ~SYM_STRUCT, NULL));881 ? "" : get_tok_str(t->v & ~SYM_STRUCT, NULL));
857 dwarf_uleb128(dwarf_info_section, 0);882 dwarf_uleb128(dwarf_info_section, 0);
858 dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);883 dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);
859 dwarf_uleb128(dwarf_info_section, file->line_num);884 dwarf_uleb128(dwarf_info_section, file->line_num);
860 j = dwarf_info_section->data_offset + 5 - dwarf_info.start;
861 dwarf_data4(dwarf_info_section, j);
862 dwarf_data1(dwarf_info_section, 0);
863 for (j = 0; j < debug_anon_hash[i].n_debug_type; j++)885 for (j = 0; j < debug_anon_hash[i].n_debug_type; j++)
864 write32le(dwarf_info_section->data +886 write32le(dwarf_info_section->data +
865 debug_anon_hash[i].debug_type[j],887 debug_anon_hash[i].debug_type[j],
@@ -1032,7 +1054,7 @@ ST_FUNC void tcc_debug_bincl(TCCState *s1) · 166 unmodified lines
1032 *undo = '/';1054 *undo = '/';
1033 }1055 }
1034 if (strcmp(filename, "<command line>")) {1056 if (strcmp(filename, "<command line>")) {
1035 for (j = 0; j < dwarf_line.filename_size; j++)1057 for (j = 1; j < dwarf_line.filename_size; j++)
1036 if (dwarf_line.filename_table[j].dir_entry == i &&1058 if (dwarf_line.filename_table[j].dir_entry == i &&
1037 strcmp (dwarf_line.filename_table[j].name, filename) == 0)1059 strcmp (dwarf_line.filename_table[j].name, filename) == 0)
1038 break;1060 break;
@@ -1417,7 +1439,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 378 unmodified lines
1417 t = t->type.ref;1439 t = t->type.ref;
1418 debug_type = tcc_debug_find(s1, t, 1);1440 debug_type = tcc_debug_find(s1, t, 1);
1419 if (debug_type == -1) {1441 if (debug_type == -1) {
1420 int pos_sib, i, *pos_type;1442 int pos_sib = 0, i, *pos_type;
1421 1443
1422 debug_type = tcc_debug_add(s1, t, 1);1444 debug_type = tcc_debug_add(s1, t, 1);
1423 e = t;1445 e = t;
@@ -1428,16 +1450,21 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 4 unmodified lines
1428 }1450 }
1429 pos_type = (int *) tcc_malloc(i * sizeof(int));1451 pos_type = (int *) tcc_malloc(i * sizeof(int));
1430 dwarf_data1(dwarf_info_section,1452 dwarf_data1(dwarf_info_section,
1431 IS_UNION (t->type.t) ? DWARF_ABBREV_UNION_TYPE1453 IS_UNION (t->type.t)
1432 : DWARF_ABBREV_STRUCTURE_TYPE);1454 ? t->next ? DWARF_ABBREV_UNION_TYPE
1455 : DWARF_ABBREV_UNION_EMPTY_TYPE
1456 : t->next ? DWARF_ABBREV_STRUCTURE_TYPE
1457 : DWARF_ABBREV_STRUCTURE_EMPTY_TYPE);
1433 dwarf_strp(dwarf_info_section,1458 dwarf_strp(dwarf_info_section,
1434 (t->v & ~SYM_STRUCT) >= SYM_FIRST_ANOM1459 (t->v & ~SYM_STRUCT) >= SYM_FIRST_ANOM
1435 ? "" : get_tok_str(t->v & ~SYM_STRUCT, NULL));1460 ? "" : get_tok_str(t->v & ~SYM_STRUCT, NULL));
1436 dwarf_uleb128(dwarf_info_section, t->c);1461 dwarf_uleb128(dwarf_info_section, t->c);
1437 dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);1462 dwarf_uleb128(dwarf_info_section, dwarf_line.cur_file);
1438 dwarf_uleb128(dwarf_info_section, file->line_num);1463 dwarf_uleb128(dwarf_info_section, file->line_num);
1439 pos_sib = dwarf_info_section->data_offset;1464 if (t->next) {
1440 dwarf_data4(dwarf_info_section, 0);1465 pos_sib = dwarf_info_section->data_offset;
1466 dwarf_data4(dwarf_info_section, 0);
1467 }
1441 e = t;1468 e = t;
1442 i = 0;1469 i = 0;
1443 while (e->next) {1470 while (e->next) {
@@ -1462,9 +1489,11 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 18 unmodified lines
1462 else1489 else
1463 dwarf_uleb128(dwarf_info_section, e->c);1490 dwarf_uleb128(dwarf_info_section, e->c);
1464 }1491 }
1465 dwarf_data1(dwarf_info_section, 0);1492 if (t->next) {
1466 write32le(dwarf_info_section->data + pos_sib,1493 dwarf_data1(dwarf_info_section, 0);
1467 dwarf_info_section->data_offset - dwarf_info.start);1494 write32le(dwarf_info_section->data + pos_sib,
1495 dwarf_info_section->data_offset - dwarf_info.start);
1496 }
1468 e = t;1497 e = t;
1469 i = 0;1498 i = 0;
1470 while (e->next) {1499 while (e->next) {
@@ -1602,14 +1631,16 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 131 unmodified lines
1602 dwarf_info_section->data_offset - dwarf_info.start);1631 dwarf_info_section->data_offset - dwarf_info.start);
1603 }1632 }
1604 else if (type == VT_FUNC) {1633 else if (type == VT_FUNC) {
1605 int sib_pos, *pos_type;1634 int sib_pos = 0, *pos_type;
1606 Sym *f;1635 Sym *f;
1607 1636
1608 i = dwarf_info_section->data_offset;1637 i = dwarf_info_section->data_offset;
1609 debug_type = tcc_get_dwarf_info(s1, t->type.ref);1638 debug_type = tcc_get_dwarf_info(s1, t->type.ref);
1610 if (retval == debug_type)1639 if (retval == debug_type)
1611 retval = i;1640 retval = i;
1612 dwarf_data1(dwarf_info_section, DWARF_ABBREV_SUBROUTINE_TYPE);1641 dwarf_data1(dwarf_info_section,
1642 t->type.ref->next ? DWARF_ABBREV_SUBROUTINE_TYPE
1643 : DWARF_ABBREV_SUBROUTINE_EMPTY_TYPE);
1613 if (last_pos != -1) {1644 if (last_pos != -1) {
1614 tcc_debug_check_anon(s1, e, last_pos);1645 tcc_debug_check_anon(s1, e, last_pos);
1615 write32le(dwarf_info_section->data + last_pos,1646 write32le(dwarf_info_section->data + last_pos,
@@ -1618,8 +1649,10 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 2 unmodified lines
1618 last_pos = dwarf_info_section->data_offset;1649 last_pos = dwarf_info_section->data_offset;
1619 e = t->type.ref;1650 e = t->type.ref;
1620 dwarf_data4(dwarf_info_section, 0);1651 dwarf_data4(dwarf_info_section, 0);
1621 sib_pos = dwarf_info_section->data_offset;1652 if (t->type.ref->next) {
1622 dwarf_data4(dwarf_info_section, 0);1653 sib_pos = dwarf_info_section->data_offset;
1654 dwarf_data4(dwarf_info_section, 0);
1655 }
1623 f = t->type.ref;1656 f = t->type.ref;
1624 i = 0;1657 i = 0;
1625 while (f->next) {1658 while (f->next) {
@@ -1635,9 +1668,11 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s) · 9 unmodified lines
1635 pos_type[i++] = dwarf_info_section->data_offset;1668 pos_type[i++] = dwarf_info_section->data_offset;
1636 dwarf_data4(dwarf_info_section, 0);1669 dwarf_data4(dwarf_info_section, 0);
1637 }1670 }
1638 dwarf_data1(dwarf_info_section, 0);1671 if (t->type.ref->next) {
1639 write32le(dwarf_info_section->data + sib_pos,1672 dwarf_data1(dwarf_info_section, 0);
1640 dwarf_info_section->data_offset - dwarf_info.start);1673 write32le(dwarf_info_section->data + sib_pos,
1674 dwarf_info_section->data_offset - dwarf_info.start);
1675 }
1641 f = t->type.ref;1676 f = t->type.ref;
1642 i = 0;1677 i = 0;
1643 while (f->next) {1678 while (f->next) {
@@ -1710,7 +1745,9 @@ static void tcc_debug_finish (TCCState *s1, struct _debug_info *cur) · 66 unmodified lines
1710 tcc_free (s->str);1745 tcc_free (s->str);
1711 }1746 }
1712 tcc_free (cur->sym);1747 tcc_free (cur->sym);
1713 dwarf_data1(dwarf_info_section, DWARF_ABBREV_LEXICAL_BLOCK);1748 dwarf_data1(dwarf_info_section,
1749 cur->child ? DWARF_ABBREV_LEXICAL_BLOCK
1750 : DWARF_ABBREV_LEXICAL_EMPTY_BLOCK);
1714 dwarf_reloc(dwarf_info_section, section_sym, R_DATA_PTR);1751 dwarf_reloc(dwarf_info_section, section_sym, R_DATA_PTR);
1715#if PTR_SIZE == 41752#if PTR_SIZE == 4
1716 dwarf_data4(dwarf_info_section, func_ind + cur->start);1753 dwarf_data4(dwarf_info_section, func_ind + cur->start);
@@ -1720,7 +1757,8 @@ static void tcc_debug_finish (TCCState *s1, struct _debug_info *cur) · 3 unmodified lines
1720 dwarf_data8(dwarf_info_section, cur->end - cur->start);1757 dwarf_data8(dwarf_info_section, cur->end - cur->start);
1721#endif1758#endif
1722 tcc_debug_finish (s1, cur->child);1759 tcc_debug_finish (s1, cur->child);
1723 dwarf_data1(dwarf_info_section, 0);1760 if (cur->child)
1761 dwarf_data1(dwarf_info_section, 0);
1724 }1762 }
1725 else1763 else
1726 {1764 {
tccmacho.c+36−24
@@ -228,6 +228,8 @@ struct dyld_chained_ptr_64_bind · 227 unmodified lines
228 228
229#define S_ATTR_PURE_INSTRUCTIONS 0x80000000229#define S_ATTR_PURE_INSTRUCTIONS 0x80000000
230#define S_ATTR_SOME_INSTRUCTIONS 0x00000400230#define S_ATTR_SOME_INSTRUCTIONS 0x00000400
231#define S_ATTR_DEBUG 0x02000000
232
231 233
232typedef uint32_t lc_str;234typedef uint32_t lc_str;
233 235
@@ -372,18 +374,18 @@ enum skind { · 138 unmodified lines
372 sk_ro_data,374 sk_ro_data,
373 sk_uw_info,375 sk_uw_info,
374 sk_nl_ptr, // non-lazy pointers, aka GOT376 sk_nl_ptr, // non-lazy pointers, aka GOT
375 sk_la_ptr, // lazy pointers
376 sk_init,
377 sk_fini,
378 sk_rw_data,
379 sk_stab,
380 sk_stab_str,
381 sk_debug_info,377 sk_debug_info,
382 sk_debug_abbrev,378 sk_debug_abbrev,
383 sk_debug_line,379 sk_debug_line,
384 sk_debug_aranges,380 sk_debug_aranges,
385 sk_debug_str,381 sk_debug_str,
386 sk_debug_line_str,382 sk_debug_line_str,
383 sk_stab,
384 sk_stab_str,
385 sk_la_ptr, // lazy pointers
386 sk_init,
387 sk_fini,
388 sk_rw_data,
387 sk_bss,389 sk_bss,
388 sk_linkedit,390 sk_linkedit,
389 sk_last391 sk_last
@@ -407,7 +409,7 @@ struct nlist_64 { · 17 unmodified lines
407 409
408struct macho {410struct macho {
409 struct mach_header_64 mh;411 struct mach_header_64 mh;
410 int seg2lc[5], nseg;412 int seg2lc[6], nseg;
411 struct load_command **lc;413 struct load_command **lc;
412 struct entry_point_command *ep;414 struct entry_point_command *ep;
413 int nlc;415 int nlc;
@@ -1202,20 +1204,20 @@ const struct { · 788 unmodified lines
1202 /*[sk_ro_data] =*/ { 2, S_REGULAR, "__rodata" },1204 /*[sk_ro_data] =*/ { 2, S_REGULAR, "__rodata" },
1203 /*[sk_uw_info] =*/ { 0 },1205 /*[sk_uw_info] =*/ { 0 },
1204 /*[sk_nl_ptr] =*/ { 2, S_NON_LAZY_SYMBOL_POINTERS, "__got" },1206 /*[sk_nl_ptr] =*/ { 2, S_NON_LAZY_SYMBOL_POINTERS, "__got" },
1205 /*[sk_la_ptr] =*/ { 3, S_LAZY_SYMBOL_POINTERS, "__la_symbol_ptr" },1207 /*[sk_debug_info] =*/ { 3, S_REGULAR | S_ATTR_DEBUG, "__debug_info" },
1206 /*[sk_init] =*/ { 3, S_MOD_INIT_FUNC_POINTERS, "__mod_init_func" },1208 /*[sk_debug_abbrev] =*/ { 3, S_REGULAR | S_ATTR_DEBUG, "__debug_abbrev" },
1207 /*[sk_fini] =*/ { 3, S_MOD_TERM_FUNC_POINTERS, "__mod_term_func" },1209 /*[sk_debug_line] =*/ { 3, S_REGULAR | S_ATTR_DEBUG, "__debug_line" },
1208 /*[sk_rw_data] =*/ { 3, S_REGULAR, "__data" },1210 /*[sk_debug_aranges] =*/ { 3, S_REGULAR | S_ATTR_DEBUG, "__debug_aranges" },
1209 /*[sk_stab] =*/ { 3, S_REGULAR, "__stab" },1211 /*[sk_debug_str] =*/ { 3, S_REGULAR | S_ATTR_DEBUG, "__debug_str" },
1210 /*[sk_stab_str] =*/ { 3, S_REGULAR, "__stab_str" },1212 /*[sk_debug_line_str] =*/ { 3, S_REGULAR | S_ATTR_DEBUG, "__debug_line_str" },
1211 /*[sk_debug_info] =*/ { 3, S_REGULAR, "__debug_info" },1213 /*[sk_stab] =*/ { 4, S_REGULAR, "__stab" },
1212 /*[sk_debug_abbrev] =*/ { 3, S_REGULAR, "__debug_abbrev" },1214 /*[sk_stab_str] =*/ { 4, S_REGULAR, "__stab_str" },
1213 /*[sk_debug_line] =*/ { 3, S_REGULAR, "__debug_line" },1215 /*[sk_la_ptr] =*/ { 4, S_LAZY_SYMBOL_POINTERS, "__la_symbol_ptr" },
1214 /*[sk_debug_aranges] =*/ { 3, S_REGULAR, "__debug_aranges" },1216 /*[sk_init] =*/ { 4, S_MOD_INIT_FUNC_POINTERS, "__mod_init_func" },
1215 /*[sk_debug_str] =*/ { 3, S_REGULAR, "__debug_str" },1217 /*[sk_fini] =*/ { 4, S_MOD_TERM_FUNC_POINTERS, "__mod_term_func" },
1216 /*[sk_debug_line_str] =*/ { 3, S_REGULAR, "__debug_line_str" },1218 /*[sk_rw_data] =*/ { 4, S_REGULAR, "__data" },
1217 /*[sk_bss] =*/ { 3, S_ZEROFILL, "__bss" },1219 /*[sk_bss] =*/ { 4, S_ZEROFILL, "__bss" },
1218 /*[sk_linkedit] =*/ { 4, S_REGULAR, NULL },1220 /*[sk_linkedit] =*/ { 5, S_REGULAR, NULL },
1219};1221};
1220 1222
1221#ifdef CONFIG_NEW_MACHO1223#ifdef CONFIG_NEW_MACHO
@@ -1285,7 +1287,7 @@ static void bind_rebase(TCCState *s1, struct macho *mo) · 63 unmodified lines
1285 *ptr++ = BIND_OPCODE_SET_DYLIB_SPECIAL_IMM |1287 *ptr++ = BIND_OPCODE_SET_DYLIB_SPECIAL_IMM |
1286 (BIND_SPECIAL_DYLIB_FLAT_LOOKUP & 0xf);1288 (BIND_SPECIAL_DYLIB_FLAT_LOOKUP & 0xf);
1287 *ptr++ = BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM | 0;1289 *ptr++ = BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM | 0;
1288 strcpy(ptr, name);1290 strcpy((char *)ptr, name);
1289 ptr += strlen(name) + 1;1291 ptr += strlen(name) + 1;
1290 *ptr++ = BIND_OPCODE_DO_BIND;1292 *ptr++ = BIND_OPCODE_DO_BIND;
1291 *ptr = BIND_OPCODE_DONE;1293 *ptr = BIND_OPCODE_DONE;
@@ -1316,7 +1318,7 @@ static void bind_rebase(TCCState *s1, struct macho *mo) · 24 unmodified lines
1316 *ptr++ = BIND_OPCODE_SET_DYLIB_SPECIAL_IMM |1318 *ptr++ = BIND_OPCODE_SET_DYLIB_SPECIAL_IMM |
1317 (BIND_SPECIAL_DYLIB_FLAT_LOOKUP & 0xf);1319 (BIND_SPECIAL_DYLIB_FLAT_LOOKUP & 0xf);
1318 *ptr++ = BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM | 0;1320 *ptr++ = BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM | 0;
1319 strcpy(ptr, name);1321 strcpy((char *)ptr, name);
1320 ptr += strlen(name) + 1;1322 ptr += strlen(name) + 1;
1321 *ptr++ = BIND_OPCODE_SET_TYPE_IMM | BIND_TYPE_POINTER;1323 *ptr++ = BIND_OPCODE_SET_TYPE_IMM | BIND_TYPE_POINTER;
1322 set_segment_and_offset(mo, s->sh_addr, ptr,1324 set_segment_and_offset(mo, s->sh_addr, ptr,
@@ -1582,6 +1584,11 @@ static void collect_sections(TCCState *s1, struct macho *mo) · 259 unmodified lines
1582 seg->initprot = 3; // rw-1584 seg->initprot = 3; // rw-
1583 seg->flags = SG_READ_ONLY;1585 seg->flags = SG_READ_ONLY;
1584 1586
1587 seg = add_segment(mo, "__DWARF");
1588 seg->vmaddr = -1;
1589 seg->maxprot = 7; // rwx
1590 seg->initprot = 3; // rw-
1591
1585 seg = add_segment(mo, "__DATA");1592 seg = add_segment(mo, "__DATA");
1586 seg->vmaddr = -1;1593 seg->vmaddr = -1;
1587 seg->maxprot = 3; // rw-1594 seg->maxprot = 3; // rw-
@@ -1592,6 +1599,10 @@ static void collect_sections(TCCState *s1, struct macho *mo) · 4 unmodified lines
1592 seg->maxprot = 1; // r--1599 seg->maxprot = 1; // r--
1593 seg->initprot = 1; // r--1600 seg->initprot = 1; // r--
1594 1601
1602 /* trick to avoid __DWARF vmaddr = -1 */
1603 if (dwarf_info_section == NULL)
1604 dwarf_info_section = new_section(s1, ".debug_info", SHT_PROGBITS, 0);
1605
1595#ifdef CONFIG_NEW_MACHO1606#ifdef CONFIG_NEW_MACHO
1596 chained_fixups_lc = add_lc(mo, LC_DYLD_CHAINED_FIXUPS,1607 chained_fixups_lc = add_lc(mo, LC_DYLD_CHAINED_FIXUPS,
1597 sizeof(struct linkedit_data_command));1608 sizeof(struct linkedit_data_command));
@@ -1638,7 +1649,8 @@ static void collect_sections(TCCState *s1, struct macho *mo) · 40 unmodified lines
1638 type = s->sh_type;1649 type = s->sh_type;
1639 flags = s->sh_flags;1650 flags = s->sh_flags;
1640 sk = sk_unknown;1651 sk = sk_unknown;
1641 if (flags & SHF_ALLOC) {1652 /* debug sections have sometimes no SHF_ALLOC */
1653 if ((flags & SHF_ALLOC) || !strncmp(s->name, ".debug_", 7)) {
1642 switch (type) {1654 switch (type) {
1643 default: sk = sk_unknown; break;1655 default: sk = sk_unknown; break;
1644 case SHT_INIT_ARRAY: sk = sk_init; break;1656 case SHT_INIT_ARRAY: sk = sk_init; break;

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