changeset 564:d89a6822b7e0

Use library search path for crt?.o, and for ld script libraries with no path.
author Rob Landley <rob@landley.net>
date Tue, 11 Mar 2008 23:45:07 -0500
parents 8e32c8615b39
children 1dadc72cb41f
files tcc.c tccelf.c
diffstat 2 files changed, 21 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/tcc.c	Tue Mar 11 23:22:40 2008 -0500
+++ b/tcc.c	Tue Mar 11 23:45:07 2008 -0500
@@ -8918,19 +8918,15 @@
 int tcc_add_file_internal(TCCState *s1, char *filename, int flags)
 {
     char *ext, *filename1;
-    Elf32_Ehdr ehdr;
     int fd, ret;
     BufferedFile *saved_file;
 
     /* find source file type with extension */
     filename1 = strrchr(filename, '/');
-    if (filename1)
-        filename1++;
-    else
-        filename1 = filename;
+    if (filename1) filename1++;
+    else filename1 = filename;
     ext = strrchr(filename1, '.');
-    if (ext)
-        ext++;
+    if (ext) ext++;
 
     /* open the file */
     saved_file = file;
@@ -8965,6 +8961,8 @@
     } else
 #endif
     {
+        Elf32_Ehdr ehdr;
+
         fd = file->fd;
         /* assume executable format: auto guess file type */
         ret = read(fd, &ehdr, sizeof(ehdr));
@@ -9042,13 +9040,17 @@
 static int tcc_add_dll(TCCState *s, char *filename, int flags)
 {
     char buf[1024];
-    int i;
-
-    for(i = 0; i < tccg_library_paths.len; i++) {
+    int i = 0;
+
+    for(;;) {
+        int test;
+
         snprintf(buf, sizeof(buf), "%s/%s", 
                  tccg_library_paths.data[i], filename);
-        if (tcc_add_file_internal(s, buf, flags) == 0)
+        test = tccg_library_paths.len == ++i;
+        if (!tcc_add_file_internal(s, buf, test ? flags : (flags & ~AFF_PRINT_ERROR)))
             return 0;
+        if (test) break;
     }
     return -1;
 }
@@ -9070,7 +9072,7 @@
     }
 
     snprintf(buf, sizeof(buf), "lib%s.a", libraryname);
-    return tcc_add_dll(s, buf, 0);
+    return tcc_add_dll(s, buf, AFF_PRINT_ERROR);
 }
 
 int tcc_add_symbol(TCCState *s, char *name, unsigned long val)
@@ -9136,8 +9138,8 @@
         && !tccg_nostdlib)
     {
         if (tccg_output_type != TCC_OUTPUT_DLL)
-            tcc_add_file(s, CC_CRTDIR "/crt1.o");
-        tcc_add_file(s, CC_CRTDIR "/crti.o");
+            tcc_add_dll(s, "crt1.o", AFF_PRINT_ERROR);
+        tcc_add_dll(s, "crti.o", AFF_PRINT_ERROR);
     }
 #endif
     return 0;
--- a/tccelf.c	Tue Mar 11 23:22:40 2008 -0500
+++ b/tccelf.c	Tue Mar 11 23:45:07 2008 -0500
@@ -1014,7 +1014,7 @@
         tcc_add_library(s1, "tinyccrt-" TINYCC_TARGET);
       // add crt end if not memory output
       if (tccg_output_type != TCC_OUTPUT_MEMORY)
-          tcc_add_file(s1, CC_CRTDIR "/crtn.o");
+          tcc_add_dll(s1, "crtn.o", AFF_PRINT_ERROR);
     }
 }
 
@@ -2334,8 +2334,10 @@
                 return ret;
         } else {
             /* TODO: Implement AS_NEEDED support. Ignore it for now */
-            if (!as_needed)
-                tcc_add_file(s1, filename);
+            if (!as_needed) {
+                if (*filename=='/') tcc_add_file(s1, filename);
+                else tcc_add_dll(s1, filename, AFF_PRINT_ERROR);
+            }
         }
         t = ld_next(s1, filename, sizeof(filename));
         if (t == ',') {