Solved

Newbie : Linux Word Size...

Posted on 2002-06-21
2
376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Patching and EXE 3 1,030
SwapWord function 11 1,210
i7 introduced date in different markets 4 545
MIPS Assembly Language 3 798
Enabling the Skype for Business Meeting Scheduler in Hybrid OWA
No single Antivirus application (despite claims by manufacturers) will catch or protect you from all Virus / Malware or Spyware threats. That doesn't stop you from further protecting yourself however - and this article is to show you how.

749 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