changeset 255:e02822de9d86

[project @ 2003-04-27 11:45:01 by bellard] added -nostdlib
author bellard
date Sun, 27 Apr 2003 11:45:01 +0000
parents ec0379c33f9e
children b47b8f2aebf6
files tcc.c tccelf.c
diffstat 2 files changed, 21 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/tcc.c	Sat Apr 26 21:28:09 2003 +0000
+++ b/tcc.c	Sun Apr 27 11:45:01 2003 +0000
@@ -392,9 +392,9 @@
     /* exported dynamic symbol section */
     Section *dynsym;
 
-    /* if true, no standard headers are added */
-    int nostdinc;
-    
+    int nostdinc; /* if true, no standard headers are added */
+    int nostdlib; /* if true, no standard libraries are added */
+
     /* if true, static linking is performed */
     int static_link;
 
@@ -9478,8 +9478,8 @@
     }
 
     /* add libc crt1/crti objects */
-    if (output_type == TCC_OUTPUT_EXE || 
-        output_type == TCC_OUTPUT_DLL) {
+    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");
@@ -9620,6 +9620,7 @@
     TCC_OPTION_m,
     TCC_OPTION_f,
     TCC_OPTION_nostdinc,
+    TCC_OPTION_nostdlib,
     TCC_OPTION_print_search_dirs,
     TCC_OPTION_rdynamic,
     TCC_OPTION_run,
@@ -9653,6 +9654,7 @@
     { "m", TCC_OPTION_m, TCC_OPTION_HAS_ARG },
     { "f", TCC_OPTION_f, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
     { "nostdinc", TCC_OPTION_nostdinc, 0 },
+    { "nostdlib", TCC_OPTION_nostdlib, 0 },
     { "print-search-dirs", TCC_OPTION_print_search_dirs, 0 }, 
     { "v", TCC_OPTION_v, 0 },
     { NULL },
@@ -9804,6 +9806,9 @@
             case TCC_OPTION_nostdinc:
                 s->nostdinc = 1;
                 break;
+            case TCC_OPTION_nostdlib:
+                s->nostdlib = 1;
+                break;
             case TCC_OPTION_print_search_dirs:
                 print_search_dirs = 1;
                 break;
--- a/tccelf.c	Sat Apr 26 21:28:09 2003 +0000
+++ b/tccelf.c	Sun Apr 27 11:45:01 2003 +0000
@@ -778,8 +778,10 @@
     int i;
     Section *s;
 
-    snprintf(buf, sizeof(buf), "%s/%s", tcc_lib_path, "libtcc1.o");
-    tcc_add_file(s1, buf);
+    if (!s1->nostdlib) {
+        snprintf(buf, sizeof(buf), "%s/%s", tcc_lib_path, "libtcc1.o");
+        tcc_add_file(s1, buf);
+    }
 #ifdef CONFIG_TCC_BCHECK
     if (do_bounds_check) {
         unsigned long *ptr;
@@ -811,7 +813,7 @@
     }
 #endif
     /* add libc if not memory output */
-    if (s1->output_type != TCC_OUTPUT_MEMORY) {
+    if (s1->output_type != TCC_OUTPUT_MEMORY && !s1->nostdlib) {
         tcc_add_library(s1, "c");
         tcc_add_file(s1, CONFIG_TCC_CRT_PREFIX "/crtn.o");
     }
@@ -1248,12 +1250,14 @@
 
                 p = s1->plt->data;
                 p_end = p + s1->plt->data_offset;
-                put32(p + 2, get32(p + 2) + s1->got->sh_addr);
-                put32(p + 8, get32(p + 8) + s1->got->sh_addr);
-                p += 16;
-                while (p < p_end) {
+                if (p < p_end) {
                     put32(p + 2, get32(p + 2) + s1->got->sh_addr);
+                    put32(p + 8, get32(p + 8) + s1->got->sh_addr);
                     p += 16;
+                    while (p < p_end) {
+                        put32(p + 2, get32(p + 2) + s1->got->sh_addr);
+                        p += 16;
+                    }
                 }
             }