tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] Library path search problem


From: Ahilan Anantha
Subject: [Tinycc-devel] Library path search problem
Date: Tue, 17 May 2005 16:08:22 -0700
User-agent: Mozilla Thunderbird 1.0.2-1.3.3 (X11/20050513)

Hi,

I've encountered what I believe is a bug in TinyCC version 0.9.22.

tcc searches the whole library path for a shared library before searching for a matching static library. The link stage for "bash" does something like this:

tcc -o bash ... -L ./lib/readline -lreadline

There's a static library in ./lib/readline, libreadline.a . When compiling with gcc, gcc picks this static library. But when compiling with tcc, tcc chooses my /usr/lib/readline.so instead.

I think you're only supposed to prefer the shared library over a static library that's in the same directory. But otherwise you always prefer the library found earlier in the path.

Another thing I noticed was that tcc adds /lib, /usr/lib, and /usr/local/lib into the search path before parsing the arguments. But I'm pretty sure those directories are supposed to be searched after the ones specified on the command line with -L.

Attaching a patch. I can get bash built but it will still segfault instantly upon startup.

Thanks for tinycc,

Ahilan
--- tcc.c.orig  2005-05-16 21:54:07.000000000 -0700
+++ tcc.c       2005-05-17 16:00:26.000000000 -0700
@@ -9587,11 +9587,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);
 
@@ -9828,19 +9823,21 @@
     char buf[1024];
     int i;
     
-    /* first we look for the dynamic library if not static linking */
-    if (!s->static_link) {
-        snprintf(buf, sizeof(buf), "lib%s.so", libraryname);
-        if (tcc_add_dll(s, buf, 0) == 0)
-            return 0;
-    }
-
-    /* then we look for the static library */
+    /* look for the library */
     for(i = 0; i < s->nb_library_paths; i++) {
-        snprintf(buf, sizeof(buf), "%s/lib%s.a", 
-                 s->library_paths[i], libraryname);
-        if (tcc_add_file_internal(s, buf, 0) == 0)
-            return 0;
+       /* if dynamically linking, prefer the dynamic library
+          to the shared library */
+       if (!s->static_link) {
+           snprintf(buf, sizeof(buf), "%s/lib%s.so", 
+                    s->library_paths[i], libraryname);
+           if (tcc_add_file_internal(s, buf, 0) == 0)
+               return 0;
+       }
+
+       snprintf(buf, sizeof(buf), "%s/lib%s.a", 
+                s->library_paths[i], libraryname);
+       if (tcc_add_file_internal(s, buf, 0) == 0)
+           return 0;
     }
     return -1;
 }
@@ -10380,6 +10377,11 @@
 
     optind = parse_args(s, argc - 1, argv + 1) + 1;
 
+    /* default library paths */
+    tcc_add_library_path(s, "/usr/local/lib");
+    tcc_add_library_path(s, "/usr/lib");
+    tcc_add_library_path(s, "/lib");
+
     if (print_search_dirs) {
         /* enough for Linux kernel */
         printf("install: %s/\n", tcc_lib_path);

reply via email to

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