Bug 25809 - [readelf] --dyn-syms: Display a warning if SHT_DYNSYM and PT_DYNAMIC disagree about the location
Summary: [readelf] --dyn-syms: Display a warning if SHT_DYNSYM and PT_DYNAMIC disagree...
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.35
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2020-04-10 00:20 UTC by Fangrui Song
Modified: 2020-05-19 15:49 UTC (History)
3 users (show)

See Also:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2020-04-10 00:20:44 UTC
--use-dynamic is a prehistoric option (available at "19990502 sourceware import") supports. The intention may be to defeat malware's cheating of the location of the dynamic table.

If SHT_DYNSYM and PT_DYNAMIC disagree with the location, llvm-readelf --dyn-syms has a warning:

warning: 'a1.o': SHT_DYNAMIC section header and PT_DYNAMIC program header disagree about the location of the dynamic table

Additionally, there are several other warnings. Some may be applicable to GNU readelf, some may not:

warning: '[[FILE]]': invalid PT_DYNAMIC size (0x1)
warning: '[[FILE]]': no valid dynamic table was found
warning: '[[FILE]]': The SHT_DYNAMIC section '.dynamic' is not at the start of PT_DYNAMIC segment
warning: '[[FILE]]': PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used
Comment 1 Lucille F. Parham 2020-04-15 07:16:26 UTC Comment hidden (spam)
Comment 2 cvs-commit@gcc.gnu.org 2020-05-19 15:48:08 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:


commit 8ac10c5bfca0602398b38cc69976db213a7d9917
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue May 19 16:47:12 2020 +0100

    Allow readelf to issue warnings if checking is enabled and there are discrepancies between the dynamic tags and the dynamic sections.
            PR binutils/25809
            * readelf.c (process_program_headers): Warn if the PT_DYNAMIC
            segment doesn't match the .dynamic section and checks are
            (struct filedata): Add dynamic_symtab_section and
            dynamic_strtab_section fields.
            (process_section_headers): Set dynamic_symtab_section to the
            .dynsym section.  Set dynamic_strtab_section to the .dynstr
            (process_dynamic_section): Warn if the .dynsym section doesn't
            match DT_SYMTAB and DT_SYMENT or the .dynstr section doesn't
            DT_STRTAB and DT_STRSZ.  But only if checks are enabled.
Comment 3 Nick Clifton 2020-05-19 15:49:27 UTC
I have applied H.J.'s patch, modified slightly to put the new variables into the filedata structure and to make the warnings only happen if checks are enabled (ie via --enable-checks).