diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2020-10-07 14:27:56 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2020-10-16 13:43:49 +0100 |
commit | 874ef0386fe438d654f0c3c230d4a9d0c4db9213 (patch) | |
tree | d60d334d383bd1a1476da0341ce543583417fb74 /ld/testsuite | |
parent | 54874444da47cab42de1d0b22e7009e7ca3eb6f2 (diff) | |
download | gdb-874ef0386fe438d654f0c3c230d4a9d0c4db9213.zip gdb-874ef0386fe438d654f0c3c230d4a9d0c4db9213.tar.gz gdb-874ef0386fe438d654f0c3c230d4a9d0c4db9213.tar.bz2 |
ld: Allow symbols from PROVIDE to be use in MEMORY regions
I wanted to write a linker script like this:
PROVIDE(mem_origin = 0x1000);
PROVIDE(mem_length = 0x1000);
MEMORY
{
REGION : ORIGIN = mem_origin, LENGTH = mem_length
}
....
Then when I link using this script I can optionally supply:
--defsym=mem_origin=..... --defsym=mem_length=....
to override the defaults.
And though passing `--defsym' does work, if I remove the use of
`--defsym' and just rely on the defaults I get an error:
ld-new: invalid origin for memory region REGION
Interestingly, if I make the above error non-fatal and dump a linker
map file I see that (a) REGION has origin 0x0, and length 0xffff...,
and (b) the symbol from the PROVIDE is provided.
An examination of ldlang.c:lang_process shows us what the issue is,
the origin and length of all memory regions are set as a result of a
single call to lang_do_memory_regions, this call is done after calling
open_input_bfds.
During the open_input_bfds call provide statements can be converted to
provided statements if we know that the assigned symbol is needed, but
for symbols that are only used in the memory regions we are unaware
that we need these symbols.
What I propose in this patch is to make two calls to
lang_do_memory_regions, in the first call we process the expressions
for the origin and length fields of each region, however, errors,
especially undefined symbols, will be ignored. The origin and length
values are not updated. However, by evaluating the expressions any
symbols we need will be added to the symbol table.
Now when we call open_input_bfds, when we process the provide
statements, we will see that the assigned symbol is needed add its new
value to the symbol table.
Finally we reach the original call to lang_do_memory_regions, in
this (now second) call we again process the expressions, and this time
update the origin and length values. Any errors encountered now are
reported to the user.
ld/ChangeLog:
* ldlang.c (lang_process): Add extra call to
lang_do_memory_regions, and pass parameter.
(lang_do_memory_regions): Add parameter, only define origin and
length when requested. Reindent.
* testsuite/ld-scripts/provide-10.d: New file.
* testsuite/ld-scripts/provide-10.map: New file.
* testsuite/ld-scripts/provide-11.d: New file.
* testsuite/ld-scripts/provide-11.map: New file.
* testsuite/ld-scripts/provide-12.d: New file.
* testsuite/ld-scripts/provide-12.map: New file.
* testsuite/ld-scripts/provide-9.d: New file.
* testsuite/ld-scripts/provide-9.map: New file.
* testsuite/ld-scripts/provide-9.t: New file.
Diffstat (limited to 'ld/testsuite')
-rw-r--r-- | ld/testsuite/ld-scripts/provide-10.d | 3 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/provide-10.map | 6 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/provide-11.d | 3 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/provide-11.map | 6 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/provide-12.d | 3 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/provide-12.map | 6 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/provide-9.d | 3 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/provide-9.map | 6 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/provide-9.t | 25 |
9 files changed, 61 insertions, 0 deletions
diff --git a/ld/testsuite/ld-scripts/provide-10.d b/ld/testsuite/ld-scripts/provide-10.d new file mode 100644 index 0000000..7481a92 --- /dev/null +++ b/ld/testsuite/ld-scripts/provide-10.d @@ -0,0 +1,3 @@ +#source: provide-5.s +#ld: --defsym=mem_origin=0x300 --defsym=mem_length=0x400 -T provide-9.t +#map: provide-10.map diff --git a/ld/testsuite/ld-scripts/provide-10.map b/ld/testsuite/ld-scripts/provide-10.map new file mode 100644 index 0000000..022b962 --- /dev/null +++ b/ld/testsuite/ld-scripts/provide-10.map @@ -0,0 +1,6 @@ +#... +Memory Configuration + +Name Origin Length Attributes +FOO 0x[0-9a-f]+300 +0x[0-9a-f]+400 +#pass diff --git a/ld/testsuite/ld-scripts/provide-11.d b/ld/testsuite/ld-scripts/provide-11.d new file mode 100644 index 0000000..79bcfa6 --- /dev/null +++ b/ld/testsuite/ld-scripts/provide-11.d @@ -0,0 +1,3 @@ +#source: provide-5.s +#ld: --defsym=mem_length=0x400 -T provide-9.t +#map: provide-11.map diff --git a/ld/testsuite/ld-scripts/provide-11.map b/ld/testsuite/ld-scripts/provide-11.map new file mode 100644 index 0000000..7176312 --- /dev/null +++ b/ld/testsuite/ld-scripts/provide-11.map @@ -0,0 +1,6 @@ +#... +Memory Configuration + +Name Origin Length Attributes +FOO 0x[0-9a-f]+100 +0x[0-9a-f]+400 +#pass diff --git a/ld/testsuite/ld-scripts/provide-12.d b/ld/testsuite/ld-scripts/provide-12.d new file mode 100644 index 0000000..41d9590 --- /dev/null +++ b/ld/testsuite/ld-scripts/provide-12.d @@ -0,0 +1,3 @@ +#source: provide-5.s +#ld: --defsym=mem_origin=0x300 -T provide-9.t +#map: provide-12.map diff --git a/ld/testsuite/ld-scripts/provide-12.map b/ld/testsuite/ld-scripts/provide-12.map new file mode 100644 index 0000000..e76654b --- /dev/null +++ b/ld/testsuite/ld-scripts/provide-12.map @@ -0,0 +1,6 @@ +#... +Memory Configuration + +Name Origin Length Attributes +FOO 0x[0-9a-f]+300 +0x[0-9a-f]+200 +#pass diff --git a/ld/testsuite/ld-scripts/provide-9.d b/ld/testsuite/ld-scripts/provide-9.d new file mode 100644 index 0000000..94dc029 --- /dev/null +++ b/ld/testsuite/ld-scripts/provide-9.d @@ -0,0 +1,3 @@ +#source: provide-5.s +#ld: -T provide-9.t +#map: provide-9.map diff --git a/ld/testsuite/ld-scripts/provide-9.map b/ld/testsuite/ld-scripts/provide-9.map new file mode 100644 index 0000000..e35e3e2 --- /dev/null +++ b/ld/testsuite/ld-scripts/provide-9.map @@ -0,0 +1,6 @@ +#... +Memory Configuration + +Name Origin Length Attributes +FOO 0x[0-9a-f]+100 +0x[0-9a-f]+200 +#pass diff --git a/ld/testsuite/ld-scripts/provide-9.t b/ld/testsuite/ld-scripts/provide-9.t new file mode 100644 index 0000000..00d906a --- /dev/null +++ b/ld/testsuite/ld-scripts/provide-9.t @@ -0,0 +1,25 @@ +PROVIDE (mem_origin = 0x100); +PROVIDE (mem_length = 0x200); + +MEMORY +{ + FOO : ORIGIN = mem_origin, LENGTH = mem_length +} + +SECTIONS +{ + .data : { + *(.data .data.*) + } >FOO + + .text : { + *(.text .text.*) + } >FOO + + .bss : { + *(.bss .bss.*) + } >FOO + + /DISCARD/ : { *(.*) } +} + |