Hi team,

I'm probably not too far to have a working tcc on OpenBSD.

-          I've got a tcc which produces a .o: tcc -c foo.c

-          The link sequence is /usr/lib/crtbegin.o foo.o /usr/lib/crtend.o
and tcc has already been modified to produce this sequence on OpenBSD
instead or crti.o/crtn.o

-          The foo.o and crtend.o ELF look good but crtbegin.o is not

It fails with: crtbegin.o: error: Invalid relocation entry [ 2] '.rela.text'
@ 0000006a

 

You can reproduce this issue with tcc on Linux x64  with enclosed crtbegin.o

 

[jullien@fedora64 ~]$ tcc -o foo crtbegin.o foo.o

crtbegin.o: error: Invalid relocation entry [ 2] '.rela.text' @ 0000006a

[jullien@fedora64 ~]$

 

The code fails here with type == 2, I tried to filter this type with no
luck:

            for_each_elem(s, (offset / sizeof(*rel)), rel, ElfW_Rel) {

                int type;

                unsigned sym_index;

                /* convert symbol index */

                type = ELFW(R_TYPE)(rel->r_info);

                sym_index = ELFW(R_SYM)(rel->r_info);

                /* NOTE: only one symtab assumed */

                if (sym_index >= nb_syms)

                    goto invalid_reloc;

                sym_index = old_to_new_syms[sym_index];

                /* ignore link_once in rel section. */

                if (!sym_index && !sm_table[sh->sh_info].link_once

#ifdef TCC_TARGET_ARM

                    && type != R_ARM_V4BX

#elif defined TCC_TARGET_RISCV64

                    && type != R_RISCV_ALIGN

                    && type != R_RISCV_RELAX

#endif

                   ) {

                invalid_reloc:

                    tcc_error_noabort("Invalid relocation entry [%2d] '%s' @
%.\

8x",

                        i, strsec + sh->sh_name, (int)rel->r_offset);

                    goto fail;

                }

 

I confess I'm an early bird with ELF.

Mod includes all required changes.

 

Your help is welcome.

 

C.

Attachment: crtbegin.o
Description: Binary data

_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to