• AVR Freaks

Hot!Variable location conflict: address() attribute vs small data section (-G num)

Author
ThierryV
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2014/11/27 01:18:29
  • Location: 0
  • Status: offline
2020/05/26 00:23:12 (permalink)
0

Variable location conflict: address() attribute vs small data section (-G num)

Hello,
 
I need to locate a variable at a specific address in RAM:
unsigned long __attribute__((far,address(0xA001FFFC),persistent)) MyVar;

 
But the linker fails with this error:
xc32-ld.exe: small-data section exceeds 64KB; lower small-data size limit (see option -G)
build/Release/production/_ext/761766712/main.o: In function `Init':
.../c/main/main.c:92:(.text+0x44): relocation truncated to fit: R_MIPS_GPREL16 against `MyVar'
collect2.exe: error: ld returned 255 exit status
make[2]: *** [nbproject/Makefile-Release.mk:1443: dist/Release/production/8619_Processing.X.production.hex] Error 255
make[1]: *** [nbproject/Makefile-Release.mk:105: .build-conf] Error 2
make: *** [nbproject/Makefile-impl.mk:39: .build-impl] Error 2

BUILD FAILED (exit value 2, total time: 44s)

 
 
It seems that the linker would like to place my variable inside the small data section, despite my 'far' attribute.
 
How to solve that conflict?
#1

6 Replies Related Threads

    ThierryV
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2014/11/27 01:18:29
    • Location: 0
    • Status: offline
    Re: Variable location conflict: address() attribute vs small data section (-G num) 2020/05/26 00:35:43 (permalink)
    0
    I alos try with a specific section, according to this FAQ:
    https://microchipdeveloper.com/faq:3434
    unsigned long __attribute__((far,section("mysection"),address(0xA001FFF0),persistent)) MyVar;

     
    Same issue.
    #2
    ThierryV
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2014/11/27 01:18:29
    • Location: 0
    • Status: offline
    Re: Variable location conflict: address() attribute vs small data section (-G num) 2020/05/26 02:44:05 (permalink)
    0
    I defined this variable in one .c file (along with anothers global variables with specific address) and I use it in another .c file.
     
    Finaly, it works if I define this variable in the .c file where I use it.
     
    Do you uderstand the reason?
     
    What happens if I need to access that variable in a second .c file?
    #3
    ric
    Super Member
    • Total Posts : 28324
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Variable location conflict: address() attribute vs small data section (-G num) 2020/05/26 02:45:51 (permalink)
    0
    ThierryV
    I defined this variable in one .c file (along with anothers global variables with specific address) and I use it in another .c file.
     
    Finaly, it works if I define this variable in the .c file where I use it.
     
    Do you uderstand the reason?
     
    What happens if I need to access that variable in a second .c file?


    You have to declare the variable in a header file that both C files #include.
    This is the standard way that all variables are shared in C.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    ThierryV
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2014/11/27 01:18:29
    • Location: 0
    • Status: offline
    Re: Variable location conflict: address() attribute vs small data section (-G num) 2020/05/26 03:48:37 (permalink)
    0
    ric
    You have to declare the variable in a header file that both C files #include.
    This is the standard way that all variables are shared in C.

     
    Okay, I have to repeat the attributes in the header file.
     
    Originally, I had:
     
    A.c:
    unsigned long __attribute__((far,section("mysection"),address(0xA001FFF0),persistent)) MyVar;

    A.h:
    extern unsigned long MyVar;

    B.c:
    if( MyVar > ... )
    {
        ...
    }

     
    With this header, it's OK:
    A.h
    extern unsigned long __attribute__((far,section("mysection"),address(0xA001FFF0),persistent)) MyVar;

    (I thought the attributes were only part of the definition, such as assigning a value...)
    post edited by ThierryV - 2020/05/26 03:56:36
    #5
    ric
    Super Member
    • Total Posts : 28324
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Variable location conflict: address() attribute vs small data section (-G num) 2020/05/26 04:01:27 (permalink)
    +2 (2)
    ThierryV
    (I thought the attributes were only part of the declaration, such as assigning a value...)

    No, the whole point of having a common declaration is so that all the C files can see all the same attributes.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    moser
    Super Member
    • Total Posts : 587
    • Reward points : 0
    • Joined: 2015/06/16 02:53:47
    • Location: Germany
    • Status: offline
    Re: Variable location conflict: address() attribute vs small data section (-G num) 2020/06/08 04:57:16 (permalink)
    0
    Attributes can affect how the variable needs to get accessed. And if another compile unit (C file) is accessing that variable, it needs to know how to do that, and it only has the declaration to get that information. And of course everywhere you should have the same information.
     
    The easy way is to copy the whole variable definition from the .c file (except initialization of course), add an "extern" in front, and that's the declaration for your .h file. Simple and safe.
     
    Also it helps to place a comment next to the definition, which tells you this is an extern used variable. In case you change it later, it is less likely that you forget to change the declaration accordingly.
    #7
    Jump to:
    © 2020 APG vNext Commercial Version 4.5