From 3d7d68054f82fbcace1152da32657e2838e450d2 Mon Sep 17 00:00:00 2001
From: Joerg Wunsch <j@uriah.heep.sax.de>
Date: Wed, 18 Apr 2012 16:00:21 +0000
Subject: [PATCH] * fileio.c (elf2b): When checking the bounds of the current
 program header segment, subtract `low' from ph[n].p_paddr in order to correct
 the magic section offsets for the AVR's non-flash memory regions.

git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@1080 81a1dc3b-b13d-400b-aceb-764788c761c2
---
 avrdude/ChangeLog | 7 +++++++
 avrdude/fileio.c  | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/avrdude/ChangeLog b/avrdude/ChangeLog
index 65a04946..a5b93d12 100644
--- a/avrdude/ChangeLog
+++ b/avrdude/ChangeLog
@@ -1,3 +1,10 @@
+2012-04-18  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
+
+	* fileio.c (elf2b): When checking the bounds of the current
+	program header segment, subtract `low' from ph[n].p_paddr in order
+	to correct the magic section offsets for the AVR's non-flash
+	memory regions.
+
 2012-04-18  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
 
 	* fileio.c (elf_get_scn): Rather than trying to just match whether
diff --git a/avrdude/fileio.c b/avrdude/fileio.c
index 0f859f19..f625543e 100644
--- a/avrdude/fileio.c
+++ b/avrdude/fileio.c
@@ -948,7 +948,7 @@ static int elf2b(char * infile, FILE * inf,
      * from it, using the "foff" offset obtained above.
      */
     if (mem->size != 1 &&
-        ph[i].p_paddr + ph[i].p_filesz > mem->size) {
+        ph[i].p_paddr - low + ph[i].p_filesz > mem->size) {
       fprintf(stderr,
               "%s: ERROR: program header entry #%d does not fit into \"%s\" memory:\n"
               "    0x%x + %u > %u\n",