Hi everyone,

I am a undergradaute student, and this semester I have a project to port TCC to 
a new OS written by our prof.

Basically I want to implement the function that we type in a string in the OS, 
and we can compile the string into memory, and get the result. Same as the 
illustration for the libtcc.

But I encounter a problem that after I compile my string, I can not get the 
main function from symbol table. I am unable to find out why and what happened. 
I am thinking it might because I didn’t fill the address for main in when I 
invoke tcc_compile_string. But I don’t know how can I check.

Any help will be so great.

Best,

Xuan

#include "tcc.h"
main_func handle_tcc_script(char *tcc_program) {
    
nk_vc_printf("\nBegin handle_tcc_script 0..");
        TCCState *s;
        int (*func)();

        s = tcc_new();
nk_vc_printf("..10..");
        if (!s) {
                nk_vc_printf("\nCould not create tcc state\n");
                return NULL;
        }
nk_vc_printf("..20..");

        tcc_set_output_type(s, TCC_OUTPUT_MEMORY);

nk_vc_printf("..30..");

        if (tcc_compile_string(s,tcc_program) == -1) {
                nk_vc_printf("\nCould not compile program\n");
                return NULL;
        }
nk_vc_printf("..40..");

        if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0) {
                nk_vc_printf("\nCould not relocate program\n");
                return NULL;
        }
nk_vc_printf("..50..");

        func = tcc_get_symbol(s, "main");
        if (!func) {
                nk_vc_printf("\nCould not find main()\n");
                return NULL;
        }
nk_vc_printf("..100.. Done handle_tcc_script\n");

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

Reply via email to