어셈블리에 관해 질문이 있습니다...

koonpal의 이미지

질문이 있습니다...

변수 공간 할당문제 때문에 이렇게 질문을 남김니다...

void function(int a, int b, int c) {
char buffer[x];
}

를 디스어셈블리 해서 보니까요...

pushl %ebp
movl %esp, %ebp
subl $y, %esp

c언어의 x가 1에서 4일때 까지 값일 때는 어셈코드에서 y가 4가 나오는데요...

정상이라 이해가 가고요...

그런데 x가 5 이상이 되면 y가 24가 나오거든요...

이유를 잘 몰라서 그러는데 답변 좀 해 주세요...

부탁드립니다...

익명 사용자의 이미지

그냥 gcc bug(?) 때문이라고 알고 있습니다. 큰 문제는 아니고 그냥 스택 공간이 낭비되는거죠. 현재 개발중인 gcc 4.0에서는 고쳐졌다고 들었습니다.

익명 사용자의 이미지

속도 문제, 보안 문제의 짬뽕입니다.

5바이트보다 8바이트(일반적인 경우)가 빠릅니다.

그리고 더미 바이트를 추가해서 오버플로우 공격 등에 좀더 대비할 수 있다는 장점도 가집니다.

익명 사용자의 이미지

gcc구버전에는 없던 feature입니다.

지금도 옵션을 조절해서 5면 5씩 할당하게도 할 수 있습니다.

flyduck의 이미지

지역 변수의 크기보다 크게 스택을 잡는 가장 기본적인 이유는 alignment입니다. gcc는 stack frame을 시작할 때 이를 일정한 boundary에 둘려고 합니다. x86에서는 기본적으로 16 byte alignment을 하고, 이 값은 -mpreferred-stack-boundary 옵션으로 바꿀 수 있습니다. 기본값은 4이고 (2^4=16), 최소 4 byte alignment까지 가능합니다 (-mpreferred-stack-boundary=2). 위에 분이 5바이트(1 byte boundary)도 가능하다고 했는데, 어떤 옵션으로 가능한지는 모르겠군요.

gcc version에 따라서 frame 시작 위치를 계산하는 방법이 조금씩 다른데, 16 byte alignment인데 24 byte를 할당하는 이유는 모르겠군요.

Freedom is another word for nothing left to lose,
Nothing doesn't mean nothing if it ain't free.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.