strip producing invalid executable

Jan Beulich jbeulich@suse.com
Mon Sep 15 03:11:07 GMT 2025


On 15.09.2025 00:33, H.J. Lu wrote:
> On Sun, Sep 14, 2025 at 3:02 PM Paul Edwards <mutazilah@gmail.com> wrote:
> 
>> I produce 32-bit x86 ELF executables, with relocations, using pdld.
>>
>> They run fine.
>>
>>
>> But when I attempt to strip them (noting that "file" claims
>> they are already stripped), strip silently produces a broken
>> executable.
>>
>>
>> root@kerravon2-pc:/home/kerravon/w2kshare# ./pdptest.orig
>> welcome to pdptest
>> main function is at 004011F4
>> allocating 10 bytes
>> m1 is EA192004
>> allocating 20 bytes
>> m2 is EA191004
>> stack is around FFA44934
>> usage: pdptest [-bb/-tt/-tb/-bt] <infile> <outfile>
>> default is text to text copy
>>
>> root@kerravon2-pc:/home/kerravon/w2kshare# ./pdptest.strip
>> Segmentation fault (core dumped)
>> root@kerravon2-pc:/home/kerravon/w2kshare#
>>
>>
>> root@kerravon2-pc:/home/kerravon/w2kshare# ls -l pdptest.orig
>> -rwxrwx--- 1 root vboxsf 39480 Sep 14 18:27 pdptest.orig
>> root@kerravon2-pc:/home/kerravon/w2kshare# ls -l pdptest.strip
>> -rwxrwx--- 1 root vboxsf 39340 Sep 14 18:28 pdptest.strip
>> root@kerravon2-pc:/home/kerravon/w2kshare# file pdptest.orig
>> pdptest.orig: ELF 32-bit LSB executable, Intel 80386, version 1
>> (SYSV), statically linked, stripped
>> root@kerravon2-pc:/home/kerravon/w2kshare#
>>
>>
>> If anyone is interested, I have uploaded those two files as:
>>
>> https://pdos.org/stripbug.zip
> 
> 
> The section header is wrong:
> 
>  Section Headers:
>   [Nr] Name              Type            Addr     Off    Size   ES Flg Lk
> Inf Al
>   [ 0]                   NULL            00000000 000000 000000 00      0
> 0  0
>   [ 1] .text             PROGBITS        00401000 001000 0062ea 00   X  0
> 0 4096
>   [ 2] .rel.text         REL             00000000 0072ec 001088 08      0
> 1  4
>   [ 3] .data             PROGBITS        00408000 009000 0007f0 00   W  0
> 0 4096
>   [ 4] .rel.data         REL             00000000 0097f0 000080 08      0
> 3  4
>   [ 5] .bss              NOBITS          00409000 000000 006bb0 00  WA  0
> 0 4096
>   [ 6] .shstrtab         STRTAB          00000000 009870 000024 00      0
> 0  1
> 
> The SHF_ALLOC bit is unset on  .text  and .data sections.

And? The section table isn't relevant for running an executable, is it?
strip shouldn't be corrupting the program headers (presumably due to
re-building them from the section table). In fact, for an already
stripped binary strip would likely best do nothing.

Jan


More information about the Binutils mailing list