Solved

Number of bytes allocated for char arrays by subl %esp seems much too high (in linux 2.4, gcc 3.2.2)

Posted on 2003-12-06
7
299 Views
Last Modified: 2008-03-17
Hi!

I noticed that when I declare a buffer of, for example, char[5], the assembly code generated by gcc actually allocates a much larger buffer, in this case 24 bytes:

subl $24, (%esp)

How can this be explained?
0
Comment
Question by:dn6
  • 3
7 Comments
 
LVL 22

Accepted Solution

by:
grg99 earned 43 total points
Comment Utility
If you mean at function entry, the compiler might allocate some extra space to store temporary results, or to store registers, or to align the stack pointer, or to set up some kind of exception stack frame, or to pre-allocate some space needed in any variables declared in interior code blocks.  
0
 
LVL 37

Assisted Solution

by:Bing CISM / CISSP
Bing CISM / CISSP earned 41 total points
Comment Utility
for static or constant char buffer, commonly the compiler may allocate same-size memory, or a bit more for memory alignment. for char buffer of a function, depends on its type, usage and how compiler push them into stack. for dynamic allocated char buffer, it needs extra memory for MCB, memory control block, it describes the size, type and other attributes of a memory block.

hope it helps,
bbao
0
 
LVL 5

Assisted Solution

by:mtmike
mtmike earned 41 total points
Comment Utility
GCC aligns the stack pointer to a multiple of 16 bytes by default. You can change its behaviour using the -mpreferred-stack-boundary switch. For example, 'gcc -mpreferred-stack-boundary=2' forces gcc to align the stack pointer to a multiple of 2^2=4 bytes. Optimizing for size (-Os) has the same effect.
0
 
LVL 37

Expert Comment

by:Bing CISM / CISSP
Comment Utility
yes, it depends on type, processor, operating system and even compiler.
0
 
LVL 37

Expert Comment

by:Bing CISM / CISSP
Comment Utility
dn6, any feedback please?
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now