elflint: Allow zero p_memsz for PT_RISCV_ATTRIBUTES

Message ID mvm1qtplszi.fsf@suse.de
State Committed
Headers
Series elflint: Allow zero p_memsz for PT_RISCV_ATTRIBUTES |

Commit Message

Andreas Schwab Aug. 9, 2022, 8:29 a.m. UTC
  The RISCV_ATTRIBUTES segment is not meant to be loaded.

Signed-off-by: Andreas Schwab <schwab@suse.de>
---
 src/ChangeLog | 5 +++++
 src/elflint.c | 5 ++++-
 2 files changed, 9 insertions(+), 1 deletion(-)
  

Comments

Mark Wielaard Aug. 9, 2022, 5:11 p.m. UTC | #1
Hi Andreas,

On Tue, Aug 09, 2022 at 10:29:53AM +0200, Andreas Schwab wrote:
> The RISCV_ATTRIBUTES segment is not meant to be loaded.

That makes sense. Pushed.

Thanks,

Mark
  

Patch

diff --git a/src/ChangeLog b/src/ChangeLog
index 42ce6640..fbcef29e 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@ 
+2022-08-09  Andreas Schwab  <schwab@suse.de>
+
+	* elflint.c (check_program_header): Don't complain about p_filesz
+	> p_memsz if p_memsz is zero and p_type is PT_RISCV_ATTRIBUTES.
+
 2022-08-01  Mark Wielaard  <mark@klomp.org>
 
 	* readelf.c (handle_dynamic): Pass start of buffer to memrchr.
diff --git a/src/elflint.c b/src/elflint.c
index d919936f..b0e5415e 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -4731,7 +4731,10 @@  section [%2zu] '%s' must not be executable\n"),
 	}
 
       if (phdr->p_filesz > phdr->p_memsz
-	  && (phdr->p_memsz != 0 || phdr->p_type != PT_NOTE))
+	  && (phdr->p_memsz != 0
+	      || (phdr->p_type != PT_NOTE
+		  && !(ehdr->e_machine == EM_RISCV
+		       && phdr->p_type == PT_RISCV_ATTRIBUTES))))
 	ERROR (_("\
 program header entry %d: file size greater than memory size\n"),
 	       cnt);