--- tcc.c.ori 2005-05-10 19:22:56.000000000 +0200 +++ tcc.c 2005-05-10 21:11:06.000000000 +0200 @@ -107,7 +107,9 @@ /* path to find crt1.o, crti.o and crtn.o. Only needed when generating executables or dlls */ +#if 0 /* for Konvalo we need it to be supplied at runtime -- pin */ #define CONFIG_TCC_CRT_PREFIX "/usr/lib" +#endif #define INCLUDE_STACK_SIZE 32 #define IFDEF_STACK_SIZE 64 @@ -413,6 +415,11 @@ char **library_paths; int nb_library_paths; + /* make pathnames to crt files to be defined at runtime */ + char *crt1_path; + char *crti_path; + char *crtn_path; + /* array of all loaded dlls (including those referenced by loaded dlls) */ DLLReference **loaded_dlls; @@ -1033,6 +1040,30 @@ return ptr; } +/* we use the first supplied library path if any as the prefix -- pin */ +/* suffix can be '1', 'i', 'n' */ +static +char * CONFIG_TCC_CRT_PREFIX ( TCCState *s, int suffix ) +{ + char **target; + char buf[1024], *prefix; + + switch (suffix) { + case '1': target = &(s->crt1_path); break; + case 'i': target = &(s->crti_path); break; + case 'n': target = &(s->crtn_path); break; + default: return "/"; /* fallback, should never happen */ + } + /* already present? */ + if( *target ) return *target; + /* otherwise */ + if (s->nb_library_paths > 0) prefix = s->library_paths[0]; + else prefix = "/usr/lib"; + snprintf( buf, sizeof(buf), "%s/crt%c.o", prefix, suffix ); + *target = tcc_strdup( buf ); + return *target; +} + #define free(p) use_tcc_free(p) #define malloc(s) use_tcc_malloc(s) #define realloc(p, s) use_tcc_realloc(p, s) @@ -9590,11 +9621,6 @@ tcc_define_symbol(s, "__PTRDIFF_TYPE__", "int"); tcc_define_symbol(s, "__WCHAR_TYPE__", "int"); - /* default library paths */ - tcc_add_library_path(s, "/usr/local/lib"); - tcc_add_library_path(s, "/usr/lib"); - tcc_add_library_path(s, "/lib"); - /* no section zero */ dynarray_add((void ***)&s->sections, &s->nb_sections, NULL); @@ -9656,6 +9682,11 @@ tcc_free(s1->library_paths[i]); tcc_free(s1->library_paths); + /* crt files */ + if(s1->crt1_path) tcc_free(s1->crt1_path); + if(s1->crti_path) tcc_free(s1->crti_path); + if(s1->crtn_path) tcc_free(s1->crtn_path); + /* cached includes */ for(i = 0; i < s1->nb_cached_includes; i++) tcc_free(s1->cached_includes[i]); @@ -9904,8 +9935,8 @@ if ((output_type == TCC_OUTPUT_EXE || output_type == TCC_OUTPUT_DLL) && !s->nostdlib) { if (output_type != TCC_OUTPUT_DLL) - tcc_add_file(s, CONFIG_TCC_CRT_PREFIX "/crt1.o"); - tcc_add_file(s, CONFIG_TCC_CRT_PREFIX "/crti.o"); + tcc_add_file(s, CONFIG_TCC_CRT_PREFIX(s, '1')); + tcc_add_file(s, CONFIG_TCC_CRT_PREFIX(s, 'i')); } return 0; } @@ -10360,6 +10391,12 @@ } } } + /* it is here we should add the standard library_paths -- pin */ + /* default library paths */ + tcc_add_library_path(s, "/usr/local/lib"); + tcc_add_library_path(s, "/usr/lib"); + tcc_add_library_path(s, "/lib"); + return optind; } --- tccelf.c.ori 2005-05-10 20:10:26.000000000 +0200 +++ tccelf.c 2005-05-10 21:09:40.000000000 +0200 @@ -1000,7 +1000,7 @@ } /* add crt end if not memory output */ if (s1->output_type != TCC_OUTPUT_MEMORY && !s1->nostdlib) { - tcc_add_file(s1, CONFIG_TCC_CRT_PREFIX "/crtn.o"); + tcc_add_file(s1, CONFIG_TCC_CRT_PREFIX(s1, 'n')); } }