Altera_Forum
Honored Contributor
20 years agoDisabling GP-addressing in generated source code
Hi Everybody,
I would like to share some thougts about the way to control when the compiler uses GP-addressing to address global data structures. This is resulted also from a talk with Monkeyboy, that I thanks for having enlightened me :-) Baically, my knownledge is the following: - small data that is generated into the .sdata / .sbss section will use GP-addressing - I can disable GP addressing for the entire compilation unit using the compiler option -G0 - if I want to remove GP addressing from a small data, I have to DECLARE the data putting it in some different section, like for exeample the ".data" section, something like <div class='quotetop'>QUOTE </div> --- Quote Start --- extern volatile int mickey __attribute__ ((section (".data")));[/b] --- Quote End --- What I do not like in this method is that I have to put into the declaration (that stays for example inside a .h) the fact that the item will be allocated inside the ".data" section. I do not like it because the resulting object file will not contain any allocation in the data segment for that variable... I also tried the following piece of code: <div class='quotetop'>QUOTE </div> --- Quote Start --- extern volatile int mydata __attribute__ ((section (".data"))); void goofy(void) { mydata++; } volatile int mydata __attribute__ ((section (".sdata"))); void mickey(void) { mydata++; } [/b] --- Quote End --- ...that is, 1) declaring a variable mydata putting it in .data (no GP-relative addressing 2) using mydata into goofy (generating absolute code (the same ontained with -G0)) 3) REDEFINING mydata to be put in .sdata (the compiler should give a warning because of the section that has changed?????) 4) using mydata into mickey (generating GP-relative code) As the result, I obtain the following assembler (I only quoted the most interesting parts) <div class='quotetop'>QUOTE </div> --- Quote Start --- .section .text .align 2 .global goofy .type goofy, @function goofy: addi sp, sp, -4 stw fp, 0(sp) mov fp, sp movhi r3, %hiadj(mydata) addi r3, r3, %lo(mydata) movhi r2, %hiadj(mydata) addi r2, r2, %lo(mydata) ldw r2, 0(r2) addi r2, r2, 1 stw r2, 0(r3) ldw fp, 0(sp) addi sp, sp, 4 ret .size goofy, .-goofy .align 2 .global mickey .type mickey, @function mickey: addi sp, sp, -4 stw fp, 0(sp) mov fp, sp ldw r2, %gprel(mydata)(gp) addi r2, r2, 1 stw r2, %gprel(mydata)(gp) ldw fp, 0(sp) addi sp, sp, 4 ret .size mickey, .-mickey .global mydata .section .sdata,"aws",@progbits .align 2 .type mydata, @object .size mydata, 4 mydata: .zero 4 .section .debug_frame,"",@progbits[/b] --- Quote End --- That is, - goofy IS NOT using GP-relative addressing - mickey IS using GP-relative addressing - the compiler does not complain about the mismatch of the sections! What I would like to have is: - the possibility to DEFINE a data structure putting it in some section (as it is now) - the possibility to DECLARE a data structure without saying in which section it will be allocated, but just saying "hey, I want to disable GP-addressing" Questions: 1- is it possible to DECLARE a data structure without saying in which section it will be allocated, but just saying "hey, I want to disable GP-addressing"? 2- Why the compiler do not give a warning about the conflicting sections? 3- it seems that generating GP-relative code is related ONLY to the section where the compiler HOPES the variable will be allocated to. So in some sense having __attribute__ ((section (".data"))) after a data declaration is a sufficent answer to question 1? ok, that's all for now, Paolo