On 12-12-21 03:20 PM, Aleksandar Ristovski wrote: > Hello all, > > > Currently gdb may use mismatched binary without complaining or noticing. > This is particularly often the case when debugging remote targets, or > multiple of, with multiple versions of libraries. > > The situation is possible on self hosted as well. > > For example, consider having: > 1) a library called 'libso.so.1', with SONAME 'libso.so.1'; > 2) a program linked against it; > 3) environment in which program can be executed and library from 1) > found by the dynamic linker; > 4) modified libso.so.1, different from the one found by the dynamic > linker in 3), in the current working directory of gdb; > 5) attach to process stared in 3) using gdb. > > What happens is, gdb will happily use modified libso.so.1 from current > working directory without noticing the mismatch. This causes a lot of > confusion. > > (I can elaborate on the example if needed). > > > Change introduces new target_so_ops function dedicated to performing > validation. If we have loaded and relocated the object, validation > fails, we throw away bfd and loading of the object fails. > > The gist of the change is in solib-svr4.c and solib.c The rest are > mechanical changes to fill-in new field with valid value. > > (for bonus points, solib-svr4.c now compiles without -Wno-unused) > > Regression test suite shows no regressions. (tested on > x86_64-unknown-linux-gnu). > > While writing a testcase I realized the patch as posted did not work in general cases. Comparing whole elf header and whole pheader is not an option as they change depending on whether the binary is stripped and such. New change log: Aleksandar Ristovski * mips-linux-tdep.c (mips_linux_init_abi): Assign validate value. * ppc-linux-tdep.c (ppc_linux_init_abi): Ditto. * solib-darwin.c (_initialize_darwin_solib): Ditto. * solib-dsbt.c (_initialize_dsbt_solib): Ditto. * solib-frv.c (_initialize_frv_solib): Ditto. * solib-ia64-hpux.c (ia64_hpux_target_so_ops): Ditto. * solib-irix.c (_initialize_irix_solib): Ditto. * solib-osf.c (_initialize_osf_solib): Ditto. * solib-pa64.c (_initialize_pa64_solib): Ditto. * solib-som.c (_initialize_som_solib): Ditto. * solib-spu.c (set_spu_solib_ops): Ditto. * solib-sunos.c (_initialize_sunos_solib): Ditto. * solib-svr4.c (read_program_headers_from_bfd, read_elf_header_from_bfd): Forward declare. (lm_addr_check): New formal argument TRUSTED. (svr4_keep_data_in_core): Remove unused variable. (read_elf_header_from_target, read_program_headers_from_target, svr4_validate_ehdr_match, svr4_validate_phdr_match, svr4_validate_hdrs_match, svr4_validate): New function. (svr4_read_so_list): Remove unused variable. (enable_break): Pass TRUSTED to lm_addr_check. (read_elf_header_from_bfd): New function. (svr4_relocate_section_address): Pass TRUSTED to lm_addr_check. (_initialize_svr4_solib): Use svr4_validate. * solib-target.c (solib.h): Include. (_initialize_solib_target): Assign validate value. * solib.c (solib_map_sections): Validate loaded SO. (solib_validate): New function. * solib.h (solib_validate): Declare. * solist.h (target_so_ops): New field 'validate'. Test suite change log: Aleksandar Ristovski * gdb.base/solib-mismatch-lib.c: New file. * gdb.base/solib-mismatch-libmod.c: New file. * gdb.base/solib-mismatch-libmod2.c: New file. * gdb.base/solib-mismatch.c: New file. * gdb.base/solib-mismatch.exp: New test for solib validation. Updated patch, including tests attached. Thank you, Aleksandar