test.S

 .text
       .global _start

   _start:
       mov $0xa, %rdx
       mov $0xb, %rdx
       mov $0xc, %rdx

       mov _head(%rip), %rcx
       mov $_head, %rcx
       mov $_ehead, %rcx


TEST 1 :: AT(ADDR(.text)) 사용

test.ld

SECTIONS {
  . = 0x100;
  .text : AT(ADDR(.text)){
    _head = . ;
    *(.text)
    _ehead = . ;
  }
  .data : { *(.data) } 
  .bss :  { *(.bss)  *(COMMON) } 
}


result of ./as test.S -o test.o && ld -T test.ld test.o && objdump -d a.out

a.out:     file format elf64-x86-64


Disassembly of section .text:

0000000000000100 <_head>:
 100:   48 c7 c2 0a 00 00 00    mov    $0xa,%rdx
 107:   48 c7 c2 0b 00 00 00    mov    $0xb,%rdx
 10e:   48 c7 c2 0c 00 00 00    mov    $0xc,%rdx
 115:   48 8b 0d e4 ff ff ff    mov    -0x1c(%rip),%rcx        # 100 <_head>
 11c:   48 c7 c1 00 01 00 00    mov    $0x100,%rcx
 123:   48 c7 c1 2a 01 00 00    mov    $0x12a,%rcx



Test 2 :: AT(ADDR(.text) + 10)


test.ld

SECTIONS {
  . = 0x100;
  .text : AT(ADDR(.text) + 10){
    _head = . ;
    *(.text)
    _ehead = . ;
  }
  .data : { *(.data) } 
  .bss :  { *(.bss)  *(COMMON) } 
}


result of ./as test.S -o test.o && ld -T test.ld test.o && objdump -d a.out

a.out:     file format elf64-x86-64


Disassembly of section .text:

0000000000000100 <_head>:
 100:   48 c7 c2 0a 00 00 00    mov    $0xa,%rdx
 107:   48 c7 c2 0b 00 00 00    mov    $0xb,%rdx
 10e:   48 c7 c2 0c 00 00 00    mov    $0xc,%rdx
 115:   48 8b 0d e4 ff ff ff    mov    -0x1c(%rip),%rcx        # 100 <_head>
 11c:   48 c7 c1 00 01 00 00    mov    $0x100,%rcx
 123:   48 c7 c1 2a 01 00 00    mov    $0x12a,%rcx




AT 안에 있는 두가지 $head, $_ehead가 두가지 다른 AT에 대해서 같은 결과를 내는 것 같아요..



XE Login