tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] test failures on win32 x86-64


From: Michael Matz
Subject: Re: [Tinycc-devel] test failures on win32 x86-64
Date: Wed, 19 Oct 2022 17:09:14 +0200 (CEST)
User-agent: Alpine 2.21 (LSU 202 2017-01-01)

Hi,

On Wed, 19 Oct 2022, Domingo Alvarez Duarte wrote:

Looking through the code on "tests/tcctest.c" there is more places using "[unsigned] long" that probably will need to be revised to use "[unsigned] long long" or "size_t".

Nah, you can't just blindly grep for "long" and randomly replace stuff. In most places it's correct. Sure, there's still a problem, so somebody needs to at least run this through gdb, like last time.


Ciao,
Michael.



Probably in several other places see bellow for a search on my fork:

=====

va_list.c
extern void *memcpy(void *dest, const void *src, unsigned long n);      [position 26:59]         ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align); [position 59:42]         ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align); [position 59:47]
va_list.c
extern void *memcpy(void *dest, const void *src, unsigned long n);      [position 26:59]         ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align); [position 59:42]         ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align); [position 59:47]
tcctest.c
enum ELong {      [position 598:7]
    EL_large = ((unsigned long)0xf000 << 31) << 1,      [position 601:27]
    i = ((long)p) >> 32;      [position 927:11]
    unsigned long flags;      [position 1003:14]
        unsigned long index;      [position 1011:15]
        unsigned long counters;      [position 1015:15]
        long u3;      [position 1024:6]
        long u4;      [position 1025:6]
        unsigned long compound_head;      [position 1029:15]
} __attribute__((aligned(2 * sizeof(long))));      [position 1034:37]

 unsigned long ul = 0x80000000UL;      [position 1585:14]
           (long)p, (unsigned long)p,      [position 1632:13]
           (long)p, (unsigned long)p,      [position 1632:31]
           (long long)p, (unsigned long long)p);      [position 1633:13]
           (long long)p, (unsigned long long)p);      [position 1633:18]
           (long long)p, (unsigned long long)p);      [position 1633:36]
           (long long)p, (unsigned long long)p);      [position 1633:41]
    printf("0x%lx\n", (unsigned long)(int)ul);      [position 1641:33]
    long diff;      [position 2353:5]
long __pa_symbol(void)      [position 2848:1]
       return ((long)(((unsigned long)(&rel1))) - (0xffffffff80000000UL));      [position 2855:17]        return ((long)(((unsigned long)(&rel1))) - (0xffffffff80000000UL));      [position 2855:34]
    printf("cmpfn=%lx\n", (long)cmpfn);      [position 2880:28]
    printf("cmpfn=%lx\n", (long)cmpfn);      [position 2886:28]
    printf("sizeof(long) = %d\n", sizeof(long));      [position 3006:20]
    printf("sizeof(long) = %d\n", sizeof(long));      [position 3006:42]
    printf("sizeof(unsigned long) = %d\n", sizeof(unsigned long));      [position 3007:29]     printf("sizeof(unsigned long) = %d\n", sizeof(unsigned long));      [position 3007:60]
void consume_ulong (unsigned long i)      [position 3078:15]
void consume_ulong (unsigned long i)      [position 3078:30]
       long pre = 48;      [position 3131:5]
       long post = 49;      [position 3133:5]
    printf ("stmtexpr: %ld %ld\n", (long)h.first, (long)h.last);      [position 3137:37]     printf ("stmtexpr: %ld %ld\n", (long)h.first, (long)h.last);      [position 3137:52]     consume_ulong(({ __label__ __here; __here: (unsigned long)&&__here; }));      [position 3140:14]     consume_ulong(({ __label__ __here; __here: (unsigned long)&&__here; }));      [position 3140:58]     :"0" (n/4), "q" (n),"1" ((long) to),"2" ((size_t) from) [position 3249:28]     :"0" (n/4), "q" (n),"1" ((long) to),"2" ((size_t) from) [position 3267:28]
    unsigned long addr;      [position 3336:14]
