I'm confused about the location counter, especially when setting it to
a new value in the output section.

I write a simple program and a linker script to make my question more
clear. The code is as follows:

section .text
        .globl _start
        movq $1, %rax
        movq $0, %rbx
        int $0x80

        . = 0x10;
        label_1 = .;
        custom_section : {
                . = 0x20;
                label_2 = . ;
                label_3 = ABSOLUTE(.) ;
                *(.text) ;

After linking, use nm command to print symbol addresses:

0000000000000010 T label_1
0000000000000030 T label_2
0000000000000030 A label_3
0000000000000030 T _start

I can't understand why lable_2 is 0x30. As the LD documentation
says[1], if '.' is used inside a section description, it refers to the
byte offset from the start of that section, not an absolute address.
In the custom_section, '.' is set to 0x20 which is a relative offset,
so I think label_2 should also be 0x20. The value of label_3 is
reasonable because it's an absolute address.

Could someone please explain why label_2 is 0x30? Thanks!


Hao Lee

Kernelnewbies mailing list

Reply via email to