From 40395511d7e3c53afe7774342bbd23fb2f91f16b Mon Sep 17 00:00:00 2001 From: grischka Date: Sat, 3 Oct 2020 09:26:12 +0200 Subject: [PATCH] Revert "function pointer compare" Always fine to try out things but not everything must be shown to the public. ;) Also, AFAIK pointers must compare equal only if derived directly from each other (for example by cast to void* and back). This reverts commit 8f9bf3f223da01c200c6349ae2c2448e5b121161. --- tccelf.c | 23 ++--------------------- tests/tests2/42_function_pointer.c | 8 -------- tests/tests2/42_function_pointer.expect | 3 --- 3 files changed, 2 insertions(+), 32 deletions(-) diff --git a/tccelf.c b/tccelf.c index a3ceb0e5..f9449b30 100644 --- a/tccelf.c +++ b/tccelf.c @@ -1002,25 +1002,12 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) tgt += rel->r_addend; #endif addr = s->sh_addr + rel->r_offset; - { -#if !(defined(TCC_TARGET_I386) || defined(TCC_TARGET_ARM) || \ - defined(TCC_TARGET_MACHO)) - int dynindex; - if (s == data_section && sym->st_shndx == SHN_UNDEF && - s1->dynsym && - (dynindex = get_sym_attr(s1, sym_index, 0)->dyn_index)) { - rel->r_info = ELFW(R_INFO)(dynindex, type); - *qrel++ = *rel; - } - else -#endif - relocate(s1, rel, type, ptr, addr, tgt); - } + relocate(s1, rel, type, ptr, addr, tgt); } /* if the relocation is allocated, we change its symbol table */ if (sr->sh_flags & SHF_ALLOC) { sr->link = s1->dynsym; - if (qrel != (ElfW_Rel *)sr->data) { + if (s1->output_type == TCC_OUTPUT_DLL) { size_t r = (uint8_t*)qrel - sr->data; if (sizeof ((Stab_Sym*)0)->n_value < PTR_SIZE && 0 == strcmp(s->name, ".stab")) @@ -1261,12 +1248,6 @@ ST_FUNC void build_got_entries(TCCState *s1) /* dynsym isn't set for -run :-/ */ dynindex = get_sym_attr(s1, sym_index, 0)->dyn_index; esym = (ElfW(Sym) *)s1->dynsym->data + dynindex; -#if !(defined(TCC_TARGET_I386) || defined(TCC_TARGET_ARM) || \ - defined(TCC_TARGET_MACHO)) - if (dynindex && s == data_section->reloc) - s->sh_flags |= SHF_ALLOC; - else -#endif if (dynindex && (ELFW(ST_TYPE)(esym->st_info) == STT_FUNC || (ELFW(ST_TYPE)(esym->st_info) == STT_NOTYPE diff --git a/tests/tests2/42_function_pointer.c b/tests/tests2/42_function_pointer.c index 6b9db61a..697bd79a 100644 --- a/tests/tests2/42_function_pointer.c +++ b/tests/tests2/42_function_pointer.c @@ -12,18 +12,10 @@ int (*f)(int) = &fred; (fprint here) must not be called directly anywhere in the test. */ int (*fprintfptr)(FILE *, const char *, ...) = &fprintf; -typedef int (*func) (int); -static int dummy1(int i) { return 0; } -int dummy2(int i) { return 0; } -static func allfunc[] = { putchar, dummy1, dummy2 }; - int main() { fprintfptr(stdout, "%d\n", (*f)(24)); - printf ("%d\n", allfunc[0] == putchar); - printf ("%d\n", allfunc[1] == dummy1); - printf ("%d\n", allfunc[2] == dummy2); return 0; } diff --git a/tests/tests2/42_function_pointer.expect b/tests/tests2/42_function_pointer.expect index 0a701413..6c8b6ce4 100644 --- a/tests/tests2/42_function_pointer.expect +++ b/tests/tests2/42_function_pointer.expect @@ -1,5 +1,2 @@ yo 24 42 -1 -1 -1