|
|
901878 |
commit 5e681c46b3893d87e3156a0a6c2783de5fa41c94
|
|
|
901878 |
Author: Mark Wielaard <mjw@redhat.com>
|
|
|
901878 |
Date: Wed Aug 12 00:11:26 2015 +0200
|
|
|
901878 |
|
|
|
901878 |
elflint: Add gnuld check when a NOBITS section falls inside a segment.
|
|
|
901878 |
|
|
|
901878 |
gnuld has a really bad bug where it can place a NOBITS section inside
|
|
|
901878 |
a PT_LOAD segment. Normally that would not work. But it also makes sure
|
|
|
901878 |
that the contents of the file is all zeros. So in practice it is actually
|
|
|
901878 |
a PROGBITS section with all zero data. Except that other tools will think
|
|
|
901878 |
there is an unused gap in the ELF file after the NOBITS section.
|
|
|
901878 |
|
|
|
901878 |
Recognize and check this pattern in elflint when --gnu is given.
|
|
|
901878 |
|
|
|
901878 |
Signed-off-by: Mark Wielaard <mjw@redhat.com>
|
|
|
901878 |
|
|
|
901878 |
diff --git a/src/elflint.c b/src/elflint.c
|
|
|
901878 |
index a916886..0d5f34d 100644
|
|
|
901878 |
--- a/src/elflint.c
|
|
|
901878 |
+++ b/src/elflint.c
|
|
|
901878 |
@@ -3978,9 +3978,39 @@ section [%2zu] '%s' not fully contained in segment of program header entry %d\n"
|
|
|
901878 |
{
|
|
|
901878 |
if (shdr->sh_offset < phdr->p_offset + phdr->p_filesz
|
|
|
901878 |
&& !is_debuginfo)
|
|
|
901878 |
- ERROR (gettext ("\
|
|
|
901878 |
+ {
|
|
|
901878 |
+ if (!gnuld)
|
|
|
901878 |
+ ERROR (gettext ("\
|
|
|
901878 |
section [%2zu] '%s' has type NOBITS but is read from the file in segment of program header entry %d\n"),
|
|
|
901878 |
- cnt, section_name (ebl, cnt), pcnt);
|
|
|
901878 |
+ cnt, section_name (ebl, cnt), pcnt);
|
|
|
901878 |
+ else
|
|
|
901878 |
+ {
|
|
|
901878 |
+ /* This is truly horrible. GNU ld might put a
|
|
|
901878 |
+ NOBITS section in the middle of a PT_LOAD
|
|
|
901878 |
+ segment, assuming the next gap in the file
|
|
|
901878 |
+ actually consists of zero bits...
|
|
|
901878 |
+ So it really is like a PROGBITS section
|
|
|
901878 |
+ where the data is all zeros. Check those
|
|
|
901878 |
+ zero bytes are really there. */
|
|
|
901878 |
+ bool bad;
|
|
|
901878 |
+ Elf_Data *databits;
|
|
|
901878 |
+ databits = elf_getdata_rawchunk (ebl->elf,
|
|
|
901878 |
+ shdr->sh_offset,
|
|
|
901878 |
+ shdr->sh_size,
|
|
|
901878 |
+ ELF_T_BYTE);
|
|
|
901878 |
+ bad = (databits == NULL
|
|
|
901878 |
+ || databits->d_size != shdr->sh_size);
|
|
|
901878 |
+ for (size_t idx = 0;
|
|
|
901878 |
+ idx < databits->d_size && ! bad;
|
|
|
901878 |
+ idx++)
|
|
|
901878 |
+ bad = ((char *) databits->d_buf)[idx] != 0;
|
|
|
901878 |
+
|
|
|
901878 |
+ if (bad)
|
|
|
901878 |
+ ERROR (gettext ("\
|
|
|
901878 |
+section [%2zu] '%s' has type NOBITS but is read from the file in segment of program header entry %d and file contents is non-zero\n"),
|
|
|
901878 |
+ cnt, section_name (ebl, cnt), pcnt);
|
|
|
901878 |
+ }
|
|
|
901878 |
+ }
|
|
|
901878 |
}
|
|
|
901878 |
else
|
|
|
901878 |
{
|