MSP430: Disallow use of code/data regions in the small memory model
authorJozef Lawrynowicz <jozef.l@mittosystems.com>
Mon, 29 Jul 2019 20:23:44 +0000 (20:23 +0000)
committerJozef Lawrynowicz <jozefl@gcc.gnu.org>
Mon, 29 Jul 2019 20:23:44 +0000 (20:23 +0000)
gcc/ChangeLog:

2019-07-29  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

* config/msp430/msp430.h (DRIVER_SELF_SPECS): Define and emit errors
when -m{code,data}-region are used without -mlarge.
* config/msp430/msp430.c (msp430_option_override): Error when a
non-default code or data region is used without -mlarge.
(msp430_section_attr): Emit a warning and do not add upper/lower/either
attributes when they are used without -mlarge.

gcc/testsuite/ChangeLog:

2019-07-29  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

* gcc.target/msp430/pr78818-data-region.c: Add -mlarge to dg-options.
* gcc.target/msp430/region-misuse-code.c: New test.
* gcc.target/msp430/region-misuse-data.c: Likewise.
* gcc.target/msp430/region-misuse-code-data.c: Likewise.
* gcc.target/msp430/region-attribute-misuse.c: Likewise.

From-SVN: r273884

gcc/ChangeLog
gcc/config/msp430/msp430.c
gcc/config/msp430/msp430.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/msp430/pr78818-data-region.c
gcc/testsuite/gcc.target/msp430/region-attribute-misuse.c [new file with mode: 0644]
gcc/testsuite/gcc.target/msp430/region-misuse-code-data.c [new file with mode: 0644]
gcc/testsuite/gcc.target/msp430/region-misuse-code.c [new file with mode: 0644]
gcc/testsuite/gcc.target/msp430/region-misuse-data.c [new file with mode: 0644]

index 89faa52..5ab9e12 100644 (file)
@@ -1,5 +1,14 @@
 2019-07-29  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
 
+       * config/msp430/msp430.h (DRIVER_SELF_SPECS): Define and emit errors
+       when -m{code,data}-region are used without -mlarge.
+       * config/msp430/msp430.c (msp430_option_override): Error when a
+       non-default code or data region is used without -mlarge.
+       (msp430_section_attr): Emit a warning and do not add upper/lower/either
+       attributes when they are used without -mlarge.
+
+2019-07-29  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
+
        PR target/70320
        * config/msp430/msp430.h: Define ADDITIONAL_REGISTER_NAMES.
 
index 265c2f6..c7b774e 100644 (file)
@@ -875,10 +875,26 @@ msp430_option_override (void)
   if (TARGET_LARGE && !msp430x)
     error ("%<-mlarge%> requires a 430X-compatible %<-mmcu=%>");
 
-  if (msp430_code_region == MSP430_REGION_UPPER && ! msp430x)
-    error ("%<-mcode-region=upper%> requires 430X-compatible cpu");
-  if (msp430_data_region == MSP430_REGION_UPPER && ! msp430x)
-    error ("%<-mdata-region=upper%> requires 430X-compatible cpu");
+  if (!TARGET_LARGE && msp430_code_region == MSP430_REGION_EITHER)
+    error ("%<-mcode-region=either%> requires the large memory model "
+          "(%<-mlarge%>)");
+  else if (!TARGET_LARGE && msp430_code_region == MSP430_REGION_UPPER)
+    error ("%<-mcode-region=upper%> requires the large memory model "
+          "(%<-mlarge%>)");
+  else if (!TARGET_LARGE && msp430_code_region == MSP430_REGION_LOWER)
+    error ("%<-mcode-region=lower%> requires the large memory model "
+          "(%<-mlarge%>)");
+
+  if (!TARGET_LARGE && msp430_data_region == MSP430_REGION_EITHER)
+    error ("%<-mdata-region=either%> requires the large memory model "
+          "(%<-mlarge%>)");
+  else if (!TARGET_LARGE && msp430_data_region == MSP430_REGION_UPPER)
+    error ("%<-mdata-region=upper%> requires the large memory model "
+          "(%<-mlarge%>)");
+  else if (!TARGET_LARGE && msp430_data_region == MSP430_REGION_LOWER)
+    error ("%<-mdata-region=lower%> requires the large memory model "
+          "(%<-mlarge%>)");
+
 
   if (flag_exceptions || flag_non_call_exceptions
       || flag_unwind_tables || flag_asynchronous_unwind_tables)
@@ -2038,6 +2054,17 @@ msp430_section_attr (tree * node,
        message = "already marked with 'upper' attribute";
     }
 
