Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDB might trash EAX when stepping into a PLT call #18591

Open
dlangBugzillaToGithub opened this issue May 29, 2013 · 3 comments
Open

GDB might trash EAX when stepping into a PLT call #18591

dlangBugzillaToGithub opened this issue May 29, 2013 · 3 comments
Labels

Comments

@dlangBugzillaToGithub
Copy link

Martin Nowak (@MartinNowak) reported this on 2013-05-29T19:16:53Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=10210

CC List

Description

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.
@dlangBugzillaToGithub
Copy link
Author

code (@MartinNowak) commented on 2013-05-31T11:52:36Z

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.

@dlangBugzillaToGithub
Copy link
Author

bugzilla (@WalterBright) commented on 2013-06-06T14:10:46Z

An example would be nice, please!

@dlangBugzillaToGithub
Copy link
Author

code (@MartinNowak) commented on 2013-06-06T15:14:37Z

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 :(.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant