Bug 21212 - Improve "Empty loadable segment detected" warning
Summary: Improve "Empty loadable segment detected" warning
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.29
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-02 08:45 UTC by Martin Bickel
Modified: 2017-03-03 10:24 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
git patch (843 bytes, patch)
2017-03-02 08:45 UTC, Martin Bickel
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Bickel 2017-03-02 08:45:19 UTC
Created attachment 9868 [details]
git patch

This warning is currently shown (among other situations) when a segment has p_filesz = 0 and a p_memsz > 0 , which is a valid setup to initialize flash memory of embedded systems with zeros and explicitly mentioned in the ELF specification as a valid use case.
The attached patch limits the warning to situations when p_filesz > 0 - which happens when a segment is truncated to 0 length by an objcopy operation that removes all of the segment's sections.

When the warning is shown, it should identify the segment it is talking about. The attached patch includes the p_vaddr of the segment for that purpose.
Comment 1 cvs-commit@gcc.gnu.org 2017-03-02 14:49:18 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

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

commit f98450c6eee6878ebf5b052d231758026d250427
Author: Nick Clifton <nickc@redhat.com>
Date:   Thu Mar 2 14:47:29 2017 +0000

    Disable warning message about a program header with no associated sections when that header's file size is non-zero.
    
    	PR ld/21212
    	* elf.c (rewrite_elf_program_header): Do not issue a warning for
    	empty segments which have a non-zero filesz.
Comment 2 Nick Clifton 2017-03-02 14:50:55 UTC
Hi Martin,

  Thanks for the bug report and patch.  I have applied your patch with one
  small change - the warning will still be issued if the p_filesz field is
  zero *and* p_memsz is zero.  I hope that this is OK with you.

Cheers
  Nick
Comment 3 Martin Bickel 2017-03-02 19:13:14 UTC
Hi Nick,

your updated change is ok - I don't see any value in having segments with memsz==0 , so a warning makes sense.

However, your commit message and Changelog entry is the wrong way round: the warning is disabled when filesz is zero and *memsz* is nonzero.



Here is the behavior:

filesz | memsz | original code | Martin's patch | Nick's patch
--------------------------------------------------------------
  0       0      warn             don't warn       warn
  0     > 0      warn             don't warn       don't warn
> 0     > 0      warn             warn             warn
> 0       0      warn             warn             warn

The last line shouldn't be relevant as it's illegal in ELF.
Comment 4 cvs-commit@gcc.gnu.org 2017-03-03 10:23:16 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

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

commit d20928fac9ab65449db910bd99a0f48ad29fb22b
Author: Nick Clifton <nickc@redhat.com>
Date:   Fri Mar 3 10:22:16 2017 +0000

    Fix thinko in previous changelog entry.
    
    	PR ld/21212
    	* elf.c (rewrite_elf_program_header): Do not issue a warning for
    	empty segments which have a zero filesz, but a non-zero memsz.
Comment 5 Nick Clifton 2017-03-03 10:24:19 UTC
Hi Martin,

> However, your commit message and Changelog entry is the wrong way round: the
> warning is disabled when filesz is zero and *memsz* is nonzero.

Doh!  Yes you are right.  I have checked in a fix for the changelog entry.

Cheers
  Nick