scripts: build: elf_parser: retrieve section directly

Retrieve the section holding the symbol data directly from the symbol
information, instead of trying to find a section that contains data at
the correct address. The later approach does not work for relocatable
files, which contain multiple sections all containing data in
overlapping temporary memory addresses (usually starting at 0).

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
diff --git a/scripts/build/elf_parser.py b/scripts/build/elf_parser.py
index c156e41..091240e 100644
--- a/scripts/build/elf_parser.py
+++ b/scripts/build/elf_parser.py
@@ -147,15 +147,14 @@
         """
         Retrieve the raw bytes associated with a symbol from the elf file.
         """
+        # Symbol data parameters
         addr = sym.entry.st_value
-        len = sym.entry.st_size
-        for section in self.elf.iter_sections():
-            start = section['sh_addr']
-            end = start + section['sh_size']
-
-            if (start <= addr) and (addr + len) <= end:
-                offset = addr - section['sh_addr']
-                return bytes(section.data()[offset:offset + len])
+        length = sym.entry.st_size
+        # Section associated with the symbol
+        section = self.elf.get_section(sym.entry['st_shndx'])
+        offset = addr - section['sh_addr']
+        # Extract bytes
+        return bytes(section.data()[offset:offset + length])
 
     def _symbols_find_value(self, names):
         symbols = {}