tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] Mis-parse in some situations involving a function poi


From: Jonathan Newman
Subject: Re: [Tinycc-devel] Mis-parse in some situations involving a function pointer with attributes (breaks SQLite build)
Date: Fri, 3 Aug 2018 22:32:26 +0100

Quick update: The sqlite3 crash still seems to be related to the function pointer attributes issue. Attached is a simple program that uses sqlite (opens a :memory: DB, runs a version check query, cleans up).

1. Compile test.c along with sqlite-amalgamation-3240000/sqlite3.c for Windows 32-bit. Use the following to avoid some other potential issues:
-D_WIN32 -DSQLITE_OMIT_UTF16 -DSQLITE_DISABLE_FTS3_UNICODE -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_AUTHORIZATION

2. Observe that it builds correctly, but the resulting binary segfaults.

3. Modify sqlite-amalgamation-3240000/sqlite3.c:L40401, from this:
>#define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[28].pCurrent)
to this:
>#define osGetSystemInfo ((WINAPI VOID(*)(LPSYSTEM_INFO))aSyscall[28].pCurrent)

4. Rebuild and observe that the binary now runs correctly.

Haven't had a chance to verify yet, but my initial assumptions are that
a) Either TCC is emitting code with the incorrect calling convention, i.e. the __stdcall was parsed but not applied, or something else about the specific construct used by sqlite is confusing it
b) Since other entries in the aSyscall table use the same syntax, they will probably by affected in the same way. Fixing osGetSystemInfo alone is enough for something trivial like tcc_windows32_sqlite3_test.c.





On Sun, 29 Jul 2018 at 14:51, Christian Jullien <address@hidden> wrote:

I would love to have SQLite working with tcc. Two of my favorite projects.

Especially, SQLite is an optional component of my own Lisp (OpenLisp) which currently lacks this module when compiled with tcc.

 

My contribution will be to test SQLite on all OS/processor tcc currently supports.

 

C.

 

From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=address@hidden] On Behalf Of Jonathan Newman
Sent: dimanche 29 juillet 2018 00:58
To: address@hidden
Subject: Re: [Tinycc-devel] Mis-parse in some situations involving a function pointer with attributes (breaks SQLite build)

 

Many thanks for the fix!

 

I can confirm sqlite builds on Windows now, although unfortunately it still doesn't run correctly. My earlier statement that the issue could be "worked around" was based purely on a successful build+call to sqlite3_libversion. Calling sqlite3_open segfaults somewhere around sqlite3_os_init. But this is unrelated to the function pointer parsing issue- I'll work on it and contribute a fix if I can/prepare a test case if I can't.

 

- Jonathan

 

 

On Sat, 28 Jul 2018 at 18:01, Michael Matz <address@hidden> wrote:

Hello,

On Sun, 22 Jul 2018, Jonathan Newman wrote:

> Hi;I happened across this issue while trying to build SQLite. I've attached
> a test case. To summarise:
> * Start off with a function pointer, correctly assigned to a function that
> has attributes, but cast to a void* (or indeed anything except the correct
> function pointer type)
> * Cast this void* to the correct function pointer type, and call it
> * Observe that one cast+call syntax works correctly, and another results in
> a misparse:
> * tcc thinks the type of the entire _expression_ (cast+call) is a pointer,
> instead of the correct return type of the called function (here, an
> integer).
> * gcc happily accepts both syntaxes
> * This breaks compilation of the sqlite.c amalgamation, at least on 32-bit
> windows

Thanks for report and testcase; reproducable on linux.  The parser
prematurely concluded that '__attribute__((foo)) *' can start a type
(while '*' cannot).  Fixed in mob.


Ciao,
Michael.

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

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

Attachment: tcc_windows32_sqlite3_test.c
Description: Text document


reply via email to

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