Переменные стека выравниваются GCC __ атрибут __ ((выровнялся (x)))?

Можете ли вы проверить этот документ - https://medium.com/tech-tajawal/deploying-react-app-to-google-app-engine-a6ea0d5af132

Это будет помочь тебе. Я развернул свое приложение, используя те же шаги.

Пример файла yaml

    runtime: python27
    api_version: 1
    threadsafe: true
    handlers:
    - url: /
      static_files: build/index.html
      upload: build/index.html
    - url: /
      static_dir: build

Ссылочная ссылка - https://medium.com/google-cloud/how-to-deploy-a-static-react-site-to-google -cloud-platform-55ff0bd0f509

Спасибо!

86
задан Peter Cordes 31 October 2019 в 04:30
поделиться

1 ответ

I believe the problem is that your array is on the stack, and that your compiler is too old to support over-aligned stack variables. GCC 4.6 and later fixed that bug.

C11/C++11 alignas(64) float a[4]; Just Works for any power of 2 alignment.
So does the GNU C __attribute__((aligned(x))) as you were using it.

(In C11, #include for the #define alignas _Alignas: cppref).


But in your case of a very large alignment, to a 4k page boundary, you may not want it on the stack.

Because the stack pointer could be anything when the function starts, there is no way to align the array without allocating a lot more than you need and adjusting it. (Compilers will and rsp, -4096 or equivalent and not use any of the 0 to 4088 bytes that allocated; branching on whether that space is large enough or not would be possible but isn't done because huge alignments much larger than the size of the array or other locals are not the normal case.)

If you move the array out of the function and into a global variable, it should work. The other thing you could do is keep it as a local variable (which is a very good thing), but make it static. This will prevent it from being stored on the stack. Beware that both of these ways are not thread-safe or recursion-safe, since there will be only one copy of the array.

With this code:

#include <stdio.h>

float a[4] __attribute__((aligned(0x1000))) = {1.0, 2.0, 3.0, 4.0};

int
main(void)
{
        printf("%p %p %p %p\n", &a[0], &a[1], &a[2], &a[3]);
}

I get this:

0x804c000 0x804c004 0x804c008 0x804c00c

which is what is expected. With your original code, I just get random values like you did.

96
ответ дан 24 November 2019 в 08:02
поделиться
Другие вопросы по тегам:

Похожие вопросы: