ASH: why ash_ptr_to_globals_misc is declared as const pointer

Mike Frysinger vapier at gentoo.org
Mon Jan 29 05:52:47 UTC 2018


On 28 Jan 2018 20:41, Denys Vlasenko wrote:
> On Thu, Jan 18, 2018 at 10:48 PM, Yunlian Jiang <yunlian at 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

you've only updated ash.c though ... all of the users of this style
can run into the same issue.  i see:
	test_ptr_to_statics
	lineedit_ptr_to_statics
	ptr_to_globals

might be a good time to try to unify this stuff with some helper macros ?

#ifndef GCC_COMBINE
#define G_DECL_STORAGE(type, name) type *name
#else
#define G_DECL_STORAGE(type, name) type *const name __attribute__ ((__section__ (".data")))
#endif
#define G_DECL(type, name) extern type *const name

i wonder if the barrier could be changed in a way to make clang load after the
assignment though.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20180129/de086e84/attachment.asc>


More information about the busybox mailing list