ports/141185: fix some tcc predefined macros, add -M support

Luigi Rizzo luigi at FreeBSD.org
Sat Dec 5 08:50:01 UTC 2009


>Number:         141185
>Category:       ports
>Synopsis:       fix some tcc predefined macros, add -M support
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Dec 05 08:50:00 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator:     Luigi Rizzo
>Release:        FreeBSD 8.0
>Organization:
Univ. Pisa
>Environment:

	n.a.
>Description:
	
The attached files do the following
1. a small fix to the existing patch-libtcc.c which removes the
   predefined __INTEL_COMPILER__ (which was bringing in too many
   undesired features) and instead defines the macros
   __aligned(x), __packed and __CC_SUPPORTS___INLINE which permit
   correct compilation of our code.
   I am including the whole patch-libtcc.c for convenience

2. a new patch-z1-mode_m which implements the -M option (generate
   dependencies, used by mkdep) and also ignores -std=XXX options
   sometimes used in compilations.
   This has also been submitted upstream a few days ago.

Already sent to the maintainer a few days ago, i will do the commit later
this weekend if nobody has time to handle it.


>How-To-Repeat:
>Fix:
bring these two files into ports/tcc/files, bump up portrevision

-------------- patch-z1-mode_m ----------------
diff -ubwr ./libtcc.c ../../work.luigi/tcc-0.9.25/libtcc.c
--- ./libtcc.c	2009-12-01 19:42:09.000000000 +0100
+++ ../../work.luigi/tcc-0.9.25/libtcc.c	2009-12-01 17:53:20.000000000 +0100
@@ -2119,7 +2119,9 @@
 {
     char buf[1024];
 
-    s->output_type = output_type;
+    s->output_type = output_type & 7;
+    s->mode_m = output_type & 8;
+    output_type = s->output_type;
 
     if (!s->nostdinc) {
         /* default include paths */
diff -ubwr ./tcc.c ../../work.luigi/tcc-0.9.25/tcc.c
--- ./tcc.c	2009-05-18 16:27:06.000000000 +0200
+++ ../../work.luigi/tcc-0.9.25/tcc.c	2009-12-01 17:54:17.000000000 +0100
@@ -66,6 +66,7 @@
 static int multiple_files;
 static int print_search_dirs;
 static int output_type;
+static int mode_m;
 static int reloc_output;
 static const char *outfile;
 static int do_bench = 0;
@@ -111,6 +112,8 @@
     TCC_OPTION_w,
     TCC_OPTION_pipe,
     TCC_OPTION_E,
+    TCC_OPTION_M,	/* mkdep */
+    TCC_OPTION_std,	/* -std= */
 };
 
 static const TCCOption tcc_options[] = {
@@ -148,6 +150,8 @@
     { "w", TCC_OPTION_w, 0 },
     { "pipe", TCC_OPTION_pipe, 0},
     { "E", TCC_OPTION_E, 0},
+    { "M", TCC_OPTION_M, 0},
+    { "std=", TCC_OPTION_std, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
     { NULL },
 };
 
@@ -399,6 +402,10 @@
                     }
                 }
                 break;
+            case TCC_OPTION_std:
+		break; /* ignore -std= */
+            case TCC_OPTION_M:
+                mode_m = 8;	/* FALLTHROUGH */
             case TCC_OPTION_E:
                 output_type = TCC_OUTPUT_PREPROCESS;
                 break;
@@ -502,7 +507,7 @@
         start_time = getclock_us();
     }
 
