심볼 해석에 대해서

declspec의 이미지

리눅스든 윈도우즈든
링커가 심볼을 해석할때...(심볼을 해석하는 주체는 링커 맞죠?)

심볼을 해석한다는 의미는 결국
아스키 코드의 문자열로 되어있는
함수명 또는 변수명(이것 외에도 심볼이 있나요?)
에 대해서 그것이 메모리상에 존재하는
가상메모리주소를 연결해주는 것이죠?

요컨대 소스파일에서

void hello(){}

void main(){
hello();
}

이런 게 있는경우
hello를 호출하는 부분에서
어셈블러의 입장을 생각하면

CALL ?; // call hello()

CALL 로 함수호출을 할때 어떤 주소를 불러줘야 할지
모르겠죠?

이것을 hello 의 시작 메모리 주소 값을 찾아서 넣어주는게
링커가 하는 일인것이죠?

그런데 동적 라이브러리의 경우 이게 어떻게 수행될까요?
즉 동적 라이브러리에 hello 의 실행코드가 존재할 경우에
그것을 참조하는 프로그램의 경우

CALL ?; // call hello()

여기서 ? 부분에 뭐가 들어가게되나요?
임시로 뭔가 다른게 들어가있을것같은데...

PLT 나 GOT 가 상관있나요?
연관되는건지...

조언 부탁합니다

bacon의 이미지

프로그램 하나 만들어서 objdump -D 하면 대충 다 나옵니다만...

$ cat b.c
#include <stdlib.h>
main () { malloc (10); }
$ cc -o b b.c
$ objdump -D b > b.dmp

.plt섹션에 있는 어떤 코드를 호출하죠.

08048384 <main>:
 8048384:       8d 4c 24 04             lea    0x4(%esp),%ecx
 8048388:       83 e4 f0                and    $0xfffffff0,%esp
 804838b:       ff 71 fc                pushl  0xfffffffc(%ecx)
 804838e:       55                      push   %ebp
 804838f:       89 e5                   mov    %esp,%ebp
 8048391:       51                      push   %ecx
 8048392:       83 ec 04                sub    $0x4,%esp
 8048395:       c7 04 24 0a 00 00 00    movl   $0xa,(%esp)
 804839c:       e8 f7 fe ff ff          call   8048298 <malloc@plt>
 80483a1:       83 c4 04                add    $0x4,%esp
 80483a4:       59                      pop    %ecx
 80483a5:       5d                      pop    %ebp
 80483a6:       8d 61 fc                lea    0xfffffffc(%ecx),%esp

여기서는 다이나믹링커가 해당 함수를 찾을수 있도록 하는 루틴으로 점프합니다.

08048298 <malloc@plt>:
 8048298:       ff 25 78 95 04 08       jmp    *0x8049578
 804829e:       68 10 00 00 00          push   $0x10
 80482a3:       e9 c0 ff ff ff          jmp    8048268 <_init+0x18>

점프해서 찾으면 GOT도 변경하고 해요. ELF스펙을 한번 읽어보세요.

declspec의 이미지

좋은답변 감사합니다~

자기실력이 좋다고 느껴지는건 공부를 안하고 있다는 신호.

댓글 달기

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