GithubHelp home page GithubHelp logo

run4flat / tinycc Goto Github PK

View Code? Open in Web Editor NEW
29.0 29.0 14.0 4.99 MB

My fork of Fabrice Bellard's Tiny C Compiler

License: GNU Lesser General Public License v2.1

Makefile 0.85% C 94.06% C++ 3.95% Assembly 0.66% Shell 0.02% Perl 0.38% Batchfile 0.06% Python 0.01%

tinycc's People

Contributors

akimd avatar aldot avatar avih avatar cypriani avatar egrimley avatar gec75 avatar jcbeaudoin avatar jsoroka avatar leeduhem avatar mikijov avatar mingodad avatar minux avatar navytux avatar pipcet avatar raphaelcohn avatar rdoeffinger avatar robotux avatar roytam1 avatar run4flat avatar s09bq5 avatar seyko2 avatar shinh avatar susematz avatar vinc17fr avatar waddlesplash avatar winspool avatar wqweto avatar xcm avatar xppxppgh avatar zde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tinycc's Issues

Remove CONFIG_TCC_EXSYMTAB from mobx

The mobx branch, which holds my current extended symtab development, produces a libtcc.h that does not support the exsymtab api, even if the compiler was build with exsymtab enabled. This sort of configuration option should not bleed into the final public api header.

Remove tcc_compile_string_ex

tcc_compile_string_ex was a convenience function for C::Blocks. That module is now sophisticated enough that it should be able to add #line directives to strings that are being compiled.

FreeBSD builds exe that SEGV

  1. compiling an executable on FreeBSD kernel produces an exe that seg faults, I am guessing in the boot strap code somewhere since even a trivial program int main() { return 0; } shows this behavior.
  2. reproduced this on both FreeBSD 10 64bit and Debian kFreeBSD so I do not believe the userland is the issue. I also get the same results from a Alien::TinyCC build.
  3. compiling code into the same process and executing it via the API works fine (tested via Alien::TinyCC and FFI::TinyCC), this is probably the more useful use case for me, so an explicit "this is not supported" would be considered acceptable to me (though obviously a fix would be better :)
  4. Just as an aside, starting with FreeBSD 10, clang is used instead of gcc as the bundled compiler, so perhaps consider using cc as the default compiler on FreeBSD (cc is gcc on 9 and clang on 10). cc might be the more appropriate default on other platforms as well.
freebsd64% ./configure --cc=clang
Binary  directory   /usr/local/bin
TinyCC directory    /usr/local/lib/tcc
Library directory   /usr/local/lib
Include directory   /usr/local/include
Manual directory    /usr/local/share/man
Info directory      /usr/local/share/info
Doc directory       /usr/local/share/doc/tcc
Target root prefix
Source path      /home/ollisg/dev/tinycc
C compiler       clang
Target OS        FreeBSD
CPU              x86-64
Big Endian       no
gprof enabled    no
cross compilers  no
use libgcc       no
Creating config.mak and config.h
freebsd64% gmake
gmake: Circular Makefile <- Makefile dependency dropped.
clang -o tcc.o -c tcc.c -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fheinous-gnu-extensions
clang -o libtcc.o -c libtcc.c -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fheinous-gnu-extensions
clang -o tccpp.o -c tccpp.c -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fheinous-gnu-extensions
tccpp.c:1312:7: warning: assigning to 'const unsigned char *' from 'const char *' converts between pointers to
      integer types with different sign [-Wpointer-sign]
    s = filename;
      ^ ~~~~~~~~
tccpp.c:2292:6: warning: passing 'uint8_t *' (aka 'unsigned char *') to parameter of type 'char *' converts
      between pointers to integer types with different sign [-Wpointer-sign]
                                        p1, len, tcc_state->symtab_callback_data, 0);
                                        ^~
tccpp.c:2295:37: warning: passing 'uint8_t *' (aka 'unsigned char *') to parameter of type 'const char *' converts
      between pointers to integer types with different sign [-Wpointer-sign]
            ts = tok_alloc_new(pts, p1, len);
                                    ^~
