On Thu, Jan 18, 2018 at 10:48 PM, Yunlian Jiang <yunl...@google.com> wrote:
> Hi,
>    I tried to build busybox with clang and use it to create recovery image
> for ChromeOS.
> It fails to recover an arm based ChromeBook.
>    I digged a little bit.
>    Below patch makes it work. My question is.
>    the  ash_ptr_to_globals_misc, ash_ptr_to_globals_memstack and
> ash_ptr_to_globals_var
> are defined in ash_ptr_hack.c as normal pointers. But in ash.c, they are
> declared as const
> pointers. What is the benefit of doing that?
>
>    Thanks
> --- busybox-1.27.2/shell/ash.c
> +++ busybox-1.27.2/shell/ash.c
> @@ -378,7 +378,11 @@ struct globals_misc {
>  #endif
>         pid_t backgndpid;        /* pid of last background process */
>  };
> +#ifndef GCC_COMBINE
> +extern struct globals_misc * ash_ptr_to_globals_misc;
> +#else
>  extern struct globals_misc *const ash_ptr_to_globals_misc;
> +#endif
>  #define G_misc (*ash_ptr_to_globals_misc)
>  #define exitstatus        (G_misc.exitstatus )
>  #define back_exitstatus   (G_misc.back_exitstatus )
> @@ -1431,7 +1435,11 @@ struct globals_memstack {
>         size_t g_stacknleft; // = MINSIZE;
>         struct stack_block stackbase;
>  };
> +#ifndef GCC_COMBINE
> +extern struct globals_memstack * ash_ptr_to_globals_memstack;
> +#else
>  extern struct globals_memstack *const ash_ptr_to_globals_memstack;
> +#endif


I committed a bit different fix, a-la


+++ b/shell/ash.c
@@ -263,6 +263,18 @@ typedef long arith_t;
 # error "Do not even bother, ash will not run on NOMMU machine"
 #endif

+/* We use a trick to have more optimized code (fewer pointer reloads):
+ *  ash.c:   extern struct globals *const ash_ptr_to_globals;
+ *  ash_ptr_hack.c: struct globals *ash_ptr_to_globals;
+ * This way, compiler in ash.c knows the pointer can not change.
+ *
+ * However, this may break on weird arches or toolchains. In this case,
+ * set "-DBB_GLOBAL_CONST=''" in CONFIG_EXTRA_CFLAGS to disable this
optimization.
+ */
+#ifndef BB_GLOBAL_CONST
+# define BB_GLOBAL_CONST const
+#endif
+

 /* ============ Hash table sizes. Configurable. */

@@ -400,7 +412,7 @@ struct globals_misc {
 #endif
        pid_t backgndpid;        /* pid of last background process */
 };
-extern struct globals_misc *const ash_ptr_to_globals_misc;
+extern struct globals_misc *BB_GLOBAL_CONST ash_ptr_to_globals_misc;
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to