History

Add weak support apple

Update tccmacho.c for weak symbols. Undo tests/tcctest.c disable weak symbols test.

herman ten brugge committed 3 years ago

Commit e99cf721 parent 233d5d52 files · +13 −5Browse files

Unified · Split

2 files
  1. tccmacho.c +12 −4
  2. tests/tcctest.c +1 −1
tccmacho.c+12−4
@@ -304,7 +304,7 @@ struct macho { · 303 unmodified lines
304304 } sk_to_sect[sk_last];
305305 int *elfsectomacho;
306306 int *e2msym;
307− Section *rebase, *binding, *lazy_binding, *exports;
307+ Section *rebase, *binding, *weak_binding, *lazy_binding, *exports;
308308 Section *symtab, *strtab, *wdata, *indirsyms;
309309 Section *stubs, *stub_helper, *la_symbol_ptr;
310310 int nr_plt, n_got;
@@ -887,6 +887,7 @@ static void create_symtab(TCCState *s1, struct macho *mo) · 576 unmodified lines
887887 SHN_UNDEF, "dyld_stub_binder");
888888 mo->rebase = new_section(s1, "REBASE", SHT_LINKEDIT, SHF_ALLOC | SHF_WRITE);
889889 mo->binding = new_section(s1, "BINDING", SHT_LINKEDIT, SHF_ALLOC | SHF_WRITE);
890+ mo->weak_binding = new_section(s1, "WEAK_BINDING", SHT_LINKEDIT, SHF_ALLOC | SHF_WRITE);
890891 mo->lazy_binding = new_section(s1, "LAZY_BINDING", SHT_LINKEDIT, SHF_ALLOC | SHF_WRITE);
891892 mo->exports = new_section(s1, "EXPORT", SHT_LINKEDIT, SHF_ALLOC | SHF_WRITE);
892893
@@ -1003,11 +1004,14 @@ static void do_bind_rebase(TCCState *s1, struct macho *mo) · 110 unmodified lines
10031004 }
10041005 for (i = 0; i < mo->n_bind; i++) {
10051006 int sym_index = ELFW(R_SYM)(mo->bind[i].rel.r_info);
1007+ sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
10061008 Section *s = s1->sections[mo->bind[i].section];
1009+ Section *binding = ELFW(ST_BIND)(sym->st_info) == STB_WEAK
1010+ ? mo->weak_binding : mo->binding;
10071011
10081012 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
10091013 name = (char *) symtab_section->link->data + sym->st_name;
1010− ptr = section_ptr_add(mo->binding, 5 + strlen(name));
1014+ ptr = section_ptr_add(binding, 5 + strlen(name));
10111015 *ptr++ = BIND_OPCODE_SET_DYLIB_SPECIAL_IMM |
10121016 (BIND_SPECIAL_DYLIB_FLAT_LOOKUP & 0xf);
10131017 *ptr++ = BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM | 0;
@@ -1016,9 +1020,9 @@ static void do_bind_rebase(TCCState *s1, struct macho *mo) · 2 unmodified lines
10161020 *ptr++ = BIND_OPCODE_SET_TYPE_IMM | BIND_TYPE_POINTER;
10171021 set_segment_and_offset(mo, s->sh_addr, ptr,
10181022 BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB,
1019− mo->binding,
1023+ binding,
10201024 mo->bind[i].rel.r_offset + s->sh_addr);
1021− ptr = section_ptr_add(mo->binding, 1);
1025+ ptr = section_ptr_add(binding, 1);
10221026 *ptr++ = BIND_OPCODE_DO_BIND;
10231027 }
10241028 if (mo->rebase->data_offset) {
@@ -1270,6 +1274,10 @@ static void collect_sections(TCCState *s1, struct macho *mo) · 245 unmodified lines
12701274 mo->dyldinfo->bind_off = mo->binding->sh_offset;
12711275 mo->dyldinfo->bind_size = mo->binding->data_offset;
12721276 }
1277+ if (mo->weak_binding->data_offset) {
1278+ mo->dyldinfo->weak_bind_off = mo->weak_binding->sh_offset;
1279+ mo->dyldinfo->weak_bind_size = mo->weak_binding->data_offset;
1280+ }
12731281 if (mo->lazy_binding->data_offset) {
12741282 mo->dyldinfo->lazy_bind_off = mo->lazy_binding->sh_offset;
12751283 mo->dyldinfo->lazy_bind_size = mo->lazy_binding->data_offset;
tests/tcctest.c+1−1
@@ -3898,7 +3898,7 @@ void builtin_test(void) · 3897 unmodified lines
38983898 //printf("bera: %p\n", __builtin_extract_return_addr((void*)43));
38993899 }
39003900
3901−#if defined _WIN32 || defined __APPLE__
3901+#if defined _WIN32
39023902 void weak_test(void) {}
39033903 #else
39043904 extern int __attribute__((weak)) weak_f1(void);

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