dynamic linker is running for init

init is now built as a dynamic executable, so the dynamic linker has to
be able to run in the init process. However, since init is launched so
early, even /dev/* and /proc/* file systems are not mounted and thus
some APIs that rely on the paths do not work. The dynamic linker now
goes alternative path when it is running in the init process.

For example, /proc/self/exe is not read for the init since we always now
the path of the init (/init). Also, arc4random* APIs are not used since
the APIs rely on /dev/urandom. Linker now does not randomize library
loading order and addresses when running in the init process.

Bug: 80454183
Test: `adb reboot recovery; adb devices` shows the device ID
Change-Id: I29b6d70e4df5f7f690876126d5fe81258c1d3115
diff --git a/linker/linker_soinfo.cpp b/linker/linker_soinfo.cpp
index 3191ac7..795b01d 100644
--- a/linker/linker_soinfo.cpp
+++ b/linker/linker_soinfo.cpp
@@ -748,7 +748,14 @@
   // Make sure the handle is unique and does not collide
   // with special values which are RTLD_DEFAULT and RTLD_NEXT.
   do {
-    arc4random_buf(&handle_, sizeof(handle_));
+    if (!is_init()) {
+      arc4random_buf(&handle_, sizeof(handle_));
+    } else {
+      // arc4random* is not available in init because /dev/urandom hasn't yet been
+      // created. So, when running with init, use the monotonically increasing
+      // numbers as handles
+      handle_ += 2;
+    }
     // the least significant bit for the handle is always 1
     // making it easy to test the type of handle passed to
     // dl* functions.