This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch to fix -falign-labels
- From: Samuel Figueroa <figueroa at apple dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 16 Sep 2002 17:38:31 -0700
- Subject: Patch to fix -falign-labels
Currently (as of Sept. 9, 2002), -falign-labels doesn't work on some
platforms, such as Solaris and Mac OS X. The reason is that the .align
assembler directive that is emitted pads the text section with zeros,
which is an illegal instruction on some platforms. The following patch
fixes this for Solaris and provides a hook for fixing it on other
platforms.
* final.c (final_scan_insn): Use new macro ASM_OUTPUT_ALIGN_WITH_NOP.
*sparc.h (ASM_OUTPUT_ALIGN_WITH_NOP) New macro.
* doc/tm.texi (ASM_OUTPUT_ALIGN_WITH_NOP) New description.
*** final.c.orig Tue Aug 20 22:41:44 2002
--- final.c Mon Sep 16 19:00:11 2002
***************
*** 2185,2192 ****
--- 2185,2196 ----
#ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
ASM_OUTPUT_MAX_SKIP_ALIGN (file, align, max_skip);
#else
+ #ifdef ASM_OUTPUT_ALIGN_WITH_NOP
+ ASM_OUTPUT_ALIGN_WITH_NOP (file, align);
+ #else
ASM_OUTPUT_ALIGN (file, align);
#endif
+ #endif
}
}
#ifdef HAVE_cc0
*** config/sparc/sparc.h.orig Thu Aug 29 17:40:18 2002
--- config/sparc/sparc.h Mon Sep 16 18:42:10 2002
***************
*** 2812,2817 ****
--- 2812,2825 ----
if ((LOG) != 0) \
fprintf (FILE, "\t.align %d\n", (1<<(LOG)))
+ /* This is how to output an assembler line that says to advance
+ the location counter to a multiple of 2**LOG bytes using the
+ "nop" instruction as padding. */
+
+ #define ASM_OUTPUT_ALIGN_WITH_NOP(FILE,LOG) \
+ if ((LOG) != 0) \
+ fprintf (FILE, "\t.align %d,0x1000000\n", (1<<(LOG)))
+
#define ASM_OUTPUT_SKIP(FILE,SIZE) \
fprintf (FILE, "\t.skip %u\n", (SIZE))
*** doc/tm.texi.orig Mon Sep 9 13:04:32 2002
--- doc/tm.texi Mon Sep 16 17:33:12 2002
***************
*** 7593,7598 ****
--- 7593,7603 ----
command to advance the location counter to a multiple of 2 to the
@var{power} bytes. @var{power} will be a C expression of type
@code{int}.
+ @findex ASM_OUTPUT_ALIGN_WITH_NOP
+ @item ASM_OUTPUT_ALIGN_WITH_NOP (@var{stream}, @var{power})
+ Like @code{ASM_OUTPUT_ALIGN}, except that the ``nop'' instruction is
used
+ for padding, if necessary.
+
@findex ASM_OUTPUT_MAX_SKIP_ALIGN
@item ASM_OUTPUT_MAX_SKIP_ALIGN (@var{stream}, @var{power},
@var{max_skip})
A C statement to output to the stdio stream @var{stream} an assembler
Here is the program I used as a test case (just because it happened to
be conveniently available to me):
#include <stdio.h>
void foo (int count, char* pca, char* pcb);
main () {
char a[] = "Hello, world!";
char b = 'S';
printf ("%s\n", a);
foo (1, a, &b);
printf ("%s\n", a);
}
void foo (int count, char* pca, char* pcb) {
int i;
*pca = *pcb;
if (count > 10)
for (i = 0; i < count; ++i)
pcb += i;
else
for (i = 0; i < count; ++i)
pca += i;
*pca = *pcb;
}