old-cross-binutils/ld/testsuite/ld-plugin
Andrew Burgess ace667e59a ld: Restore file offset after a plugin fails to claim a file
When using the plugin interface to claim an input file the claim method
from (possible) many plugins can be called on an input file.  If these
claim methods read content from the input file then the file offset
stored in the underlying file descriptor will change.

As we share a file descriptor between the plugin interface (created with
dup in ld/plugin.c:plugin_object_p) and the input bfd object, then any
changes to the file offset in the file descriptor will effect the bfd
object.  Also, as the changes to the file offset did not originate from
calls through the bfd interface, but instead came from the plugin
directly, then the bfd will not be aware that the file offset has
changed.  This is a problem as the bfd library caches the file offset.
If the plugin decides not to claim an input file then, currently, we
leave the bfd in a state where the actual file offset is out of sync
with the cached file offset.

This problem came to light after a recent commit
7d0b9ebc1e (Don't include libbfd.h outside
of bfd, part 6) however, I don't believe that commit actual introduces
the bug, it just exposed the existing issue.

This commit solves the problem by backing up and restoring the file
offset for the file descriptor of the input file.  The restore is only
done if the plugin does not claim the input file, as it is in this case
that the bfd library might be used again to try and identify the
unclaimed file.

ld/ChangeLog:

	* plugin.c (plugin_call_claim_file): Restore the file offset after
	an unsuccessful attempt to claim a file.
	* testplug.c (bytes_to_read_before_claim): New global.
	(record_read_length): New function, sets new global
	bytes_to_read_before_claim.
	(parse_option): Handle 'read:<NUMBER>' option.
	(onclaim_file): Read file content before checking for claim.
	* testsuite/ld-plugin/plugin-30.d: New file.
	* testsuite/ld-plugin/plugin.exp: Add new test.
