Solved

Newbie : Linux Word Size...

Posted on 2002-06-21
2
372 Views
Last Modified: 2012-06-21
I'm running Linux (2.4.9) on an Intel box and trying to determine what is going on with this test :

Very simply, I have a function in C that goes as follows :

void f() {
  char buf[7];
}

When compiling to assembly via gcc -S and looking at the output, I see the function looks as follows :

f:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $24, %esp
        leave
        ret

Why is the assembly subtracting 24 bytes for a 7 byte buffer?  I know it has to be word aligned, but when I change buf[7] -> buf[8] I get the expected results :

f:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        leave
        ret

Shouldn't buf[7] produce the same output?

Thanks,
Steve
0
Comment
Question by:smisk
2 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 50 total points
ID: 7101454
It could make sense if your compiler options were set for debug build.   Compilers often put guard bytes in the stack frame so that in a post-mortem analysis, a good tool can point out where your program clobbered the stack.

With VC++, with release mode optimization, the function f() evaluates to one opcode C3 (return).  With all optimization off, it shows
    sub esp,8
but in Debug build, it shows
    sub esp,48h

and it fills that gap (which includes the auto variable  buf) with 0xcc bytes.

-- Dan




0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A procedure for exporting installed hotfix details of remote computers using powershell
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
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…

760 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

22 Experts available now in Live!

Get 1:1 Help Now