android: Include malloc_hook section in code range

A few reached functions from third_party/abseil-cpp are outside of the
`.text` section (while still in the executable segment). Extend the
linker_script_end_of_text by the size of this section. This way the
orderfile_instrumentation.cc does not condider them 'unexpected'.

Reduce the number of unexpected addresses from 100 to 10 to be able to
detect problems earlier.

Allow symbols outside of `.text` in the symbol_extractor. When a new
section is added, it will break the orderfile_generator until it is
properly included in the symbol_extractor, which should be in sync with
the linker script definitions.

Do not extract non-function symbols (ifuncs are extracted as normal
functions). This is hypothetically less error-prone.

I checked arm64 orderfile generation with these changes with
--streamline-for-debugging. We will need to look closely at the bot
after landing this.

Bug: 352317042
Change-Id: I442f42ff6fc35e1fd6a8da5afe47b116b853c3b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5697265
Commit-Queue: Egor Pasko <pasko@chromium.org>
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1327155}


CrOS-Libchrome-Original-Commit: ff87ee14fc73d7347342a58a40dc005ed42bf469
diff --git a/base/android/library_loader/anchor_functions.lds b/base/android/library_loader/anchor_functions.lds
index 8bd7876..4b47f1f 100644
--- a/base/android/library_loader/anchor_functions.lds
+++ b/base/android/library_loader/anchor_functions.lds
@@ -4,4 +4,8 @@
 
 # Define symbols that point to the start and end of the .text section.
 PROVIDE_HIDDEN(linker_script_start_of_text = ADDR(.text));
-PROVIDE_HIDDEN(linker_script_end_of_text = ADDR(.text) + SIZEOF(.text));
+
+# The `malloc_hook` section comes from function attributes set in
+# third_party/abseil-cpp. See http://crbug.com/352317042.
+PROVIDE_HIDDEN(linker_script_end_of_text =
+    ADDR(.text) + SIZEOF(.text) + SIZEOF(malloc_hook));
diff --git a/base/android/orderfile/orderfile_instrumentation.cc b/base/android/orderfile/orderfile_instrumentation.cc
index d5cf80f..ebefbd1 100644
--- a/base/android/orderfile/orderfile_instrumentation.cc
+++ b/base/android/orderfile/orderfile_instrumentation.cc
@@ -44,9 +44,7 @@
 // Must be applied to all functions within this file.
 #define NO_INSTRUMENT_FUNCTION __attribute__((no_instrument_function))
 
-namespace base {
-namespace android {
-namespace orderfile {
+namespace base::android::orderfile {
 
 namespace {
 // Constants used for StartDelayedDump().
@@ -145,14 +143,13 @@
       ImmediateCrash();
     }
 
-    // We should really crash at the first instance, but it does happen on bots,
-    // for a mysterious reason. Give it some leeway. Note that since we don't
-    // remember the caller address, if a single function is misplaced but we get
-    // many calls to it, then we still crash. If this is the case, add
-    // deduplication.
-    //
-    // Bumped to 100 temporarily as part of crbug.com/1265928 investigation.
-    if (g_unexpected_addresses.fetch_add(1, std::memory_order_relaxed) < 100) {
+    // Observing return addresses outside of the intended range indicates a
+    // potentially serious problem in the way the build is set up. However, a
+    // small number of unexpected addresses is tolerable for production builds.
+    // It seems useful to allow a limited number of out-of-range addresses to
+    // let the orderfile_generator guess the root causes. See
+    // crbug.com/330761384, crbug.com/352317042.
+    if (g_unexpected_addresses.fetch_add(1, std::memory_order_relaxed) < 10) {
       return;
     }
 
@@ -352,9 +349,7 @@
   return result;
 }
 
-}  // namespace orderfile
-}  // namespace android
-}  // namespace base
+}  // namespace base::android::orderfile
 
 extern "C" {