Labels at ends of functions under Mach-O

Geoffrey Keating gkeating@apple.com
Sat Jul 26 07:26:00 GMT 2003


Suppose you started with aout, and then spent ten years adding new
features to your tools without ever really having time to think about
the overall design or being able to switch to a new object file
format.  You might discover that the result has some design flaws,
especially in edge cases.

I won't try to explain the horrible problems in Mach-O that this patch
is working around; our tools guy claims they are fully documented in
the assembler documentation, and I'm not really interested in reading
the hundreds of pages to find out if he's right.  Suffice to say that,
if you upgrade to the latest Apple devtools, you will get failures in
compile/20000518-1.c among others, and this fixes it.

Bootstrapped & tested on powerpc-darwin.

-- 
- Geoffrey Keating <geoffk@apple.com>

===File ~/patches/rs6000-machofunctionendlab.patch==========
2003-07-26  Geoffrey Keating  <geoffk@apple.com>

	* config/rs6000/rs6000.c (rs6000_output_function_epilogue): Don't
	insert a label at the end of an function under Mach-O.

Index: config/rs6000/rs6000.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.508
diff -u -p -u -p -r1.508 rs6000.c
--- config/rs6000/rs6000.c	24 Jul 2003 02:30:31 -0000	1.508
+++ config/rs6000/rs6000.c	26 Jul 2003 07:18:04 -0000
@@ -12112,6 +12112,23 @@ rs6000_output_function_epilogue (file, s
 	}
     }
 
+#if TARGET_OBJECT_FORMAT == OBJECT_MACHO
+  /* Mach-O doesn't support labels at the end of objects, so if
+     it looks like we might want one, insert a NOP.  */
+  {
+    rtx insn = get_last_insn ();
+    while (insn
+	   && NOTE_P (insn)
+	   && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL)
+      insn = PREV_INSN (insn);
+    if (insn 
+	&& (LABEL_P (insn) 
+	    || (NOTE_P (insn)
+		&& NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
+      fputs ("\tnop\n", file);
+  }
+#endif
+
   /* Output a traceback table here.  See /usr/include/sys/debug.h for info
      on its format.
 
============================================================



More information about the Gcc-patches mailing list