bfd/ * linker.c (fix_syms): Don't add a symbol to a section if the symbol does not lie inclusively within the section. ld/ * testsuite/ld-elf/warn2.d: Expect Foo in ABS. * testsuite/ld-elf/zerosize1.d: New file. * testsuite/ld-elf/zerosize1.s: New file. diff --git a/bfd/linker.c b/bfd/linker.c index 7a01e11..1d9e66a 100644 --- a/bfd/linker.c +++ b/bfd/linker.c @@ -3201,6 +3201,12 @@ fix_syms (struct bfd_link_hash_entry *h, void *data) op = op1; } + /* Refuse to choose a section for which we are out of bounds. */ + /* ??? This may make most of the above moot. */ + if (h->u.def.value < op->vma + || h->u.def.value > op->vma + op->size) + op = bfd_abs_section_ptr; + h->u.def.value -= op->vma; h->u.def.section = op; } diff --git a/ld/testsuite/ld-elf/warn2.d b/ld/testsuite/ld-elf/warn2.d index 95b7ef4..a9c05f9 100644 --- a/ld/testsuite/ld-elf/warn2.d +++ b/ld/testsuite/ld-elf/warn2.d @@ -13,5 +13,5 @@ # construct and that the symbol still appears as expected. #... - +[0-9]+: +[0-9a-f]+ +20 +OBJECT +GLOBAL +DEFAULT +[1-9] Foo + +[0-9]+: +[0-9a-f]+ +20 +OBJECT +GLOBAL +DEFAULT +ABS Foo #pass diff --git a/ld/testsuite/ld-elf/zerosize1.d b/ld/testsuite/ld-elf/zerosize1.d new file mode 100644 index 0000000..0da5171 --- /dev/null +++ b/ld/testsuite/ld-elf/zerosize1.d @@ -0,0 +1,10 @@ +#source: start.s +#source: zerosize1.s +#ld: +#readelf: -s + +# Check that xyzzy is not placed in the ABS section. + +#... + +[0-9]+: +[0-9a-f]+ +0 +NOTYPE +GLOBAL +DEFAULT +ABS xyzzy +#pass diff --git a/ld/testsuite/ld-elf/zerosize1.s b/ld/testsuite/ld-elf/zerosize1.s new file mode 100644 index 0000000..4fc8198 --- /dev/null +++ b/ld/testsuite/ld-elf/zerosize1.s @@ -0,0 +1,3 @@ + .section "zerosize","aw" + .globl xyzzy +xyzzy: