ASH: why ash_ptr_to_globals_misc is declared as const pointer

Mike Frysinger vapier at gentoo.org
Tue Jan 23 00:00:06 UTC 2018


On 22 Jan 2018 22:54, Ralf Friedl wrote:
> Mike Frysinger schrieb:
> > On 22 Jan 2018 09:23, Yunlian Jiang wrote:
> >> On Fri, Jan 19, 2018 at 3:32 PM, Mike Frysinger wrote:
> >>> is it that busybox is crashing ?  is clang/lld placing this pointer in
> >>> const
> >>> memory (even though we have section(".data")) ?  or is it generating an
> >>> abort
> >>> when it reaches what it thinks is an undefined situation (like trying to
> >>> write
> >>> to a const memory location in INIT_G_var()) ?
> >>>
> >> The busybox is crashing. On arm boards, the command line
> >> 'busybox ash' gave me a segmentation fault.
> >>
> >> In the ash_ptr_hack.c, it sets the attribute  __attribute__ (section
> >> (".data")) when
> >> 'GCC_COMBINE' is defined.  But clang does not have this MACRO defined.
> > i don't think GCC_COMBINE is relevant, so just forget about it.  ash_ptr_hack.c
> > does:
> >    struct globals_misc *ash_ptr_to_globals_misc;
> > that means that pointer should end up the .data/writable memory by default.
> >
> > the fact that another compilation unit declares it as const isn't terribly
> > relevant ... the actual storage should still be writable.  you should check
> > that is happening (or if it's ending up somewhere else).  we've seen llvm
> > incorrectly propagate attributes to storage before based on decls seen in
> > other modules.
> GCC_COMBINE is relevant because it changes the definitions aof the 
> pointers. without GCC_COMBINE, they are defined as normal variables, and 
> every compiler should be able to compile them. With GCC_COMBINE they are 
> defined as const but with section ".data", and a compiler that doesn't 
> understand that will fail. in busybox GCC_COMBINE is only set in 
> scripts/Makefile.IMA, together with -combine and -fwhole-program. The 
> first line of this script says "This is completely unsupported." A 
> compiler that doesn't support -combine and -fwhole-program doesn't need 
> to define GCC_COMBINE and won't have a problem with the code. If the 
> compiler supports the concept of -fwhole-program, the trick to use a 
> different definition and declaration in different files no longer works. 
> But maybe then the compiler is smart enough to realize that there are no 
> other assignments to the pointers so it can omit the reload. If not, 
> something like the ".data" section is necessary, and if the compiler has 
> -fwhole-program but no ".data", then this can't be used.

GCC_COMBINE isn't relevant to this thread because we aren't building with
gcc, nor doing are we doing an IMA build.  hence GCC_COMBINE is never defined
and it has no impact on Yunlian's setup.  we're only interested in the clang
behavior here.
-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/20180122/8cb9e2f4/attachment.asc>


More information about the busybox mailing list