orderfile: Filter out $-symbols in orderfile

Orderfile generated from the Arm Chrome contains $x.NNN symbols.
This causes linker to silently drop the orderfile.

BUG=b:270758741
TEST=unit test

Change-Id: If93b8d3fa71e9a1b8e120e51524033b2ebc0f581
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/4321427
Reviewed-by: George Burgess <gbiv@chromium.org>
Commit-Queue: Denis Nikitin <denik@chromium.org>
Tested-by: Denis Nikitin <denik@chromium.org>
diff --git a/orderfile/post_process_orderfile.py b/orderfile/post_process_orderfile.py
index 5f52aa6..d90c1af 100755
--- a/orderfile/post_process_orderfile.py
+++ b/orderfile/post_process_orderfile.py
@@ -59,7 +59,13 @@
     head_marker = "chrome_begin_ordered_code"
     tail_marker = "chrome_end_ordered_code"
 
-    c3_ordered_syms = [x.strip() for x in c3_ordered_stream.readlines()]
+    # Filter out $symbols which can come up in the orderfile as well.
+    # Linker ignores the whole orderfile if it finds $symb.
+    c3_ordered_syms = [
+        x.strip()
+        for x in c3_ordered_stream.readlines()
+        if not x.strip().startswith("$")
+    ]
     all_chrome_syms = set(_parse_nm_output(chrome_nm_stream))
     # Sort by name, so it's predictable. Otherwise, these should all land in the
     # same hugepage anyway, so order doesn't matter as much.
diff --git a/orderfile/post_process_orderfile_test.py b/orderfile/post_process_orderfile_test.py
index 60716d8..9dd574a 100755
--- a/orderfile/post_process_orderfile_test.py
+++ b/orderfile/post_process_orderfile_test.py
@@ -29,6 +29,7 @@
 def _write_orderfile(name):
     with open(name, "w") as out:
         out.write("SymbolOrdered1\n")
+        out.write("$toignore.123\n")
         out.write("SymbolOrdered2\n")