unsigned long mconstraint_test(struct struct1231 *r) [position 3339:10]
    unsigned long ret;      [position 3341:14]
    unsigned long ret;      [position 3363:14]
    printf ("oc1: %d\n", ret == (unsigned long)&var); [position 3367:43]
        "some_symbol: .long 0\n"      [position 3415:18]
        "2:\t.long 1b - 2b, %c0 - 2b\n"      [position 3422:9]
    ".long 661b - .\n" /* This reference to 661 generates an external sym*/      [position 3440:7]
    register long val asm("r12");      [position 3484:14]
    long val2;      [position 3485:5]
    long x1, x2;      [position 3500:5]
static long cpu_number;      [position 3511:8]
void trace_console(long len, long len2)      [position 3512:20]
void trace_console(long len, long len2)      [position 3512:30]
              long pscr_ret__;      [position 3531:15]
                       long pfo_ret__;      [position 3535:24]
                       long pfo_ret__;      [position 3544:24]
  long rdi;      [position 3566:3]
    struct struct1231 s2 = { (unsigned long)&s1 }; [position 3668:40]
    unsigned long asmret;      [position 3673:14]
int force_get_order(unsigned long s)      [position 4170:30]
elf.h
libtcc.c
 * License along with this library; if not, write to the Free Software      [position 17:13]
PUB_FUNC void *tcc_malloc_base(unsigned long size)      [position 256:41]
PUB_FUNC void *tcc_mallocz_base(unsigned long size)      [position 267:42]
PUB_FUNC void *tcc_malloc(TCCState *S, unsigned long size) [position 283:49]
PUB_FUNC void *tcc_mallocz(TCCState *S, unsigned long size) [position 292:50]
PUB_FUNC void *tcc_realloc(TCCState *S, void *ptr, unsigned long size)      [position 301:61] PUB_FUNC void *tcc_malloc_debug(TCCState *S, unsigned long size, const char *file, int line)      [position 364:55] PUB_FUNC void *tcc_mallocz_debug(TCCState *S, unsigned long size, const char *file, int line)      [position 412:56] PUB_FUNC void *tcc_realloc_debug(TCCState *S, void *ptr, unsigned long size, const char *file, int line)      [position 420:67]
            longjmp(S->error_jmp_buf, 1);      [position 680:13]
tcc.c
            long bc = mf->size - mf->pos;      [position 329:13]
tcc.h
    unsigned long data_offset; /* current data offset */ [position 585:14]
    unsigned long data_allocated; /* used for realloc() handling */      [position 587:14]     unsigned long sh_size;   /* section size (only used during output) */      [position 596:14]
    unsigned long sh_offset; /* file offset */      [position 598:14]
    unsigned long offset;      [position 792:14]
    unsigned long last_file_name;      [position 793:14]
    unsigned long last_func_name;      [position 794:14]
        unsigned long value;      [position 810:18]
    unsigned long sf_arm64_func_va_list_stack;      [position 885:14]
    unsigned long sf_func_sub_sp_offset;      [position 899:14]
    unsigned long sf_func_sub_sp_offset;      [position 944:14]
    unsigned long mem_size;      [position 1101:14]
    unsigned long x86_64_gen_func_sub_sp_offset;      [position 1232:14]
    unsigned long func_bound_ind;      [position 1236:14]
