www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10210] New: calling through PLT trashes EAX

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10210

           Summary: calling through PLT trashes EAX
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Keywords: wrong-code
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: code dawg.eu


--- Comment #0 from Martin Nowak <code dawg.eu> 2013-05-29 19:16:53 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 29 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10210



--- Comment #1 from Martin Nowak <code dawg.eu> 2013-05-31 11:52:36 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 31 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10210


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com


--- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2013-06-06
14:10:46 PDT ---
An example would be nice, please!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 06 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10210


Martin Nowak <code dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|wrong-code                  |
            Summary|calling through PLT trashes |GDB might trash EAX when
                   |EAX                         |stepping into a PLT call
           Severity|critical                    |minor


--- Comment #3 from Martin Nowak <code dawg.eu> 2013-06-06 15:14:37 PDT ---
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 :(.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 06 2013