tccpp.c:194:60: note: passing argument to parameter 'str' here
static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len)
                                                           ^
3 warnings generated.
clang -o tccgen.o -c tccgen.c -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fheinous-gnu-extensions
clang -o tccelf.o -c tccelf.c -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fheinous-gnu-extensions
tccelf.c:60:12: warning: assigning to 'char *' from 'unsigned char *' converts between pointers to integer types
      with different sign [-Wpointer-sign]
    strtab = s->link->data;
           ^ ~~~~~~~~~~~~~
tccelf.c:75:26: warning: passing 'char *' to parameter of type 'const unsigned char *' converts between pointers
      to integer types with different sign [-Wpointer-sign]
            h = elf_hash(strtab + sym->st_name) % nb_buckets;
                         ^~~~~~~~~~~~~~~~~~~~~
tccelf.c:38:52: note: passing argument to parameter 'name' here
static unsigned long elf_hash(const unsigned char *name)
                                                   ^
tccelf.c:117:26: warning: passing 'const char *' to parameter of type 'const unsigned char *' converts between
      pointers to integer types with different sign [-Wpointer-sign]
            h = elf_hash(name) % nbuckets;
                         ^~~~
tccelf.c:38:52: note: passing argument to parameter 'name' here
static unsigned long elf_hash(const unsigned char *name)
                                                   ^
tccelf.c:147:18: warning: passing 'const char *' to parameter of type 'const unsigned char *' converts between
      pointers to integer types with different sign [-Wpointer-sign]
    h = elf_hash(name) % nbuckets;
                 ^~~~
tccelf.c:38:52: note: passing argument to parameter 'name' here
static unsigned long elf_hash(const unsigned char *name)
                                                   ^
