RT-Thread/rt-thread

Bug in linker script for all stm32 targets

Open

#7.527 geöffnet am 18. Mai 2023

Auf GitHub ansehen
 (0 Kommentare) (3 Reaktionen) (0 zugewiesene Personen)C (4.755 Forks)batch import
good first issue

Repository-Metriken

Stars
 (9.223 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 7T 22h) (50 gemergte PRs in 30 T)

Beschreibung

The following prints -2 but must print 1234:

void variadic_test(int n, ...) {
 va_list vl;
 va_start(vl, n);
 double val = va_arg(vl, double);
 rt_kprintf("%d", (int)val);
 va_end(vl);
}

void main() {
 double v = 1234.5678;
 variadic_test(1, v);
 while(1);
}

Seems like stack is aligned by 4 for all stm32 targets but double size is 8 bytes. The following patch fixes the issue:

--- link.lds.o  2023-05-18 11:11:50.831727100 +0300
+++ link.lds    2023-05-18 11:43:42.305975225 +0300
@@ -93,10 +93,10 @@
 
     .stack :
     {
-        . = ALIGN(4);
+        . = ALIGN(8);
         _sstack = .;
         . = . + _system_stack_size;
-        . = ALIGN(4);
+        . = ALIGN(8);
         _estack = .;
     } >RAM

Contributor Guide