| View previous topic :: View next topic |
| Author |
Message |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Mon Mar 10, 2008 6:27 am Post subject: Patches "-mpreferred-stack-boundary" for gcc-4.1.0 |
|
|
Wintermute PMs me :
| Quote: | | A couple of devkitPSP users have been asking about getting a version of the toolchain which includes your preferred stack boundary patch. I noticed it's gone from the latest psp svn patches & I've been having a bit of trouble getting it to apply to 4.1.2. |
Sure, there is some substantial changes between 4.0.x and 4.1.x to handle, but once the right patches are created, it is easy to add the option "-mpreferred-stack-boundary=n" now.
I decided to make it publicly here in case some other people may be interested.
We need to patch three files :
- mips.c.patch
| Code: | Index: mips.c
===================================================================
--- mips.c (revision 13)
+++ mips.c (working copy)
@@ -612,6 +612,8 @@
should arrange to call mips32 hard floating point code. */
int mips16_hard_float;
+unsigned int mips_preferred_stack_boundary;
+unsigned int mips_preferred_stack_align;
/* The architecture selected by -mipsN. */
static const struct mips_cpu_info *mips_isa_info;
@@ -5057,6 +5059,21 @@
mips_lo_relocs[SYMBOL_GOTOFF_LOADGP] = "%lo(%neg(%gp_rel(";
}
+ /* Validate -mpreferred-stack-boundary= value, or provide default.
+ The default of 128-bit is for newABI else 64-bit. */
+ mips_preferred_stack_boundary = (TARGET_NEWABI ? 128 : 64);
+ mips_preferred_stack_align = (TARGET_NEWABI ? 16 : 8);
+ if (mips_preferred_stack_boundary_string)
+ {
+ i = atoi (mips_preferred_stack_boundary_string);
+ if (i < 2 || i > 12)
+ error ("-mpreferred-stack-boundary=%d is not between 2 and 12", i);
+ else
+ {
+ mips_preferred_stack_align = (1 << i);
+ mips_preferred_stack_boundary = mips_preferred_stack_align * 8;
+ }
+ }
/* Thread-local relocation operators. */
mips_lo_relocs[SYMBOL_TLSGD] = "%tlsgd(";
mips_lo_relocs[SYMBOL_TLSLDM] = "%tlsldm(";
|
- mips.h.patch
| Code: | Index: mips.h
===================================================================
--- mips.h (revision 13)
+++ mips.h (working copy)
@@ -1953,7 +1953,7 @@
`current_function_outgoing_args_size'. */
#define OUTGOING_REG_PARM_STACK_SPACE
-#define STACK_BOUNDARY (TARGET_NEWABI ? 128 : 64)
+#define STACK_BOUNDARY (mips_preferred_stack_boundary)
#define RETURN_POPS_ARGS(FUNDECL,FUNTYPE,SIZE) 0
@@ -2109,7 +2109,7 @@
/* Treat LOC as a byte offset from the stack pointer and round it up
to the next fully-aligned offset. */
#define MIPS_STACK_ALIGN(LOC) \
- (TARGET_NEWABI ? ((LOC) + 15) & -16 : ((LOC) + 7) & -8)
+ ((LOC) + (mips_preferred_stack_align - 1) & -(mips_preferred_stack_align))
/* Implement `va_start' for varargs and stdarg. */
@@ -2812,6 +2812,9 @@
#endif
#endif
+extern unsigned int mips_preferred_stack_boundary;
+extern unsigned int mips_preferred_stack_align;
+extern const char *mips_preferred_stack_boundary_string;
#ifndef HAVE_AS_TLS
#define HAVE_AS_TLS 0
#endif
|
- mips.opt.patch (new file in 4.1.0)
| Code: | Index: mips.opt
===================================================================
--- mips.opt (revision 13)
+++ mips.opt (working copy)
@@ -216,3 +216,7 @@
mxgot
Target Report Var(TARGET_XGOT)
Lift restrictions on GOT size
+
+mpreferred-stack-boundary=
+Target RejectNegative Joined Var(mips_preferred_stack_boundary_string)
+Attempt to keep stack aligned to this power of 2
|
I successfully tested them with psp-gcc 4.1.0 (cygwin - psptoolchain). |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Mon Mar 10, 2008 9:32 am Post subject: |
|
|
| If you provide a single patch against current SVN I could put that in the standard toolchain for you. |
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Mon Mar 10, 2008 9:40 am Post subject: |
|
|
| jimparis wrote: | | If you provide a single patch against current SVN I could put that in the standard toolchain for you. |
this one ?
| Code: | Index: gcc/config/mips/mips.c
===================================================================
--- gcc/config/mips/mips.c (revision 13)
+++ gcc/config/mips/mips.c (working copy)
@@ -612,6 +612,8 @@
should arrange to call mips32 hard floating point code. */
int mips16_hard_float;
+unsigned int mips_preferred_stack_boundary;
+unsigned int mips_preferred_stack_align;
/* The architecture selected by -mipsN. */
static const struct mips_cpu_info *mips_isa_info;
@@ -5057,6 +5059,21 @@
mips_lo_relocs[SYMBOL_GOTOFF_LOADGP] = "%lo(%neg(%gp_rel(";
}
+ /* Validate -mpreferred-stack-boundary= value, or provide default.
+ The default of 128-bit is for newABI else 64-bit. */
+ mips_preferred_stack_boundary = (TARGET_NEWABI ? 128 : 64);
+ mips_preferred_stack_align = (TARGET_NEWABI ? 16 : 8);
+ if (mips_preferred_stack_boundary_string)
+ {
+ i = atoi (mips_preferred_stack_boundary_string);
+ if (i < 4 || i > 12)
+ error ("-mpreferred-stack-boundary=%d is not between 4 and 12", i);
+ else
+ {
+ mips_preferred_stack_align = (1 << i);
+ mips_preferred_stack_boundary = mips_preferred_stack_align * 8;
+ }
+ }
/* Thread-local relocation operators. */
mips_lo_relocs[SYMBOL_TLSGD] = "%tlsgd(";
mips_lo_relocs[SYMBOL_TLSLDM] = "%tlsldm(";
Index: gcc/config/mips/mips.h
===================================================================
--- gcc/config/mips/mips.h (revision 13)
+++ gcc/config/mips/mips.h (working copy)
@@ -1953,7 +1953,7 @@
`current_function_outgoing_args_size'. */
#define OUTGOING_REG_PARM_STACK_SPACE
-#define STACK_BOUNDARY (TARGET_NEWABI ? 128 : 64)
+#define STACK_BOUNDARY (mips_preferred_stack_boundary)
#define RETURN_POPS_ARGS(FUNDECL,FUNTYPE,SIZE) 0
@@ -2109,7 +2109,7 @@
/* Treat LOC as a byte offset from the stack pointer and round it up
to the next fully-aligned offset. */
#define MIPS_STACK_ALIGN(LOC) \
- (TARGET_NEWABI ? ((LOC) + 15) & -16 : ((LOC) + 7) & -8)
+ ((LOC) + (mips_preferred_stack_align - 1) & -(mips_preferred_stack_align))
/* Implement `va_start' for varargs and stdarg. */
@@ -2812,6 +2812,9 @@
#endif
#endif
+extern unsigned int mips_preferred_stack_boundary;
+extern unsigned int mips_preferred_stack_align;
+extern const char *mips_preferred_stack_boundary_string;
#ifndef HAVE_AS_TLS
#define HAVE_AS_TLS 0
#endif
Index: gcc/config/mips/mips.opt
===================================================================
--- gcc/config/mips/mips.opt (revision 13)
+++ gcc/config/mips/mips.opt (working copy)
@@ -216,3 +216,7 @@
mxgot
Target Report Var(TARGET_XGOT)
Lift restrictions on GOT size
+
+mpreferred-stack-boundary=
+Target RejectNegative Joined Var(mips_preferred_stack_boundary_string)
+Attempt to keep stack aligned to this power of 2
|
I'm using TortoiseSVN to create this patch. I don't know how you make yours (supposedly you want to have it in gcc-4.1.0-PSP.patch). I can also email you this patch (apparently this patch has some page jump characters I cannot remove without breaking the patch) if you want something more solid (if so, just PM me where I must send it) |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Mon Mar 10, 2008 2:22 pm Post subject: |
|
|
Well, I'd need something that I can apply with "patch" directly to a checked out copy of svn://svn.pspdev.org/psp/trunk/psptoolchain. There is no "Ygcc/config/mips/mips.c " in the repository (and it's definitely not revision 13, we're at 2366 or so).
Yeah, it would probably patch the file gcc-4.1.0-PSP.patch. |
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Mon Mar 10, 2008 5:27 pm Post subject: |
|
|
| jimparis wrote: | Well, I'd need something that I can apply with "patch" directly to a checked out copy of svn://svn.pspdev.org/psp/trunk/psptoolchain. There is no "Ygcc/config/mips/mips.c " in the repository (and it's definitely not revision 13, we're at 2366 or so).
Yeah, it would probably patch the file gcc-4.1.0-PSP.patch. |
directly to modify this patch to include mine may be hazardous.
the only thing i can see is to have two directories on a top directory : one with the original gcc (without any PSP patches) named gcc-4.1.0 and one named gcc-psp with gcc-4.1.0-PSP.patch AND my patch applied. Once done, create a newer gcc-4.1.0-PSP.patch from diff of the tops of those directories, probably with : "diff -burN gcc-4.1.0 gcc-psp" on the top directory of both gcc directories.
I'll try it when i'm back at home tonight. |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Mon Mar 10, 2008 8:51 pm Post subject: |
|
|
| Yep that sounds about right. It's a pain but that's why I asked you to do it instead of me :) (plus I'm not set up to test that it still works correctly at the moment) |
|
| Back to top |
|
 |
Heimdall
Joined: 10 Nov 2005 Posts: 259 Location: Netherlands
|
Posted: Tue Mar 11, 2008 3:50 am Post subject: |
|
|
By the time of writing of this post i'm uploading a SDK build with your patch. Since I haven't tested the new feature I've created a folder called experimental at:
http://www.box.net/shared/syudygao00
Please see if the compiler works as expected (it builds OK all the templates) but they do not use the new compiler option.
If everything is alright I'll move the SDK to the parent folder bumping the version from 0.6 to 0.6.1. |
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Tue Mar 11, 2008 6:55 am Post subject: |
|
|
First test : is the new option not rejected by gcc ? FAILURE
| Quote: | ------ Rebuild All started: Project: hurrican, Configuration: Debug Win32 ------
Performing Makefile project actions
d:/dev/pspsdk/bin/rm -f hurrican.prx hurrican.elf main.o PARAM.SFO EBOOT.PBP EBOOT.PBP
psp-g++ -I. -Id:/dev/pspsdk/psp/sdk/include -O3 -G0 -Wall -mpreferred-stack-boundary=12 -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150 -c -o main.o main.cpp
cc1plus.exe: error: unrecognized command line option "-mpreferred-stack-boundary=12"
make: *** [main.o] Error 1
Build log was saved at "file://d:\dev\hurrican\dists\psp\Debug\BuildLog.htm"
hurrican - 1 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
|
I also used -v to check if the right gcc was called and it was the case. |
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Tue Mar 11, 2008 8:46 am Post subject: |
|
|
| jimparis wrote: | | Yep that sounds about right. It's a pain but that's why I asked you to do it instead of me :) (plus I'm not set up to test that it still works correctly at the moment) |
new gcc-4.1.0.patch at http://hlide.free.fr/download/PSP/gcc-4.1.0-PSP.patch.
EDIT: i applied this patch on a non psp gcc-4.1.0, then copied the three files mips.c/h/opt on my psptoolchain\build\gcc-4.1.0\build-psp\gcc\config\mips directory so i can build it quickly (just removing mips.o is enough to make it recompile).
Once installed, i tried -mpreferred-stack-boundary=12 and get the stack base in functions prologs and epilogs to be 4096-byte aligned, which is correct. |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Tue Mar 11, 2008 12:57 pm Post subject: |
|
|
| Committed to revision 2367, thanks! |
|
| Back to top |
|
 |
Heimdall
Joined: 10 Nov 2005 Posts: 259 Location: Netherlands
|
Posted: Tue Mar 11, 2008 11:36 pm Post subject: |
|
|
My bad, I forgot to make clean ;) before!
0.6.2 includes the official patch and accepts the parameter. |
|
| Back to top |
|
 |
|