tccelf.c:151:15: warning: assigning to 'const char *' from 'unsigned char *' converts between pointers to integer
      types with different sign [-Wpointer-sign]
        name1 = s->link->data + sym->st_name;
              ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tccelf.c:434:18: warning: assigning to 'const char *' from 'unsigned char *' converts between pointers to integer
      types with different sign [-Wpointer-sign]
            name = strtab_section->data + sym->st_name;
                 ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tccelf.c:438:22: warning: assigning to 'const char *' from 'unsigned char *' converts between pointers to integer
      types with different sign [-Wpointer-sign]
                name = symtab_section->link->data + sym->st_name;
                     ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tccelf.c:1037:14: warning: assigning to 'const char *' from 'unsigned char *' converts between pointers to integer
      types with different sign [-Wpointer-sign]
        name = symtab_section->link->data + sym->st_name;
             ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tccelf.c:1628:30: warning: assigning to 'const char *' from 'unsigned char *' converts between pointers to integer
      types with different sign [-Wpointer-sign]
                        name = symtab_section->link->data + sym->st_name;
                             ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tccelf.c:1664:53: warning: assigning to 'char *' from 'unsigned char *' converts between pointers to integer types
      with different sign [-Wpointer-sign]
                                            dynname = s1->dynsymtab_section->link->data
                                                    ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tccelf.c:1694:30: warning: assigning to 'const char *' from 'unsigned char *' converts between pointers to integer
      types with different sign [-Wpointer-sign]
                        name = symtab_section->link->data + sym->st_name;
                             ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tccelf.c:1712:30: warning: assigning to 'const char *' from 'unsigned char *' converts between pointers to integer
      types with different sign [-Wpointer-sign]
                        name = s1->dynsymtab_section->link->data + esym->st_name;
                             ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tccelf.c:1756:34: warning: assigning to 'const char *' from 'unsigned char *' converts between pointers to integer
      types with different sign [-Wpointer-sign]
                            name = symtab_section->link->data + sym->st_name;
                                 ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tccelf.c:1968:37: warning: passing 'unsigned char *' to parameter of type 'const char *' converts between pointers
      to integer types with different sign [-Wpointer-sign]
                        if (!strcmp(strsec->data + s->sh_name, ".rel.got")) { // rel_size == 0) {
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/string.h:80:25: note: passing argument to parameter here
int      strcmp(const char *, const char *) __pure;
                            ^
tccelf.c:1972:37: warning: passing 'unsigned char *' to parameter of type 'const char *' converts between pointers
      to integer types with different sign [-Wpointer-sign]
                        if (!strcmp(strsec->data + s->sh_name, ".rel.bss")) { // rel_size == 0) {
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/string.h:80:25: note: passing argument to parameter here
int      strcmp(const char *, const char *) __pure;
                            ^
tccelf.c:2432:17: warning: assigning to 'char *' from 'unsigned char *' converts between pointers to integer types
      with different sign [-Wpointer-sign]
        sh_name = strsec + sh->sh_name;
                ^ ~~~~~~~~~~~~~~~~~~~~
tccelf.c:2553:26: warning: assigning to 'char *' from 'unsigned char *' converts between pointers to integer types
      with different sign [-Wpointer-sign]
                    name = strtab + sym->st_name;
                         ^ ~~~~~~~~~~~~~~~~~~~~~
tccelf.c:2569:14: warning: assigning to 'char *' from 'unsigned char *' converts between pointers to integer types
      with different sign [-Wpointer-sign]
        name = strtab + sym->st_name;
             ^ ~~~~~~~~~~~~~~~~~~~~~
tccelf.c:2673:14: warning: assigning to 'const char *' from 'const uint8_t *' (aka 'const unsigned char *')
      converts between pointers to integer types with different sign [-Wpointer-sign]
    ar_names = ar_index + nsyms * 4;
             ^ ~~~~~~~~~~~~~~~~~~~~
tccelf.c:2810:20: warning: assigning to 'const char *' from 'unsigned char *' converts between pointers to integer
      types with different sign [-Wpointer-sign]
            soname = dynstr + dt->d_un.d_val;
                   ^ ~~~~~~~~~~~~~~~~~~~~~~~
tccelf.c:2839:14: warning: assigning to 'const char *' from 'unsigned char *' converts between pointers to integer
      types with different sign [-Wpointer-sign]
        name = dynstr + sym->st_name;
             ^ ~~~~~~~~~~~~~~~~~~~~~
tccelf.c:2848:18: warning: assigning to 'const char *' from 'unsigned char *' converts between pointers to integer
      types with different sign [-Wpointer-sign]
            name = dynstr + dt->d_un.d_val;
                 ^ ~~~~~~~~~~~~~~~~~~~~~~~
22 warnings generated.
clang -o tccasm.o -c tccasm.c -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fheinous-gnu-extensions
tccasm.c:541:72: warning: data argument not used by format string [-Wformat-extra-args]
            sprintf(sname, (n?".%s%d":".%s"), get_tok_str(tok1, NULL), n);
                                      ~~~~~                            ^
1 warning generated.
clang -o tccrun.o -c tccrun.c -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fheinous-gnu-extensions
tccrun.c:228:5: warning: implicit declaration of function '__clear_cache' is invalid in C99
      [-Wimplicit-function-declaration]
    __clear_cache(ptr, ptr + length);
    ^
tccrun.c:257:18: warning: assigning to 'char *' from 'unsigned char *' converts between pointers to integer types
      with different sign [-Wpointer-sign]
        stab_str = stabstr_section->data;
                 ^ ~~~~~~~~~~~~~~~~~~~~~
tccrun.c:350:29: warning: passing 'unsigned char *' to parameter of type 'const char *' converts between pointers
      to integer types with different sign [-Wpointer-sign]
                            strtab_section->data + sym->st_name);
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./tcc.h:1031:61: note: passing argument to parameter 's' here
PUB_FUNC char *pstrcpy(char *buf, int buf_size, const char *s);
                                                            ^
3 warnings generated.
clang -o x86_64-gen.o -c x86_64-gen.c -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fheinous-gnu-extensions
clang -o i386-asm.o -c i386-asm.c -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fheinous-gnu-extensions
ar rcs libtcc.a libtcc.o tccpp.o tccgen.o tccelf.o tccasm.o tccrun.o x86_64-gen.o i386-asm.o
clang -o tcc tcc.o libtcc.a -lm -I.  -Wall -g -O2 -fheinous-gnu-extensions
clang: warning: argument unused during compilation: '-fheinous-gnu-extensions'
gmake -C lib native
gmake[1]: Entering directory `/usr/home/ollisg/dev/tinycc/lib'
mkdir -p x86_64
clang -c libtcc1.c -o x86_64/libtcc1.o -I..  -Wall -g -O2 -fheinous-gnu-extensions -DTCC_TARGET_X86_64
clang -c alloca86_64.S -o x86_64/alloca86_64.o -I..  -Wall -g -O2 -fheinous-gnu-extensions -DTCC_TARGET_X86_64
ar rcs ../libtcc1.a x86_64/libtcc1.o x86_64/alloca86_64.o
gmake[1]: Leaving directory `/usr/home/ollisg/dev/tinycc/lib'
./texi2pod.pl tcc-doc.texi tcc.pod
pod2man --section=1 --center="Tiny C Compiler" --release=`cat ./VERSION` tcc.pod > tcc.1
makeinfo --no-split --html --number-sections -o tcc-doc.html tcc-doc.texi
makeinfo tcc-doc.texi
freebsd64% gmake test
gmake: Circular Makefile <- Makefile dependency dropped.
gmake -C tests test
gmake[1]: Entering directory `/usr/home/ollisg/dev/tinycc/tests'
------------ hello-exe ------------
../tcc -B.. -I.. -I.. -I../include ../examples/ex1.c -o hello || (../tcc -vv; exit 1) && ./hello
gmake[1]: *** [hello-exe] Bus error (core dumped)
gmake[1]: Leaving directory `/usr/home/ollisg/dev/tinycc/tests'
gmake: *** [test] Error 2

Assert for ASCII

Jared Maddox suggested on the tcc mailing list:

Out of curiosity, have you added an assert() to confirm that the
character set is ASCII instead of something else? I think ASCII is the
norm, but main-frames aren't the only place I've heard of non-ASCII
encodings (not saying you should handle it, just test it; handling can
be implemented by someone with a weird machine - I think it was
embedded).

define_push_old?

Is there a reason we can't revise the symbol table copy process to use the current define_push?

segfault on Fedora 21 and Fedora 22

See run4flat/Alien-TinyCC#10 for reference. At first I thought something was broken on my end, but upgrading to Fedora 22 didn't resolve the issue, so I'm thinking this may be a bug somewhere in tcc.

Out of the box make test fails with a segfault on the hello-run test, same place as detailed in my PR above.

dcali-fedora (exsymtab=) ~/git/tinycc
[✔]▶ ./configure
Binary  directory   /usr/local/bin
TinyCC directory    /usr/local/lib/tcc
Library directory   /usr/local/lib
Include directory   /usr/local/include
Manual directory    /usr/local/share/man
Info directory      /usr/local/share/info
Doc directory       /usr/local/share/doc/tcc
Target root prefix
Source path      /home/dylan.cali/git/tinycc
C compiler       gcc
Target OS        Linux
CPU              x86-64
Big Endian       no
gprof enabled    no
cross compilers  no
use libgcc       no
Creating config.mak and config.h

dcali-fedora (exsymtab=) ~/git/tinycc
[✔]▶ make
make: Circular Makefile <- Makefile dependency dropped.
gcc -o tcc.o -c tcc.c -DCONFIG_LDDIR="\"lib64\"" -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fno-strict-aliasing -O0 -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result
gcc -o libtcc.o -c libtcc.c -DCONFIG_LDDIR="\"lib64\"" -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fno-strict-aliasing -O0 -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result
gcc -o tccpp.o -c tccpp.c -DCONFIG_LDDIR="\"lib64\"" -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fno-strict-aliasing -O0 -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result
gcc -o tccgen.o -c tccgen.c -DCONFIG_LDDIR="\"lib64\"" -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fno-strict-aliasing -O0 -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result
gcc -o tccelf.o -c tccelf.c -DCONFIG_LDDIR="\"lib64\"" -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fno-strict-aliasing -O0 -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result
gcc -o tccasm.o -c tccasm.c -DCONFIG_LDDIR="\"lib64\"" -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fno-strict-aliasing -O0 -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result
gcc -o tccrun.o -c tccrun.c -DCONFIG_LDDIR="\"lib64\"" -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fno-strict-aliasing -O0 -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result
gcc -o tccexsymtab.o -c tccexsymtab.c -DCONFIG_LDDIR="\"lib64\"" -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fno-strict-aliasing -O0 -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result
gcc -o x86_64-gen.o -c x86_64-gen.c -DCONFIG_LDDIR="\"lib64\"" -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fno-strict-aliasing -O0 -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result
x86_64-gen.c: In function ‘gtst’:
x86_64-gen.c:1572:15: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
      if (!inv == (vtop->c.i != TOK_NE))
               ^
gcc -o i386-asm.o -c i386-asm.c -DCONFIG_LDDIR="\"lib64\"" -DTCC_TARGET_X86_64 -I.  -Wall -g -O2 -fno-strict-aliasing -O0 -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result
ar rcs libtcc.a libtcc.o tccpp.o tccgen.o tccelf.o tccasm.o tccrun.o tccexsymtab.o x86_64-gen.o i386-asm.o
gcc -o tcc tcc.o libtcc.a -lm -ldl -I.  -Wall -g -O2 -fno-strict-aliasing -O0 -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result
make -C lib native
make[1]: Entering directory '/home/dylan.cali/git/tinycc/lib'
mkdir -p x86_64
gcc -c libtcc1.c -o x86_64/libtcc1.o -I..  -Wall -g -O2 -fno-strict-aliasing -O0 -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -DTCC_TARGET_X86_64
gcc -c alloca86_64.S -o x86_64/alloca86_64.o -I..  -Wall -g -O2 -fno-strict-aliasing -O0 -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -DTCC_TARGET_X86_64
ar rcs ../libtcc1.a x86_64/libtcc1.o x86_64/alloca86_64.o
make[1]: Leaving directory '/home/dylan.cali/git/tinycc/lib'
./texi2pod.pl tcc-doc.texi tcc.pod
pod2man --section=1 --center="Tiny C Compiler" --release=`cat ./VERSION` tcc.pod > tcc.1
makeinfo --no-split --html --number-sections -o tcc-doc.html tcc-doc.texi
makeinfo tcc-doc.texi

dcali-fedora (exsymtab=) ~/git/tinycc
[✔]▶ make test
make: Circular Makefile <- Makefile dependency dropped.
make -C tests test
make[1]: Entering directory '/home/dylan.cali/git/tinycc/tests'
------------ hello-exe ------------
../tcc -B.. -I.. -I.. -I../include ../examples/ex1.c -o hello || (../tcc -vv; exit 1) && ./hello
Hello World
------------ hello-run ------------
../tcc -B.. -I.. -I.. -I../include -run ../examples/ex1.c
Makefile:73: recipe for target 'hello-run' failed
make[1]: *** [hello-run] Segmentation fault (core dumped)
make[1]: Leaving directory '/home/dylan.cali/git/tinycc/tests'
Makefile:331: recipe for target 'test' failed
make: *** [test] Error 2

dcali-fedora (exsymtab= ?) ~/git/tinycc
[2]▶

Extend trie bit support

Jared Maddox suggested a mechanism for covering more bits with the trie:

How about reducing the allowed number of children
for a single trie node, and use a custom encoding to indicate that
some particular trie child node (let's say the first) is a
"continuation" node, containing the OTHER half (or third, or whatever)
of the children? The source already mentions the assumption that the
upper-case letters are used more rarely. Depending on choosen method
(something derived from UTF-8, perhaps? Nice and simple, after all,
implementable purely via comparisons: instead of indicating extension
bytes, the highest set bits would indicate "subsidiary nodes"),
extension to full Unicode might be possible (if improbable, and
ill-advised).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.