symbolize.py: add support for TEE core ASLR

With the introduction of ASLR, the abort and panic dumps for the TEE
core have gained a "Load address" line. Update the symbolize.py script
to parse that line and pass relative addresses to addr2line.

Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
Signed-off-by: Jerome Forissier <jerome@forissier.org>
diff --git a/scripts/symbolize.py b/scripts/symbolize.py
index 631ae6e..b63c745 100755
--- a/scripts/symbolize.py
+++ b/scripts/symbolize.py
@@ -15,6 +15,7 @@
 import termios
 
 CALL_STACK_RE = re.compile('Call stack:')
+TEE_LOAD_ADDR_RE = re.compile(r'Load address @ (?P<load_addr>0x[0-9a-f]+)')
 # This gets the address from lines looking like this:
 # E/TC:0  0x001044a8
 STACK_ADDR_RE = re.compile(
@@ -161,7 +162,11 @@
         cmd = self.arch_prefix('addr2line')
         if not cmd:
             return
-        self._addr2line = self.my_Popen([cmd, '-f', '-p', '-e', elf])
+        args = [cmd]
+        if elf_name == 'tee.elf' and self._tee_load_addr != '0x0':
+            args += ['-j.text']
+        args += ['-f', '-p', '-e', elf]
+        self._addr2line = self.my_Popen(args)
         self._addr2line_elf_name = elf_name
 
     # If addr falls into a region that maps a TA ELF file, return the load
@@ -184,14 +189,14 @@
             return '0x0'
         else:
             # tee.elf
-            return '0x0'
+            return self._tee_load_addr
 
     def elf_for_addr(self, addr):
+        if not self._regions:
+            return 'tee.elf'
         l_addr = self.elf_load_addr(addr)
         if l_addr is None:
             return None
-        if l_addr is '0x0':
-            return 'tee.elf'
         for k in self._elfs:
             e = self._elfs[k]
             if int(e[1], 16) == int(l_addr, 16):
@@ -364,6 +369,7 @@
         self._sections = {}  # {elf_name: [[name, addr, size], ...], ...}
         self._regions = []   # [[addr, size, elf_idx, saved line], ...]
         self._elfs = {0: ["tee.elf", 0]}  # {idx: [uuid, load_addr], ...}
+        self._tee_load_addr = 0x0
         self._func_graph_found = False
         self._func_graph_skip_line = True
 
@@ -426,6 +432,9 @@
             self._elfs[i] = [match.group('uuid'), match.group('load_addr'),
                              line]
             return
+        match = re.search(TEE_LOAD_ADDR_RE, line)
+        if match:
+            self._tee_load_addr = match.group('load_addr')
         match = re.search(CALL_STACK_RE, line)
         if match:
             self._call_stack_found = True