Browse Source

Fix and improve data variable support.

git-svn-id: file:///var/svn/tigccpp/trunk/tigcc/ld-tigcc@164 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler 19 years ago
parent
commit
a38008473e
2 changed files with 22 additions and 11 deletions
  1. 12 10
      insert/comprrlc.c
  2. 10 1
      main.c

+ 12 - 10
insert/comprrlc.c

@@ -252,15 +252,16 @@ BOOLEAN InsertCompressedRelocs (SECTION *Section, SECTION *TargetSection, SECTIO
 	// Initialize user data for list model.
 	RELOC_USER_DATA UserData = {TargetSection};
 	
+	// Do code optimizations now, since this might reduce the number
+	// of relocs. This is useful even if a target section was specified
+	// because we can't fix the code anymore after the section is frozen.
+	// This could even cause us to emit invalid code (bra +0).
+	FixCode (Section->Parent);
+
 	// If a target section is specified, it is essential now, and it may
 	// not be modified any more.
 	if (TargetSection)
 		TargetSection->Frozen = TargetSection->Essential = TRUE;
-	else
-		// Do code optimizations now, since this might reduce the number
-		// of relocs. If a target section was specified, this is pointless,
-		// as relocs into a separate section can never be optimized away.
-		FixCode (Section->Parent);
 	
 	// Apply the format documented in _compressed_format_relocs.s.
 	if (!(EmitCompressedFormatRelocs ((LIST_MODEL *) RelocListModel, MergedSection, Reference, &UserData, Section)))
@@ -1038,15 +1039,16 @@ BOOLEAN InsertMlinkRelocs (SECTION *Section, SECTION *TargetSection, SECTION *Me
 	// Initialize user data for list model.
 	RELOC_USER_DATA UserData = {TargetSection};
 	
+	// Do code optimizations now, since this might reduce the number
+	// of relocs. This is useful even if a target section was specified
+	// because we can't fix the code anymore after the section is frozen.
+	// This could even cause us to emit invalid code (bra +0).
+	FixCode (Section->Parent);
+
 	// If a target section is specified, it is essential now, and it may
 	// not be modified any more.
 	if (TargetSection)
 		TargetSection->Frozen = TargetSection->Essential = TRUE;
-	else
-		// Do code optimizations now, since this might reduce the number
-		// of relocs. If a target section was specified, this is pointless,
-		// as relocs into a separate section can never be optimized away.
-		FixCode (Section->Parent);
 	
 	// Apply the format documented in _mlink_format_relocs.s.
 	if (!(EmitMlinkFormatRelocs ((LIST_MODEL *) RelocListModel, MergedSection, Reference, &UserData, Section)))

+ 10 - 1
main.c

@@ -242,6 +242,15 @@ int main (int ArgCount, const char **Args)
 			// sections.
 			if (DatVarInfo->Name)
 			{
+				if (OptInfo->MergeConstants && (!(Program.Frozen)))
+				{
+					// Merge constants now, as we can't do it anymore after
+					// the data variable has been built.
+					MergeConstants (&Program);
+					
+					DoSpecialDump (1, "(const-merged)");
+				}
+				
 				Program.DataSection = MergeAllSections (&Program, NULL, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE);
 				// Mark the section as "handled" so it will not be merged
 				// with code.
@@ -307,7 +316,7 @@ int main (int ArgCount, const char **Args)
 					DoSpecialDump (4, "(cut)");
 				}
 				
-				if (OptInfo->MergeConstants && (!(Program.Frozen)))
+				if (!DatVarInfo->Name && OptInfo->MergeConstants && (!(Program.Frozen)))
 				{
 					// Merge constants.
 					MergeConstants (&Program);