{"action":"created","issue":{"url":"https://api.github.com/repos/riscv/riscv-gcc/issues/63","repository_url":"https://api.github.com/repos/riscv/riscv-gcc","labels_url":"https://api.github.com/repos/riscv/riscv-gcc/issues/63/labels{/name}","comments_url":"https://api.github.com/repos/riscv/riscv-gcc/issues/63/comments","events_url":"https://api.github.com/repos/riscv/riscv-gcc/issues/63/events","html_url":"https://github.com/riscv/riscv-gcc/issues/63","id":225461962,"number":63,"title":"long long int vararg on 32-Bit machine with stack pointer divisible by 4","user":{"login":"s-macke","id":3176016,"avatar_url":"https://avatars0.githubusercontent.com/u/3176016?v=3","gravatar_id":"","url":"https://api.github.com/users/s-macke","html_url":"https://github.com/s-macke","followers_url":"https://api.github.com/users/s-macke/followers","following_url":"https://api.github.com/users/s-macke/following{/other_user}","gists_url":"https://api.github.com/users/s-macke/gists{/gist_id}","starred_url":"https://api.github.com/users/s-macke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/s-macke/subscriptions","organizations_url":"https://api.github.com/users/s-macke/orgs","repos_url":"https://api.github.com/users/s-macke/repos","events_url":"https://api.github.com/users/s-macke/events{/privacy}","received_events_url":"https://api.github.com/users/s-macke/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2017-05-01T16:03:53Z","updated_at":"2017-05-04T12:12:28Z","closed_at":"2017-05-02T11:39:59Z","body":"During the boot process of 32-Bit Linux kernel several messages are shown in the console such as the found devices with their hardware addresses. \r\nHowever the debug output of 64-Bit (long long int) numbers showed sometimes random 64-Bit numbers.\r\nAfter a long quest through the Linux kernel and hours of disassembling and live debugging I figured out that the variadic arguments used by the printk command are responsible for the problem. The variadic argument implementation can't manage stack pointers which are divisible by 4.\r\n\r\nThe code to reproduce the problem is\r\n\r\n```\r\n#include<stdio.h>\r\n#include<stdarg.h>\r\n#include<string.h>\r\n\r\n\r\nvoid PrintLongLong (int n, ...)\r\n{\r\n  int i;\r\n  unsigned long long val;\r\n  va_list vl;\r\n  va_start(vl, n);\r\n  for (i=0;i<n;i++)\r\n  {\r\n    val = va_arg(vl, long long);\r\n    printf (\"0x%llx\\n\", val);\r\n  }\r\n  va_end(vl);\r\n}\r\n\r\nunsigned long long x = 0x0123456789abcdef;\r\nunsigned long long y = 0xfedcba9876543210;\r\n\r\nvoid Trampoline()\r\n{\r\n   // Move stack pointer to a offset only divisible by 4.\r\n   // A move of 8 bytes works again.\r\n    asm(\"addi sp, sp, -4\");\r\n    PrintLongLong(2, y, x);\r\n    asm(\"addi sp, sp, 4\");\r\n}\r\n\r\nint main()\r\n{\r\n        Trampoline();\r\n        return 0;\r\n}\r\n````\r\n\r\n Run with \r\n````\r\nriscv32-unknown-linux-gnu-gcc -O2 --static var_arg_problem.c\r\nspike --isa=rv32 pk ./a.out\r\n````\r\n\r\nI am unsure whether the problem is in the kernel or in the compiler.\r\nSo either the Linux kernel sets the stack pointer to a wrongly aligned address or the variadic argument implementation of gcc is wrong.\r\n"},"comment":{"url":"https://api.github.com/repos/riscv/riscv-gcc/issues/comments/299167602","html_url":"https://github.com/riscv/riscv-gcc/issues/63#issuecomment-299167602","issue_url":"https://api.github.com/repos/riscv/riscv-gcc/issues/63","id":299167602,"user":{"login":"s-macke","id":3176016,"avatar_url":"https://avatars0.githubusercontent.com/u/3176016?v=3","gravatar_id":"","url":"https://api.github.com/users/s-macke","html_url":"https://github.com/s-macke","followers_url":"https://api.github.com/users/s-macke/followers","following_url":"https://api.github.com/users/s-macke/following{/other_user}","gists_url":"https://api.github.com/users/s-macke/gists{/gist_id}","starred_url":"https://api.github.com/users/s-macke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/s-macke/subscriptions","organizations_url":"https://api.github.com/users/s-macke/orgs","repos_url":"https://api.github.com/users/s-macke/repos","events_url":"https://api.github.com/users/s-macke/events{/privacy}","received_events_url":"https://api.github.com/users/s-macke/received_events","type":"User","site_admin":false},"created_at":"2017-05-04T12:12:28Z","updated_at":"2017-05-04T12:12:28Z","body":"Now that we have MMIO support the RISC-V implementation will have feature parity with OpenRISC from the hardware emulation side - That means 32-Bit RISC-V but with more devices based on virtio.\r\nI don't plan to support 64-Bit at the moment as it requires a lot of changes in the code and additional Webassembly code for speed.\r\n\r\nThe distribution is up for discussion. Like for OpenRISC I plan to compile my own light weight distribution of around of 200MB with the typical packages which also fit in a Github repository.\r\nFor Fedora and Debian, that space on Github probably won't be enough and I would probably stretch my free account to the allowed limits :)\r\nSo what I need is just a compressed .tar file with the 32-Bit compiled root filesystem of Debian or Fedora. And to publish these distributions I probably need some server space.\r\n"}}
{"actor":{"display_login":"s-macke"}}