Home > Net >  In gnu assembly langage (for arm64), how can I specify a variable to be placed in a specific section
In gnu assembly langage (for arm64), how can I specify a variable to be placed in a specific section

Time:12-08

In assembly code, this code

.data
myval : .long 0x11111111

places the variable myval in .data section. So I wanted to define my own section in a specific address in SDRAM and use it in the assembly code to write some data for debug. I added my section in the linker script like this (this is the first section output to .sdram so I know the starting address).

.mydebug : {
    . = ALIGN(8);
    KEEP(*(.__mydebug));
} >.sdram

and used it in the assembly code like this.

.global
... skip ...
mov x6, #0x70
ldr x7, =myval
str x6, [x7]
... skip ...
.__mydebug
myval: .long 0x11111111

But the compile complains

Error: unknown pseudo-op: `.__mydebug'

How can I do this?

CodePudding user response:

Use the .section directive.

        .section .__mydebug
myval:  .long 0x11111111

One thing to know: custom sections should not have their name begin with a period. Such names are reserved for sections defined by the ABI. So perhaps call the section something like mydebug. Although in contravention of the ELF specification, it is also common to use a name like .data.mydebug for a section that is similar to .data but needs to be segregated from normal data.

  • Related