This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

A question about setting location counter to a new value in output section


Hi,

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:

-----test.s---------
section .text
        .globl _start
_start:
        movq $1, %rax
        movq $0, %rbx
        int $0x80

------test.lds------
SECTIONS
{
        . = 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[0], 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!


[0] https://sourceware.org/binutils/docs-2.30/ld/Location-Counter.html#Location-Counter

Regards,
Hao Lee


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]