Browse Source

Fix "relative reloc at `0xnnn' to `foo' in different section" errors when using --remove-unused with debugging information and KERNEL_FORMAT_ROM_CALLS (or other relocated ROM_CALLs, RAM_CALLs or library calls): Remove all ROM_CALLs, RAM_CALLs and library calls from the deleted section. GDB can't handle them anyway and they cause invalid entries in the relocation table.

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

+ 22 - 1
gcunused.c

@@ -1,7 +1,7 @@
 /* gcunused.c: Routines to remove unused sections
 
    Copyright (C) 2002-2004 Sebastian Reichelt
-   Copyright (C) 2003-2005 Kevin Kofler
+   Copyright (C) 2003-2008 Kevin Kofler
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
 
 #include "gcunused.h"
 
+#include <stdlib.h>
 #include <string.h>
 
 #include "manip.h"
@@ -94,7 +95,27 @@ NextLibCall:;
 	// debugging information purposes.
 #ifdef DEBUGGING_INFO_SUPPORT
 	if (Program->HaveDebuggingInfo)
+	{
 		Section->DebuggingInfoType = DI_DELETED;
+
+		// Remove all ROM_CALLs, RAM_CALLs and library calls from the
+		// deleted section. GDB can't handle them anyway and they cause
+		// invalid entries in the relocation table.
+#define FreeItems(Type,Item) \
+({ \
+	Type *Item, *Next##Item; \
+	for (Item = GetLast (Section->Item##s); Item; Item = Next##Item) \
+	{ \
+		Next##Item = GetPrev (Item); \
+		free (Item); \
+	} \
+	GetFirst (Section->Item##s) = GetLast (Section->Item##s) = NULL; \
+})
+		FreeItems (LIB_CALL, LibCall);
+		FreeItems (RAM_CALL, RAMCall);
+		FreeItems (ROM_CALL, ROMCall);
+#undef FreeItems
+	}
 	else
 #endif /* DEBUGGING_INFO_SUPPORT */
 		FreeSection (Section);