[PATCH] objdump: Check the SEC_CODE bit for code

Jan Beulich jbeulich@suse.com
Mon Sep 8 06:31:50 GMT 2025


On 07.09.2025 05:28, H.J. Lu wrote:
> 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>
> ---
>  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

Can SEC_CODE and SEC_DATA both be set at the same time? I suppose normally
they shouldn't be, and hence the change is fine as is.

Jan


More information about the Binutils mailing list