[Tinycc-devel] bug #47379: Compare bug

2016-05-01 Thread Sergey Korshunoff
bug #47379: Compare bug
Please test/confirm on x86-64 (no bug on x86 Linux)

include 
#include 
int main(int argc, char* argv[]) {
printf("%d\n", -2147483648);
printf("%ld\n", -2147483648LL);
printf("%d\n", (1LL) < (-2147483648LL));
return 0;
}

tcc output:
-2147483648
-2147483648
1

gcc output:
-2147483648
-2147483648
0

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


Re: [Tinycc-devel] lcall invalid hex code

2016-05-01 Thread Michael Matz

Hi,

On Mon, 2 May 2016, Sergey Korshunoff wrote:

A right constant value was detected by comparing *.o produced by gcc and 
tcc (objdump -Dtsr test.o)


You realize that you can't simply copy&paste random bytes around without 
understanding the instruction encoding, right?  You took one specific 
instruction with its specific operands and made that the "encoding" of all 
instructions with that mnemonic irrespective of operands.



Ciao,
Michael.

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


Re: [Tinycc-devel] lcall invalid hex code

2016-05-01 Thread Michael Matz

Hi,

On Mon, 2 May 2016, Michael Matz wrote:


ALT(DEF_ASM_OP2(lcall, 0x9a, 0, 0, OPT_IM16, OPT_IM32))
-ALT(DEF_ASM_OP1(lcall, 0xff, 3, 0, OPT_EA))
+ALT(DEF_ASM_OP1(lcall, 0xff1f, 3, 0, OPT_EA))
ALT(DEF_ASM_OP2(ljmp, 0xea, 0, 0, OPT_IM16, OPT_IM32))
ALT(DEF_ASM_OP1(ljmp, 0xff, 5, 0, OPT_EA))


You don't say what exactly you want to fix, but whatever it is, the patch is 
incorrect.  'lcall' is no two-byte opcode (those start with 0x0f), but rather 
the opcode is 0xff and the sub-opcode is in the mod/rm byte (aka. group #5 
[1]).  It's sub-opcode 3, hence correct above.


If anything the decoding of the above table in i386-asm.c is wrong, but I 
can't say without knowing what the problem is.


With your followup I now know your problem.  The mod/rm byte was simply 
missing from the encoding.  I've corrected this in mob.



Ciao,
Michael.

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


Re: [Tinycc-devel] lcall invalid hex code

2016-05-01 Thread Sergey Korshunoff
> This is the current kernel on the my notebook: openvz containers,
> different drivers (acronis TrueImage, parallels ufsd, aufs, android
> binder and ashmem), 32 and 64 versions

An ISO with this kernel and android-x86 userland can be checked in VirtualBox
https://forum.openvz.org/index.php?t=msg&goto=52031&S=90d4ac643a82cd2b85dcfe679554f07f&srch=android#msg_52031

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


Re: [Tinycc-devel] lcall invalid hex code

2016-05-01 Thread Sergey Korshunoff
> What is invalid? Is the actual constant incorrect

Yes. Strange, but the actual constant was invalid. Catched by trap of
the tccboot with PCI bus configuration turned on (PCnet-PCI II for
VirtualBox).  lcall constant is used only in assmbler code.

pci-pc.c (linux 2.4.37.11)
static struct {
unsigned long address;
unsigned short segment;
} bios32_indirect = { 0, __KERNEL_CS };

/*
 * Returns the entry point for the given service, NULL on error
 */

static unsigned long bios32_service(unsigned long service)
{
unsigned char return_code;<>/* %al */
unsigned long address;<><-->/* %ebx */
unsigned long length;<-><-->/* %ecx */
unsigned long entry;<--><-->/* %edx */
unsigned long flags;

__save_flags(flags); __cli();
__asm__("lcall (%%edi); cld"
: "=a" (return_code),
  "=b" (address),
  "=c" (length),
  "=d" (entry)
: "0" (service),
  "1" (0),
  "D" (&bios32_indirect));
__restore_flags(flags);

switch (return_code) {
case 0:
return address + entry;
case 0x80:  /* Not present */
printk(KERN_WARNING "bios32_service(0x%lx): not
present\n", service);
return 0;
default: /* Shouldn't happen */
printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x
-- BIOS bug!\n",
service, return_code);
}
}

A right constant value was detected by comparing *.o produced by gcc
and tcc (objdump -Dtsr test.o)

PS: I'm going to use tcc for compilation of the openvz-2.6.32 kernel.
This is the current kernel on the my notebook: openvz containers,
different drivers (acronis TrueImage, parallels ufsd, aufs, android
binder and ashmem), 32 and 64 versions, Compilation of this kernel for
the ARM processors is waiting.

