From cc9ad334a71b0c032f711e86885fb73821f3be16 Mon Sep 17 00:00:00 2001 From: Senthil Kumar Selvaraj Date: Wed, 28 Jan 2015 15:01:50 +1030 Subject: Allow symbols in MEMORY region specification This patch fixes PR 4643 by allowing symbols in the LENGTH and ORIGIN fields of MEMORY regions. Previously, only constants and constant expressions are allowed. For the AVR target, this helps define memory constraints more accurately (per device), without having to create a ton of device specific linker scripts. ld/ PR 4643 * ldexp.c (fold_name): Fold LENGTH only after lang_first_phase_enum. * ldgram.y (memory_spec): Don't evaluate ORIGIN and LENGTH rightaway. * ldlang.h (struct memory_region_struct): Add origin_exp and length_exp fields. * ldlang.c (lang_do_memory_regions): New. (lang_memory_region_lookup): Initialize origin_exp and length_exp fields. (lang_process): Call lang_do_memory_regions. ld/testsuite/ * ld-scripts/memory.t: Define new symbol tred. * ld-scripts/memory_sym.t: New. * ld-scripts/script.exp: Perform MEMORY with symbols test, and conditionally check values of linker symbols. --- ld/testsuite/ChangeLog | 7 +++++++ ld/testsuite/ld-scripts/memory.t | 3 ++- ld/testsuite/ld-scripts/memory_sym.t | 36 ++++++++++++++++++++++++++++++++++++ ld/testsuite/ld-scripts/script.exp | 21 +++++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 ld/testsuite/ld-scripts/memory_sym.t (limited to 'ld/testsuite') diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index 21cf40e..4746f14 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2015-01-28 Senthil Kumar Selvaraj + + * ld-scripts/memory.t: Define new symbol tred. + * ld-scripts/memory_sym.t: New. + * ld-scripts/script.exp: Perform MEMORY with symbols test, and + conditionally check values of linker symbols. + 2015-01-20 Andrew Burgess * ld-scripts/provide-4-map.d: Update expected output. diff --git a/ld/testsuite/ld-scripts/memory.t b/ld/testsuite/ld-scripts/memory.t index 129bd7c..937394f 100644 --- a/ld/testsuite/ld-scripts/memory.t +++ b/ld/testsuite/ld-scripts/memory.t @@ -29,5 +29,6 @@ SECTIONS data_end = .; } >DATAMEM - fred = ORIGIN(DATAMEM) + LENGTH(DATAMEM); + fred = ORIGIN(DATAMEM) + LENGTH(DATAMEM); + tred = ORIGIN(TEXTMEM) + LENGTH(TEXTMEM); } diff --git a/ld/testsuite/ld-scripts/memory_sym.t b/ld/testsuite/ld-scripts/memory_sym.t new file mode 100644 index 0000000..4ccec55 --- /dev/null +++ b/ld/testsuite/ld-scripts/memory_sym.t @@ -0,0 +1,36 @@ +TXT_ORIGIN = 0x100; +TXT_LENGTH = 32K; +MEMORY +{ + R_TEXTMEM (ARX) : ORIGIN = TXT_ORIGIN, LENGTH = TXT_LENGTH + R_DATAMEM (AW) : org = DATA_ORIGIN, l = DATA_LENGTH +} + +REGION_ALIAS ("A_TEXTMEM", R_TEXTMEM); +REGION_ALIAS ("A_DATAMEM", R_DATAMEM); + +REGION_ALIAS ("TEXTMEM", A_TEXTMEM); +REGION_ALIAS ("DATAMEM", A_DATAMEM); + +SECTIONS +{ + . = 0; + .text : + { + text_start = ORIGIN (TEXTMEM); + *(.text) + *(.pr) + text_end = .; + } > TEXTMEM + + data_start = ORIGIN (DATAMEM); + .data : + { + *(.data) + *(.rw) + data_end = .; + } >DATAMEM + + fred = ORIGIN(DATAMEM) + LENGTH(DATAMEM); + tred = ORIGIN(TEXTMEM) + LENGTH(TEXTMEM); +} diff --git a/ld/testsuite/ld-scripts/script.exp b/ld/testsuite/ld-scripts/script.exp index cee706f..6ab04ec 100644 --- a/ld/testsuite/ld-scripts/script.exp +++ b/ld/testsuite/ld-scripts/script.exp @@ -66,6 +66,13 @@ proc check_script { } { set passes 0 } + if {[info exists nm_output(tred)] \ + && $nm_output(tred) != (0x100 + 0x8000)} { + send_log "tred == $nm_output(tred)\n" + verbose "tred == $nm_output(tred)" + set passes 0 + } + if {$nm_output(text_end) < $text_end \ || $nm_output(text_end) > 0x110} { send_log "text_end == $nm_output(text_end)\n" @@ -79,6 +86,13 @@ proc check_script { } { set passes 0 } + if {[info exists nm_output(fred)] \ + && $nm_output(fred) != (0x1000 + 0x10000)} { + send_log "fred == $nm_output(fred)\n" + verbose "fred == $nm_output(fred)" + set passes 0 + } + if {$nm_output(data_end) < $data_end \ || $nm_output(data_end) > 0x1010} { send_log "data_end == $nm_output(data_end)\n" @@ -126,6 +140,13 @@ if ![ld_simple_link $ld tmpdir/script "$flags -T $srcdir/$subdir/memory.t tmpdir check_script } +set testname "MEMORY with symbols" +if ![ld_simple_link $ld tmpdir/script "$flags -defsym DATA_ORIGIN=0x1000 -defsym DATA_LENGTH=0x10000 -T $srcdir/$subdir/memory_sym.t tmpdir/script.o"] { + fail $testname +} else { + check_script +} + set test_script_list [lsort [glob $srcdir/$subdir/region-alias-*.t]] foreach test_script $test_script_list { -- cgit v1.1