PUB_FUNC void *tcc_malloc_base(unsigned long size);      [position 1436:41]
PUB_FUNC void *tcc_mallocz_base(unsigned long size); [position 1437:42]
PUB_FUNC void *tcc_malloc(TCCState *S, unsigned long size); [position 1440:49] PUB_FUNC void *tcc_mallocz(TCCState *S, unsigned long size); [position 1441:50] PUB_FUNC void *tcc_realloc(TCCState *S, void *ptr, unsigned long size);      [position 1442:61] PUB_FUNC void *tcc_malloc_debug(TCCState *S, unsigned long size, const char *file, int line);      [position 1451:55] PUB_FUNC void *tcc_mallocz_debug(TCCState *S, unsigned long size, const char *file, int line);      [position 1452:56] PUB_FUNC void *tcc_realloc_debug(TCCState *S, void *ptr, unsigned long size, const char *file, int line);      [position 1453:67] ST_FUNC void put_extern_sym2(TCCState *S, Sym *sym, int sh_num, addr_t value, unsigned long size, int can_add_underscore); [position 1633:88] ST_FUNC void put_extern_sym(TCCState *S, Sym *sym, Section *section, addr_t value, unsigned long size);      [position 1634:93] ST_FUNC void greloc(TCCState *S, Section *s, Sym *sym, unsigned long offset, int type);      [position 1636:65] ST_FUNC void greloca(TCCState *S, Section *s, Sym *sym, unsigned long offset, int type, addr_t addend);      [position 1638:66] ST_FUNC Sym *get_sym_ref(TCCState *S, CType *type, Section *sec, unsigned long offset, unsigned long size);      [position 1687:75] ST_FUNC Sym *get_sym_ref(TCCState *S, CType *type, Section *sec, unsigned long offset, unsigned long size);      [position 1687:97] ST_FUNC void section_realloc(TCCState *S, Section *sec, unsigned long new_size);      [position 1721:66] ST_FUNC int put_elf_sym(TCCState *S, Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);      [position 1728:73] ST_FUNC int set_elf_sym(Section *S, addr_t value, unsigned long size, int info, int other, int shndx, const char *name); [position 1729:60] ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol);      [position 1731:66] ST_FUNC void put_elf_reloca(Section *symtab, Section *s, unsigned long offset, int type, int symbol, addr_t addend);      [position 1732:67] ST_FUNC void put_stabs(TCCState *S, const char *str, int type, int other, int desc, unsigned long value);      [position 1734:94] ST_FUNC void put_stabs_r(TCCState *S, const char *str, int type, int other, int desc, unsigned long value, Section *sec, int sym_index);      [position 1735:96] ST_FUNC void *load_data(TCCState *S, int fd, unsigned long file_offset, unsigned long size);      [position 1743:55] ST_FUNC void *load_data(TCCState *S, int fd, unsigned long file_offset, unsigned long size);      [position 1743:82] ST_FUNC int tcc_load_object_file(TCCState *S, int fd, unsigned long file_offset);      [position 1745:64]
tccasm.c
    long n;      [position 438:5]
    case TOK_ASMDIR_long:      [position 572:21]
            unsigned long n;      [position 671:22]
tccelf.c
ST_FUNC void section_realloc(TCCState *S, Section *sec, unsigned long new_size)      [position 287:66]
    unsigned long size;      [position 289:14]
static void section_reserve(TCCState *S, Section *sec, unsigned long size)      [position 329:65]
static unsigned long elf_hash(const unsigned char *name) [position 373:17]
    unsigned long h = 0, g;      [position 375:14]
ST_FUNC int put_elf_sym(TCCState *S, Section *s, addr_t value, unsigned long size,      [position 425:73] ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size,      [position 646:60] ST_FUNC void put_elf_reloca(Section *symtab, Section *s, unsigned long offset,      [position 734:67] ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset,      [position 764:66]
                      unsigned long value)      [position 772:32]
                        unsigned long value, Section *sec, int sym_index)      [position 800:34]
                    unsigned long offset;      [position 1746:30]
    unsigned long data_offset;      [position 1893:14]
        unsigned long s_align;      [position 1928:18]
        long long tmp;      [position 1929:9]
        long long tmp;      [position 1929:14]
    unsigned long file_offset = 0;      [position 2251:14]
