Op 14-11-2025 om 09:56 schreef DFP:
Running mob branch on amd64 (x86_64) Linux, and when combining -nostdlib and 
-run flags -- argc and argv get passed differently onto the program. Usually, 
if just -nostdlib is used, they get passed on the stack as per the x86_64 ABI. 
But when -run is additionally passed, arguments no longer seem to be on the 
stack, and are instead passed in registers. Causing an unexpecting program to 
crash.

An intermediate fix could be to have a macro called something like 
__TINY_C_RUN__, which is 0 when -run is not supplied, and 1 when it is. But I 
wonder how hard it would be to fix it properly. I might take a crack at it 
myself. Any thoughts?
The problem is in tccrun.c. If you disable check for nostdlib it works:

diff --git a/tccrun.c b/tccrun.c
index 8ef0b65..cae0640 100644
--- a/tccrun.c
+++ b/tccrun.c
@@ -220,7 +220,7 @@ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv)
         return 0;

     tcc_add_symbol(s1, "__rt_exit", rt_exit);
-    if (s1->nostdlib) {
+    if (0&&s1->nostdlib) {
         s1->run_main = top_sym = s1->elf_entryname ? s1->elf_entryname : "_start";
     } else {
         tcc_add_support(s1, "runmain.o");

The code now calls main instead of _start with help of runmain.o.
The _start is not used any more when tcc -run is used.
The _start and main code entry points have different api's so I do
not understand this code.

    Herman


_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to