[arm-gnu] Static template member in assigned section -- section type conflict

Gene Smith gds at chartertn.net
Tue Jan 31 02:35:50 UTC 2012


On 01/30/2012 09:54 AM, Carlos O'Donell wrote:
> On 1/28/2012 3:01 PM, Gene Smith wrote:
>> Program output:
>> $ ./a.out
>> 0x600c70&priv<---in .mysect
>> 0x600da0&priv.a<---in .bss
>> 0x600c6c&priv.b<---in .mysect
>> 0x600c70&priv.c[0]<---in .mysect
>>
>> Exactly what I want!
>
> Does `static' still work correctly?
>
> Cheers,
> Carlos.

Seems to. I defined a non-static variable "local" like this:

// main.cpp
#include <iostream>
using namespace std;
#include "temp.h"

int main (void)
{
     static outer<int,int> priv __attribute__((section(".mysect")));  // 
li:31

     priv.a = 10;
     priv.b = 10;

     priv.c[0] = 144;
     priv.c[1] = 145;
     priv.c[2] = 146;

     cout << &priv << " &priv\n";
     cout << &priv.a << " &priv.a\n";
     cout << &priv.b << " &priv.b\n";
     cout << &priv.c[0] << " &priv.c[0]\n";

     outer<int,int> local;
     local.a = 10;
     local.b = 10;

     local.c[0] = 144;
     local.c[1] = 145;
     local.c[2] = 146;

     cout << &local << " &local\n";
     cout << &local.a << " &local.a\n";
     cout << &local.b << " &local.b\n";
     cout << &local.c[0] << " &local.c[0]\n";
}

Statics print the same address but containing object and non-static element
c[] differs:

$ ./a.out
0x600d40 &priv
0x600e80 &priv.a	<-- static
0x600d3c &priv.b	<---static
0x600d40 &priv.c[0]
0x7fff96482990 &local
0x600e80 &local.a	<---static (still .bss)
0x600d3c &local.b	<---static (still .mysect)
0x7fff96482990 &local.c[0]




More information about the arm-gnu mailing list