Move sort_syms to avoid linker error

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.
This commit is contained in:
herman ten brugge 2024-10-20 10:57:50 +02:00
parent 7a6f3fded4
commit 5a467ddc98

View file

@ -2527,6 +2527,8 @@ static int tcc_output_elf(TCCState *s1, FILE *f, int phnum, ElfW(Phdr) *phdr)
ElfW(Ehdr) ehdr;
ElfW(Shdr) shdr, *sh;
sort_syms(s1, s1->symtab);
file_type = s1->output_type;
shnum = s1->nb_sections;
@ -2614,8 +2616,6 @@ static int tcc_output_elf(TCCState *s1, FILE *f, int phnum, ElfW(Phdr) *phdr)
offset += fwrite(sh, 1, sizeof(ElfW(Shdr)), f);
}
sort_syms(s1, s1->symtab);
/* output sections */
for(i = 1; i < s1->nb_sections; i++) {
s = s1->sections[i];