[MSP430] Define __crt0_init_bss/__crt0_movedata symbols when .lower or .either prefixed sections are present

Message ID 20190417120147.0b44689c@jozef-kubuntu
State New
Headers show
Series
  • [MSP430] Define __crt0_init_bss/__crt0_movedata symbols when .lower or .either prefixed sections are present
Related show

Commit Message

Jozef Lawrynowicz April 17, 2019, 11:01 a.m.
To facilitate a reduced code size runtime environment, the MSP430 assembler
defines symbols to "pull in" functions from the runtime (crt0) only when they
are required. The assembler examines the section names in the input file to
determine which symbols need to be defined.
For example, the symbol for a function which initializes data in the
upper memory region is only defined if there is a data section which has a name
starting with ".upper".

The attached patch changes the behaviour so symbols for functions that
initialize data and bss in the lower region are also defined if a section name
starting with ".lower" or ".either" is seen.

Successfully regtested the gas testsuite with these changes.

If the patch is acceptable, I would appreciate if someone would commit it for
me, as I do not have write access.

Thanks,
Jozef

Comments

Nick Clifton April 17, 2019, 2:07 p.m. | #1
Hi Jozef,

> The attached patch changes the behaviour so symbols for functions that

> initialize data and bss in the lower region are also defined if a section name

> starting with ".lower" or ".either" is seen.

> 

> Successfully regtested the gas testsuite with these changes.

> 

> If the patch is acceptable, I would appreciate if someone would commit it for

> me, as I do not have write access.


Approved and applied.

Cheers
  Nick

Patch

From 23b303fa266970e1272bca7bf7e6a98271164890 Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
Date: Tue, 16 Apr 2019 22:05:35 +0100
Subject: [PATCH] MSP430: Define __crt0_init_bss/__crt0_movedata symbols when
 .lower or .either prefixed sections are present

gas/ChangeLog:

2019-04-17  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	* config/tc-msp430.c (msp430_make_init_symbols): Define __crt0_init_bss
	symbol when .lower.bss or .either.bss sections exist.
	Define __crt0_movedata when .lower.data or .either.data sections exist.
	* testsuite/gas/msp430/either-data-bss-sym.d: New test.
	* testsuite/gas/msp430/low-data-bss-sym.d: New test.
	* testsuite/gas/msp430/either-data-bss-sym.s: New test source.
	* testsuite/gas/msp430/low-data-bss-sym.s: New test source.
	* testsuite/gas/msp430/msp430.exp: Run new tests.
	Enable large code model when running -mdata-region={upper,either}
	tests.
---
 gas/config/tc-msp430.c                        |  5 +++-
 .../gas/msp430/either-data-bss-sym.d          |  9 +++++++
 .../gas/msp430/either-data-bss-sym.s          | 24 +++++++++++++++++++
 gas/testsuite/gas/msp430/low-data-bss-sym.d   |  7 ++++++
 gas/testsuite/gas/msp430/low-data-bss-sym.s   | 24 +++++++++++++++++++
 gas/testsuite/gas/msp430/msp430.exp           |  6 +++--
 6 files changed, 72 insertions(+), 3 deletions(-)
 create mode 100644 gas/testsuite/gas/msp430/either-data-bss-sym.d
 create mode 100644 gas/testsuite/gas/msp430/either-data-bss-sym.s
 create mode 100644 gas/testsuite/gas/msp430/low-data-bss-sym.d
 create mode 100644 gas/testsuite/gas/msp430/low-data-bss-sym.s