https://github.com/seyko2/openvz_rhel6_kernel_mirror

cellRocks patches are published on gitthub and partially ported to
this kernel too (todo on my whish list)
https://github.com/Cellrox/devns-patches

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


Re: [Tinycc-devel] lcall invalid hex code

2016-05-01 Thread Michael Matz

Hi,

On Sun, 1 May 2016, Sergey Korshunoff wrote:


diff --git a/i386-asm.h b/i386-asm.h
index 486cffe..637568b 100644
--- a/i386-asm.h
+++ b/i386-asm.h
@@ -213,7 +213,7 @@ ALT(DEF_ASM_OP1(jmp, 0xff, 0, OPC_JMP | OPC_WL, OPT_REGW))
#endif
.
ALT(DEF_ASM_OP2(lcall, 0x9a, 0, 0, OPT_IM16, OPT_IM32))
-ALT(DEF_ASM_OP1(lcall, 0xff, 3, 0, OPT_EA))
+ALT(DEF_ASM_OP1(lcall, 0xff1f, 3, 0, OPT_EA))
ALT(DEF_ASM_OP2(ljmp, 0xea, 0, 0, OPT_IM16, OPT_IM32))
ALT(DEF_ASM_OP1(ljmp, 0xff, 5, 0, OPT_EA))


You don't say what exactly you want to fix, but whatever it is, the patch 
is incorrect.  'lcall' is no two-byte opcode (those start with 0x0f), but 
rather the opcode is 0xff and the sub-opcode is in the mod/rm byte (aka. 
group #5 [1]).  It's sub-opcode 3, hence correct above.


If anything the decoding of the above table in i386-asm.c is wrong, but I 
can't say without knowing what the problem is.



Ciao,
Michael.
[1] See any decent x86 opcode listing, like sandpile.org or x86asm.net.

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


Re: [Tinycc-devel] tcc build on OSX

2016-05-01 Thread David Mertens
Hello Assaf,

On Sun, May 1, 2016 at 6:03 PM, Assaf Gordon  wrote:

> Hello,
>
> I can try to test some things on Mac OS X (10.10.4 with clang-602.0.53).
> please let me know if there are specific tests to do.
>

That would be great!


> from a cursory look, perhaps it is possible that 'tcc' still compiles
> linux/ELF format despite being on Mac?
>

That is correct. It does produce proper machine code, however. This means
that tcc can be used when invoked with the -run command-line option, and it
can be used a jit compiler. So, I think the output that you give below
makes sense.

David


> regards,
>  - gordon
>
>
> ===
> $ uname
> Darwin x 14.4.0 Darwin Kernel Version 14.4.0: Thu May 28 11:35:04 PDT
> 2015; root:xnu-2782.30.5~1/RELEASE_X86_64 x86_64 i386 MacBookAir6,1 Darwin
>
> $ git id
> release_0_9_26-676-g6afe668
>
> $ make distclean
> $ ./configure
> ./configure
> Binary  directory   /usr/local/bin
> TinyCC directory/usr/local/lib/tcc
> Library directory   /usr/local/lib64
> Include directory   /usr/local/include
> Manual directory/usr/local/share/man
> Info directory  /usr/local/share/info
> Doc directory   /usr/local/share/doc//usr/local/lib/tcc
> Target root prefix
> Source path  /Users/gordon/sources/tinycc
> C compiler   gcc
> cross compilers  no
> Target CPU   x86-64
> Host OS  Darwin
> Target OSDarwin
> Big Endian   no
> gprof enabledno
> use libgcc   no
> Creating config.mak and config.h
>
> $ make
>
> $ ./tcc -v
> tcc version 0.9.26 (x86-64 Linux)
>
> $ cat 1.c
> #include 
>
> int main()
> {
>   printf("hello TCC world\n");
>   return 0;
> }
>
> $ ./tcc -c -o 1.o 1.c
> In file included from 1.c:1:
> In file included from /usr/include/stdio.h:64:
> /usr/include/sys/cdefs.h:81: warning: #warning "Unsupported compiler
> detected"
>
> $ file 1.o
> 1.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
>
> $ ./tcc -o 1 1.c
> tcc: error: file 'crt1.o' not found
> tcc: error: file 'crti.o' not found
> In file included from 1.c:1:
> In file included from /usr/include/stdio.h:64:
> /usr/include/sys/cdefs.h:81: warning: #warning "Unsupported compiler
> detected"
> tcc: error: file 'crtn.o' not found
> tcc: error: undefined symbol 'printf'
> ===
>
>
>
>
> For reference, here's the compilation and linking with apple's LLVM:
> ===
> $ cc -v -c -o 1.o 1.c
> Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
> Target: x86_64-apple-darwin14.4.0
> Thread model: posix
>  
> "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
> -cc1 -triple x86_64-apple-macosx10.10.0 -emit-obj -mrelax-all -disable-free
> -disable-llvm-verifier -main-file-name 1.c -mrelocation-model pic
> -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu
> core2 -target-linker-version 242.2 -v -dwarf-column-info -coverage-file
> /Users/gordon/sources/tinycc/1.o -resource-dir
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0
> -fdebug-compilation-dir /Users/gordon/sources/tinycc -ferror-limit 19
> -fmessage-length 150 -stack-protector 1 -mstackrealign -fblocks
> -fobjc-runtime=macosx-10.10.0 -fencode-extended-block-signature
> -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o 1.o -x
> c 1.c
> clang -cc1 version 6.1.0 based upon LLVM 3.6.0svn default target
> x86_64-apple-darwin14.4.0
> #include "..." search starts here:
> #include <...> search starts here:
>  /usr/local/include
>
>  
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0/include
>
>  
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
>  /usr/include
>  /System/Library/Frameworks (framework directory)
>  /Library/Frameworks (framework directory)
> End of search list.
>
> $ file 1.o
> 1.o: Mach-O 64-bit object x86_64
>
> $ cc -v -o 1 1.o
> Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
> Target: x86_64-apple-darwin14.4.0
> Thread model: posix
>  
> "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld"
> -demangle -dynamic -arch x86_64 -macosx_version_min 10.10.0 -o 1 1.o
> -lSystem
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0/lib/darwin/libclang_rt.osx.a
>
> $ file 1
> 1: Mach-O 64-bit executable x86_64
> ===
>
>
>
> ___
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>



-- 
 "Debugging is twice as hard as writing the code in the first place.
  Therefore, if you write the code as cleverly as possible, you are,
  by definition, not smart enough to debug it." -- Brian Kernighan
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] lcall invalid hex code

