Bug 241287
Summary: | Calling sprintf/printf from Ada segfaults on x86_64 | ||
---|---|---|---|
Product: | [Fedora] Fedora | Reporter: | Orion Poplawski <orion> |
Component: | gcc | Assignee: | Jakub Jelinek <jakub> |
Status: | CLOSED NOTABUG | QA Contact: | |
Severity: | medium | Docs Contact: | |
Priority: | medium | ||
Version: | rawhide | ||
Target Milestone: | --- | ||
Target Release: | --- | ||
Hardware: | x86_64 | ||
OS: | Linux | ||
Whiteboard: | |||
Fixed In Version: | Doc Type: | Bug Fix | |
Doc Text: | Story Points: | --- | |
Clone Of: | Environment: | ||
Last Closed: | 2007-05-24 21:12:34 UTC | Type: | --- |
Regression: | --- | Mount Type: | --- |
Documentation: | --- | CRM: | |
Verified Versions: | Category: | --- | |
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
Cloudforms Team: | --- | Target Upstream Version: | |
Embargoed: |
Description
Orion Poplawski
2007-05-24 20:42:40 UTC
This is clearly invalid code. procedure Printf( format : in char_array; variable: in Long_Float ); pragma Import(C, Printf, "printf" ); You are lying to the compiler, printf is not printf (const char *, double) but printf (const char *, ...). While on i386 these two happen to have the same calling convention, on x86_64 they don't (vararg functions need to additionally set %rax register to the number of used %xmm* argument). With the incorrect declaration, %rax contains some random value and if it is bigger than 7, the code to save %xmm0..%xmm[%rax-1] registers to stack (see x86_64 ABI) will just jump either to a middle of some instruction or some unrelated instruction. Not sure if Ada allows you to specify a vararg function some way, if yes, use it, if not, you can't call these functions directly, you'd need to write a short wrapper function in C that will do that: int printf_arg_double (const char *fmt, double d) { return printf (fmt, d); } and call that from Ada instead. Thanks for the explanation Jakub - much appreciated. |