what's the meaning of ".option push"

1,542 views
Skip to first unread message

leishangwen

unread,
Jul 1, 2017, 2:15:20 AM7/1/17
to sw-...@groups.riscv.org
Hi, when i read the "hello" example with FreedomStudio, i was puzzled by the following program in start.S

.option push
.option norelax
la gp, __global_pointer$
.option pop
la sp, _sp

i cannot find the meaning of ".option push", ".option norelax", ".option pop"
what's the meaning of ".option push", ".option norelax", ".option pop"?
and where can i find a manual to study?
Thank you


 

Bruce Hoult

unread,
Jul 1, 2017, 4:30:44 AM7/1/17
to leishangwen, RISC-V SW Dev
In assemblers or compilers ".option push" (or similar) is used to save all existing settings for options so that you can change something temporarily. Doing "option pop" later restores all the previous options without having to change each one back individually.

In this case it might have been ok to instead do...

.option norelax
la gp, __global_pointer$
.option relax
la sp, _sp

... except that if .option norelax was already the setting before getting here then we're just changed it without meaning to! The push/pop use means the previous settings are restored without knowing what they were.




 

--
You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sw-dev+unsubscribe@groups.riscv.org.
To post to this group, send email to sw-...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/sw-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/18a7c6d4.512b.15cfcc9fbf7.Coremail.leishangwen%40163.com.

Michael Clark

unread,
Jul 1, 2017, 4:31:21 AM7/1/17
to leishangwen, sw-...@groups.riscv.org
.option push saves the current options so that they can be later restored (there are other options such as .option rvc for compressed code)

.option norelax tells the linker to not relax AUIPC+ADDI to a gp relative reference (constant pool). Obviously the load of gp needs to be fully qualified and can’t be relaxed.

.option pop restores the previous options.

A sequence like this:

1: auipc a0, %pcrel_hi(sym)
lw a1, %pcrel_lo(1b)(a0)

can be relaxed by the linker to:

lw a1, %gprel(sym)(gp)

assuming certain conditions are met. i.e. the model is not a shared object and the symbol is within a certain distance from the global pointer which points to somewhere in the data section (I can’t remember the exact rules of the top of my head). The idea is that global pointer relaxation generates smaller code for access to commonly used constants.

Someone chime in if there is any inaccuracy in this description. I have a feeling the %gprel assembler function doesn’t exist in practice, and is handled by the linker, however if could be implemented if folk want to hand code gp relative accesses in assembler.

--
You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sw-dev+un...@groups.riscv.org.

Michael Clark

unread,
Jul 1, 2017, 4:41:34 AM7/1/17
to leishangwen, sw-...@groups.riscv.org
On 1 Jul 2017, at 8:31 PM, Michael Clark <michae...@mac.com> wrote:

.option push saves the current options so that they can be later restored (there are other options such as .option rvc for compressed code)

There is also .option norvc and .option pic
 
.option norelax tells the linker to not relax AUIPC+ADDI to a gp relative reference (constant pool). Obviously the load of gp needs to be fully qualified and can’t be relaxed.

Correction: AUIPC+LW, AUIPC+LD, AUIPC+SW and AUIPC+SD, etc. gp-relative constant pool accesses don’t apply to AUIPC+ADDI

BTW .option norelax is not in the assembly guide:


The document is very much just a starting point at the moment and needs to be expanded.

leishangwen

unread,
Jul 1, 2017, 7:34:39 AM7/1/17
to Michael Clark, sw-...@groups.riscv.org
Yes, Thank you for you sharing 


 

Reply all
Reply to author
Forward
0 new messages