x86-64 default memory models

Leif Ekblad leif@rdos.net
Sun Dec 16 10:35:00 GMT 2012


Hi,

There seems to be something missing in regards to default memory models in 
the C compiler. There are memory model switches for small, medium and large 
memory models, and there are switches for position independent code (pic and 
pie), but there is no way (that I can find) to build a cross-compiler that 
defaults to anything else than the small memory model. There is a special 
case for Windows-based platforms that changes to small memory model and pic, 
but other than that, the default seems to be small memory model and no pic. 
I imagine this supports the major platforms (Linux, Windows), so nobody 
thinks there is a need for other cases.

Since it is not possible to build different parts of an application with 
different memory model switches, there is a need to build everything with 
the same switches, including libgcc and libc/newlib. It is no good to patch 
every project with these switches, as it adds unnecesary complexity to these 
projects as well. Therefore, there is a need to be able to build cross 
compilers that have other defaults for memory model than small.

I posted a prosed solution for this eariler, but got no relevant responses 
for it, so here it is again:

1. Add a new macro to i386.h:

diff -u -r -N gcc-4.8-20121202/gcc/config/i386/i386.h
gcc-work/gcc/config/i386/i386.h
--- gcc-4.8-20121202/gcc/config/i386/i386.h 2012-11-23 17:02:10.000000000
+0100
+++ gcc-work/gcc/config/i386/i386.h 2012-12-08 12:17:40.000000000 +0100
@@ -86,6 +86,8 @@
 #define TARGET_LP64 TARGET_ABI_64
 #define TARGET_X32 TARGET_ABI_X32
+#define TARGET_MEDIUM_PIC   0
+
 /* SSE4.1 defines round instructions */
 #define OPTION_MASK_ISA_ROUND OPTION_MASK_ISA_SSE4_1
 #define TARGET_ISA_ROUND ((ix86_isa_flags & OPTION_MASK_ISA_ROUND) != 0)

2. Add support for the macro in i386.c:

diff -u -r -N gcc-4.8-20121202/gcc/config/i386/i386.c
gcc-work/gcc/config/i386/i386.c
--- gcc-4.8-20121202/gcc/config/i386/i386.c 2012-12-02 00:43:52.000000000
+0100
+++ gcc-work/gcc/config/i386/i386.c 2012-12-11 21:43:48.000000000 +0100
@@ -3235,6 +3235,8 @@
   DLL, and is essentially just as efficient as direct addressing.  */
       if (TARGET_64BIT && DEFAULT_ABI == MS_ABI)
  ix86_cmodel = CM_SMALL_PIC, flag_pic = 1;
+      else if (TARGET_64BIT && TARGET_MEDIUM_PIC)
+    ix86_cmodel = CM_MEDIUM_PIC, flag_pic = 1;
       else if (TARGET_64BIT)
  ix86_cmodel = flag_pic ? CM_SMALL_PIC : CM_SMALL;
       else

3. Override the macro in an OS-defined file:

+#undef TARGET_MEDIUM_PIC
+#define TARGET_MEDIUM_PIC 1

Regards,
Leif Ekblad



More information about the Gcc mailing list