Am Sa., 9. Okt. 2021 um 20:22 Uhr schrieb 余生与君 <[email protected]>:
>
> Done and tested:
> http://lists.busybox.net/pipermail/busybox/2021-October/089292.html
>
>
> On Sat, Oct 9, 2021 at 7:58 PM Denys Vlasenko <[email protected]> 
> wrote:
> >
> > On Fri, Oct 8, 2021 at 10:39 AM 余生与君 <[email protected]> wrote:
> > > On Thu, Oct 7, 2021 at 9:48 PM Denys Vlasenko <[email protected]> 
> > > wrote:
> > > > On Thu, Oct 7, 2021 at 3:25 PM 余生与君 <[email protected]> wrote:
> > > > > > where p is a dummy, unused variable
> > > > > No. p here shadows the global variable with the same name local
> > > > > variable so the following context (scope) will use this local variable
> > > > > instead of the global one.
> > > >
> > > > Aha...
> > > > The problem here is that even though later uses of "p" in this block
> > > > where we use ASSIGN_CONST_PTR() macro will use the local "p" pointer,
> > > > when we exit the block, the following uses will refer to the global one.
> > > > Nothing prevents them to still use incorrect value.
> > > > The fix depends only on the hope that there won't be such uses.
> > > > But they already exist:
> > > >
> > > > inetd.c:
> > > >         INIT_G();
> > > >         real_uid = getuid();
> > > >
> > > > ftpgetput.c:
> > > >         INIT_G();
> > > >         /* Set default values */
> > > >         user = "anonymous";
> > > >         password = "busybox";
> > >
> > > Yes, I noticed that, and that's why I removed do-while in the INIT_G
> > > in this patch.
> > >
> > > > Can you try something more? E.g. (in current git):
> > > >
> > > > #define ASSIGN_CONST_PTR(p, v) do { \
> > > >         *(void**)not_const_pp(&p) = (void*)(v); \
> > > >         /* At least gcc 3.4.6 on mipsel needs optimization barrier */ \
> > > >         barrier(); \
> > > > +       sleep(0); \
> > > > } while (0)
> > >
> > > Cool! Sleep(0) does the magic!
> > >
> > > ADRP            X21, #ash_ptr_to_globals_misc_ptr@PAGE
> > > LDR             X21, [X21,#ash_ptr_to_globals_misc_ptr@PAGEOFF]
> > > MOV             X8, X21
> > > STR             X0, [X8]
> > > MOV             W0, WZR
> > > BL              sleep
> > > LDR             X21, [X21]
> > >
> > >
> > > And further investigation shows that a dummy function can also do this 
> > > trick!
> > >
> > > hack.c:
> > > void clang_barrier() {
> > > }
> > >
> > > libbb.h:
> > > void clang_barrier(); // invisible in this file
> > > #define ASSIGN_CONST_PTR(p, v) do { \
> > >         *(void**)not_const_pp(&p) = (void*)(v); \
> > >         /* At least gcc 3.4.6 on mipsel needs optimization barrier */ \
> > > -        barrier(); \
> > > +       clang_barrier(); \
> > > } while (0)
> >
> > Let's go with having a function.
> >
> > All ASSIGN_CONST_PTR's except one assign a malloced address.
> >
> > Let's have XZALLOC_CONST_PTR(&cptr, size), and let's
> > make it a function, not macro, for clang. It will act
> > a barrier function.
> _______________________________________________
> busybox mailing list
> [email protected]
> http://lists.busybox.net/mailman/listinfo/busybox

You have a some small piece of code for reproducing the issue?

The problem sounds lot like what std::launder [1] is supposed to
solve, there is a builtin `__builtin_launder` for this very purpose
(not sure which version of clang added it).
If this is the case, then the builtin should be preferred whenever available.

Norbert

[1] - https://en.cppreference.com/w/cpp/utility/launder
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to