Browse Source

Apply Lionel Patch (and first real commit on this marvelous fork #hehe#)

git-svn-id: file:///var/svn/tigccpp/trunk/tigcc/ld-tigcc@1260 9552661e-59e3-4036-b4f2-dbe53926924f
godzil 16 years ago
parent
commit
24b3727562
3 changed files with 75 additions and 0 deletions
  1. 6 0
      data.h
  2. 37 0
      main.c
  3. 32 0
      special.c

+ 6 - 0
data.h

@@ -25,6 +25,8 @@
 #include "lists.h"
 #include "intrface.h"
 
+#include <time.h>
+
 #define MAX_SYM_LEN 255
 
 struct PROGRAM;
@@ -138,6 +140,10 @@ typedef struct PROGRAM {
 #endif /* DATA_VAR_SUPPORT */
 	OPTIMIZE_INFO
 		*OptimizeInfo;    // Optimization settings and results.
+	struct {
+		time_t LinkTime;
+		unsigned short year, month, day;
+	} LinkTime;           // Time info, initialized when linking starts.
 } PROGRAM;
 
 // Section in a Program

+ 37 - 0
main.c

@@ -39,6 +39,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
+#include <time.h>
 
 #define RESULT_OK             0
 #define RESULT_GENERAL_ERROR  1
@@ -121,6 +122,39 @@ static char CalcTolower(char Lower)
 	return c;
 }
 
+// Fill internal structures with time information
+static void ComputeTimeInformation(PROGRAM *Program)
+{
+	// Get the timestamp.
+	if (time(&Program->LinkTime.LinkTime) != (time_t)-1)
+	{
+		struct tm * broken_down_time;
+
+		broken_down_time = gmtime(&Program->LinkTime.LinkTime);
+		if (broken_down_time != NULL) {
+			// gmtime returns the number of years since 1900.
+			Program->LinkTime.year = broken_down_time->tm_year + 1900;
+			// gmtime returns the month between 0 and 11.
+			Program->LinkTime.month = broken_down_time->tm_mon + 1;
+			Program->LinkTime.day = broken_down_time->tm_mday;
+			// Convert from "seconds since Jan 1, 1970" to "seconds since Jan 1, 1997".
+			// 197x: 8x365 days, 2x366 days (leap years: 1972, 1976) => 315532800 seconds
+			// 198x: 7x365 days, 3x366 days (leap years: 1980, 1984, 1988) => 315619200 seconds
+			// 199x: 5x365 days, 2x366 days (leap years: 1992, 1996) => 220924800 seconds
+			// Total: 852076800 seconds.
+			Program->LinkTime.LinkTime -= (time_t)852076800L;
+			return;
+		}
+	}
+
+	// Failed, so set dummy values.
+	Warning (NULL, "Couldn't get current time, setting dummy values.");
+	Program->LinkTime.LinkTime = (time_t)0,
+	Program->LinkTime.year = 1997,
+	Program->LinkTime.month = 1,
+	Program->LinkTime.day = 1;
+}
+
 int main (int ArgCount, const char **Args)
 {
 	OPTIMIZE_INFO _OptimizeInfo;
@@ -169,6 +203,9 @@ int main (int ArgCount, const char **Args)
 	
 	// Initialize.
 	memset (&Program, 0, sizeof (Program));
+	
+	ComputeTimeInformation(&Program);
+	
 	Program.EntryPoint.SymbolName = "__entry_point";
 #ifdef TARGET_EMBEDDED
 	ErrorFunction = ErrorMessage;

+ 32 - 0
special.c

@@ -756,6 +756,38 @@ BOOLEAN ResolveSpecialSymbolLocation (SECTION *Section, LOCATION *Location, BOOL
 					HasValue = TRUE;
 				}
 			}
+			else if (SymNameMatches ("link_time_y")) // Preliminary name
+			{
+				if (Program->ResolveAllBuiltins)
+				{
+					NewValue = Program->LinkTime.year;
+					HasValue = TRUE;
+				}
+			}
+			else if (SymNameMatches ("link_time_m")) // Preliminary name
+			{
+				if (Program->ResolveAllBuiltins)
+				{
+					NewValue = Program->LinkTime.month;
+					HasValue = TRUE;
+				}
+			}
+			else if (SymNameMatches ("link_time_d")) // Preliminary name
+			{
+				if (Program->ResolveAllBuiltins)
+				{
+					NewValue = Program->LinkTime.day;
+					HasValue = TRUE;
+				}
+			}
+			else if (SymNameMatches ("link_time_timestamp")) // Preliminary name
+			{
+				if (Program->ResolveAllBuiltins)
+				{
+					NewValue = Program->LinkTime.LinkTime;
+					HasValue = TRUE;
+				}
+			}
 			else if (SymNameMatches ("kernel_flags"))
 			{
 				if (Program->ResolveAllBuiltins)