tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] tcc no longer compiles on Windows


From: Christian Jullien
Subject: Re: [Tinycc-devel] tcc no longer compiles on Windows
Date: Mon, 17 Dec 2018 17:07:10 +0100

As nobody complained, I suppose it’s Ok so I pushed the fix on mob.

 

C.

 

From: Tinycc-devel [mailto:address@hidden On Behalf Of Christian Jullien
Sent: dimanche 9 d├ęcembre 2018 17:15
To: address@hidden
Subject: Re: [Tinycc-devel] tcc no longer compiles on Windows

 

It looks it is broken since Thomas commit:

 

commit

776aa0c093cc6083cbb61d0db8e303209b21bbad

author

Thomas Preud'homme <address@hidden>

Sat, 24 Feb 2018 16:50:14 +0100 (24 15:50 +0000)

committer

Thomas Preud'homme <address@hidden>

Sat, 24 Feb 2018 20:35:15 +0100 (24 19:35 +0000)

tree

0092974992ee82aa3971f6003dbf18d754ad1fd1

tree | snapshot (tar.gz zip)

parent

3e6515b64fe615b90dc758d95862a1626494862f

commit | diff

Prevent dead code on !x86 in prepare_dynamic_rel

In prepare_dynamic_rel() on non x86 targets the count++ statements
appear before any case label and are therefore dead code. This triggers
build failure when building with -Werror. This patch adds an extra guard
around all the x86 case labels and their associated action, leaving just
the default case label for non x86 targets which builds fine.

 

I propose this patch which, at least on Windows x64 fixes compilation error. Thomas, can you please review this patch and apply it in mod if you agree?

 

diff --git a/tccelf.c b/tccelf.c

index ead8eed..d381c4f 100644

--- a/tccelf.c

+++ b/tccelf.c

@@ -866,12 +866,14 @@ static void relocate_rel(TCCState *s1, Section *sr)

static int prepare_dynamic_rel(TCCState *s1, Section *sr)

{

     ElfW_Rel *rel;

-    int sym_index, type, count;

+    int type, count;

 

     count = 0;

     for_each_elem(sr, 0, rel, ElfW_Rel) {

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

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

+#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)

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

+#endif

         switch(type) {

#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)

#if defined(TCC_TARGET_I386)

 

From: Tinycc-devel [mailto:address@hidden On Behalf Of Christian Jullien
Sent: vendredi 7 d├ęcembre 2018 07:04
To: address@hidden
Subject: [Tinycc-devel] tcc no longer compiles on Windows

 

Tccelf.c has an undefined reference to sym_index with R_X86_64_PC32 case line 897.

 

The declaration of sym_index at line 877 is not covered by this case.

 

static int prepare_dynamic_rel(TCCState *s1, Section *sr)

{

    ElfW_Rel *rel;

    int type, count;

 

    count = 0;

    for_each_elem(sr, 0, rel, ElfW_Rel) {

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

        switch(type) {

#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)

#if defined(TCC_TARGET_I386)

        int sym_index = ELFW(R_SYM)(rel->r_info);  <<<< definition limited to I386

        case R_386_32:

            if (!get_sym_attr(s1, sym_index, 0)->dyn_index

                && ((ElfW(Sym)*)symtab_section->data + sym_index)->st_shndx == SHN_UNDEF) {

                /* don't fixup unresolved (weak) symbols */

                rel->r_info = ELFW(R_INFO)(sym_index, R_386_RELATIVE);

                break;

            }

#elif defined(TCC_TARGET_X86_64)

        case R_X86_64_32:

        case R_X86_64_32S:

        case R_X86_64_64:

#endif

            count++;

            break;

#if defined(TCC_TARGET_I386)

        case R_386_PC32:

#elif defined(TCC_TARGET_X86_64)

        case R_X86_64_PC32:

#endif

            if (get_sym_attr(s1, sym_index, 0)->dyn_index)

                count++;

            break;

#endif

        default:

            break;

        }

    }

    if (count) {

        /* allocate the section */

        sr->sh_flags |= SHF_ALLOC;

        sr->sh_size = count * sizeof(ElfW_Rel);

    }

    return count;

}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]