compiling with tcc and linking with gcc gives error: tcc -c a.c gcc a.o usr/bin/ld: a.o: .symtab local symbol at index 0 (>= sh_info of 0) /usr/bin/ld: a.o: error adding symbols: bad value collect2: error: ld returned 1 exit status Solved by moving call to sort_syms.
Unified · Split
| @@ -2527,6 +2527,8 @@ static int tcc_output_elf(TCCState *s1, FILE *f, int phnum, ElfW(Phdr) *phdr) · 2526 unmodified lines | ||
| 2527 | 2527 | ElfW(Ehdr) ehdr; |
| 2528 | 2528 | ElfW(Shdr) shdr, *sh; |
| 2529 | 2529 | |
| 2530 | + sort_syms(s1, s1->symtab); | |
| 2531 | + | |
| 2530 | 2532 | file_type = s1->output_type; |
| 2531 | 2533 | shnum = s1->nb_sections; |
| 2532 | 2534 | |
| @@ -2614,8 +2616,6 @@ static int tcc_output_elf(TCCState *s1, FILE *f, int phnum, ElfW(Phdr) *phdr) · 81 unmodified lines | ||
| 2614 | 2616 | offset += fwrite(sh, 1, sizeof(ElfW(Shdr)), f); |
| 2615 | 2617 | } |
| 2616 | 2618 | |
| 2617 | − sort_syms(s1, s1->symtab); | |
| 2618 | − | |
| 2619 | 2619 | /* output sections */ |
| 2620 | 2620 | for(i = 1; i < s1->nb_sections; i++) { |
| 2621 | 2621 | s = s1->sections[i]; |