return amount;
}
+#define WARN_UPPER 0
+#define WARN_LOWER 1
+#define WARN_TEXT 0
+#define WARN_DATA 1
+#define WARN_BSS 2
+#define WARN_RODATA 3
+
+/* Warn only once per output section.
+ * NAME starts with ".upper." or ".lower.". */
+static void
+warn_no_output_section (const char *name)
+{
+ static bfd_boolean warned[2][4] = {{FALSE, FALSE, FALSE, FALSE},
+ {FALSE, FALSE, FALSE, FALSE}};
+ int i = WARN_LOWER;
+
+ if (strncmp (name, ".upper.", 7) == 0)
+ i = WARN_UPPER;
+
+ if (!warned[i][WARN_TEXT] && strcmp (name + 6, ".text") == 0)
+ warned[i][WARN_TEXT] = TRUE;
+ else if (!warned[i][WARN_DATA] && strcmp (name + 6, ".data") == 0)
+ warned[i][WARN_DATA] = TRUE;
+ else if (!warned[i][WARN_BSS] && strcmp (name + 6, ".bss") == 0)
+ warned[i][WARN_BSS] = TRUE;
+ else if (!warned[i][WARN_RODATA] && strcmp (name + 6, ".rodata") == 0)
+ warned[i][WARN_RODATA] = TRUE;
+ else
+ return;
+ einfo ("%P: warning: no input section rule matches %s in linker script\n",
+ name);
+}
+
+
/* Place an orphan section. We use this to put .either sections
into either their lower or their upper equivalents. */
if (constraint != 0)
return NULL;
+ if (strncmp (secname, ".upper.", 7) == 0
+ || strncmp (secname, ".lower.", 7) == 0)
+ {
+ warn_no_output_section (secname);
+ return NULL;
+ }
+
/* We only need special handling for .either sections. */
if (strncmp (secname, ".either.", 8) != 0)
return NULL;
return FALSE;
}
-static void
-move_prefixed_section (asection *s, char *new_name,
- lang_output_section_statement_type * new_output_sec)
-{
- s->name = new_name;
- if (s->output_section == NULL)
- lang_add_section (& (new_output_sec->children), s, NULL, new_output_sec);
- else
- {
- lang_output_section_statement_type * curr_output_sec
- = lang_output_section_find (s->output_section->name);
- change_output_section (&(curr_output_sec->children.head), s,
- new_output_sec);
- }
-}
-
static void
add_region_prefix (bfd *abfd, asection *s,
ATTRIBUTE_UNUSED void *unused)
{
const char *curr_name = bfd_get_section_name (abfd, s);
- char * base_name;
- char * new_input_sec_name = NULL;
- char * new_output_sec_name = NULL;
int region = REGION_NONE;
if (strncmp (curr_name, ".text", 5) == 0)
- {
- region = code_region;
- base_name = concat (".text", NULL);
- }
+ region = code_region;
else if (strncmp (curr_name, ".data", 5) == 0)
- {
- region = data_region;
- base_name = concat (".data", NULL);
- }
+ region = data_region;
else if (strncmp (curr_name, ".bss", 4) == 0)
- {
- region = data_region;
- base_name = concat (".bss", NULL);
- }
+ region = data_region;
else if (strncmp (curr_name, ".rodata", 7) == 0)
- {
- region = data_region;
- base_name = concat (".rodata", NULL);
- }
+ region = data_region;
else
return;
case REGION_NONE:
break;
case REGION_UPPER:
- new_input_sec_name = concat (".upper", curr_name, NULL);
- new_output_sec_name = concat (".upper", base_name, NULL);
- lang_output_section_statement_type * upper
- = lang_output_section_find (new_output_sec_name);
- if (upper != NULL)
- {
- move_prefixed_section (s, new_input_sec_name, upper);
- }
- else
- einfo (_("%P: error: no section named %s in linker script\n"),
- new_output_sec_name);
+ bfd_rename_section (abfd, s, concat (".upper", curr_name, NULL));
break;
case REGION_LOWER:
- new_input_sec_name = concat (".lower", curr_name, NULL);
- new_output_sec_name = concat (".lower", base_name, NULL);
- lang_output_section_statement_type * lower
- = lang_output_section_find (new_output_sec_name);
- if (lower != NULL)
- {
- move_prefixed_section (s, new_input_sec_name, lower);
- }
- else
- einfo (_("%P: error: no section named %s in linker script\n"),
- new_output_sec_name);
+ bfd_rename_section (abfd, s, concat (".lower", curr_name, NULL));
break;
case REGION_EITHER:
s->name = concat (".either", curr_name, NULL);
FAIL ();
break;
}
- free (base_name);
- if (new_input_sec_name)
- {
- free (new_input_sec_name);
- free (new_output_sec_name);
- }
}
static void
return
}
-# List contains test-items with 3 items followed by 2 lists and one more item:
-# 0:name 1:ld early options 2:ld late options 3:assembler options
-# 4:filenames of assembler files 5: action and options. 6: name of output file
-
-# Actions:
-# objdump: Apply objdump options on result. Compare with regex (last arg).
-# nm: Apply nm options on result. Compare with regex (last arg).
-# readelf: Apply readelf options on result. Compare with regex (last arg).
-
+# List contains test-items with 3 items followed by 2 lists, one item and
+# one optional item:
+# 0:name
+# 1:ld/ar leading options, placed before object files
+# 2:ld/ar trailing options, placed after object files
+# 3:assembler options
+# 4:filenames of assembler files
+# 5:list of actions, options and expected outputs.
+# 6:name of output file
+# 7:compiler flags (optional)
+#
+# Actions: { command command-line-options file-containg-expected-output-regexps }
+# Commands:
+# objdump: Apply objdump options on result.
+# nm: Apply nm options on result.
+# readelf: Apply readelf options on result.
+# ld: Don't apply anything on result. Compare output during linking with
+# the file containing regexps (which is the second arg, not the third).
+# Note that this *must* be the first action if it is to be used at all;
+# in all other cases, any output from the linker during linking is
+# treated as a sign of an error and FAILs the test.
+#
+#
set msp430regionprefixtests {
{"Move main() to .upper.text" "-T msp430.ld --code-region=upper"
"" "" {main-with-text-rodata.s} {{objdump -d main-text-upper.d}} "main-upper"}
{{objdump -D main-const-upper.d}} "either-to-upper-const-unique-sec"}
}
+set msp430warntests {
+ {"Warn when section cannot be transformed because output section does not exist in linker script (text,data,bss,rodata)"
+ "-T msp430-no-lower.ld --code-region=lower --data-region=lower" "" "" {warn-no-lower.s}
+ {{ld warn-no-lower.r}} "warn-no-lower"}
+ {"Warn when section cannot be transformed because output section does not exist in linker script (text only)"
+ "-T msp430-no-lower.ld --code-region=lower" "" "" {warn-no-lower.s}
+ {{ld warn-no-lower-code.r}} "warn-no-lower-code"}
+ {"Warn when section cannot be transformed because output section does not exist in linker script (data,bss,rodata)"
+ "-T msp430-no-lower.ld --data-region=lower" "" "" {warn-no-lower.s}
+ {{ld warn-no-lower-data.r}} "warn-no-lower-data"}
+}
+
+# Don't run section shuffle tests when msp430 ISA is selected
+if {[string match "*-mcpu=msp430 *" [board_info [target_info name] multilib_flags]]
+ || [string match "*-mcpu=msp430" [board_info [target_info name] multilib_flags]]} {
+ return
+}
run_ld_link_tests $msp430regionprefixtests
run_ld_link_tests $msp430regionprefixuniquesectiontests
run_ld_link_tests $msp430eithershuffletests
+run_ld_link_tests $msp430warntests
+
+run_dump_test valid-map