2016-05-01 Thread David Mertens
@Sergey,

I have a general request for the patches of yours that you submit in the
future. Could you assume that I don't actually know much at all about
compilers, but I would like to learn? That would be a useful assumption,
because it's true. :-P

Speaking only for myself, I have no idea what this patch practically does.
I can see that it changes one hex value in assembler-related stuff to
something else, but I'm not given enough context to teach myself and make
an assessment. What is invalid? Is the actual constant incorrect, or is the
notation for it in the C code simply incorrect? What did it used to do
before? Do you have any links for assembler op codes so that I might learn
more?

Give me just enough context and I'll teach myself. Thanks!

On Sun, May 1, 2016 at 2:58 PM, Sergey Korshunoff  wrote:

> Hi!
>
> diff --git a/i386-asm.h b/i386-asm.h
> index 486cffe..637568b 100644
> --- a/i386-asm.h
> +++ b/i386-asm.h
> @@ -213,7 +213,7 @@ ALT(DEF_ASM_OP1(jmp, 0xff, 0, OPC_JMP | OPC_WL,
> OPT_REGW))
>  #endif
> .
>  ALT(DEF_ASM_OP2(lcall, 0x9a, 0, 0, OPT_IM16, OPT_IM32))
> -ALT(DEF_ASM_OP1(lcall, 0xff, 3, 0, OPT_EA))
> +ALT(DEF_ASM_OP1(lcall, 0xff1f, 3, 0, OPT_EA))
>  ALT(DEF_ASM_OP2(ljmp, 0xea, 0, 0, OPT_IM16, OPT_IM32))
>  ALT(DEF_ASM_OP1(ljmp, 0xff, 5, 0, OPT_EA))
>
> ___
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>



-- 
 "Debugging is twice as hard as writing the code in the first place.
  Therefore, if you write the code as cleverly as possible, you are,
  by definition, not smart enough to debug it." -- Brian Kernighan
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] tcc build on OSX

2016-05-01 Thread Assaf Gordon
Hello,

I can try to test some things on Mac OS X (10.10.4 with clang-602.0.53). please 
let me know if there are specific tests to do.


from a cursory look, perhaps it is possible that 'tcc' still compiles linux/ELF 
format despite being on Mac?

regards,
 - gordon


===
$ uname
Darwin x 14.4.0 Darwin Kernel Version 14.4.0: Thu May 28 11:35:04 PDT 2015; 
root:xnu-2782.30.5~1/RELEASE_X86_64 x86_64 i386 MacBookAir6,1 Darwin

$ git id
release_0_9_26-676-g6afe668