ST_FUNC void *load_data(TCCState *S, int fd, unsigned long file_offset, unsigned long size)      [position 2841:55] ST_FUNC void *load_data(TCCState *S, int fd, unsigned long file_offset, unsigned long size)      [position 2841:82]     unsigned long offset;  /* offset of the new section in the existing section */      [position 2853:14]                                 int fd, unsigned long file_offset)      [position 2880:50]
tccgen.c
static void init_putv(TCCState *S, init_params *p, CType *type, unsigned long c);      [position 139:74] static void decl_initializer(TCCState *S, init_params *p, CType *type, unsigned long c, int flags);      [position 140:81] static void tcc_debug_stabs (TCCState *S, const char *str, int type, unsigned long value,      [position 425:79]     unsigned long last_offset = S->tccgen_tcov_data.offset;      [position 721:14]                             addr_t value, unsigned long size, [position 975:52]                            addr_t value, unsigned long size) [position 1043:51] ST_FUNC void greloca(TCCState *S, Section *s, Sym *sym, unsigned long offset, int type,      [position 1050:66] ST_FUNC void greloc(TCCState *S, Section *s, Sym *sym, unsigned long offset, int type)      [position 1069:65] ST_FUNC Sym *get_sym_ref(TCCState *S, CType *type, Section *sec, unsigned long offset, unsigned long size)      [position 1518:75] ST_FUNC Sym *get_sym_ref(TCCState *S, CType *type, Section *sec, unsigned long offset, unsigned long size)      [position 1518:97] static void vpush_ref(TCCState *S, CType *type, Section *sec, unsigned long offset, unsigned long size)      [position 1531:72] static void vpush_ref(TCCState *S, CType *type, Section *sec, unsigned long offset, unsigned long size)      [position 1531:94]
            unsigned long offset;      [position 2257:22]
static void init_putz(TCCState *S, init_params *p, unsigned long c, int size)      [position 7643:61] static int decl_designator(TCCState *S, init_params *p, CType *type, unsigned long c,      [position 7703:79]
    unsigned long corig = c;      [position 7708:14]
static void init_putv(TCCState *S, init_params *p, CType *type, unsigned long c)      [position 7833:74]                 unsigned long relofs = ssec->reloc->data_offset;      [position 7898:26] static void decl_initializer(TCCState *S, init_params *p, CType *type, unsigned long c, int flags)      [position 8025:81]
tcclib.h
long int strtol(const char *nptr, char **endptr, int base); [position 19:1]
unsigned long int strtoul(const char *nptr, char **endptr, int base);      [position 20:10]
tccrun.c
static void set_pages_executable(TCCState *S, int mode, void *ptr, unsigned long length);      [position 58:77] static void set_pages_executable(TCCState *S, int mode, void *ptr, unsigned long length)      [position 349:77] static long __stdcall cpu_exception_handler(EXCEPTION_POINTERS *ex_info)      [position 821:8]
tcctok.h
tcctools.c
static unsigned long le2belong(unsigned long ul) {      [position 46:17]
static unsigned long le2belong(unsigned long ul) {      [position 46:27]
static unsigned long le2belong(unsigned long ul) {      [position 46:41]
x86_64-gen.c
static unsigned long func_sub_sp_offset;      [position 157:17]
static unsigned long func_bound_ind;      [position 162:17]
float.h
/* horrible intel long double */      [position 29:19]
stdatomic.h
typedef _Atomic(long) atomic_long;      [position 44:17]
typedef _Atomic(long) atomic_long;      [position 44:30]
typedef _Atomic(unsigned long) atomic_ulong;      [position 45:26]
typedef _Atomic(unsigned long) atomic_ulong;      [position 45:40]
typedef _Atomic(long long) atomic_llong;      [position 46:17]
typedef _Atomic(long long) atomic_llong;      [position 46:22]
typedef _Atomic(long long) atomic_llong;      [position 46:36]
stddef.h
            __FILE__, __FUNCTION__, p, (unsigned long)offset);      [position 514:50]             __FILE__, __FUNCTION__, p, (unsigned long)offset);                 \      [position 562:50]                     (void *) (addr + fp), (unsigned long) p[1]);      [position 642:53]                         (void *) (addr + fp), (unsigned long) p[1]);      [position 717:57]             __FILE__, __FUNCTION__, p, (unsigned long)size); [position 737:50]
        unsigned long start;      [position 1007:18]
        unsigned long end;      [position 1008:18]
        unsigned long ad =      [position 1009:18]
            (unsigned long) __builtin_return_address(0); [position 1010:23]
                    (void *) p[0], (unsigned long) p[1]); [position 1082:46]
                        argv[i], (unsigned long)(strlen (argv[i]) + 1));      [position 1114:44]                         *p, (unsigned long)(strlen (*p) + 1));      [position 1138:39]
                         (unsigned long) tree->size); [position 1193:36]
                     __FILE__, __FUNCTION__, ptr, (unsigned long)size);      [position 1442:61]             __FILE__, __FUNCTION__, ptr, (unsigned long)size);      [position 1452:52]             __FILE__, __FUNCTION__, ptr, (unsigned long)size);      [position 1491:52]             __FILE__, __FUNCTION__, new_ptr, (unsigned long)size);      [position 1569:56]                      __FILE__, __FUNCTION__, ptr, (unsigned long)size);      [position 1606:61]              __FILE__, __FUNCTION__, ptr, (unsigned long)size);      [position 1614:53]             __FILE__, __FUNCTION__, start, (unsigned long)size);      [position 1637:54]             __FILE__, __FUNCTION__, start, (unsigned long)size);      [position 1653:54]
                p, (unsigned long)size, function);      [position 1672:30]
                p1, (unsigned long)n1, p2, (unsigned long)n2, function);      [position 1687:31]                 p1, (unsigned long)n1, p2, (unsigned long)n2, function);      [position 1687:54]             __FILE__, __FUNCTION__, dest, src, (unsigned long)n);      [position 1696:58]             __FILE__, __FUNCTION__, s1, s2, (unsigned long)n);      [position 1712:55]             __FILE__, __FUNCTION__, dest, src, (unsigned long)n);      [position 1732:58]             __FILE__, __FUNCTION__, s, c, (unsigned long)n); [position 1742:53]             __FILE__, __FUNCTION__, dest, src, (unsigned long)n);      [position 1752:58]             __FILE__, __FUNCTION__, dest, src, (unsigned long)n);      [position 1764:58]             __FILE__, __FUNCTION__, dest, src, (unsigned long)n);      [position 1774:58]             __FILE__, __FUNCTION__, dest, src, (unsigned long)n);      [position 1784:58]             __FILE__, __FUNCTION__, s, c, (unsigned long)n); [position 1794:53]             __FILE__, __FUNCTION__, dest, src, (unsigned long)n);      [position 1836:58]             __FILE__, __FUNCTION__, s1, s2, (unsigned long)n);      [position 1871:55]             __FILE__, __FUNCTION__, new, (unsigned long)(p -s));      [position 1931:52]
            (void *) t->start, (unsigned long) t->size, [position 2185:42]
