ELF format을 공부하고 있습니다. c코드중에 지역변수는 심볼이

dionysos의 이미지

#include<stdio.h>

/* well comment */
/* well2 comment */

int glovalvariable=10;

double uninitvariable;

void callfunction1()
{
	printf("printfunc1");
}

void callfunction2()
{
	printf("printfunc2");
}

int main()
{
	int loccal1;
	int loccal2;
	int loccalinit1;
	int loccalinit2;
	loccal1 = 100;
	loccal2 = 300;
	loccalinit1 = loccal1;
	loccalinit2 = loccal2;
	printf("mainprint %d",loccalinit1);
	callfunction1();
	callfunction2();
	getchar();
	return 1;
}

gcc3.2 version 에서 컴파일에서 ELF포멧을분석하고 있습니다.

여기에서 전역변수, 함수이름등은 .strtab 에 등록되어 있고

.symtab 에도 등록되어 있는데 지역변수인 loccal1, loccal2,

loccalinit1, loccalinit2은 .strtab 이나 .symtab 에서 찾을

수 없습니다. 왜 그럴까요.

File attachments: 
첨부파일 크기
Image icon 화면.JPG22.63 KB
dionysos의 이미지

지역변수들의 정보는 어디에 저장될까요.
이상하군요..

댓글 첨부 파일: 
첨부파일 크기
Image icon 0바이트

노력은 배반하지 않는다.

정태영의 이미지

지역변수는 그냥 스택에 들어가지 않나요?

오랫동안 꿈을 그리는 사람은 그 꿈을 닮아간다...

http://mytears.org ~(~_~)~
나 한줄기 바람처럼..

dionysos의 이미지

하나의 소스파일이면 몰라도 심볼이 등록이 안되어 있다면

링커가 여러개의 소스를 합칠때 문제가 되는걸로 알고 있습니

다. 아닌가요..;;

노력은 배반하지 않는다.

정태영의 이미지

지역변수에 다른 오브젝트파일에서 접근할 방법이 있던가요? 같은 오브젝트에서도 다른 scope 에 있는 변수는 접근할 방법이 없는데요... (포인터로 어떻게 적당히 계산해서 하는 방법은 예외지만요 :evil:) 때문에 상관 없을 듯 한데요 ;)

오랫동안 꿈을 그리는 사람은 그 꿈을 닮아간다...

http://mytears.org ~(~_~)~
나 한줄기 바람처럼..

dionysos의 이미지

그럼 컴파일 하여 obj 파일을 생성할때 지역변수 사용하는부분은 셈블러(예를들어 push)로 바 뀌고 심볼테이블[위치정보]이나 스트링테이블[변수이름]등의 부가정도가 들어가지 않나요

노력은 배반하지 않는다.

정태영의 이미지

예전 kldpconf 에서 세미나 했던 자료가 아직도 웹상에 그대로 있군요 :)

제 외장하드가 날라가면서 그 때 자료들 받아놨던게 날라가서 아쉬웠는데... 참 다행입니다...

http://wiki.kldp.org/wiki.php/KLDPConf/20031011

여기서 어셈블리 관련 강좌 동영상을 보면 C Calling Conversion 에 대해서 설명하고 있습니다 :) 파워포인트 자료 33페이지 쯤에 나오는 부분을 잘 찾아서 보시면 도움이 될 듯 싶습니다... 마지막 페이지에 나온 내용을 인용해보면...

Quote:
Global
* Defined outside of any function and are stored at fixed memory locations (data/bss segments) and exist from the beginning of the program until the end.
* If declared as static, only the functions in the same module can access them. (not external)

Static
* Local variables of a function but stored at fixed memory likes data/bss.
* Only be accessed by in the function they are defined in.

Automatic
* Allocated in stack, unallocated when the function returns

지역 변수는 automatic 이 될 거 같네요 +_+
(사실 저도 잘 몰라서 :evil:)

오랫동안 꿈을 그리는 사람은 그 꿈을 닮아간다...

http://mytears.org ~(~_~)~
나 한줄기 바람처럼..

dionysos의 이미지

소스를 간단하게 해서 역어셈블 해본결과 제가 잘못 이해한거 같군요
지역변수는 저장 안되는게 맞습니다.

무지가..ㅡ.ㅡ.;; 답변감사드립니다.

노력은 배반하지 않는다.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.