Created attachment 5980 [details] Truncated object that ld.gold silently accepts. gold silently accepts truncated input file (tested with ELF64 on amd64). Example of how to reproduce: # compile trivial source file $ echo "int foo(void) { return 42; }" > foo.c $ gcc -c foo.c # create a truncated version of the object # just cutting off one byte creates a broken file, # but gold seems to accept even worse corruption $ stat foo.o | grep Size Size: 1216 Blocks: 8 IO Block: 4096 regular file $ dd if=foo.o of=foo-truncated.o bs=1215 count=1 1+0 records in 1+0 records out 1215 bytes (1.2 kB) copied, 0.000272381 s, 4.5 MB/s # verify that the file is indeed corrupted $ readelf -a foo-truncated.o > /dev/null readelf: Error: Unable to read in 0x18 bytes of relocs $ objdump -r foo-truncated.o foo-truncated.o: file format elf64-x86-64 RELOCATION RECORDS FOR [.eh_frame]:objdump: foo-truncated.o: File truncated # now ask gold to relink it: $ ld.gold -r foo-truncated.o -o relinked.o $ # by the way ld.bfd correctly rejects the file: $ ld.bfd -r foo-truncated.o -o relinked.o foo-truncated.o: could not read symbols: File truncated This can cause difficult-to-track-down issues if an object in larger project is corrupted. (Attaching the exact file I used to reproduce this issue, as the object is compiler dependent and you could possibly get different results with different object.)
With --map-whole-files, gold doesn't bother to check that the requested view is wholly contained within the file. With --no-map-whole-files, we get the expected error: $ ./ld-new --no-map-whole-files -r foo-truncated.o ./ld-new: fatal error: foo-truncated.o: attempt to map 24 bytes at offset 1192 exceeds size of file; the file may be corrupt
Patch posted for review: http://sourceware.org/ml/binutils/2011-10/msg00093.html
*** Bug 13290 has been marked as a duplicate of this bug. ***
CVSROOT: /cvs/src Module name: src Changes by: ccoutant@sourceware.org 2011-10-17 23:36:43 Modified files: gold : ChangeLog fileread.cc Log message: PR gold/13288 * gold/fileread.cc (File_read::find_view): Add assert. (File_read::make_view): Move bounds check (replace with assert)... (File_read::find_or_make_view): ... to here. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/ChangeLog.diff?cvsroot=src&r1=1.835&r2=1.836 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/fileread.cc.diff?cvsroot=src&r1=1.74&r2=1.75
Fixed in trunk.
CVSROOT: /cvs/src Module name: src Branch: binutils-2_22-branch Changes by: ian@sourceware.org 2011-12-19 21:14:40 Modified files: gold : ChangeLog Makefile.am Makefile.in configure configure.ac dwarf_reader.cc expression.cc fileread.cc gold.cc i386.cc incremental.cc incremental.h layout.cc options.cc options.h output.cc output.h plugin.cc powerpc.cc readsyms.cc resolve.cc script-sections.cc script.cc script.h sparc.cc symtab.cc symtab.h x86_64.cc gold/testsuite : Makefile.in plugin_test_2.sh script_test_2.t Log message: Copy from mainline to binutils 2.22 branch: 2011-12-17 Cary Coutant <ccoutant@google.com> * dwarf_reader.cc (Sized_dwarf_line_info::read_lines): Add casts. * resolve.cc (Symbol_table::resolve): Likewise. * i386.cc (Target_i386::do_code_fill): Use char constants for nop arrays. * x86_64.cc (Target_x86_64::do_code_fill): Likewise. 2011-10-31 Cary Coutant <ccoutant@google.com> PR gold/13023 * expression.cc (Expression::eval_with_dot): Add is_section_dot_assignment parameter. (Expression::eval_maybe_dot): Likewise. Adjust value when rhs is absolute and assigning to dot within a section. * script-sections.cc (Output_section_element_assignment::set_section_addresses): Pass dot_section to set_if_absolute. (Output_section_element_dot_assignment::finalize_symbols): Pass TRUE as is_section_dot_assignment flag to eval_with_dot. (Output_section_element_dot_assignment::set_section_addresses): Likewise. * script.cc (Symbol_assignment::set_if_absolute): Add dot_section parameter. Also set value if relative to dot_section; set the symbol's output_section. * script.h (Expression::eval_with_dot): Add is_section_dot_assignment parameter. Adjust all callers. (Expression::eval_maybe_dot): Likewise. (Symbol_assignment::set_if_absolute): Add dot_section parameter. Adjust all callers. * testsuite/script_test_2.t: Test assignment of an absolute value to dot within an output section element. 2011-10-31 Cary Coutant <ccoutant@google.com> * options.h (class General_options): Add --[no-]gnu-unique options. * symtab.cc (Symbol_table::sized_write_globals): Convert STB_GNU_UNIQUE to STB_GLOBAL if --no-gnu-unique. 2011-10-31 Cary Coutant <ccoutant@google.com> PR gold/13359 * i386.cc (Target_i386::Relocate::relocate_tls): Remove unnecessary assertion. * x86_64.cc (Target_x86_64::Relocate::relocate_tls): Likewise. 2011-10-31 Sriraman Tallam <tmsriram@google.com> * symtab.h (Symbol_table::gc_mark_symbol_for_shlib): Rename to gc_mark_symbol. * symtab.cc (Symbol_table::gc_mark_symbol_for_shlib): Rename to gc_mark_symbol. Change to just keep the section associated with symbol. (Symbol_table::add_from_relobj): Mark symbols as not garbage when they are externally visible and --export-dynamic is turned on. (Symbol_table::gc_mark_dyn_syms): Call gc_mark_symbol. 2011-10-19 Ian Lance Taylor <iant@google.com> PR gold/13163 * script-sections.cc (Output_section_element_dot_assignment::needs_output_section): New function. 2011-10-19 Ian Lance Taylor <iant@google.com> PR gold/13204 * layout.cc (Layout::segment_precedes): Don't assert failure if a --section-start option was seen. * options.h (General_options::any_section_start): New function. 2011-10-18 Cary Coutant <ccoutant@google.com> * output.cc (posix_fallocate): Return 0 on success, errno on failure. (Output_file::map_no_anonymous): Check for non-zero return code from posix_fallocate. 2011-10-17 Cary Coutant <ccoutant@google.com> PR gold/13245 * plugin.cc (is_visible_from_outside): Check for symbols referenced from dynamic objects. * resolve.cc (Symbol_table::resolve): Don't count references from dynamic objects as references from real ELF files. * testsuite/plugin_test_2.sh: Adjust expected result. 2011-10-17 Cary Coutant <ccoutant@google.com> * readsyms.cc (Read_symbols::run): Don't queue an unblocker task for members of lib groups. 2011-10-17 Cary Coutant <ccoutant@google.com> PR gold/13288 * fileread.cc (File_read::find_view): Add assert. (File_read::make_view): Move bounds check (replace with assert)... (File_read::find_or_make_view): ... to here. 2011-10-12 Cary Coutant <ccoutant@google.com> * output.cc (Output_file::open_base_file): Handle case where ::read returns less than requested size. 2011-10-10 Cary Coutant <ccoutant@google.com> * incremental.cc (Sized_relobj_incr::Sized_relobj_incr): Initialize defined_count_. (Sized_relobj_incr::do_add_symbols): Count defined symbols. (Sized_relobj_incr::do_get_global_symbol_counts): Rewrite. (Sized_incr_dynobj::Sized_incr_dynobj): Initialize defined_count_. (Sized_incr_dynobj::do_add_symbols): Count defined symbols. (Sized_incr_dynobj::do_get_global_symbol_counts): Rewrite. * incremental.h (Sized_relobj_incr::defined_count_): New data member. (Sized_incr_dynobj::defined_count_): New data member. * plugin.cc (Sized_pluginobj::do_get_global_symbol_counts): Return zeroes instead of internal error. 2011-10-10 Cary Coutant <ccoutant@google.com> PR gold/13249 * output.cc (Output_reloc::Output_reloc): Add use_plt_offset flag. (Output_reloc::symbol_value): Return PLT offset if flag is set. * output.h (class Output_reloc): Add use_plt_offset flag. (Output_reloc::type_): Adjust size of bit field. (Output_reloc::use_plt_offset_): New bit field. (class Output_data_reloc): Adjust all calls to Output_reloc_type. (Output_data_reloc::add_local_relative): (RELA only) Add use_plt_offset flag. Adjust all callers. * x86_64.cc (Target_x86_64::Scan::local): Check for IFUNC when creating RELATIVE relocations. 2011-10-03 Diego Novillo <dnovillo@google.com> * options.cc (parse_uint): Fix dereference of RETVAL. 2011-09-29 Cary Coutant <ccoutant@google.com> * incremental.cc (Sized_incremental_binary::do_process_got_plt): Check for NULL. * symtab.cc (Symbol_table::add_from_relobj): Ignore version symbols during incremental update. (Symbol_table::add_from_dynobj): Likewise. 2011-09-26 Cary Coutant <ccoutant@google.com> * gold.cc (queue_initial_tasks): Move option checks ... * options.cc (General_options::finalize): ... to here. Disable some options; make others fatal. 2011-09-23 Simon Baldwin <simonb@google.com> * configure.ac: Add new --with-gold-ldadd and --with-gold-ldflags configuration options. * configure: Regenerate. * Makefile.am: Handle GOLD_LDADD and GOLD_LDFLAGS. * Makefile.in: Regenerate. * testsuite/Makefile.in: Regenerate. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.824.2.6&r2=1.824.2.7 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/Makefile.am.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.62&r2=1.62.4.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/Makefile.in.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.89&r2=1.89.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/configure.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.69&r2=1.69.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/configure.ac.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.66&r2=1.66.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/dwarf_reader.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.33&r2=1.33.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/expression.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.18&r2=1.18.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/fileread.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.74&r2=1.74.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/gold.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.94&r2=1.94.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/i386.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.141&r2=1.141.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/incremental.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.47&r2=1.47.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/incremental.h.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.28&r2=1.28.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/layout.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.220&r2=1.220.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/options.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.114&r2=1.114.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/options.h.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.169.2.1&r2=1.169.2.2 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/output.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.159&r2=1.159.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/output.h.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.128&r2=1.128.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/plugin.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.48.2.1&r2=1.48.2.2 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/powerpc.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.39&r2=1.39.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/readsyms.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.51&r2=1.51.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/resolve.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.63&r2=1.63.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/script-sections.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.53&r2=1.53.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/script.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.84&r2=1.84.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/script.h.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.37&r2=1.37.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/sparc.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.48.2.1&r2=1.48.2.2 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/symtab.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.159.2.1&r2=1.159.2.2 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/symtab.h.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.125&r2=1.125.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/x86_64.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.139&r2=1.139.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/testsuite/Makefile.in.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.191.2.2&r2=1.191.2.3 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/testsuite/plugin_test_2.sh.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.2&r2=1.2.8.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/testsuite/script_test_2.t.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.3&r2=1.3.14.1