Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.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?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading