Solved

Newbie : Linux Word Size...

Posted on 2002-06-21
2
374 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Is it possible to create a dynamic array in MIPS? 9 2,239
Intel DX58SO board 7 877
Convert MP3/Wav to bin format ? 4 910
restoring epb 1 360
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Data breaches are on the rise, and companies are preparing by boosting their cybersecurity budgets. According to the Cybersecurity Market Report (http://www.cybersecurityventures.com/cybersecurity-market-report), worldwide spending on cybersecurity …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 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