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]

Re: How define absolute local symbol by GNU as?


On 07/07/2011 07:40 AM, Oleksandr Gavenko wrote:
On 07.07.2011 17:25, Andreas Schwab wrote:
Oleksandr Gavenko<gavenko@bifit.com.ua> writes:

But how declare it local?

Don't declare it global.


OK, but how?

If I write:

   .global @feat.00
    @feat.00=1

I get:

  $ nm test.obj | grep feat
00000001 A @feat.00

If I write:

   /* .global @feat.00 */
    @feat.00=1

I get:

  $ nm test.obj | grep feat
<empty>

So I expect existence of some directive to get wanted.
One suggestion is to write what you want in C, then use gcc's -S option to produce the assembly language, and look to see how gcc does it. For example,
int y = 456;


int func() {
    static int x = 123;
    x = x + 1;
    y = y + 1;
    return x + y;
}

gives

    .file    "static.c"
.globl y
    .data
    .align 4
    .type    y, @object
    .size    y, 4
y:
    .long    456
    .text
.globl func
    .type    func, @function
func:On 07/07/2011 07:40 AM, Oleksandr Gavenko wrote:
On 07.07.2011 17:25, Andreas Schwab wrote:
Oleksandr Gavenko<gavenko@bifit.com.ua> writes:

But how declare it local?

Don't declare it global.


OK, but how?

If I write:

   .global @feat.00
    @feat.00=1

I get:

  $ nm test.obj | grep feat
00000001 A @feat.00

If I write:

   /* .global @feat.00 */
    @feat.00=1

I get:

  $ nm test.obj | grep feat
<empty>

So I expect existence of some directive to get wanted.
One suggestion is to write what you want in C, then use gcc's -S option to produce the assembly language, and look to see how gcc does it. For example,
int y = 456;


int func() {
    static int x = 123;
    x = x + 1;
    y = y + 1;
    return x + y;
}

gives

    .file    "static.c"
.globl y
    .data
    .align 4
    .type    y, @object
    .size    y, 4
y:
    .long    456
    .text
.globl func
    .type    func, @function
func:
.LFB0:
    .cfi_startproc
    pushq    %rbp
    .cfi_def_cfa_offset 16
    movq    %rsp, %rbp
    .cfi_offset 6, -16On 07/07/2011 07:40 AM, Oleksandr Gavenko wrote:
On 07.07.2011 17:25, Andreas Schwab wrote:
Oleksandr Gavenko<gavenko@bifit.com.ua> writes:

But how declare it local?

Don't declare it global.


OK, but how?

If I write:

   .global @feat.00
    @feat.00=1

I get:

  $ nm test.obj | grep feat
00000001 A @feat.00

If I write:

   /* .global @feat.00 */
    @feat.00=1

I get:

  $ nm test.obj | grep feat
<empty>

So I expect existence of some directive to get wanted.
One suggestion is to write what you want in C, then use gcc's -S option to produce the assembly language, and look to see how gcc does it. For example,
int y = 456;


int func() {
    static int x = 123;
    x = x + 1;
    y = y + 1;
    return x + y;
}

gives

    .file    "static.c"
.globl y
    .data
    .align 4
    .type    y, @object
    .size    y, 4
y:
    .long    456
    .text
.globl func
    .type    func, @function
func:
.LFB0:
    .cfi_startproc
    pushq    %rbp
    .cfi_def_cfa_offset 16
    movq    %rsp, %rbp
    .cfi_offset 6, -16
    .cfi_def_cfa_register 6
    movl    x.1616(%rip), %eax
    addl    $1, %eax
    movl    %eax, x.1616(%rip)
    movl    y(%rip), %eax
    addl    $1, %eax
    movl    %eax, y(%rip)
    movl    x.1616(%rip), %edx
    movl    y(%rip), %eax
    leal    (%rdx,%rax), %eax
    leave
    .cfi_def_cfa 7, 8
    ret
    .cfi_endproc
.LFE0:
    .size    func, .-func
    .data
    .align 4
    .type    x.1616, @object
    .size    x.1616, 4
x.1616:
    .long    123
    .ident    "GCC: (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2"
    .section    .note.GNU-stack,"",@progbits
    .cfi_def_cfa_register 6
    movl    x.1616(%rip), %eax
    addl    $1, %eax
    movl    %eax, x.1616(%rip)
    movl    y(%rip), %eax
    addl    $1, %eax
    movl    %eax, y(%rip)
    movl    x.1616(%rip), %edx
    movl    y(%rip), %eax
    leal    (%rdx,%rax), %eax
    leave
    .cfi_def_cfa 7, 8
    ret
    .cfi_endproc
.LFE0:
    .size    func, .-func
    .data
    .align 4
    .type    x.1616, @object
    .size    x.1616, 4
x.1616:
    .long    123
    .ident    "GCC: (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2"
    .section    .note.GNU-stack,"",@progbits
.LFB0:
    .cfi_startproc
    pushq    %rbp
    .cfi_def_cfa_offset 16
    movq    %rsp, %rbp
    .cfi_offset 6, -16
    .cfi_def_cfa_register 6
    movl    x.1616(%rip), %eax
    addl    $1, %eax
    movl    %eax, x.1616(%rip)
    movl    y(%rip), %eax
    addl    $1, %eax
    movl    %eax, y(%rip)
    movl    x.1616(%rip), %edx
    movl    y(%rip), %eax
    leal    (%rdx,%rax), %eax
    leave
    .cfi_def_cfa 7, 8
    ret
    .cfi_endproc
.LFE0:
    .size    func, .-func
    .data
    .align 4
    .type    x.1616, @object
    .size    x.1616, 4
x.1616:
    .long    123
    .ident    "GCC: (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2"
    .section    .note.GNU-stack,"",@progbits

which causes me to believe that placing your variable in the .data segment without a .global directive would give what you want.

--Bob


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