2016-07-19 09:58:01 +01:00
..
dummy.c Add LTO tests 2012-12-07 19:23:50 +00:00
dummy.s Add LTO tests 2012-12-07 19:23:50 +00:00
func.c Add tests for non-object IR file 2015-02-11 05:02:12 -08:00
func1p.c Add plugin visibility test 2012-12-07 19:14:41 +00:00
func2i.c Add plugin visibility test 2012-12-07 19:14:41 +00:00
func3h.c Add plugin visibility test 2012-12-07 19:14:41 +00:00
lto-1a.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-1b.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-2.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-3.d Add LTO tests 2012-12-07 19:23:50 +00:00
lto-3.out Add LTO tests 2012-12-07 19:23:50 +00:00
lto-3a.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-3b.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-3c.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-3r.d Add LTO tests 2012-12-07 19:23:50 +00:00
lto-5.d Add LTO tests 2012-12-07 19:23:50 +00:00
lto-5.out Add LTO tests 2012-12-07 19:23:50 +00:00
lto-5a.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-5b.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-5r.d Add LTO tests 2012-12-07 19:23:50 +00:00
lto-6.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-7.out Add LTO tests 2012-12-07 19:23:50 +00:00
lto-7a.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-7b.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-7c.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-7d.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-8.out Add LTO tests 2012-12-07 19:23:50 +00:00
lto-8a.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-8b.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-9.cc Add LTO tests 2012-12-07 19:23:50 +00:00
lto-9.d Add LTO tests 2012-12-07 19:23:50 +00:00
lto-11.out Add LTO tests 2012-12-07 19:23:50 +00:00
lto-11a.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-11b.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-11c.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-12.out Add LTO tests 2012-12-07 19:23:50 +00:00
lto-12a.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-12b.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-12c.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-13.out Add LTO tests 2012-12-07 19:23:50 +00:00
lto-13a.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-13b.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-13c.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-14.out Add LTO tests 2012-12-07 19:23:50 +00:00
lto-14a.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-14b.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-14c.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-15.out Add LTO tests 2012-12-07 19:23:50 +00:00
lto-15a.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-15b.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-16a.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-16a.d * ld-plugin/lto-16a.d: Match powerpc64 function symbol type. 2013-01-15 05:05:26 +00:00
lto-16b.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-16b.d * ld-plugin/lto-16a.d: Match powerpc64 function symbol type. 2013-01-15 05:05:26 +00:00
lto-17a.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto-17a.d * ld-plugin/lto-16a.d: Match powerpc64 function symbol type. 2013-01-15 05:05:26 +00:00
lto-17b-1.d Add LTO tests 2012-12-07 19:23:50 +00:00
lto-17b-2.d * ld-plugin/lto-16a.d: Match powerpc64 function symbol type. 2013-01-15 05:05:26 +00:00
lto-17b.c Add LTO tests 2012-12-07 19:23:50 +00:00
lto.exp Add -flto to PR ld/20321 test 2016-07-05 07:35:52 -07:00
main.c
pass.out PR ld/20276: Set non_ir_ref on common symbol 2016-06-20 11:26:13 +09:30
plugin-1.d The initial support for LDPT_GET_VIEW 2015-01-28 10:27:31 -08:00
plugin-2.d The initial support for LDPT_GET_VIEW 2015-01-28 10:27:31 -08:00
plugin-3.d The initial support for LDPT_GET_VIEW 2015-01-28 10:27:31 -08:00
plugin-4.d The initial support for LDPT_GET_VIEW 2015-01-28 10:27:31 -08:00
plugin-5.d The initial support for LDPT_GET_VIEW 2015-01-28 10:27:31 -08:00
plugin-6.d The initial support for LDPT_GET_VIEW 2015-01-28 10:27:31 -08:00
plugin-7.d Properly mark the plugin symbol undefined 2015-02-06 04:29:35 -08:00
plugin-8.d Properly mark the plugin symbol undefined 2015-02-06 04:29:35 -08:00
plugin-9.d The initial support for LDPT_GET_VIEW 2015-01-28 10:27:31 -08:00
plugin-10.d The initial support for LDPT_GET_VIEW 2015-01-28 10:27:31 -08:00
plugin-11.d The initial support for LDPT_GET_VIEW 2015-01-28 10:27:31 -08:00
plugin-12.d PR ld/12365 2011-04-17 23:15:13 +00:00
plugin-13.d Add tests for non-object IR file 2015-02-11 05:02:12 -08:00
plugin-14.d Add tests for non-object IR file 2015-02-11 05:02:12 -08:00
plugin-15.d Add tests for non-object IR file 2015-02-11 05:02:12 -08:00
plugin-16.d Add tests for non-object IR file 2015-02-11 05:02:12 -08:00
plugin-17.d Add tests for non-object IR file 2015-02-11 05:02:12 -08:00
plugin-18.d Add tests for non-object IR file 2015-02-11 05:02:12 -08:00
plugin-19.d Add tests for non-object IR file 2015-02-11 05:02:12 -08:00
plugin-20.d Add tests for non-object IR file 2015-02-11 05:02:12 -08:00
plugin-21.d Add tests for non-object IR file 2015-02-11 05:02:12 -08:00
plugin-22.d Add tests for non-object IR file 2015-02-11 05:02:12 -08:00
plugin-23.d Add tests for non-object IR file 2015-02-11 05:02:12 -08:00
plugin-24.d Add tests for non-object IR file 2015-02-11 05:02:12 -08:00
plugin-25.d Add tests for non-object IR file 2015-02-11 05:02:12 -08:00
plugin-26.d Add tests for non-object IR file 2015-02-11 05:02:12 -08:00
plugin-27.d Output "warning:" or "error:" in plugin messages 2015-02-11 14:00:51 -08:00
plugin-28.d Output "warning:" or "error:" in plugin messages 2015-02-11 14:00:51 -08:00
plugin-29.d Output "warning:" or "error:" in plugin messages 2015-02-11 14:00:51 -08:00
plugin-30.d ld: Restore file offset after a plugin fails to claim a file 2016-07-19 09:58:01 +01:00
plugin-vis-1.d Properly convert LTO plugin visibility to ELF visibility. 2010-12-06 00:00:15 +00:00
plugin.exp ld: Restore file offset after a plugin fails to claim a file 2016-07-19 09:58:01 +01:00
pr12365a.c Mark the plugin symbol undefined 2015-02-03 09:03:23 -08:00
pr12365b.c Mark the plugin symbol undefined 2015-02-03 09:03:23 -08:00
pr12365c.c Mark the plugin symbol undefined 2015-02-03 09:03:23 -08:00
pr12696-1.cc Add LTO tests 2012-12-07 19:23:50 +00:00
pr12758a.s Add LTO tests 2012-12-07 19:23:50 +00:00
pr12758b.c Add LTO tests 2012-12-07 19:23:50 +00:00
pr12760a.c Add LTO tests 2012-12-07 19:23:50 +00:00
pr12760b.c Add LTO tests 2012-12-07 19:23:50 +00:00
pr12942.out Add LTO tests 2012-12-07 19:23:50 +00:00
pr12942a.cc PR ld/15227 2013-04-03 11:44:41 +00:00
pr12942a.h Add LTO tests 2012-12-07 19:23:50 +00:00
pr12942b.cc Add LTO tests 2012-12-07 19:23:50 +00:00
pr12942c.cc Add LTO tests 2012-12-07 19:23:50 +00:00
pr12975.c Add LTO tests 2012-12-07 19:23:50 +00:00
pr12975.d Add LTO tests 2012-12-07 19:23:50 +00:00
pr12975.t Add LTO tests 2012-12-07 19:23:50 +00:00
pr12982.c Add LTO tests 2012-12-07 19:23:50 +00:00
pr12982.d PR ld/12982 2013-05-21 07:15:22 +00:00
pr13066.cc Add LTO tests 2012-12-07 19:23:50 +00:00
pr13066.out Add LTO tests 2012-12-07 19:23:50 +00:00
pr13183.d Add LTO tests 2012-12-07 19:23:50 +00:00
pr13183a.c Add LTO tests 2012-12-07 19:23:50 +00:00
pr13183b.c Add LTO tests 2012-12-07 19:23:50 +00:00
pr13201.c Add LTO tests 2012-12-07 19:23:50 +00:00
pr13201.out Add LTO tests 2012-12-07 19:23:50 +00:00
pr13229.cc Add LTO tests 2012-12-07 19:23:50 +00:00
pr13229.d Add LTO tests 2012-12-07 19:23:50 +00:00
pr13244.c Add LTO tests 2012-12-07 19:23:50 +00:00
pr13244.d Add LTO tests 2012-12-07 19:23:50 +00:00
pr13287.cc Add LTO tests 2012-12-07 19:23:50 +00:00
pr14918.c Add a testcase for PR ld/14918 2015-02-03 08:24:50 -08:00
pr14918.d Add a testcase for PR ld/14918 2015-02-03 08:24:50 -08:00
pr15146.d Don't add DT_NEEDED for references from the dummy bfd 2013-02-16 17:54:37 +00:00
pr15146a.c Don't add DT_NEEDED for references from the dummy bfd 2013-02-16 17:54:37 +00:00
pr15146b.c Don't add DT_NEEDED for references from the dummy bfd 2013-02-16 17:54:37 +00:00
pr15146c.c missed from last commit 2013-02-18 04:44:16 +00:00
pr15146d.c Don't add DT_NEEDED for references from the dummy bfd 2013-02-16 17:54:37 +00:00
pr15323.out Set non_ir_ref if a symbol is referenced by a non-shared object 2013-03-30 00:38:39 +00:00
pr15323a.c Add "ld -r" tests for PR ld/15323 2015-09-11 10:02:57 -07:00
pr15323b.c Set non_ir_ref if a symbol is referenced by a non-shared object 2013-03-30 00:38:39 +00:00
pr16746a.c Don't issue a warning for references in LTO IR to warning symbols 2014-08-07 10:28:48 +09:30
pr16746b.c Don't issue a warning for references in LTO IR to warning symbols 2014-08-07 10:28:48 +09:30
pr16746c.c Don't issue a warning for references in LTO IR to warning symbols 2014-08-07 10:28:48 +09:30
pr16746d.c Don't issue a warning for references in LTO IR to warning symbols 2014-08-07 10:28:48 +09:30
pr16846a.c Add tests for PR ld/16846 2014-04-22 10:22:39 -07:00
pr16846b.c Add tests for PR ld/16846 2014-04-22 10:22:39 -07:00
pr16846c.c Add tests for PR ld/16846 2014-04-22 10:22:39 -07:00
pr17973.d Add a testcase for PR ld/17973 2015-02-14 06:26:20 -08:00
pr17973.s Add a testcase for PR ld/17973 2015-02-14 06:26:20 -08:00
pr19317.c ld -r doesn't need plugin for slim lto object 2015-12-10 12:35:50 -08:00
pr19317.out ld -r doesn't need plugin for slim lto object 2015-12-10 12:35:50 -08:00
pr20070.d Handle symbols defined/referenced only within IR 2016-05-12 16:50:52 -07:00
pr20070a.c Handle symbols defined/referenced only within IR 2016-05-12 16:50:52 -07:00
pr20070b.c Handle symbols defined/referenced only within IR 2016-05-12 16:50:52 -07:00
pr20103a.c Skip an archive element if not added by linker 2016-05-25 08:41:05 -07:00
pr20103b.c Skip an archive element if not added by linker 2016-05-25 08:41:05 -07:00
pr20103c.c Skip an archive element if not added by linker 2016-05-25 08:41:05 -07:00
pr20267a.c Use the IR symbol table for the IR input object 2016-06-20 05:10:46 -07:00
pr20267b.c Use the IR symbol table for the IR input object 2016-06-20 05:10:46 -07:00
pr20276a.c PR ld/20276: Set non_ir_ref on common symbol 2016-06-20 11:26:13 +09:30
pr20276b.c PR ld/20276: Set non_ir_ref on common symbol 2016-06-20 11:26:13 +09:30
pr20321.c Warn and return for duplicated plugin 2016-07-04 08:55:20 -07:00
run-ie.c Add LTO tests 2012-12-07 19:23:50 +00:00
run-ie.out Add LTO tests 2012-12-07 19:23:50 +00:00
text.c