+  /* It does not make sense to use upper/lower/either attributes without
+     -mlarge.
+     Without -mlarge, "lower" is the default and only region, so is redundant.
+     Without -mlarge, "upper" will (and "either" might) place code/data in the
+     upper region, which for data could result in relocation overflows, and for
+     code could result in stack mismanagement and incorrect call/return
+     instructions.  */
+  if (!TARGET_LARGE)
+    message = G_("%qE attribute ignored. large memory model (%<-mlarge%>) "
+                "is required");
+
   if (message)
     {
       warning (OPT_Wattributes, message, name);
index 5b91c83..3361771 100644 (file)
@@ -68,6 +68,14 @@ extern bool msp430x;
 #define LINK_SPEC "%{mrelax:--relax} %{mlarge:%{!r:%{!g:--gc-sections}}} " \
   "%{mcode-region=*:--code-region=%*} %{mdata-region=*:--data-region=%*}"
 
+#define DRIVER_SELF_SPECS \
+  " %{!mlarge:%{mcode-region=*:%{mdata-region=*:%e-mcode-region and "  \
+    "-mdata-region require the large memory model (-mlarge)}}}" \
+  " %{!mlarge:%{mcode-region=*:"       \
+    "%e-mcode-region requires the large memory model (-mlarge)}}"      \
+  " %{!mlarge:%{mdata-region=*:"       \
+    "%e-mdata-region requires the large memory model (-mlarge)}}"
+
 extern const char * msp430_select_hwmult_lib (int, const char **);
 # define EXTRA_SPEC_FUNCTIONS                          \
   { "msp430_hwmult_lib", msp430_select_hwmult_lib },
index a52d108..2e69275 100644 (file)
@@ -1,5 +1,13 @@
 2019-07-29  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
 
+       * gcc.target/msp430/pr78818-data-region.c: Add -mlarge to dg-options.
+       * gcc.target/msp430/region-misuse-code.c: New test.
+       * gcc.target/msp430/region-misuse-data.c: Likewise.
+       * gcc.target/msp430/region-misuse-code-data.c: Likewise.
+       * gcc.target/msp430/region-attribute-misuse.c: Likewise.
+
+2019-07-29  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
+
        PR target/70320
        * gcc.target/msp430/asm-register-names-lower-case.c: New test.
        * gcc.target/msp430/asm-register-names-upper-case.c: Likewise.
index 3244c0a..5b0721e 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
-/* { dg-options "-mdata-region=either" } */
+/* { dg-skip-if "" { *-*-* } { "-mcpu=msp430" } { "" } } */
+/* { dg-options "-mlarge -mdata-region=either" } */
 
 /* { dg-final { scan-assembler-not "\\.either\\.data" } } */
 /* { dg-final { scan-assembler-not "\\.either\\.bss" } } */
diff --git a/gcc/testsuite/gcc.target/msp430/region-attribute-misuse.c b/gcc/testsuite/gcc.target/msp430/region-attribute-misuse.c
new file mode 100644 (file)
index 0000000..fe4617b
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-mcpu=msp430" "-mlarge" "-mcode-region=*" "-mdata-region=*" } { "" } } */
+/* { dg-final { scan-assembler-not ".section.*bss" } } */
+/* { dg-final { scan-assembler ".section.*upper.data" } } */
+/* { dg-final { scan-assembler ".section.*lower.data" } } */
+/* { dg-final { scan-assembler ".section.*either.data" } } */
+
+int __attribute__((upper)) upper_bss; /* { dg-warning "'upper' attribute ignored. large memory model .'-mlarge'. is required" } */
+int __attribute__((lower)) lower_bss; /* { dg-warning "'lower' attribute ignored. large memory model .'-mlarge'. is required" } */
+int __attribute__((either)) either_bss; /* { dg-warning "'either' attribute ignored. large memory model .'-mlarge'. is required" } */
+
+/* Verify that even without -mlarge, objects can still be placed in
+   upper/lower/either regions manually.  */
+int __attribute__((section(".upper.data"))) upper_data = 1;
+int __attribute__((section(".lower.data"))) lower_data = 2;
+int __attribute__((section(".either.data"))) either_data = 3;
diff --git a/gcc/testsuite/gcc.target/msp430/region-misuse-code-data.c b/gcc/testsuite/gcc.target/msp430/region-misuse-code-data.c
new file mode 100644 (file)
index 0000000..72a160d
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-mlarge" } { "" } } */
+/* { dg-options "-mcode-region=either -mdata-region=none" } */
+/* { dg-error "-mcode-region and -mdata-region require the large memory model .-mlarge." "" { target *-*-* } 0 } */
diff --git a/gcc/testsuite/gcc.target/msp430/region-misuse-code.c b/gcc/testsuite/gcc.target/msp430/region-misuse-code.c
new file mode 100644 (file)
index 0000000..6441b77
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-mlarge" "-mdata-region=*" } { "" } } */
+/* { dg-options "-mcode-region=lower" } */
+/* { dg-error "-mcode-region requires the large memory model .-mlarge." "" { target *-*-* } 0 } */
diff --git a/gcc/testsuite/gcc.target/msp430/region-misuse-data.c b/gcc/testsuite/gcc.target/msp430/region-misuse-data.c
new file mode 100644 (file)
index 0000000..07523b6
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-mlarge" "-mdata-region=*" } { "" } } */
+/* { dg-options "-mdata-region=upper" } */
+/* { dg-error "-mdata-region requires the large memory model .-mlarge." "" { target *-*-* } 0 } */