瀏覽代碼

Implement MarkSection.

git-svn-id: file:///var/svn/tigccpp/trunk/tigcc/ld-tigcc@156 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler 19 年之前
父節點
當前提交
92f00a0d0f
共有 1 個文件被更改,包括 23 次插入0 次删除
  1. 23 0
      gcunused.c

+ 23 - 0
gcunused.c

@@ -22,10 +22,33 @@
 #include "manip.h"
 #include "special.h"
 
+// Recursively mark the target section of the specified location, if any (i.e.
+// if the location is non-NULL), as referenced.
+#define MarkLocation(Location) \
+	if ((Location) && (Location)->Symbol) \
+		MarkSection ((Location)->Symbol->Parent)
+
+
 // 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)
 {
+	RELOC *Reloc;
+
+	// If the section is already marked, return immediately.
+	if (Section->Referenced)
+		return;
+
+	// Mark the section right now to avoid infinite recursion.
+	Section->Referenced = TRUE;
+
+	// Recursively mark the target section and the relation section of all
+	// relocs in this section
+	for_each (Reloc, Section->Relocs)
+	{
+		MarkLocation (&(Reloc->Target));
+		MarkLocation (Reloc->Relation);
+	}
 }
 
 // Free a section if it is no longer referenced. Update the ReferencedLibCount