X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:message-id:date:mime-version :content-type; q=dns; s=default; b=OToEQ3mV0Np4wXzv6oOI3OSmNlwKi xD0EaXEZWcACS0x53afTbT38GCPe83Cd4GLsxZOns03s2cqP+q7jdH01oM7uzI76 dUvlGPrWrr2ef/zkMeUYuW99hLyvBbgWT+y5QS7cfvkkhPPeMCLkErKgibq+2u4m zYGhmxUFgD8sm4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:message-id:date:mime-version :content-type; s=default; bh=hxUF+o67G2Ij26Oowm85JywGg1U=; b=Ujd X8W0Bf/pb+4r4P37O8SrisJIHlLnC+gi7r/RT78FLbANrrDewVqI+c/txeDX6GjA dblPAF0KZCQ3zbocHPEKvKxSmmGlnfYRK6COZegR5GdtEQmA0ZZR6eSDChHE9sRb J8rSHVQNhEZVuNo+BuelhJLIfKOAu2ErqyxbBSxM= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.1 required=5.0 tests=BAYES_50,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: smtp130.dfw.emailsrvr.com X-Sender-Id: hds AT mesquite DOT com To: cygwin AT cygwin DOT com From: Herb Schwetman Subject: gcc on 64-bit cywin - problems with __builtin_frame_address and __builtin_return_address Message-ID: <55E85B00.8020807@mesquite.com> Date: Thu, 3 Sep 2015 09:36:48 -0500 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080006060509020000010405" --------------080006060509020000010405 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hello The 64-bit gcc procedure prolog pushes registers onto the stack in a manner that is different from the 32-bit gcc version. Furthermore, this appears to be unique to Cygwin64, and this does not happen on Linux. This shows up when you use __builtin_frame_address(n) and __builtin_return_address(n). This is illustrated with the attached C++ program. If the local variables in the sub() procedure are designated as register variables, the sub procedure does not find the frame address and return address of the caller (main). If these variables are not designated a register variables, the sub procedure does find and print the correct values. If you look at the generated code (-S option), you can see that the 64-bit versions pushes the saved registers onto the stack before the frame pointer is updated, while the 32-bit version pushes the saved registers onto the stack after the frame pointer is updated. 64-bit version .seh_proc _Z3subv _Z3subv: .LFB7: pushq %rbp .seh_pushreg %rbp pushq %rdi .seh_pushreg %rdi pushq %rsi .seh_pushreg %rsi pushq %rbx .seh_pushreg %rbx movq %rsp, %rbp .seh_setframe %rbp, 0 subq $40, %rsp 32-bit version .def __Z3subv; .scl 2; .type 32; .endef __Z3subv: LFB7: .cfi_startproc pushl %ebp .cfi_def_cfa_offset 8 .cfi_offset 5, -8 movl %esp, %ebp .cfi_def_cfa_register 5 pushl %edi pushl %esi pushl %ebx subl $28, %esp Herb Schwetman Mesquite Software, Inc. --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus --------------080006060509020000010405 Content-Type: text/plain; charset=UTF-8; name="testBuiltin.cpp" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="testBuiltin.cpp" Ly8JdGVzdGJ1aWx0aW4uY3BwCgojaW5jbHVkZSA8c3RkaW8uaD4KCnZvaWQg c3ViKCkKewoJcmVnaXN0ZXIgaW50IGEsIGIsIGM7Ci8vCWludCBhLCBiLCBj OwoKCXByaW50ZigiXG5zdWJcbiIpOwoJcHJpbnRmKCJmcmFtZSBhZGRyZXNz ICUwMTZsbHhcbiIsIF9fYnVpbHRpbl9mcmFtZV9hZGRyZXNzKDApKTsKCXBy aW50ZigicmV0dXJuIGFkZHJlc3MgJTAxNmxseFxuIiwgX19idWlsdGluX3Jl dHVybl9hZGRyZXNzKDApKTsKCXByaW50ZigiZnJhbWUgYWRkcmVzcyBjYWxs ZXIgJTAxNmxseFxuIiwgX19idWlsdGluX2ZyYW1lX2FkZHJlc3MoMSkpOwoJ cHJpbnRmKCJyZXR1cm4gYWRkcmVzcyBjYWxsZXIgJTAxNmxseFxuIiwgX19i dWlsdGluX3JldHVybl9hZGRyZXNzKDEpKTsKCWEgPSAxOyBiID0gMjsgYyA9 IDM7CglwcmludGYoImEgJWQsIGIgJWQsIGMgJWRcbiIsIGEsICBiLCBjKTsK fQoKaW50IG1haW4oKQp7CglpbnQgYSwgYiwgYzsKCglwcmludGYoImZyYW1l IGFkZHJlc3MgJTAxNmxseFxuIiwgX19idWlsdGluX2ZyYW1lX2FkZHJlc3Mo MCkpOwoJcHJpbnRmKCJyZXR1cm4gYWRkcmVzcyAlMDE2bGx4XG4iLCBfX2J1 aWx0aW5fcmV0dXJuX2FkZHJlc3MoMCkpOwoJYSA9IDE7IGIgPSAyOyBjID0g MzsKCXByaW50ZigiYSAlZCwgYiAlZCwgYyAlZFxuIiwgYSwgIGIsIGMpOwoJ c3ViKCk7CglyZXR1cm4gMDsKfQoK --------------080006060509020000010405 Content-Type: text/plain; charset=us-ascii -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple --------------080006060509020000010405--