Skip to content

Patmos simulator fails when calling printf() with multiple cores #18

@michael-platzer

Description

@michael-platzer

The Patmos simulator pasim produces an error (unaligned memory access) when the function printf() is called and the number of cores is greater than 1.

To reproduce, write a short Hello World program and execute following commands:

$ cat test.c
#include <stdio.h>
int main() {
    printf("Hello world!\n");
    return 0;
}
$ patmos-clang test.c
$ pasim a.out 
Hello world!
$ pasim -N 2 a.out 
[Error] Unaligned memory access: 00000003

00047280<pthread_mutex_init:.LBB163_2:.LBB163_3 + 0x8>:              lwm r2 = [r1 + 0]

Cycle : 48930, PC : 0004728c<pthread_mutex_init:.LBB163_2:.LBB163_3 + 0x14>
Stacktrace:
#0 0x471e4 <pthread_mutex_init>(): $rsp 0x6c8 stack cache size 0x780
   at 0x4728c (base: 0x47244 <pthread_mutex_init:.LBB163_2:.Ltmp1904 + 0xc>, offset: 0x48 <pthread_mutex_init:.LBB163_2:.LBB163_3 + 0x14>)
t-crest/patmos#1 0x25304 <std>(): $rsp 0x6c8 stack cache size 0x7a0
   at 0x253a0 (base: 0x25304 <.LBB46_0:std>, offset: 0x9c <std + 0x9c>)
t-crest/patmos#2 0x24f34 <__sinit>(): $rsp 0x6c8 stack cache size 0x7e0
   at 0x25014 (base: 0x24fb4 <__sinit:.LBB38_2:.Ltmp260 + 0xc>, offset: 0x60 <__sinit:.LBB38_2:.Ltmp260 + 0x6c>)

No error is produced if printf() is removed from the program:

$ cat test.c
#include <stdio.h>
int main() {
    return 0;
}
$ patmos-clang test.c
$ pasim -N 2 a.out
$ echo $?
0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions