This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

subl $<large number>, %esp related segfault


Dear All,
	I am getting segfaults in a FORTRAN program compiled with g95
under Linux/i386 but the problem is not specific to g95.  I can simulate
it with g77 which similarly uses gcc's assembler generation routines.  It
is just that I have some quite large subroutines (originally Fortran 77)
which been trivially converted to use a derived datatype under g95 which
has the effect of substantially increasing the code size and memory usage
-- to the extent that the problem I'm describing occurs.  The problem
subroutines are part of a set of similar, numerically intensive ones, most
of which work fine.  It is just the few biggest ones which have this
problem.  Here is some assembler O/P from g95 for a problem subroutine.


        .type   fo7dma0dmc0_, @function
fo7dma0dmc0_:
.LFB93:
        .loc 1 1 0
        pushl   %ebp
.LCFI315:
        movl    %esp, %ebp
.LCFI316:
        pushl   %edi
.LCFI317:
        pushl   %esi
.LCFI318:
        pushl   %ebx
.LCFI319:
        subl    $9389456, %esp
.LCFI320:
        .loc 2 20 0
.LBB47:
        pushl   $3
        pushl   $.LC0
etc. etc.

Here is my analysis: The 'subl $9389456, %esp' pulls the stack pointer
down by that large number.  When the 'pushl $3' tries to execute it
overflows the stack and gets a segfault.  My FORTRAN code uses static
allocation. The thing I don't understand is; what precisely is the subl's
purpose? Is there a way to reduce its size? eg. a compiler option. I'm
reluctant to try splitting the subroutine up into two smaller ones.
Any other ideas?

Thanks
Tom.

Ps. Where can I find a description of GNU/Linux procedure calling 
standard?

-- 
Tom Crane, Dept. Physics, Royal Holloway, University of London, Egham Hill,
Egham, Surrey, TW20 0EX, England. 
Email:  T.Crane@rhul.ac.uk
Fax:    +44 (0) 1784 472794


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]