Browse Source

Make RemoveSectionIfUnused a void function. Add MarkSection (still empty) and use it in RemoveUnusedSections to mark essential sections.

git-svn-id: file:///var/svn/tigccpp/trunk/tigcc/ld-tigcc@155 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler 19 years ago
parent
commit
64b0767e96
1 changed files with 16 additions and 4 deletions
  1. 16 4
      gcunused.c

+ 16 - 4
gcunused.c

@@ -22,9 +22,15 @@
 #include "manip.h"
 #include "special.h"
 
+// Mark a section as referenced. If it was not already marked, follow all relocs
+// from this section and recursively mark the target sections of all the relocs.
+static void MarkSection (SECTION *Section)
+{
+}
+
 // Free a section if it is no longer referenced. Update the ReferencedLibCount
 // accordingly.
-static BOOLEAN RemoveSectionIfUnused (SECTION *Section)
+static void RemoveSectionIfUnused (SECTION *Section)
 {
 	PROGRAM *Program = Section->Parent;
 	SECTION *OtherSection;
@@ -32,7 +38,7 @@ static BOOLEAN RemoveSectionIfUnused (SECTION *Section)
 	
 	// Don't free the section if it is still referenced.
 	if (Section->Referenced)
-		return FALSE;
+		return;
 
 	// If this section references any libraries, and if it was the last one to
 	// reference them, we need to mark the library as no longer referenced.
@@ -60,8 +66,6 @@ NextLibCall:;
 
 	// Now free the section.
 	FreeSection (Section);
-	
-	return TRUE;
 }
 
 // Remove all unused sections.
@@ -69,6 +73,14 @@ void RemoveUnusedSections (PROGRAM *Program)
 {
 	SECTION *Section, *NextSection;
 	
+	for_each (Section, Program->Sections)
+	{
+		// If the section is an essential section, mark it (and all sections it
+		// references) as referenced.
+		if (Section->Essential)
+			MarkSection (Section);
+	}
+	
 	// For each section...
 	for (Section = GetFirst (Program->Sections); Section; Section = NextSection)
 	{