====

On 19/10/22 14:36, Michael Matz wrote:
 Hello,


 On Fri, 14 Oct 2022, avih via Tinycc-devel wrote:

 0x00007ff72b42b266 <+50>: repnz scas %es:(%rdi),%al
 0x00007ff72b42b268 <+52>: dec %edi

 This is the problem.  "dec %edi" truncates the %rdi register to 32bit by
 zero-extension, so that ...

 0x00007ff72b42b26a <+54>: mov 0x30(%rbp),%ecx
 0x00007ff72b42b26d <+57>: dec %ecx
 0x00007ff72b42b26f <+59>: js 0x7ff72b42b277 <strncat1+67>
 0x00007ff72b42b271 <+61>: lods %ds:(%rsi),%al
 => 0x00007ff72b42b272 <+62>: stos %al,%es:(%rdi)

 ... this insn now segfault.  That only matters if the stack (which %rdi
 points into) is setup such that it's beyond 32bit, which ...

 rdi 0xcb9ff955 3416258901
 rbp 0x4ecb9ff8f0 0x4ecb9ff8f0
 rsp 0x4ecb9ff8e0 0x4ecb9ff8e0

 ... is indeed the case on win10 for you.  So, it's not malloc() result,
 but it does have to do with address space layout.

 The problem is that win64 is an IL32 platform, so that 'long' is not the
 same size as a pointer, but the strncat1 implementation, coming from the
 linux kernel, expects that to be the case.  The below patch should fix it,
 but I can't test on win64, so please check yourself and commit if it does.


 Ciao,
 Michael.

 ----------------------------------------------

 diff --git a/tests/tcctest.c b/tests/tcctest.c
 index f5bd9aab..1d625b0c 100644
 --- a/tests/tcctest.c
 +++ b/tests/tcctest.c
 @@ -3254,7 +3254,7 @@ void local_label_test(void)
  /* from linux kernel */
  static char * strncat1(char * dest,const char * src,size_t count)
  {
 -long d0, d1, d2, d3;
 +size_t d0, d1, d2, d3;
  __asm__ __volatile__(
         "repne\n\t"
         "scasb\n\t"
 @@ -3276,7 +3276,7 @@ return dest;

  static char * strncat2(char * dest,const char * src,size_t count)
  {
 -long d0, d1, d2, d3;
 +size_t d0, d1, d2, d3;
  __asm__ __volatile__(
         "repne scasb\n\t" /* one-line repne prefix + string op */
         "dec %1\n\t"

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

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


reply via email to

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