History

Fix dll support for macho

Export now all global symbols in export trie instead of only text symbols. I wrote too much data into dylib file because I did not check for sk_unknown/sk_discard/sk_uw_info. Simplified code in tccrun.c

herman ten brugge committed 3 years ago

Commit f6f3d641 parent 04810db2 files · +12 −17Browse files

Unified · Split

2 files
  1. tccmacho.c +10 −8
  2. tccrun.c +2 −9
tccmacho.c+10−8
@@ -1529,7 +1529,7 @@ static void export_trie(TCCState *s1, struct macho *mo) · 1528 unmodified lines
15291529 ElfW(Sym) *sym = (ElfW(Sym) *)symtab_section->data + sym_index;
15301530 const char *name = (char*)symtab_section->link->data + sym->st_name;
15311531
1532− if (sym->st_shndx == text_section->sh_num &&
1532+ if (sym->st_shndx != SHN_UNDEF && sym->st_shndx < SHN_LORESERVE &&
15331533 (ELFW(ST_BIND)(sym->st_info) == STB_GLOBAL ||
15341534 ELFW(ST_BIND)(sym->st_info) == STB_WEAK)) {
15351535 int flag = EXPORT_SYMBOL_FLAGS_KIND_REGULAR;
@@ -1538,7 +1538,7 @@ static void export_trie(TCCState *s1, struct macho *mo) · 2 unmodified lines
15381538
15391539 if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK)
15401540 flag |= EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION;
1541− dprintf ("%s %d %llx\n", name, flag, addr + vm_addr);
1541+ dprintf ("%s %d %llx\n", name, flag, (long long)addr + vm_addr);
15421542 trie = tcc_realloc(trie, (n_trie + 1) * sizeof(struct trie_info));
15431543 trie[n_trie].name = name;
15441544 trie[n_trie].flag = flag;
@@ -1769,7 +1769,7 @@ static void collect_sections(TCCState *s1, struct macho *mo, const char *filenam · 224 unmodified lines
17691769 seg = NULL;
17701770 numsec = 0;
17711771 mo->elfsectomacho = tcc_mallocz(sizeof(*mo->elfsectomacho) * s1->nb_sections);
1772− for (sk = sk_text; sk < sk_last; sk++) {
1772+ for (sk = sk_unknown; sk < sk_last; sk++) {
17731773 struct section_64 *sec = NULL;
17741774 if (seg) {
17751775 seg->vmsize = curaddr - seg->vmaddr;
@@ -1786,7 +1786,8 @@ static void collect_sections(TCCState *s1, struct macho *mo, const char *filenam · 10 unmodified lines
17861786 export_trie(s1, mo);
17871787 }
17881788 #endif
1789− if ((s1->output_type != TCC_OUTPUT_EXE || mo->segment[sk]) &&
1789+ if (skinfo[sk].seg_initial &&
1790+ (s1->output_type != TCC_OUTPUT_EXE || mo->segment[sk]) &&
17901791 mo->sk_to_sect[sk].s) {
17911792 uint64_t al = 0;
17921793 int si;
@@ -1838,14 +1839,14 @@ static void collect_sections(TCCState *s1, struct macho *mo, const char *filenam · 45 unmodified lines
18381839 for (s = mo->sk_to_sect[sk].s; s; s = s->prev) {
18391840 al = s->sh_addralign;
18401841 curaddr = (curaddr + al - 1) & -al;
1841− dprintf("curaddr now 0x%lx\n", (long)curaddr);
1842+ dprintf("%s: curaddr now 0x%lx\n", s->name, (long)curaddr);
18421843 s->sh_addr = curaddr;
18431844 curaddr += s->sh_size;
18441845 if (s->sh_type != SHT_NOBITS) {
18451846 fileofs = (fileofs + al - 1) & -al;
18461847 s->sh_offset = fileofs;
18471848 fileofs += s->sh_size;
1848− dprintf("fileofs now %ld\n", (long)fileofs);
1849+ dprintf("%s: fileofs now %ld\n", s->name, (long)fileofs);
18491850 }
18501851 if (sec)
18511852 mo->elfsectomacho[s->sh_num] = numsec;
@@ -1964,7 +1965,8 @@ static void macho_write(TCCState *s1, struct macho *mo, FILE *fp) · 112 unmodified lines
19641965
19651966 for (sk = sk_unknown; sk < sk_last; sk++) {
19661967 //struct segment_command_64 *seg;
1967− if ((s1->output_type == TCC_OUTPUT_EXE && !mo->segment[sk]) ||
1968+ if (skinfo[sk].seg_initial == 0 ||
1969+ (s1->output_type == TCC_OUTPUT_EXE && !mo->segment[sk]) ||
19681970 !mo->sk_to_sect[sk].s)
19691971 continue;
19701972 /*seg =*/ get_segment(mo, mo->segment[sk]);
@@ -2058,7 +2060,7 @@ ST_FUNC void bind_rebase_import(TCCState *s1, struct macho *mo) · 87 unmodified lines
20582060 for (j = 0; j < page_count; j++) {
20592061 addr_t start = seg->vmaddr + j * SEG_PAGE_SIZE;
20602062 addr_t end = start + SEG_PAGE_SIZE;
2061− void *last;
2063+ void *last = NULL;
20622064 addr_t last_o = 0;
20632065 addr_t cur_o, cur;
20642066 struct dyld_chained_ptr_64_rebase *rebase;
tccrun.c+2−9
@@ -771,9 +771,6 @@ static addr_t rt_printline_dwarf (rt_context *rc, addr_t wanted_pc, · 770 unmodified lines
771771 } filename_table[FILE_TABLE_SIZE];
772772 addr_t last_pc;
773773 addr_t pc;
774−#if defined TCC_TARGET_MACHO
775− addr_t first_pc;
776−#endif
777774 addr_t func_addr;
778775 int line;
779776 char *filename;
@@ -782,9 +779,6 @@ static addr_t rt_printline_dwarf (rt_context *rc, addr_t wanted_pc, · 2 unmodified lines
782779 next:
783780 ln = rc->dwarf_line;
784781 while (ln < rc->dwarf_line_end) {
785−#if defined TCC_TARGET_MACHO
786− first_pc = 0;
787−#endif
788782 dir_size = 0;
789783 filename_size = 0;
790784 last_pc = 0;
@@ -937,9 +931,8 @@ check_pc: · 146 unmodified lines
937931 pc = dwarf_read_8(cp, end);
938932 #endif
939933 #if defined TCC_TARGET_MACHO
940− if (first_pc == 0 && rc->prog_base != (addr_t) -1)
941− first_pc += rc->prog_base;
942− pc += first_pc;
934+ if (rc->prog_base != (addr_t) -1)
935+ pc += rc->prog_base;
943936 #endif
944937 opindex = 0;
945938 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