binutils-gdb/ld/testsuite
Maciej W. Rozycki c9f02c3e29 readelf: Fix incorrect "Version definition past end of section" message
Fix a commit 74e1a04b97 ("More fixes for reading corrupt ELF files.")
`readelf --version-info' regression that caused "Version definition past
end of section" to be always printed at the end, even with good section
data.

For example with the `mips-linux' target we get:

$ cat ver_def.s
	.data
	.globl	new_foo
	.type	new_foo, %object
new_foo:
	.symver	new_foo, foo@@ver_foo
$ cat ver_def.ver
{ global: *foo*; local: *; };
$ as -o ver_def.o ver_def.s
$ ld -e 0 --export-dynamic --version-script=ver_def.ver -o ver_def ver_def.o
$ readelf -V ver_def

Version symbols section '.gnu.version' contains 4 entries:
 Addr: 000000000000007e  Offset: 0x01007e  Link: 2 (.dynsym)
  000:   0 (*local*)       2 (ver_foo)       1 (*global*)      2 (ver_foo)

Version definition section '.gnu.version_d' contains 2 entries:
  Addr: 0x0000000000000088  Offset: 0x010088  Link: 3 (.dynstr)
  000000: Rev: 1  Flags: BASE   Index: 1  Cnt: 1  Name: ver_def
  0x001c: Rev: 1  Flags: none  Index: 2  Cnt: 1  Name: ver_foo
  Version definition past end of section
$

The cause is the `if (idx + ent.vd_next <= idx)' condition introduced to
ensure forward progress, which however always triggers for good version
definition section data as the last entry will have its `vd_next' value
set to 0.

Adjust the condition then, to say `if (idx + ent.vd_next < idx)' instead
and to ensure forward progress limit the number of entries processed to
the size of the version definition section, removing the problematic
message from output quoted above, while ensuring the original PR 17531
test case is still handled gracefully.

Add a suitable test case so that we have `readelf --version-info'
coverage; due to the lack of infrastructure needed to run the linker in
the `binutils' test suite and limited justification to implement it add
a new `readelf.exp' script to the `ld' test suite instead, intended to
gather any `readelf' test cases that require the linker to be run.  If
ever we decide to have linker infrastructure added to the `binutils'
test suite, then the script can be moved between the test suites.

	binutils/
	* readelf.c (process_version_sections) <SHT_GNU_verdef>: Limit
	the number of entries processed by the section size.  Don't
	break out of the loop if `ent.vd_next' is 0.

	ld/
	* testsuite/ld-elf/ver_def.d: New test.
	* testsuite/ld-elf/ver_def.ld: New test linker script.
	* testsuite/ld-elf/ver_def.ver: New test version script.
	* testsuite/ld-elf/ver_def.s: New test source.
	* testsuite/ld-elf/readelf.exp: New test script.
2017-02-24 13:48:10 +00:00
..
config Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-aarch64 Fix AArch64 relocation handling in ILP32 mode. 2017-01-23 17:07:13 +00:00
ld-alpha Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-arc [ARC] Add new linker emulation for nps 2017-01-10 10:55:13 +00:00
ld-arm Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-auto-import Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-avr Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-bootstrap Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-cdtest Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-checks Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-cris LD: vfinfo: Make clever formatters consistent WRT function name reporting 2017-02-15 13:41:51 +00:00
ld-crx Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-cygwin Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-d10v Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-discard Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-elf readelf: Fix incorrect "Version definition past end of section" message 2017-02-24 13:48:10 +00:00
ld-elfcomm Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-elfvers Add -rpath-link to various tests 2017-01-03 12:36:02 +10:30
ld-elfvsb Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-elfweak Add -rpath-link to various tests 2017-01-03 12:36:02 +10:30
ld-fastcall Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-frv Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-gc Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-h8300 Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-i386 i386: Allow "lea foo@GOT, %reg" in PIC 2017-02-15 11:39:48 -08:00
ld-ia64 Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-ifunc Fix compile time warning message in linker testsuite test. 2017-02-21 11:00:21 +00:00
ld-libs Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-linkonce Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-m68hc11 Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-m68k Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-mep Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-metag Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-mips-elf MIPS/BFD: Remove duplicate NewABI JALR relocation handling 2017-02-23 23:49:14 +00:00
ld-misc Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-mmix Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-mn10300 Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-nds32 Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-nios2 Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-pe Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-pie Don't run C tests in ld testsuite unless we have a C compiler 2017-01-03 11:47:47 +10:30
ld-plugin ld: Add additional checking for warnings/errors in testsuite 2017-02-16 13:06:12 +00:00
ld-powerpc Correct VLE 16D and SDAREL relocations 2017-02-23 12:33:51 +10:30
ld-pru PRU LD Port 2016-12-31 12:04:11 +10:30
ld-s390 Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-scripts hppa -z relro again 2017-02-16 23:09:38 +10:30
ld-selective Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-sh Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-shared Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-size Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-sparc Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-spu Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-srec Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-tic6x Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-tilegx Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-tilepro Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-undefined Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-unique [ld, testsuite] Append $board_cflags in one more place in ld-unique/unique.exp 2017-02-01 12:57:25 +00:00
ld-v850 Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-vax-elf Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-versados Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-visium Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-vxworks Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-x86-64 x86-64: Also generate unwind info for .plt.bnd 2017-01-12 10:32:17 -08:00
ld-xc16x Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-xstormy16 Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
ld-xtensa Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ld-z8k Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
lib ld: Add additional checking for warnings/errors in testsuite 2017-02-16 13:06:12 +00:00
ChangeLog-2004
ChangeLog-2005
ChangeLog-2006
ChangeLog-2007
ChangeLog-2008
ChangeLog-2009
ChangeLog-2010
ChangeLog-2011
ChangeLog-2012
ChangeLog-2013
ChangeLog-2014
ChangeLog-2015
ChangeLog-9303