scripts: gen_handles.py: take device start symbol as argument.

The current gen_handles.py script uses linker defined symbols.
As preparation for support of more linkers the gen_tables.py now takes
the device start symbol as argument.

For example, armlink and ld uses different symbols.
With ld those can be named explicitly, but for armlink the linker
decides the names.

For ld, Zephyr defines: __device_start
For armlink, the symbol is defined as: Image$$<section name>$$Base

Therefore knowledge of the linker symbol to be used must be passed to
gen_handles.py so that the correct symbol can be used for locating
devices.

To support this change, the creation of the asm, compiler, compiler-cpp,
linker targets has been moved from target_toolchain_flags.cmake to
target_toolchain.cmake.

All linkers has been updated to support the use of the
device_start_symbol on the linker target.

List of linkers updated:
- ld
- lld
- arcmwdt

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
diff --git a/scripts/gen_handles.py b/scripts/gen_handles.py
index 441ad64..c8354d9 100755
--- a/scripts/gen_handles.py
+++ b/scripts/gen_handles.py
@@ -73,6 +73,11 @@
                         is not provided the environment will be checked for \
                         the ZEPHYR_BASE environment variable.")
 
+    parser.add_argument("-s", "--start-symbol", required=True,
+                        help="Symbol name of the section which contains the \
+                        devices. The symbol name must point to the first \
+                        device in that section.")
+
     args = parser.parse_args()
     if "VERBOSE" in os.environ:
         args.verbose = 1
@@ -145,7 +150,7 @@
             else:
                 format += "Q"
                 size = 8
-            offset = self.ld_constants["DEVICE_STRUCT_HANDLES_OFFSET"]
+            offset = self.ld_constants["_DEVICE_STRUCT_HANDLES_OFFSET"]
             self.__handles = struct.unpack(format, data[offset:offset + size])[0]
         return self.__handles
 
@@ -172,7 +177,8 @@
     devices = []
     handles = []
     # Leading _ are stripped from the stored constant key
-    want_constants = set(["__device_start",
+
+    want_constants = set([args.start_symbol,
                           "_DEVICE_STRUCT_SIZEOF",
                           "_DEVICE_STRUCT_HANDLES_OFFSET"])
     ld_constants = dict()
@@ -181,7 +187,7 @@
         if isinstance(section, SymbolTableSection):
             for sym in section.iter_symbols():
                 if sym.name in want_constants:
-                    ld_constants[sym.name.lstrip("_")] = sym.entry.st_value
+                    ld_constants[sym.name] = sym.entry.st_value
                     continue
                 if sym.entry.st_info.type != 'STT_OBJECT':
                     continue
@@ -204,7 +210,7 @@
 
     devices = sorted(devices, key = lambda k: k.sym.entry.st_value)
 
-    device_start_addr = ld_constants["device_start"]
+    device_start_addr = ld_constants[args.start_symbol]
     device_size = 0
 
     assert len(devices) == len(handles), 'mismatch devices and handles'