Patch: use BB_GLOBAL_CONST where applicable

Denys Vlasenko vda.linux at googlemail.com
Tue Jun 18 16:38:30 UTC 2019


On Mon, Jun 17, 2019 at 2:30 PM Luís Marques <luismarques at lowrisc.org> wrote:
>
> On Thu, Jun 6, 2019 at 7:19 PM Denys Vlasenko <vda.linux at googlemail.com> wrote:
> > Can you experiment with LLVM and find a definition of SET_PTR_TO_GLOBALS()
> > which works for it?
>
> I did not find any correct solution for this other than disabling the
> optimization for Clang/LLVM.

Works for me with the following versions:
llvm-libs-8.0.0-7.fc31.x86_64
llvm-8.0.0-7.fc31.x86_64
clang-libs-8.0.0-3.fc31.x86_64
clang-8.0.0-3.fc31.x86_64


struct globals;
extern struct globals *const ptr_to_globals;
#define barrier() __asm__ __volatile__("":::"memory")
#define SET_PTR_TO_GLOBALS(x) do { \
        (*(struct globals**)&ptr_to_globals) = (void*)(x); \
        barrier(); \
} while (0)
void f(void *p)
{
        SET_PTR_TO_GLOBALS(p);
}

$ clang -Os -Wall -S t.c
$ cat t.s
        .text
        .file   "t.c"
        .globl  f                       # -- Begin function f
        .type   f, at function
f:                                      # @f
        .cfi_startproc
# %bb.0:
        movq    %rdi, ptr_to_globals(%rip)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ store to ptr_to_globals
        #APP
        #NO_APP
        retq
.Lfunc_end0:
        .size   f, .Lfunc_end0-f
        .cfi_endproc
                                        # -- End function

        .ident  "clang version 8.0.0 (Fedora 8.0.0-3.fc31)"
        .section        ".note.GNU-stack","", at progbits
        .addrsig


More information about the busybox mailing list