aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJozef Lawrynowicz <jozef.l@mittosystems.com>2019-07-29 20:23:44 +0000
committerJozef Lawrynowicz <jozefl@gcc.gnu.org>2019-07-29 20:23:44 +0000
commit49c432df666bdb3b680246c94735274a1b39cfc8 (patch)
tree5cbfa54f367e75b1911830bfba3159243508605e /gcc
parent37816988909ba2b10722aff56d7cbd8ff48bf21d (diff)
downloadgcc-49c432df666bdb3b680246c94735274a1b39cfc8.zip
gcc-49c432df666bdb3b680246c94735274a1b39cfc8.tar.gz
gcc-49c432df666bdb3b680246c94735274a1b39cfc8.tar.bz2
MSP430: Disallow use of code/data regions in the small memory model
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/config/msp430/msp430.c35
-rw-r--r--gcc/config/msp430/msp430.h8
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/gcc.target/msp430/pr78818-data-region.c3
-rw-r--r--gcc/testsuite/gcc.target/msp430/region-attribute-misuse.c16
-rw-r--r--gcc/testsuite/gcc.target/msp430/region-misuse-code-data.c4
-rw-r--r--gcc/testsuite/gcc.target/msp430/region-misuse-code.c4
-rw-r--r--gcc/testsuite/gcc.target/msp430/region-misuse-data.c4
9 files changed, 86 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 89faa52..5ab9e12 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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.
diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c
index 265c2f6..c7b774e 100644
--- a/gcc/config/msp430/msp430.c
+++ b/gcc/config/msp430/msp430.c
@@ -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);
diff --git a/gcc/config/msp430/msp430.h b/gcc/config/msp430/msp430.h
index 5b91c83..3361771 100644
--- a/gcc/config/msp430/msp430.h
+++ b/gcc/config/msp430/msp430.h
@@ -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 },
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a52d108..2e69275 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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.
diff --git a/gcc/testsuite/gcc.target/msp430/pr78818-data-region.c b/gcc/testsuite/gcc.target/msp430/pr78818-data-region.c
index 3244c0a..5b0721e 100644
--- a/gcc/testsuite/gcc.target/msp430/pr78818-data-region.c
+++ b/gcc/testsuite/gcc.target/msp430/pr78818-data-region.c
@@ -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
index 0000000..fe4617b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/msp430/region-attribute-misuse.c
@@ -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
index 0000000..72a160d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/msp430/region-misuse-code-data.c
@@ -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
index 0000000..6441b77
--- /dev/null
+++ b/gcc/testsuite/gcc.target/msp430/region-misuse-code.c
@@ -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
index 0000000..07523b6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/msp430/region-misuse-data.c
@@ -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 } */