$ make distclean
$ ./configure
./configure 
Binary  directory   /usr/local/bin
TinyCC directory/usr/local/lib/tcc
Library directory   /usr/local/lib64
Include directory   /usr/local/include
Manual directory/usr/local/share/man
Info directory  /usr/local/share/info
Doc directory   /usr/local/share/doc//usr/local/lib/tcc
Target root prefix  
Source path  /Users/gordon/sources/tinycc
C compiler   gcc
cross compilers  no
Target CPU   x86-64
Host OS  Darwin
Target OSDarwin
Big Endian   no
gprof enabledno
use libgcc   no
Creating config.mak and config.h

$ make

$ ./tcc -v
tcc version 0.9.26 (x86-64 Linux)

$ cat 1.c
#include 

int main()
{
  printf("hello TCC world\n");
  return 0;
}

$ ./tcc -c -o 1.o 1.c
In file included from 1.c:1:
In file included from /usr/include/stdio.h:64:
/usr/include/sys/cdefs.h:81: warning: #warning "Unsupported compiler detected"

$ file 1.o
1.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped

$ ./tcc -o 1 1.c 
tcc: error: file 'crt1.o' not found
tcc: error: file 'crti.o' not found
In file included from 1.c:1:
In file included from /usr/include/stdio.h:64:
/usr/include/sys/cdefs.h:81: warning: #warning "Unsupported compiler detected"
tcc: error: file 'crtn.o' not found
tcc: error: undefined symbol 'printf'
===




For reference, here's the compilation and linking with apple's LLVM:
===
$ cc -v -c -o 1.o 1.c 
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.4.0
Thread model: posix
 
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
 -cc1 -triple x86_64-apple-macosx10.10.0 -emit-obj -mrelax-all -disable-free 
-disable-llvm-verifier -main-file-name 1.c -mrelocation-model pic -pic-level 2 
-mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 
-target-linker-version 242.2 -v -dwarf-column-info -coverage-file 
/Users/gordon/sources/tinycc/1.o -resource-dir 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0
 -fdebug-compilation-dir /Users/gordon/sources/tinycc -ferror-limit 19 
-fmessage-length 150 -stack-protector 1 -mstackrealign -fblocks 
-fobjc-runtime=macosx-10.10.0 -fencode-extended-block-signature 
-fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o 1.o -x c 
1.c
clang -cc1 version 6.1.0 based upon LLVM 3.6.0svn default target 
x86_64-apple-darwin14.4.0
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0/include
 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.

$ file 1.o 
1.o: Mach-O 64-bit object x86_64

$ cc -v -o 1 1.o 
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.4.0
Thread model: posix
 
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld"
 -demangle -dynamic -arch x86_64 -macosx_version_min 10.10.0 -o 1 1.o -lSystem 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0/lib/darwin/libclang_rt.osx.a

$ file 1
1: Mach-O 64-bit executable x86_64
===



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


[Tinycc-devel] TOK_PPNUM for asm

2016-05-01 Thread Sergey Korshunoff
Hi!
Proposed patch: handle 0x1e+1 as 0x1e +1 if (parse_flags & PARSE_FLAG_ASM_FILE)
This helps to compile asm code like:
__asm("mov $0x1e" "-1");
(a code from linux kernel)

https://github.com/seyko2/tinycc/commit/22d279c24ce8873b3f90b364478fad70f8a6dae3

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


[Tinycc-devel] lcall invalid hex code

2016-05-01 Thread Sergey Korshunoff
Hi!

diff --git a/i386-asm.h b/i386-asm.h
index 486cffe..637568b 100644
--- a/i386-asm.h
+++ b/i386-asm.h
@@ -213,7 +213,7 @@ ALT(DEF_ASM_OP1(jmp, 0xff, 0, OPC_JMP | OPC_WL, OPT_REGW))
 #endif
.
 ALT(DEF_ASM_OP2(lcall, 0x9a, 0, 0, OPT_IM16, OPT_IM32))
-ALT(DEF_ASM_OP1(lcall, 0xff, 3, 0, OPT_EA))
+ALT(DEF_ASM_OP1(lcall, 0xff1f, 3, 0, OPT_EA))
 ALT(DEF_ASM_OP2(ljmp, 0xea, 0, 0, OPT_IM16, OPT_IM32))
 ALT(DEF_ASM_OP1(ljmp, 0xff, 5, 0, OPT_EA))

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


Re: [Tinycc-devel] X(X(1)) (nested macro substitution)

2016-05-01 Thread Sergey Korshunoff
a 3rd version of the patch attached

2016-05-01 5:52 GMT+03:00, Sergey Korshunoff :
>> No result.  Make the patch 10 lines in the right place instead
>> of 60 lines in the wrong place, and it will work.
>
> Where is the right place? That is the question.
>
> PS: a modified version attached.
> Algorithm changed: we can expand a next macro too.
>


03-space_after_TOK_PPNUM.patch.gz
Description: GNU Zip compressed data
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel