--- /dev/null
+#! /bin/sh /usr/share/dpatch/dpatch-run
+## 502-binutils-msp-ldscripts.dpatch by <smckown@stevex2>
+##
+## All lines beginning with `## DP:' are a description of the patch.
+## DP: Add new ldscripts for cpu variations of the msp430 architecture
+
+@DPATCH@
+
+diff -ru binutils-2.17.orig/ld/scripttempl/elf32msp430.sc binutils-2.17/ld/scripttempl/elf32msp430.sc
+--- binutils-2.17.orig/ld/scripttempl/elf32msp430.sc 2008-05-23 02:00:49.049465400 +0300
++++ binutils-2.17/ld/scripttempl/elf32msp430.sc 2008-05-24 18:13:23.343750000 +0300
+@@ -14,7 +14,7 @@
+ ${RELOCATING+ PROVIDE (__heap_bottom = .) ; }
+ ${RELOCATING+ PROVIDE (__heap_top = ${HEAP_START} + ${HEAP_LENGTH}) ; }
+ } ${RELOCATING+ > heap}"
+-HEAP_MEMORY_MSP430="heap(rwx) : ORIGIN = $HEAP_START, LENGTH = $HEAP_LENGTH"
++HEAP_MEMORY_MSP430="heap(rwx) : ORIGIN = $HEAP_START, LENGTH = $HEAP_LENGTH"
+ fi
+
+
+@@ -24,12 +24,12 @@
+
+ MEMORY
+ {
+- text (rx) : ORIGIN = $ROM_START, LENGTH = $ROM_SIZE
+- data (rwx) : ORIGIN = $RAM_START, LENGTH = $RAM_SIZE
+- vectors (rw) : ORIGIN = $VECTORS_START LENGTH = $VECTORS_SIZE
+- bootloader(rx) : ORIGIN = 0x0c00, LENGTH = 1K
+- infomem(rx) : ORIGIN = 0x1000, LENGTH = 256
+- infomemnobits(rx) : ORIGIN = 0x1000, LENGTH = 256
++ text (rx) : ORIGIN = $ROM_START, LENGTH = $ROM_SIZE
++ data (rwx) : ORIGIN = $RAM_START, LENGTH = $RAM_SIZE
++ vectors (rw) : ORIGIN = $VECTORS_START, LENGTH = $VECTORS_SIZE
++ bootloader(rx) : ORIGIN = 0x0c00, LENGTH = 1K
++ infomem(rx) : ORIGIN = 0x1000, LENGTH = 256
++ infomemnobits(rx) : ORIGIN = 0x1000, LENGTH = 256
+ ${HEAP_MEMORY_MSP430}
+ }
+
+@@ -100,22 +100,35 @@
+ {
+ ${RELOCATING+. = ALIGN(2);}
+ *(.init)
+- *(.init0) /* Start here after reset. */
+- *(.init1)
+- *(.init2) /* Copy data loop */
+- *(.init3)
+- *(.init4) /* Clear bss */
+- *(.init5)
+- *(.init6) /* C++ constructors. */
+- *(.init7)
+- *(.init8)
+- *(.init9) /* Call main(). */
++ KEEP(*(.init))
++ *(.init0) /* Start here after reset. */
++ KEEP(*(.init0))
++ *(.init1) /* User definable. */
++ KEEP(*(.init1))
++ *(.init2) /* Initialize stack. */
++ KEEP(*(.init2))
++ *(.init3) /* Initialize hardware, user definable. */
++ KEEP(*(.init3))
++ *(.init4) /* Copy data to .data, clear bss. */
++ KEEP(*(.init4))
++ *(.init5) /* User definable. */
++ KEEP(*(.init5))
++ *(.init6) /* C++ constructors. */
++ KEEP(*(.init6))
++ *(.init7) /* User definable. */
++ KEEP(*(.init7))
++ *(.init8) /* User definable. */
++ KEEP(*(.init8))
++ *(.init9) /* Call main(). */
++ KEEP(*(.init9))
+
+ ${CONSTRUCTING+ __ctors_start = . ; }
+ ${CONSTRUCTING+ *(.ctors) }
++ ${CONSTRUCTING+ KEEP(*(.ctors)) }
+ ${CONSTRUCTING+ __ctors_end = . ; }
+ ${CONSTRUCTING+ __dtors_start = . ; }
+ ${CONSTRUCTING+ *(.dtors) }
++ ${CONSTRUCTING+ KEEP(*(.dtors)) }
+ ${CONSTRUCTING+ __dtors_end = . ; }
+
+ ${RELOCATING+. = ALIGN(2);}
+@@ -124,31 +137,45 @@
+ *(.text.*)
+
+ ${RELOCATING+. = ALIGN(2);}
+- *(.fini9) /* */
+- *(.fini8)
+- *(.fini7)
+- *(.fini6) /* C++ destructors. */
+- *(.fini5)
+- *(.fini4)
+- *(.fini3)
+- *(.fini2)
+- *(.fini1)
++ *(.fini9) /* Jumps here after main(). User definable. */
++ KEEP(*(.fini9))
++ *(.fini8) /* User definable. */
++ KEEP(*(.fini8))
++ *(.fini7) /* User definable. */
++ KEEP(*(.fini7))
++ *(.fini6) /* C++ destructors. */
++ KEEP(*(.fini6))
++ *(.fini5) /* User definable. */
++ KEEP(*(.fini5))
++ *(.fini4) /* User definable. */
++ KEEP(*(.fini4))
++ *(.fini3) /* User definable. */
++ KEEP(*(.fini3))
++ *(.fini2) /* User definable. */
++ KEEP(*(.fini2))
++ *(.fini1) /* User definable. */
++ KEEP(*(.fini1))
+ *(.fini0) /* Infinite loop after program termination. */
++ KEEP(*(.fini0))
+ *(.fini)
++ KEEP(*(.fini))
+
+ _etext = .;
+ } ${RELOCATING+ > text}
+
+- .data ${RELOCATING-0} : ${RELOCATING+AT (ADDR (.text) + SIZEOF (.text))}
++ .data ${RELOCATING-0} :
+ {
+ ${RELOCATING+ PROVIDE (__data_start = .) ; }
+ ${RELOCATING+. = ALIGN(2);}
+ *(.data)
++ *(SORT_BY_ALIGNMENT(.data.*))
+ ${RELOCATING+. = ALIGN(2);}
+ *(.gnu.linkonce.d*)
+ ${RELOCATING+. = ALIGN(2);}
+ ${RELOCATING+ _edata = . ; }
+- } ${RELOCATING+ > data}
++ } ${RELOCATING+ > data AT > text}
++ ${RELOCATING+ PROVIDE (__data_load_start = LOADADDR(.data) ); }
++ ${RELOCATING+ PROVIDE (__data_size = SIZEOF(.data) ); }
+
+ /* Bootloader. */
+ .bootloader ${RELOCATING-0} :
+@@ -175,19 +202,22 @@
+ *(.infomemnobits.*)
+ } ${RELOCATING+ > infomemnobits}
+
+- .bss ${RELOCATING+ SIZEOF(.data) + ADDR(.data)} :
++ .bss ${RELOCATING-0} :
+ {
+ ${RELOCATING+ PROVIDE (__bss_start = .) ; }
+ *(.bss)
++ *(SORT_BY_ALIGNMENT(.bss.*))
+ *(COMMON)
+ ${RELOCATING+ PROVIDE (__bss_end = .) ; }
+ ${RELOCATING+ _end = . ; }
+ } ${RELOCATING+ > data}
++ ${RELOCATING+ PROVIDE (__bss_size = SIZEOF(.bss) ); }
+
+- .noinit ${RELOCATING+ SIZEOF(.bss) + ADDR(.bss)} :
++ .noinit ${RELOCATING-0} :
+ {
+ ${RELOCATING+ PROVIDE (__noinit_start = .) ; }
+ *(.noinit)
++ *(.noinit.*)
+ *(COMMON)
+ ${RELOCATING+ PROVIDE (__noinit_end = .) ; }
+ ${RELOCATING+ _end = . ; }
+@@ -197,6 +227,7 @@
+ {
+ ${RELOCATING+ PROVIDE (__vectors_start = .) ; }
+ *(.vectors*)
++ KEEP(*(.vectors*))
+ ${RELOCATING+ _vectors_end = . ; }
+ } ${RELOCATING+ > vectors}
+
+diff -ru binutils-2.17.orig/ld/scripttempl/elf32msp430_3.sc binutils-2.17/ld/scripttempl/elf32msp430_3.sc
+--- binutils-2.17.orig/ld/scripttempl/elf32msp430_3.sc 2008-05-23 02:00:49.033840400 +0300
++++ binutils-2.17/ld/scripttempl/elf32msp430_3.sc 2008-05-24 17:50:27.953125000 +0300
+@@ -6,7 +6,7 @@
+ {
+ text (rx) : ORIGIN = $ROM_START, LENGTH = $ROM_SIZE
+ data (rwx) : ORIGIN = $RAM_START, LENGTH = $RAM_SIZE
+- vectors (rw) : ORIGIN = $VECTORS_START LENGTH = $VECTORS_SIZE
++ vectors (rw) : ORIGIN = $VECTORS_START, LENGTH = $VECTORS_SIZE
+ }
+
+ SECTIONS
+@@ -76,22 +76,35 @@
+ {
+ ${RELOCATING+. = ALIGN(2);}
+ *(.init)
+- *(.init0) /* Start here after reset. */
+- *(.init1)
+- *(.init2)
+- *(.init3)
+- *(.init4)
+- *(.init5)
+- *(.init6) /* C++ constructors. */
+- *(.init7)
+- *(.init8)
+- *(.init9) /* Call main(). */
++ KEEP(*(.init))
++ *(.init0) /* Start here after reset. */
++ KEEP(*(.init0))
++ *(.init1) /* User definable. */
++ KEEP(*(.init1))
++ *(.init2) /* Initialize stack. */
++ KEEP(*(.init2))
++ *(.init3) /* Initialize hardware, user definable. */
++ KEEP(*(.init3))
++ *(.init4) /* Copy data to .data, clear bss. */
++ KEEP(*(.init4))
++ *(.init5) /* User definable. */
++ KEEP(*(.init5))
++ *(.init6) /* C++ constructors. */
++ KEEP(*(.init6))
++ *(.init7) /* User definable. */
++ KEEP(*(.init7))
++ *(.init8) /* User definable. */
++ KEEP(*(.init8))
++ *(.init9) /* Call main(). */
++ KEEP(*(.init9))
+
+ ${CONSTRUCTING+ __ctors_start = . ; }
+ ${CONSTRUCTING+ *(.ctors) }
++ ${CONSTRUCTING+ KEEP(*(.ctors)) }
+ ${CONSTRUCTING+ __ctors_end = . ; }
+ ${CONSTRUCTING+ __dtors_start = . ; }
+ ${CONSTRUCTING+ *(.dtors) }
++ ${CONSTRUCTING+ KEEP(*(.dtors)) }
+ ${CONSTRUCTING+ __dtors_end = . ; }
+
+ ${RELOCATING+. = ALIGN(2);}
+@@ -100,43 +113,60 @@
+ *(.text.*)
+
+ ${RELOCATING+. = ALIGN(2);}
+- *(.fini9)
+- *(.fini8)
+- *(.fini7)
+- *(.fini6) /* C++ destructors. */
+- *(.fini5)
+- *(.fini4)
+- *(.fini3)
+- *(.fini2)
+- *(.fini1)
++ *(.fini9) /* Jumps here after main(). User definable. */
++ KEEP(*(.fini9))
++ *(.fini8) /* User definable. */
++ KEEP(*(.fini8))
++ *(.fini7) /* User definable. */
++ KEEP(*(.fini7))
++ *(.fini6) /* C++ destructors. */
++ KEEP(*(.fini6))
++ *(.fini5) /* User definable. */
++ KEEP(*(.fini5))
++ *(.fini4) /* User definable. */
++ KEEP(*(.fini4))
++ *(.fini3) /* User definable. */
++ KEEP(*(.fini3))
++ *(.fini2) /* User definable. */
++ KEEP(*(.fini2))
++ *(.fini1) /* User definable. */
++ KEEP(*(.fini1))
+ *(.fini0) /* Infinite loop after program termination. */
++ KEEP(*(.fini0))
+ *(.fini)
++ KEEP(*(.fini))
+
+ ${RELOCATING+ _etext = . ; }
+ } ${RELOCATING+ > text}
+
+- .data ${RELOCATING-0} : ${RELOCATING+AT (ADDR (.text) + SIZEOF (.text))}
++ .data ${RELOCATING-0} :
+ {
+ ${RELOCATING+ PROVIDE (__data_start = .) ; }
+ *(.data)
++ *(SORT_BY_ALIGNMENT(.data.*))
+ *(.gnu.linkonce.d*)
+ ${RELOCATING+. = ALIGN(2);}
+ ${RELOCATING+ _edata = . ; }
+- } ${RELOCATING+ > data}
++ } ${RELOCATING+ > data AT > text}
++ ${RELOCATING+ PROVIDE (__data_load_start = LOADADDR(.data) ); }
++ ${RELOCATING+ PROVIDE (__data_size = SIZEOF(.data) ); }
+
+- .bss ${RELOCATING+ SIZEOF(.data) + ADDR(.data)} :
++ .bss ${RELOCATING-0} :
+ {
+ ${RELOCATING+ PROVIDE (__bss_start = .) ; }
+ *(.bss)
++ *(SORT_BY_ALIGNMENT(.bss.*))
+ *(COMMON)
+ ${RELOCATING+ PROVIDE (__bss_end = .) ; }
+ ${RELOCATING+ _end = . ; }
+ } ${RELOCATING+ > data}
++ ${RELOCATING+ PROVIDE (__bss_size = SIZEOF(.bss) ); }
+
+- .noinit ${RELOCATING+ SIZEOF(.bss) + ADDR(.bss)} :
++ .noinit ${RELOCATING-0} :
+ {
+ ${RELOCATING+ PROVIDE (__noinit_start = .) ; }
+ *(.noinit)
++ *(SORT_BY_ALIGNMENT(.noinit.*))
+ *(COMMON)
+ ${RELOCATING+ PROVIDE (__noinit_end = .) ; }
+ ${RELOCATING+ _end = . ; }
+@@ -146,6 +176,7 @@
+ {
+ ${RELOCATING+ PROVIDE (__vectors_start = .) ; }
+ *(.vectors*)
++ KEEP(*(.vectors*))
+ ${RELOCATING+ _vectors_end = . ; }
+ } ${RELOCATING+ > vectors}
+