+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
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)
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);
#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 },
+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
/* { 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" } } */
--- /dev/null
+/* { 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;
--- /dev/null
+/* { 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 } */
--- /dev/null
+/* { 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 } */
--- /dev/null
+/* { 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 } */