October 23, 2024
Chicago 12, Melborne City, USA
C#

Structures inside custom section are inverted when compiling with aarch64-none-elf-gcc


When I compile using gcc for x86, the structures are placed in the section in the order I declare them. However, when I compile using aarch64-none-elf-gcc for an ARM target, the structures appear to be placed in the section in reverse order.

typedef struct test_t {
    char *test_name;
} test_t;

test_t test1 __attribute__((section("my_section"))) = { "Test 1" };
test_t test2 __attribute__((section("my_section"))) = { "Test 2" };
test_t test3 __attribute__((section("my_section"))) = { "Test 3" };

int main(int argc, char *argv[])
{
    extern __start_my_section;
    extern __stop_my_section;

    for (test_t *t = &__start_my_section; t != &__stop_my_section; t++) {
        printf("%s\n",t->test_name);
    }

    return 0;
}

when building with gcc on x86 , this prints

Test1
Test2
Test3

but, when building with aarch64-none-elf-gcc for an aarch64 target, i get

Test3
Test2
Test1

any body know why?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video