public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* gcc on 64-bit cywin - problems with __builtin_frame_address and __builtin_return_address
@ 2015-09-03 14:36 Herb Schwetman
  0 siblings, 0 replies; only message in thread
From: Herb Schwetman @ 2015-09-03 14:36 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1801 bytes --]

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

[-- Attachment #2: testBuiltin.cpp --]
[-- Type: text/plain, Size: 696 bytes --]

//	testbuiltin.cpp

#include <stdio.h>

void sub()
{
	register int a, b, c;
//	int a, b, c;

	printf("\nsub\n");
	printf("frame address %016llx\n", __builtin_frame_address(0));
	printf("return address %016llx\n", __builtin_return_address(0));
	printf("frame address caller %016llx\n", __builtin_frame_address(1));
	printf("return address caller %016llx\n", __builtin_return_address(1));
	a = 1; b = 2; c = 3;
	printf("a %d, b %d, c %d\n", a,  b, c);
}

int main()
{
	int a, b, c;

	printf("frame address %016llx\n", __builtin_frame_address(0));
	printf("return address %016llx\n", __builtin_return_address(0));
	a = 1; b = 2; c = 3;
	printf("a %d, b %d, c %d\n", a,  b, c);
	sub();
	return 0;
}


[-- Attachment #3: Type: text/plain, Size: 218 bytes --]

--
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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-09-03 14:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-03 14:36 gcc on 64-bit cywin - problems with __builtin_frame_address and __builtin_return_address Herb Schwetman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).