D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10210 - GDB might trash EAX when stepping into a PLT call
Summary: GDB might trash EAX when stepping into a PLT call
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P3 minor
Assignee: No Owner
URL:
Keywords: DebugInfo
Depends on:
Blocks:
 
Reported: 2013-05-29 19:16 UTC by Martin Nowak
Modified: 2024-12-13 18:07 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2013-05-29 19:16:53 UTC
This affects shared libraries on X86 32-bit. The linker stub doesn't restore the content of EAX. This may lead to corruption because dmd may pass an argument in EAX.
Comment 1 Martin Nowak 2013-05-31 11:52:36 UTC
Until now I don't know any solution other than to not use EAX for parameter passing. Maybe ECX or EDX would work as alternative.
Comment 2 Walter Bright 2013-06-06 14:10:46 UTC
An example would be nice, please!
Comment 3 Martin Nowak 2013-06-06 15:14:37 UTC
cat > bug.d << CODE
import lib;

void main()
{
    int val;
    printf("%p\n", &val);
    deref(&val) == 0 || assert(0);
}
CODE

cat > lib.d << CODE
extern(C) int printf(const char*, ...);

int deref(int* p)
{
    printf("%p\n", p);
    return *p;
}
CODE

dmd -g -m32 -fPIC -shared lib.d -ofliblib.so
dmd -g -m32 -fPIC bug.d -L-L. -L-llib -L-rpath=.
./bug

----

Oh, the above code actually works. It's not the PLT stub but the attached debugger (gdb-7.5.1) that trashes EAX. It only happens when stepping into a function called via PLT and I can only reproduce with emacs-GUD, probably because of some automatic variable update.

It also means there is another reason why phobos unittests crash on X86 :(.
Comment 4 dlangBugzillaToGithub 2024-12-13 18:07:14 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18591

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB