Skip to content

Commit 66af40f

Browse files
committed
variants/_ldscripts: Fix static thread data alignment.
The _static_thread_data struct contains int64_t members that require 8-byte alignment. When placed in a 4-byte aligned section, it causes the linker to insert padding, which in turn causes __static_thread_data_list_start to point to the padding not to the first iterable. GNU ld automatically aligns output sections based on the strictest alignment requirement of input sections, so moving __static_thread_data_list to its own section fixes the problem. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
1 parent cbf7e44 commit 66af40f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

variants/_ldscripts/build-dynamic.ld

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ SECTIONS {
3434
KEEP (*(.ctors))
3535
KEEP (*(.dtors))
3636
KEEP (*(.fini))
37+
}
3738

39+
.static_thread_data_area : {
3840
__static_thread_data_list_start = .;
39-
KEEP(*(SORT_BY_NAME(.__static_thread_data.static.*)));
41+
KEEP(*(.static_thread_data_area SORT_BY_NAME(.__static_thread_data.*)));
4042
__static_thread_data_list_end = .;
4143
}
4244

@@ -87,4 +89,4 @@ SECTIONS {
8789
.got : {
8890
KEEP(*(.got .got.* .got.plt .got.plt*))
8991
}
90-
}
92+
}

variants/_ldscripts/build-static.ld

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ SECTIONS {
2323
KEEP (*(.ctors))
2424
KEEP (*(.dtors))
2525
KEEP (*(.fini))
26+
} >FLASH
2627

28+
.static_thread_data_area : {
2729
__static_thread_data_list_start = .;
28-
KEEP(*(SORT_BY_NAME(.__static_thread_data.static.*)));
30+
KEEP(*(.static_thread_data_area SORT_BY_NAME(.__static_thread_data.*)));
2931
__static_thread_data_list_end = .;
3032
} >FLASH
3133

0 commit comments

Comments
 (0)