[binutils-gdb] objdump: Check the SEC_CODE bit for code

H.J. Lu hjl@sourceware.org
Mon Sep 8 12:42:04 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6b27a220321ecead5435b170f1db02f1876cee08

commit 6b27a220321ecead5435b170f1db02f1876cee08
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sat Sep 6 20:28:13 2025 -0700

    objdump: Check the SEC_CODE bit for code
    
    If a shared library has
    
    $ readelf -D -sW x.so | grep _PROCEDURE_LINKAGE_TABLE_
         3: 00000000000002c0     0 OBJECT  GLOBAL DEFAULT    5 _PROCEDURE_LINKAGE_TABLE_
    $
    
    Disassembler treats PLT0 as data:
    
    $ objdump -dw x.so
    
    x.so:     file format elf64-x86-64
    
    Disassembly of section .plt:
    
    00000000000002c0 <_PROCEDURE_LINKAGE_TABLE_>:
     2c0:   ff 35 7a 01 10 00 ff 25 7c 01 10 00 0f 1f 40 00     .5z....%|.....@.
    
    00000000000002d0 <foo@plt>:
     2d0:   ff 25 7a 01 10 00       jmp    *0x10017a(%rip)        # 100450 <foo>
     2d6:   68 00 00 00 00          push   $0x0
     2db:   e9 e0 ff ff ff          jmp    2c0 <_PROCEDURE_LINKAGE_TABLE_>
    
    Disassembly of section .text:
    
    00000000000002e0 <func>:
     2e0:   e8 eb ff ff ff          call   2d0 <foo@plt>
     2e5:   c3                      ret
    
    Check the SEC_CODE bit on section for code.
    
            PR binutils/33389
            * objdump.c (disassemble_section): Check SEC_CODE for code.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>

Diff:
---
 binutils/objdump.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/binutils/objdump.c b/binutils/objdump.c
index 0bea4d0761c..d322775e72d 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -4091,6 +4091,7 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
       if (disassemble_all
 	  || sym == NULL
 	  || sym->section != section
+	  || (section->flags & SEC_CODE) != 0
 	  || bfd_asymbol_value (sym) > addr
 	  || ((sym->flags & BSF_OBJECT) == 0
 	      && (strstr (bfd_asymbol_name (sym), "gnu_compiled")


More information about the Binutils-cvs mailing list