diff --git a/gas/config/tc-msp430.c b/gas/config/tc-msp430.c
index 31bbdbbc81..4374133df5 100644
--- a/gas/config/tc-msp430.c
+++ b/gas/config/tc-msp430.c
@@ -1484,13 +1484,16 @@  static void
 msp430_make_init_symbols (const char * name)
 {
   if (strncmp (name, ".bss", 4) == 0
+      || strncmp (name, ".lower.bss", 10) == 0
+      || strncmp (name, ".either.bss", 11) == 0
       || strncmp (name, ".gnu.linkonce.b.", 16) == 0)
     (void) symbol_find_or_make ("__crt0_init_bss");
 
   if (strncmp (name, ".data", 5) == 0
+      || strncmp (name, ".lower.data", 11) == 0
+      || strncmp (name, ".either.data", 12) == 0
       || strncmp (name, ".gnu.linkonce.d.", 16) == 0)
     (void) symbol_find_or_make ("__crt0_movedata");
-
   /* Note - data assigned to the .either.data section may end up being
      placed in the .upper.data section if the .lower.data section is
      full.  Hence the need to define the crt0 symbol.
diff --git a/gas/testsuite/gas/msp430/either-data-bss-sym.d b/gas/testsuite/gas/msp430/either-data-bss-sym.d
new file mode 100644
index 0000000000..9e4154fe95
--- /dev/null
+++ b/gas/testsuite/gas/msp430/either-data-bss-sym.d
@@ -0,0 +1,9 @@ 
+#objdump: -t
+#name: Check symbols to initialise data and bss have been defined for .either sections
+#...
+.*__crt0_movedata.*
+.*__crt0_move_highdata.*
+#...
+.*__crt0_init_bss.*
+.*__crt0_init_highbss.*
+#pass
diff --git a/gas/testsuite/gas/msp430/either-data-bss-sym.s b/gas/testsuite/gas/msp430/either-data-bss-sym.s
new file mode 100644
index 0000000000..c847d9e2ce
--- /dev/null
+++ b/gas/testsuite/gas/msp430/either-data-bss-sym.s
@@ -0,0 +1,24 @@ 
+	.file	"main.c"
+.text
+	.global	a
+	.section	.either.data,"aw"
+	.balign 2
+	.type	a, @object
+	.size	a, 2
+a:
+	.short	42
+	.global	b
+	.section	.either.bss,"aw",@nobits
+	.balign 2
+	.type	b, @object
+	.size	b, 2
+b:
+	.zero	2
+.text
+	.balign 2
+	.global	main
+	.type	main, @function
+main:
+.L2:
+	BR	#.L2
+	.size	main, .-main
diff --git a/gas/testsuite/gas/msp430/low-data-bss-sym.d b/gas/testsuite/gas/msp430/low-data-bss-sym.d
new file mode 100644
index 0000000000..0ed57c6d69
--- /dev/null
+++ b/gas/testsuite/gas/msp430/low-data-bss-sym.d
@@ -0,0 +1,7 @@ 
+#objdump: -t
+#name: Check symbols to initialise data and bss have been defined for .lower sections
+#...
+.*__crt0_movedata.*
+#...
+.*__crt0_init_bss.*
+#pass
diff --git a/gas/testsuite/gas/msp430/low-data-bss-sym.s b/gas/testsuite/gas/msp430/low-data-bss-sym.s
new file mode 100644
index 0000000000..317fb175a1
--- /dev/null
+++ b/gas/testsuite/gas/msp430/low-data-bss-sym.s
@@ -0,0 +1,24 @@ 
+	.file	"main.c"
+.text
+	.global	a
+	.section	.lower.data,"aw"
+	.balign 2
+	.type	a, @object
+	.size	a, 2
+a:
+	.short	42
+	.global	b
+	.section	.lower.bss,"aw",@nobits
+	.balign 2
+	.type	b, @object
+	.size	b, 2
+b:
+	.zero	2
+.text
+	.balign 2
+	.global	main
+	.type	main, @function
+main:
+.L2:
+	BR	#.L2
+	.size	main, .-main
diff --git a/gas/testsuite/gas/msp430/msp430.exp b/gas/testsuite/gas/msp430/msp430.exp
index 6d02d2a9f7..9f6d0234ad 100644
--- a/gas/testsuite/gas/msp430/msp430.exp
+++ b/gas/testsuite/gas/msp430/msp430.exp
@@ -24,8 +24,10 @@  if [expr [istarget "msp430-*-*"]]  then {
     run_dump_test "bad"
     run_dump_test "errata_warns"
     run_dump_test "errata_fixes"
-    run_dump_test "high-data-bss-sym" { { as "-mdata-region=upper" } }
-    run_dump_test "high-data-bss-sym" { { as "-mdata-region=either" } }
+    run_dump_test "low-data-bss-sym"
+    run_dump_test "either-data-bss-sym"
+    run_dump_test "high-data-bss-sym" { { as "-ml -mdata-region=upper" } }
+    run_dump_test "high-data-bss-sym" { { as "-ml -mdata-region=either" } }
     run_dump_test "pr22133"
     run_dump_test "nop-int-430"
     run_dump_test "nop-int-430x"
-- 
2.17.1