-    tcc_set_output_type(s, output_type);
+    tcc_set_output_type(s, output_type | mode_m);
 
     /* compile or add each files or library */
     for(i = 0; i < nb_files && ret == 0; i++) {
diff -ubwr ./tcc.h ../../work.luigi/tcc-0.9.25/tcc.h
--- ./tcc.h	2009-05-18 16:27:06.000000000 +0200
+++ ../../work.luigi/tcc-0.9.25/tcc.h	2009-12-01 17:49:44.000000000 +0100
@@ -367,6 +367,7 @@
 
 struct TCCState {
     int output_type;
+    int mode_m;	/* tcc -M */
  
     BufferedFile **include_stack_ptr;
     int *ifdef_stack_ptr;
diff -ubwr ./tccpp.c ../../work.luigi/tcc-0.9.25/tccpp.c
--- ./tccpp.c	2009-05-18 16:27:06.000000000 +0200
+++ ../../work.luigi/tcc-0.9.25/tccpp.c	2009-12-01 19:39:27.000000000 +0100
@@ -2897,6 +2897,7 @@
     Sym *define_start;
     BufferedFile *file_ref;
     int token_seen, line_ref;
+    const char *base_file;
 
     preprocess_init(s1);
     define_start = define_stack;
@@ -2908,6 +2909,12 @@
     line_ref = 0;
     file_ref = NULL;
 
+    base_file = file->filename;
+    if (s1->mode_m) {
+	int l = strlen(base_file);
+	fprintf(s1->outfile, "%.*s.o: %s", l-2, base_file, base_file);
+    }
+
     for (;;) {
         next();
         if (tok == TOK_EOF) {
@@ -2919,16 +2926,25 @@
             token_seen = 0;
         } else if (!token_seen) {
             int d = file->line_num - line_ref;
+	  if (s1->mode_m) {
+	    if (file != file_ref && file->filename != base_file &&
+		!search_cached_include(s1, '>', file->filename))
+	      fprintf(s1->outfile, " \\\n  %s", file->filename);
+	  } else {
             if (file != file_ref || d < 0 || d >= 8)
                 fprintf(s1->outfile, "# %d \"%s\"\n", file->line_num, file->filename);
             else
                 while (d)
                     fputs("\n", s1->outfile), --d;
+	  }
             line_ref = (file_ref = file)->line_num;
             token_seen = 1;
         }
+      if (!s1->mode_m)
         fputs(get_tok_str(tok, &tokc), s1->outfile);
     }
+    if (s1->mode_m)
+	fprintf(s1->outfile, "\n");
     free_defines(define_start); 
     return 0;
 }
-----------------------------------------------------


----- patch-libtcc.c ---------------------------------
diff -ubwr ./libtcc.c ../../work.2/tcc-0.9.25/libtcc.c
--- ./libtcc.c	2009-05-18 16:27:06.000000000 +0200
+++ ../../work.2/tcc-0.9.25/libtcc.c	2009-11-29 02:25:14.000000000 +0100
@@ -1509,10 +1509,18 @@
 
     if (level == 0) {
         /* XXX: only support linux */
+#if defined(__FreeBSD__) 
+        *paddr = uc->uc_mcontext.mc_rip;
+#else
         *paddr = uc->uc_mcontext.gregs[REG_RIP];
+#endif
         return 0;
     } else {
+#if defined(__FreeBSD__) 
+        fp = uc->uc_mcontext.mc_rbp;
+#else
         fp = uc->uc_mcontext.gregs[REG_RBP];
+#endif
         for(i=1;i<level;i++) {
             /* XXX: check address validity with program info */
             if (fp <= 0x1000)
@@ -1784,7 +1792,9 @@
     tcc_define_symbol(s, "__STDC__", NULL);
     tcc_define_symbol(s, "__STDC_VERSION__", "199901L");
 #if defined(TCC_TARGET_I386)
-    tcc_define_symbol(s, "__i386__", NULL);
+    tcc_define_symbol(s, "__i386__", "1");
+    tcc_define_symbol(s, "__i386", "1");
+    tcc_define_symbol(s, "i386", "1");
 #endif
 #if defined(TCC_TARGET_X86_64)
     tcc_define_symbol(s, "__x86_64__", NULL);
@@ -1802,8 +1812,17 @@
 #ifdef TCC_TARGET_PE
     tcc_define_symbol(s, "_WIN32", NULL);
 #else
-    tcc_define_symbol(s, "__unix__", NULL);
-    tcc_define_symbol(s, "__unix", NULL);
+    tcc_define_symbol(s, "__unix__", "1");
+    tcc_define_symbol(s, "__unix", "1");
+    tcc_define_symbol(s, "unix", "1");
+#if defined(__FreeBSD__)
+#define str(s) #s
+    tcc_define_symbol(s, "__FreeBSD__", str( __FreeBSD__));
+    tcc_define_symbol(s, "__aligned(x)", "__attribute__((__aligned__(x)))");
+    tcc_define_symbol(s, "__packed", "__attribute__((packed))");
+    tcc_define_symbol(s, "__CC_SUPPORTS___INLINE", "1");
+#undef str
+#endif
 #if defined(__linux)
     tcc_define_symbol(s, "__linux__", NULL);
     tcc_define_symbol(s, "__linux", NULL);
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list